/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --c-bg:        #f0f4f8;
  --c-surface:   #ffffff;
  --c-border:    #d1d9e0;
  --c-text:      #1e293b;
  --c-muted:     #64748b;
  --c-primary:   #4f46e5;
  --c-primary-h: #3730a3;
  --c-success:   #059669;
  --c-danger:    #dc2626;
  --c-warn:      #d97706;
  --c-due:       #7c3aed;
  --radius:      10px;
  --shadow:      0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.12);
  --nav-h:       56px;
  --transition:  .2s ease;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  padding-bottom: 72px; /* mobile nav */
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
[x-cloak] { display: none !important; }

/* ── Typography ────────────────────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.25rem; font-weight: 600; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; font-weight: 600; }
p  { margin-bottom: .5rem; }
.text-muted  { color: var(--c-muted); font-size: .875rem; }
.text-success { color: var(--c-success); }
.text-danger  { color: var(--c-danger); }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.main-content {
  max-width: 860px;
  margin: 0 auto;
  padding: calc(var(--nav-h) + 1.5rem) 1rem 2rem;
}

/* ── Top bar ───────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center;
  padding: 0 1.25rem;
  gap: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-logo { font-size: 1.25rem; font-weight: 800; color: var(--c-primary); letter-spacing: -.02em; }
.topbar-nav  { display: flex; gap: 1rem; margin-left: auto; }
.topbar-nav a { font-size: .9rem; color: var(--c-muted); font-weight: 500; }
.topbar-nav a:hover { color: var(--c-text); text-decoration: none; }
.topbar-logout { color: var(--c-danger) !important; }
.topbar-menu-btn { display: none; background: none; border: none; font-size: 1.25rem; cursor: pointer; margin-left: auto; }

/* ── Mobile nav ────────────────────────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: 64px;
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  flex-direction: row;
}
.mobile-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .65rem; color: var(--c-muted); gap: 2px; text-decoration: none; padding: .5rem;
}
.mobile-nav a span { font-size: .65rem; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .5rem 1.1rem; border-radius: var(--radius);
  font-size: .9rem; font-weight: 500; cursor: pointer;
  border: 1.5px solid transparent; transition: background var(--transition), border-color var(--transition);
  text-decoration: none; white-space: nowrap;
}
.btn-primary  { background: var(--c-primary);  color: #fff; }
.btn-primary:hover  { background: var(--c-primary-h); color: #fff; text-decoration: none; }
.btn-success  { background: var(--c-success);  color: #fff; }
.btn-success:hover  { background: #047857; color: #fff; text-decoration: none; }
.btn-danger   { background: var(--c-danger);   color: #fff; }
.btn-danger:hover   { background: #b91c1c; color: #fff; text-decoration: none; }
.btn-ghost    { background: transparent; border-color: var(--c-border); color: var(--c-text); }
.btn-ghost:hover    { background: var(--c-bg); text-decoration: none; }
.btn-lg { padding: .7rem 1.5rem; font-size: 1.05rem; }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }
.btn-xs { padding: .2rem .6rem; font-size: .75rem; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1rem; color: var(--c-muted); width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.btn-icon:hover { background: var(--c-bg); }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-ok    { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #7f1d1d; border: 1px solid #fecaca; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-box    { background: var(--c-surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); max-width: 560px; }
.form-group  { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-control {
  width: 100%; padding: .5rem .75rem; border: 1.5px solid var(--c-border);
  border-radius: 6px; font-size: .9rem; background: var(--c-bg); color: var(--c-text);
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--c-primary); background: #fff; }
.form-control-lg    { padding: .75rem 1rem; font-size: 1.05rem; }
.form-control-sm    { padding: .35rem .6rem; font-size: .85rem; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }
.required { color: var(--c-danger); }
.field-hint { font-size: .8rem; color: var(--c-muted); margin-top: .25rem; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-size: .9rem; cursor: pointer; }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-header h1 { margin: 0; }
.page-header-actions { display: flex; gap: .5rem; flex-shrink: 0; margin-top: .25rem; }
.breadcrumb { font-size: .8rem; color: var(--c-muted); margin-bottom: .25rem; }
.breadcrumb a { color: var(--c-muted); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin: 1.5rem 0 .75rem; }
.section-header h2 { margin: 0; }
.see-all { text-align: right; font-size: .875rem; margin-top: .5rem; }

/* ── Hero ──────────────────────────────────────────────────────────────────── */
.hero { text-align: center; padding: 4rem 1rem 3rem; }
.hero-title { font-size: 3rem; font-weight: 900; color: var(--c-primary); letter-spacing: -.04em; margin-bottom: .5rem; }
.hero-sub   { font-size: 1.2rem; color: var(--c-muted); margin-bottom: 2rem; }
.hero-form  { margin-bottom: 1rem; }
.hero-note  { font-size: .85rem; color: var(--c-muted); }
.features   { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-top: 2rem; }
.feature-card { background: var(--c-surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); text-align: center; }
.feature-icon { font-size: 2rem; margin-bottom: .5rem; }

