:root {
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --color-primary: #0052cc;
  --color-primary-hover: #003e99;
  --color-primary-light: #e6f0ff;
  --color-secondary: #475569;
  --color-secondary-hover: #334155;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text-main: #0f172a;
  --color-text-muted: #64748b;
  --color-success: #16a34a;
  --color-success-hover: #15803d;
  --color-success-light: #f0fdf4;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-danger-light: #fef2f2;
  --color-warning: #ea580c;
  --color-accent: #0284c7;

  --box-1-color: #ef4444;
  --box-2-color: #f97316;
  --box-3-color: #eab308;
  --box-4-color: #3b82f6;
  --box-5-color: #10b981;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

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

body {
  font-family: var(--font-main);
  background-color: var(--color-bg);
  color: var(--color-text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--color-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.flag-icon {
  font-size: 2.2rem;
  line-height: 1;
}

.brand h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--color-primary);
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.nav-tabs {
  display: flex;
  gap: 8px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: var(--radius-md);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-tab:hover {
  color: var(--color-text-main);
}

.nav-tab.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.stat-card.highlight {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.stat-card.highlight .stat-value {
  color: var(--color-primary);
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--color-text-muted);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-main);
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-success {
  background: var(--color-success);
  color: white;
}
.btn-success:hover {
  background: var(--color-success-hover);
}

.btn-danger {
  background: var(--color-danger);
  color: white;
}
.btn-danger:hover {
  background: var(--color-danger-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
}

.btn-icon-sm {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 2px 4px;
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

.study-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 680px;
  margin: 0 auto;
}

.session-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.session-progress {
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.box-badge {
  background: var(--color-primary);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.flashcard-scene {
  width: 100%;
  min-height: 380px;
  height: auto;
  perspective: 1200px;
  cursor: pointer;
}

.flashcard-flipper {
  width: 100%;
  min-height: 380px;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-columns: 1fr;
}

.flashcard-flipper.flipped {
  transform: rotateY(180deg);
}

.card-face {
  grid-area: 1 / 1;
  width: 100%;
  min-height: 380px;
  box-sizing: border-box;
  backface-visibility: hidden;
  border-radius: var(--radius-xl);
  padding: 28px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  overflow-y: auto;
  max-height: 70vh;
}

.card-back {
  transform: rotateY(180deg);
  background: #fafcff;
}

.card-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.word-type-tag {
  background: var(--color-primary-light);
  color: var(--color-primary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.card-center {
  text-align: center;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.card-prompt {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--color-primary);
  letter-spacing: -0.02em;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  transition: font-size 0.2s ease;
}

.card-prompt.long-text {
  font-size: 1.8rem;
}

.card-prompt.very-long-text {
  font-size: 1.4rem;
}

.card-answer {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--color-text-main);
  letter-spacing: -0.02em;
  line-height: 1.3;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  transition: font-size 0.2s ease;
}

.card-answer.long-text {
  font-size: 1.5rem;
}

.card-answer.very-long-text {
  font-size: 1.2rem;
}

.phonetic-hint {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--color-text-muted);
  margin-top: 6px;
}

.example-box, .grammar-box {
  background: #f8fafc;
  border: 1px solid var(--color-border);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  text-align: left;
}

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

.example-label, .grammar-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.example-text {
  font-size: 0.95rem;
  color: var(--color-text-main);
}

.example-translation {
  font-size: 1rem;
  color: var(--color-text-muted);
  font-style: italic;
  margin-top: 8px;
}

.grammar-text {
  font-size: 0.85rem;
  color: #334155;
  margin-top: 4px;
}

.card-hint-footer {
  text-align: center;
}

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

kbd {
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  border: 1px solid #cbd5e1;
}

.box-transition-preview {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
  padding-top: 8px;
}

.trans-demote {
  color: var(--color-danger);
}

.trans-promote {
  color: var(--color-success);
}

.review-controls {
  display: flex;
  gap: 16px;
  margin-top: 24px;
  width: 100%;
}

.review-controls .btn {
  flex: 1;
  padding: 14px 20px;
  font-size: 1rem;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  max-width: 600px;
  margin: 20px auto;
}

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

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

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

.empty-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.typing-container {
  max-width: 640px;
  margin: 0 auto;
}

.typing-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

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

.typing-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-primary-light);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.typing-prompt-area {
  text-align: center;
  margin-bottom: 24px;
}

.typing-prompt-label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.typing-english-prompt {
  font-size: 2rem;
  font-weight: 800;
  color: var(--color-text-main);
  margin: 8px 0;
}

.typing-hint-sentence {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 0.95rem;
}

.diacritic-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.diacritic-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.btn-diacritic {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: #f1f5f9;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-diacritic:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.input-with-button {
  display: flex;
  gap: 8px;
  width: 100%;
}

.typing-input {
  flex: 1;
  padding: 14px 18px;
  font-size: 1.1rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  outline: none;
  transition: border-color 0.2s;
  font-family: var(--font-main);
}

.typing-input:focus {
  border-color: var(--color-primary);
}

.typing-feedback {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.typing-feedback.correct {
  background: var(--color-success-light);
  border: 1px solid var(--color-success);
}

.typing-feedback.incorrect {
  background: var(--color-danger-light);
  border: 1px solid var(--color-danger);
}

.feedback-status {
  font-weight: 700;
  font-size: 1.1rem;
}

.feedback-details {
  font-size: 0.95rem;
}

.feedback-audio {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.boxes-header {
  margin-bottom: 24px;
  text-align: center;
  max-width: 640px;
  margin: 0 auto 32px auto;
}

.boxes-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
}

.boxes-header p {
  color: var(--color-text-muted);
  margin-top: 6px;
}

.boxes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.box-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.box-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.box-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
}

.box-card.box-1::before { background: var(--box-1-color); }
.box-card.box-2::before { background: var(--box-2-color); }
.box-card.box-3::before { background: var(--box-3-color); }
.box-card.box-4::before { background: var(--box-4-color); }
.box-card.box-5::before { background: var(--box-5-color); }

.box-card-num {
  font-size: 1.1rem;
  font-weight: 800;
}

.box-card-interval {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: 16px;
}

.box-card-counts {
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  padding: 12px 0;
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
}

.box-count-val {
  font-weight: 700;
  font-size: 1.2rem;
}

.box-card-btn {
  margin-top: 12px;
  width: 100%;
}

.manager-toolbar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.search-wrap {
  flex: 1;
  min-width: 250px;
}

.search-input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-family: var(--font-main);
}

.filter-wrap {
  display: flex;
  gap: 12px;
}

.select-filter {
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-family: var(--font-main);
  background: white;
}

.table-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.cards-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.cards-table th {
  background: #f8fafc;
  padding: 14px 16px;
  font-weight: 700;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

.cards-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.cards-table tr:last-child td {
  border-bottom: none;
}

.cards-table tr:hover {
  background: #fafcff;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-dialog {
  background: var(--color-surface);
  width: 100%;
  max-width: 580px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border);
}

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

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
}

.modal-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-group.half {
  flex: 1;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-main);
}

.form-group input, .form-group textarea, .form-group select {
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-family: var(--font-main);
}

.form-checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .nav-tabs {
    width: 100%;
    overflow-x: auto;
  }
  .flashcard-scene {
    min-height: 380px;
    height: auto;
  }
  .card-prompt {
    font-size: 1.8rem;
  }
  .review-controls {
    flex-direction: column;
  }
}

/* --- Live Processing Console (Terminal) --- */
.console-wrapper {
  margin-top: 28px;
  margin-bottom: 24px;
}

.terminal-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.terminal-header {
  background: #1e293b;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #334155;
}

.terminal-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.terminal-controls .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot-red { background: #ef4444; }
.dot-yellow { background: #f59e0b; }
.dot-green { background: #22c55e; }

.terminal-title {
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 600;
  margin-left: 6px;
  letter-spacing: 0.5px;
}

.terminal-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-terminal-clear {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #cbd5e1;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-terminal-clear:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.terminal-status-badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-idle {
  background: #334155;
  color: #94a3b8;
}

.badge-busy {
  background: #0284c7;
  color: #ffffff;
}

.terminal-body {
  padding: 14px 18px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.6;
}

.log-line {
  margin-bottom: 4px;
  word-break: break-word;
}

.log-dim { color: #64748b; }
.log-info { color: #38bdf8; }
.log-success { color: #4ade80; }
.log-warning { color: #fbbf24; }
.log-error { color: #f87171; }

/* --- Google Authentication & Header Actions --- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 20px; /* Spacious breathing room between profile and + Add Card */
}

.auth-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-google:hover {
  background: #f9fafb;
  border-color: #9ca3af;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 4px 10px 4px 6px;
  border-radius: 30px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--color-border);
}

.user-details {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text);
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.btn-logout:hover {
  text-decoration: underline;
}