:root {
  --bg: #f6f5f0;
  --surface: #ffffff;
  --surface-muted: #f1efe9;
  --text: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #8a837b;
  --border: #e5e1d8;
  --primary: #1e293b;
  --primary-hover: #0f172a;
  --accent: #2563eb;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #059669;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(28, 25, 23, 0.06);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
}

.app-shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 18px 96px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: 20px;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

/* Navigation */
.nav-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  padding: 5px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Stats strip */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.stat-value.warn {
  color: var(--danger);
}

/* Flashcard */
.card-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
  min-height: 360px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-muted);
  color: var(--text-secondary);
}

.badge.writing {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge.weak {
  background: #fef2f2;
  color: #b91c1c;
}

.badge.mastered {
  background: #ecfdf5;
  color: #047857;
}

.card-main {
  text-align: center;
  padding: 28px 8px 20px;
}

.expression-row {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.expression-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  line-height: 1.25;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.hint-box {
  margin: 18px auto 0;
  max-width: 640px;
  padding: 12px 16px;
  background: var(--surface-muted);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 15px;
  text-align: left;
}

.answer-section {
  border-top: 1px dashed var(--border);
  margin-top: 20px;
  padding-top: 20px;
  text-align: left;
}

.answer-block {
  margin-bottom: 14px;
}

.answer-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.answer-meaning {
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
}

.answer-text {
  font-size: 15px;
  color: var(--text-secondary);
}

/* Rating Buttons */
.action-area {
  margin-top: 22px;
}

.reveal-btn {
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

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

.choice-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.choice-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.choice-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 15px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.choice-btn:active {
  transform: scale(0.97);
}

.choice-btn strong {
  font-size: 16px;
}

.choice-btn span {
  font-size: 12px;
  opacity: 0.85;
}

.choice-btn.known { border-color: #a7f3d0; background: #ecfdf5; color: #047857; }
.choice-btn.fuzzy { border-color: #fde68a; background: #fffbeb; color: #b45309; }
.choice-btn.unknown { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.choice-btn.recalled { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }

.choice-btn:hover {
  filter: brightness(0.96);
}

.cue-card {
  margin: 20px auto 0;
  max-width: 660px;
  padding: 16px 18px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 14px;
  text-align: left;
}

.cue-title {
  font-size: 12px;
  font-weight: 700;
  color: #b45309;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cue-sentence {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  color: var(--text);
  line-height: 1.65;
}

.cue-sentence mark {
  background: #fef08a;
  color: inherit;
  padding: 0 4px;
  border-radius: 4px;
}

.verdict-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  font-size: 13px;
  background: var(--surface-muted);
  color: var(--text-secondary);
}

.verdict-bar.v1 { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.verdict-bar.v2 { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.verdict-bar.v3 { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.verdict-bar.v4 { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

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

.verify-actions .reveal-btn {
  flex: 1;
}

/* Panels & Lists */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.input, .select, .textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
}

.input.grow {
  flex: 1;
  min-width: 180px;
}

.textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.danger {
  color: var(--danger);
  border-color: #fecaca;
}

.btn.sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* List items */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  background: #fff;
}

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

.item-title {
  font-size: 17px;
  font-weight: 700;
  font-family: Georgia, serif;
}

.item-sub {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.item-context {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  place-items: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop.open {
  display: grid;
}

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.modal h3 {
  margin: 0 0 14px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
}

.hidden {
  display: none !important;
}

/* Responsive for iPad & Mobile */
@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .nav-tabs {
    position: fixed;
    bottom: 12px;
    left: 12px;
    right: 12px;
    z-index: 50;
    justify-content: space-around;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
  }
  .nav-btn {
    flex: 1;
    text-align: center;
    padding: 10px 6px;
    font-size: 13px;
  }
  .expression-text {
    font-size: 28px;
  }
  .choice-grid-3 {
    grid-template-columns: 1fr;
  }
  .verify-actions {
    flex-direction: column-reverse;
  }
}