/* ── Stats row ─────────────────────────────────────────────────────────────── */
.stats-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat-card {
  background: var(--c-surface); border-radius: var(--radius); padding: 1rem 1.25rem;
  box-shadow: var(--shadow); flex: 1; min-width: 100px; text-align: center;
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--c-muted); margin-top: .2rem; }

/* ── XP bar ────────────────────────────────────────────────────────────────── */
.xp-bar-wrap { height: 8px; background: var(--c-border); border-radius: 99px; overflow: hidden; margin: .5rem 0 .25rem; }
.xp-bar      { height: 100%; background: var(--c-primary); border-radius: 99px; transition: width .5s; }
.xp-label    { font-size: .8rem; color: var(--c-muted); }

/* ── List grid ─────────────────────────────────────────────────────────────── */
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.list-card {
  background: var(--c-surface); border-radius: var(--radius); padding: 1.1rem;
  box-shadow: var(--shadow); text-decoration: none; color: inherit;
  border: 1.5px solid transparent; transition: border-color var(--transition), box-shadow var(--transition);
  display: flex; flex-direction: column; gap: .35rem;
}
.list-card:hover { border-color: var(--c-primary); box-shadow: var(--shadow-lg); text-decoration: none; }
.list-card.has-due { border-color: var(--c-due); }
.list-card-header  { display: flex; justify-content: space-between; align-items: center; }
.list-card-lang    { font-size: .75rem; color: var(--c-muted); }
.list-card-name    { font-weight: 600; font-size: 1rem; }
.list-card-count   { font-size: .8rem; color: var(--c-muted); }
.due-badge         { background: var(--c-due); color: #fff; border-radius: 99px; font-size: .7rem; padding: .1rem .5rem; font-weight: 600; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.card-table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: .5rem; }
.card-table th, .card-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--c-border); text-align: left; }
.card-table th  { font-size: .8rem; color: var(--c-muted); font-weight: 600; background: var(--c-bg); }
.card-table tr:hover td { background: #f8fafc; }
.card-table .col-box     { width: 56px; text-align: center; }
.card-table .col-actions { width: 140px; text-align: right; white-space: nowrap; }
.card-example { font-size: .8rem; color: var(--c-muted); margin-top: .15rem; font-style: italic; }
.card-note    { font-size: .8rem; color: var(--c-warn); margin-top: .1rem; }
.row-correct td { background: #f0fdf4 !important; }
.row-incorrect td { background: #fef2f2 !important; }

/* ── Box badges ────────────────────────────────────────────────────────────── */
.box-badge { display: inline-block; width: 24px; height: 24px; border-radius: 50%; font-size: .75rem; font-weight: 700; text-align: center; line-height: 24px; }
.box-1 { background: #fee2e2; color: #7f1d1d; }
.box-2 { background: #fef3c7; color: #78350f; }
.box-3 { background: #dbeafe; color: #1e3a5f; }
.box-4 { background: #ede9fe; color: #3b0764; }
.box-5, .box-6, .box-7, .box-8 { background: #d1fae5; color: #065f46; }

/* ── Add card / import ─────────────────────────────────────────────────────── */
.add-card-box { background: var(--c-surface); border-radius: var(--radius); border: 1px solid var(--c-border); margin-bottom: 1rem; }
.add-card-box summary { padding: .75rem 1rem; cursor: pointer; font-weight: 500; list-style: none; font-size: .9rem; color: var(--c-primary); }
.add-card-box summary::marker, .add-card-box summary::-webkit-details-marker { display: none; }
.add-card-form, .import-form { padding: 0 1rem 1rem; }
.card-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: .5rem; }
.import-row    { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.danger-zone   { margin-top: 2rem; }
.danger-zone summary { padding: .5rem 0; cursor: pointer; list-style: none; }
.danger-actions { display: flex; gap: 1rem; margin-top: .75rem; align-items: flex-start; flex-wrap: wrap; }
.inline-rename, .inline-edit-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* ── Auth ──────────────────────────────────────────────────────────────────── */
.auth-box { max-width: 380px; margin: 3rem auto; background: var(--c-surface); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow-lg); }
.auth-box h1 { margin-bottom: .5rem; }

/* ── Study Setup ───────────────────────────────────────────────────────────── */
.setup-box  { max-width: 580px; background: var(--c-surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.setup-info { font-size: .9rem; color: var(--c-muted); margin-bottom: 1.25rem; }
.setup-form { display: flex; flex-direction: column; gap: 1rem; }
.setup-fieldset { border: none; padding: 0; }
.setup-fieldset legend { font-size: .85rem; font-weight: 600; color: var(--c-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .5rem; }
.radio-card { display: flex; cursor: pointer; }
.radio-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.radio-card-body { flex: 1; padding: .6rem .9rem; border-radius: 7px; border: 1.5px solid var(--c-border); margin-bottom: .35rem; }
.radio-card-body strong { display: block; }
.radio-card-body span  { font-size: .8rem; color: var(--c-muted); }
.radio-card input:checked + .radio-card-body { border-color: var(--c-primary); background: #eef2ff; }
.setup-hint { font-size: .8rem; color: var(--c-muted); margin-top: 1rem; }
kbd { display: inline-block; padding: .1em .4em; border-radius: 4px; border: 1px solid #c0c0c0; background: #f5f5f5; font-size: .8em; font-family: monospace; }

/* ── Flashcard ─────────────────────────────────────────────────────────────── */
.session-wrap   { max-width: 640px; margin: 0 auto; }
.session-progress { height: 6px; background: var(--c-border); border-radius: 99px; overflow: hidden; margin-bottom: .5rem; }
.session-progress-bar { height: 100%; background: var(--c-primary); border-radius: 99px; transition: width .4s; }
.session-meta { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; color: var(--c-muted); margin-bottom: 1.5rem; }

.flashcard-area   { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; }
.flashcard-wrapper { width: 100%; max-width: 520px; height: 280px; perspective: 1000px; cursor: pointer; }
.flashcard { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.4,0,.2,1); }
.flashcard.is-flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; width: 100%; height: 100%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 14px; background: var(--c-surface); box-shadow: var(--shadow-lg);
  padding: 2rem; text-align: center; gap: .75rem;
}
.flashcard-back { transform: rotateY(180deg); }
.card-word  { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.card-lang  { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--c-muted); }
.flip-hint  { font-size: .8rem; color: var(--c-muted); margin-top: .5rem; }
.flashcard-actions { display: flex; gap: 1.5rem; align-items: center; justify-content: center; flex-wrap: wrap; }
.box-display { font-size: .85rem; color: var(--c-muted); }

/* ── Typing / Cloze ────────────────────────────────────────────────────────── */
.typing-area { display: flex; flex-direction: column; gap: 1.25rem; }
.typing-question { background: var(--c-surface); border-radius: 14px; padding: 2rem; text-align: center; box-shadow: var(--shadow-lg); min-height: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; }
.cloze-context  { font-size: .85rem; color: var(--c-muted); text-align: center; font-style: italic; margin-bottom: -.5rem; }
.cloze-sentence { background: var(--c-surface); border-radius: 14px; padding: 1.75rem; font-size: 1.2rem; line-height: 1.8; box-shadow: var(--shadow-lg); }
.typing-input-wrap { display: flex; flex-direction: column; gap: .75rem; }
.input-row { display: flex; gap: .5rem; }
.input-row .form-control { flex: 1; }
.input-retry { border-color: var(--c-warn) !important; background: #fffbeb !important; }

/* ── Feedback ──────────────────────────────────────────────────────────────── */
.feedback { padding: 1rem 1.25rem; border-radius: var(--radius); display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.feedback-correct  { background: #d1fae5; color: #065f46; }
.feedback-incorrect { background: #fee2e2; color: #7f1d1d; flex-direction: column; align-items: flex-start; }
.feedback-icon { font-size: 1.5rem; }
.feedback-solution { font-size: 1rem; }
.typo-note { font-size: .8rem; background: rgba(0,0,0,.08); padding: .1rem .4rem; border-radius: 4px; }

/* ── Diff display ──────────────────────────────────────────────────────────── */
.diff-display { background: #fff8e1; border: 1px solid #fde68a; border-radius: 7px; padding: .75rem 1rem; }
.diff-label   { font-size: .8rem; color: var(--c-muted); display: block; margin-bottom: .25rem; }
.diff-expected { font-size: .85rem; margin-top: .35rem; color: var(--c-muted); }
.diff-ok  { background: #bbf7d0; border-radius: 2px; padding: 0 1px; }
.diff-err { background: #fecaca; border-radius: 2px; padding: 0 1px; text-decoration: underline; }
.diff-missing { color: #94a3b8; }

/* ── Session done ──────────────────────────────────────────────────────────── */
.session-done { text-align: center; padding: 3rem 1rem; }
.done-icon { font-size: 3rem; margin-bottom: 1rem; }

/* ── Summary ───────────────────────────────────────────────────────────────── */
.summary-box  { background: var(--c-surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.summary-score { text-align: center; margin-bottom: 1rem; }
.summary-pct  { font-size: 3rem; font-weight: 800; color: var(--c-primary); }
.summary-sub  { color: var(--c-muted); font-size: .9rem; }
.summary-actions { display: flex; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }

/* ── Stats activity ────────────────────────────────────────────────────────── */
.activity-grid { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 1rem; }
.activity-cell { width: 14px; height: 14px; border-radius: 3px; background: var(--c-border); }
.activity-cell.level-1 { background: #a7f3d0; }
.activity-cell.level-2 { background: #34d399; }
.activity-cell.level-3 { background: #059669; }

/* ── Personal link ─────────────────────────────────────────────────────────── */
.personal-link { display: block; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 6px; padding: .6rem .9rem; font-size: .85rem; word-break: break-all; margin: .5rem 0; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--c-surface); border-radius: var(--radius); padding: 1.5rem 2rem; box-shadow: var(--shadow-lg); max-width: 380px; width: 90%; }
.modal h2 { margin-bottom: 1rem; }
.key-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.key-table td { padding: .4rem .5rem; border-bottom: 1px solid var(--c-border); font-size: .9rem; }
.key-table td:first-child { width: 40%; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--c-muted); }
.empty-state p { margin-bottom: 1rem; }

/* ── Error page ────────────────────────────────────────────────────────────── */
.error-page { text-align: center; padding: 4rem 1rem; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .topbar-nav { display: none; }
  .topbar-menu-btn { display: flex; }
  .mobile-nav { display: flex; }
  body { padding-bottom: 80px; }
  .main-content { padding-top: calc(var(--nav-h) + 1rem); }

  .flashcard-wrapper { height: 220px; }
  .card-word { font-size: 1.4rem; }
  .form-row, .card-form-row { grid-template-columns: 1fr; }
  .flashcard-actions { gap: .75rem; }
  .btn-lg { padding: .6rem 1.1rem; font-size: .95rem; }
  .stats-row { gap: .5rem; }
  .stat-card { min-width: 80px; }
}

@media (max-width: 400px) {
  .card-word { font-size: 1.2rem; }
  .features  { grid-template-columns: 1fr; }
}
