:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #131b2e;
  --bg-card: #1c2640;
  --bg-card-hover: #233052;
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.6);
  --card-radius: 16px;
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 270px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.logo-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 0 16px var(--accent-glow);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border-color: rgba(99, 102, 241, 0.3);
}

.nav-item svg {
  flex-shrink: 0;
}

.badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-main);
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.storage-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.storage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.storage-tag {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-success);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.7rem;
}

.actions-row {
  display: flex;
  gap: 8px;
}

.btn-secondary-sm, .upload-label {
  flex: 1;
  text-align: center;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-block;
}

.btn-secondary-sm:hover, .upload-label:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #1e1b4b1a, transparent 40%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(11, 15, 25, 0.7);
  backdrop-filter: blur(12px);
}

.stats-pills {
  display: flex;
  gap: 16px;
}

.pill {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.82rem;
  display: flex;
  gap: 8px;
  align-items: center;
}

.pill-label {
  color: var(--text-dim);
}

.pill-val {
  font-weight: 700;
  color: var(--text-main);
}

.text-warning { color: var(--accent-warning) !important; }
.text-success { color: var(--accent-success) !important; }
.text-danger { color: var(--accent-danger) !important; }

/* Buttons */
.btn-primary-sm {
  background: var(--accent-primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary-sm:hover {
  background: var(--accent-primary-hover);
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
  border: none;
  padding: 10px 22px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 10px 20px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

/* Tab Panes */
.tab-pane {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.tab-pane.active {
  display: block;
}

.pane-header {
  margin-bottom: 24px;
}

.pane-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.pane-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.flex-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
}

/* Search Box Area */
.search-box-wrapper {
  max-width: 760px;
  margin-bottom: 28px;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 8px 10px 8px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
  color: var(--text-dim);
  margin-right: 12px;
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 1.05rem;
  font-family: inherit;
}

.search-box input::placeholder {
  color: var(--text-dim);
}

.search-suggestions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.hint-title {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.chip-example {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-muted);
  padding: 3px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.chip-example:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border-color: rgba(99, 102, 241, 0.3);
}

/* Dictionary Result Card */
.dict-result-card {
  max-width: 760px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.dict-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  gap: 16px;
}

.dict-title-box {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.dict-word {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.1;
}

.dict-phonetic {
  color: #a5b4fc;
  font-size: 1rem;
  font-weight: 500;
}

.btn-audio {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #a5b4fc;
  cursor: pointer;
  transition: background 0.2s;
  vertical-align: middle;
  margin-left: 6px;
}

.btn-audio:hover {
  background: rgba(99, 102, 241, 0.3);
}

.dict-actions {
  display: flex;
  gap: 10px;
}

.dict-meanings {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.meaning-block {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border-color);
}

.part-of-speech {
  font-style: italic;
  color: #818cf8;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 10px;
  text-transform: capitalize;
}

.definitions-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-left: 20px;
}

.def-item {
  color: #e2e8f0;
  font-size: 0.95rem;
}

.def-example {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 4px;
  font-style: italic;
  display: block;
}

.synonyms-box {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.syn-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 700;
}

.syn-pill {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.78rem;
  color: #cbd5e1;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  width: 100%;
  max-width: 540px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: modalScale 0.2s ease-out;
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
}

.close-modal {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group label .req {
  color: var(--accent-danger);
}

.form-group input, .form-group textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus, .form-group textarea:focus {
  border-color: var(--border-focus);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* My Cards Grid */
.header-filters, .study-filters {
  display: flex;
  gap: 12px;
}

.filter-search, .filter-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px 14px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
}

.filter-select {
  cursor: pointer;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.card-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
}

.card-item:hover {
  transform: translateY(-3px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.4);
}

.card-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.category-tag {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
}

.status-badge.learning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-warning);
}

.status-badge.mastered {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-success);
}

.card-item-front {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 8px;
}

.card-item-back {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-item-example {
  background: rgba(0, 0, 0, 0.2);
  border-left: 2px solid #6366f1;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
  border-radius: 0 6px 6px 0;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.card-item-date {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.card-item-actions {
  display: flex;
  gap: 6px;
}

.action-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.action-icon-btn.delete:hover {
  color: var(--accent-danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  max-width: 440px;
  margin: 40px auto;
}

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 24px;
}

/* Study Revision View */
.study-viewport {
  max-width: 680px;
  margin: 10px auto 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.study-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-card);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #10b981);
  transition: width 0.3s ease;
}

.study-counter {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 16px;
}

/* 3D Flip Card Container */
.flip-card-wrapper {
  perspective: 1200px;
  width: 100%;
  height: 380px;
  cursor: pointer;
}

.flip-card {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flip-card.flipped {
  transform: rotateY(180deg);
}

.flip-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 20px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  user-select: none;
}

.flip-card-front {
  background: linear-gradient(145deg, #182238, #111728);
  border-color: rgba(99, 102, 241, 0.3);
}

.flip-card-back {
  background: linear-gradient(145deg, #1c2844, #141c30);
  border-color: rgba(16, 185, 129, 0.3);
  transform: rotateY(180deg);
}

.card-tag-badge {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #a5b4fc;
}

.card-center {
  text-align: center;
  margin: auto 0;
}

.word-text {
  font-family: var(--font-serif);
  font-size: 2.8rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.5px;
}

.pronounce-text {
  color: #818cf8;
  font-size: 1.1rem;
  margin-top: 8px;
  font-weight: 500;
}

.card-bottom-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.card-content-scroll {
  overflow-y: auto;
  max-height: 250px;
  padding-right: 6px;
  margin: auto 0;
}

.sub-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.definition-text {
  font-size: 1.15rem;
  line-height: 1.5;
  color: #f1f5f9;
  margin-bottom: 16px;
}

.example-quote {
  font-style: italic;
  color: #cbd5e1;
  background: rgba(0, 0, 0, 0.25);
  padding: 10px 14px;
  border-left: 3px solid var(--accent-success);
  border-radius: 0 8px 8px 0;
  font-size: 0.95rem;
}

/* Study Actions */
.study-actions {
  display: flex;
  gap: 16px;
  margin-top: 24px;
  width: 100%;
}

.btn-review-bad, .btn-review-okay, .btn-review-good {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-emoji {
  font-size: 1.2rem;
}

.btn-review-bad {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-review-bad:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-review-okay {
  background: rgba(245, 158, 11, 0.1);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

.btn-review-okay:hover {
  background: rgba(245, 158, 11, 0.25);
}

.btn-review-good {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
}

.btn-review-good:hover {
  background: rgba(16, 185, 129, 0.25);
}

/* Finish Screen */
.finish-screen {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 48px 32px;
  text-align: center;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.3s ease;
}

.celebration-emoji {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.finish-screen h2 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.finish-screen p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.finish-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 28px;
}

.f-stat {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.f-stat strong {
  display: block;
  font-size: 1.6rem;
  color: var(--text-main);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  border: 1px solid #475569;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 200;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Responsive */
@media (max-width: 840px) {
  .app-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    padding: 14px;
  }
  .sidebar-footer {
    display: none;
  }
  .nav-menu {
    flex-direction: row;
    margin-top: 12px;
  }
  .nav-item span:not(.badge) {
    display: none;
  }
  .tab-pane {
    padding: 18px;
  }
  .topbar {
    padding: 12px 18px;
  }
}
