/* ── Reset & custom props ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #1a1d27;
  --bg3:       #232635;
  --border:    #2e3248;
  --text:      #e2e4f0;
  --muted:     #7c82a3;
  --accent:    #7c8cf8;
  --accent2:   #a78bfa;
  --nom:       #60a5fa;
  --acc:       #f87171;
  --dat:       #4ade80;
  --gen:       #fbbf24;
  --correct:   #22c55e;
  --wrong:     #ef4444;
  --close:     #f59e0b;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);
  --font:      'Inter', system-ui, sans-serif;
  --mono:      'JetBrains Mono', 'Fira Code', monospace;
  --transition: .18s ease;
}

[data-theme="light"] {
  --bg:    #f4f5fb;
  --bg2:   #ffffff;
  --bg3:   #eaecf7;
  --border:#d0d4e8;
  --text:  #1a1d27;
  --muted: #6b7280;
  --accent:#4f5ef7;
  --accent2:#7c3aed;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  font-size: 15px;
}

/* ── Layout ─────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Nav ─────────────────────────────────────────────────────── */
nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  margin-right: auto;
  letter-spacing: -.01em;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .85rem;
  font-family: var(--font);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.nav-btn:hover  { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--bg3); color: var(--accent); font-weight: 600; }
.nav-btn .icon  { font-size: 1.1rem; }

#theme-toggle {
  margin-left: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  transition: color var(--transition);
}
#theme-toggle:hover { color: var(--text); }

/* ── Main content ─────────────────────────────────────────────── */
main { flex: 1; padding: 24px 16px; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ── Cards / panels ───────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ── Typography helpers ───────────────────────────────────────── */
.section-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 16px; }
.muted         { color: var(--muted); font-size: .85rem; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--bg3);
  color: var(--muted);
}
.badge.noun        { background:#1e3a5f; color:#60a5fa; }
.badge.verb        { background:#2d1e5f; color:#a78bfa; }
.badge.adjective   { background:#1e4d2e; color:#4ade80; }
.badge.adverb      { background:#3b2e1a; color:#fbbf24; }
.badge.conjunction { background:#3b1a1a; color:#f87171; }
.badge.preposition { background:#1a3b3b; color:#34d399; }
.badge.pronoun     { background:#2b2b1a; color:#fde68a; }
.badge.numeral     { background:#1a2b3b; color:#7dd3fc; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius);
  border: none; cursor: pointer; font-family: var(--font);
  font-size: .9rem; font-weight: 600;
  transition: opacity var(--transition), transform var(--transition);
}
.btn:hover  { opacity: .88; }
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-secondary{ background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-danger   { background: var(--wrong); color: #fff; }
.btn-success  { background: var(--correct); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }

/* ── Input / search ───────────────────────────────────────────── */
input[type="text"], input[type="search"], select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-family: var(--font);
  font-size: .9rem;
  outline: none;
  transition: border-color var(--transition);
}
input[type="text"]:focus,
input[type="search"]:focus,
select:focus { border-color: var(--accent); }
select option { background: var(--bg2); }

/* ── Special char keyboard ────────────────────────────────────── */
.char-keyboard {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0;
}
.char-key {
  padding: 5px 9px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: .95rem; font-family: var(--mono);
  color: var(--text); transition: background var(--transition);
}
.char-key:hover { background: var(--accent); color: #fff; }

/* ── Word Explorer ────────────────────────────────────────────── */
#explorer { display: flex; flex-direction: column; gap: 16px; }

.explorer-controls {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.explorer-controls input  { flex: 1; min-width: 160px; }
.explorer-controls select { min-width: 120px; }

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.word-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  position: relative;
}
.word-card:hover         { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.word-card.learned       { border-left: 3px solid var(--correct); }
.word-card .word-main    { font-size: 1.05rem; font-weight: 700; }
.word-card .word-english { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.word-card .word-meta    { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.word-card .learned-dot  {
  position: absolute; top: 12px; right: 12px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--correct);
}

/* ── Word Detail Modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 700px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  padding: 28px;
  animation: slideUp .2s ease;
  box-shadow: var(--shadow);
}
@keyframes slideUp { from { transform: translateY(20px); opacity:0; } to { transform: translateY(0); opacity:1; } }

.modal-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.modal-word   { font-size: 2rem; font-weight: 800; }
.modal-close  { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.4rem; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }

/* ── Declension table ─────────────────────────────────────────── */
.decl-table { width: 100%; border-collapse: collapse; font-size: .88rem; margin-top: 12px; }
.decl-table th, .decl-table td {
  padding: 8px 12px; border: 1px solid var(--border); text-align: left;
}
.decl-table th        { background: var(--bg3); font-weight: 600; color: var(--muted); }
.decl-table tr:nth-child(even) { background: var(--bg); }
.nom-cell  { color: var(--nom);  font-weight: 600; }
.acc-cell  { color: var(--acc);  font-weight: 600; }
.dat-cell  { color: var(--dat);  font-weight: 600; }
.gen-cell  { color: var(--gen);  font-weight: 600; }
.def-cell  { font-style: italic; opacity: .8; }

/* ── Flashcard Mode ───────────────────────────────────────────── */
#flashcard { display: flex; flex-direction: column; align-items: center; gap: 20px; }

.flashcard-area {
  perspective: 1000px; width: 100%; max-width: 520px; height: 280px;
  cursor: pointer;
}
.flashcard-inner {
  width: 100%; height: 100%; position: relative;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.4,0,.2,1);
}
.flashcard-area.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.flashcard-front { background: var(--bg2); }
.flashcard-back  { background: var(--bg3); transform: rotateY(180deg); }

.card-hint       { font-size: .8rem; color: var(--muted); margin-bottom: 12px; }
.card-question   { font-size: 1.6rem; font-weight: 700; }
.card-answer     { font-size: 2rem; font-weight: 800; color: var(--accent); }
.card-grammar    { font-size: .85rem; color: var(--muted); margin-top: 10px; }

.rating-row {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
}
.rating-btn {
  padding: 10px 22px; border-radius: var(--radius); border: none;
  cursor: pointer; font-family: var(--font); font-weight: 700; font-size: .9rem;
  transition: transform var(--transition), opacity var(--transition);
}
.rating-btn:hover { transform: translateY(-2px); }
.r-again { background:#4b1b1b; color: var(--wrong);   border:1px solid var(--wrong); }
.r-hard  { background:#3b2e1a; color: var(--close);   border:1px solid var(--close); }
.r-good  { background:#1e3a5f; color: var(--nom);     border:1px solid var(--nom); }
.r-easy  { background:#1e4d2e; color: var(--correct); border:1px solid var(--correct); }

.fc-progress { font-size: .85rem; color: var(--muted); }
.fc-status   { font-size: .8rem; color: var(--muted); }

/* ── Deep Drill ───────────────────────────────────────────────── */
#deepdrill { display: flex; flex-direction: column; gap: 16px; }

.drill-form-display {
  font-size: 1.1rem; color: var(--muted); font-family: var(--mono);
  margin-bottom: 6px;
}
.drill-question {
  font-size: 1.4rem; font-weight: 700; margin-bottom: 14px;
}
.drill-input-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.drill-input-row input { flex: 1; min-width: 180px; font-family: var(--mono); font-size: 1rem; }

.feedback-correct { color: var(--correct); font-weight: 700; font-size: 1.1rem; }
.feedback-close   { color: var(--close);   font-weight: 700; font-size: 1.1rem; }
.feedback-wrong   { color: var(--wrong);   font-weight: 700; font-size: 1.1rem; }

.drill-summary-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.drill-summary-table th, .drill-summary-table td {
  padding: 7px 12px; border: 1px solid var(--border);
}
.drill-summary-table th { background: var(--bg3); font-weight: 600; }
.status-correct { color: var(--correct); }
.status-close   { color: var(--close); }
.status-wrong   { color: var(--wrong); }

/* ── Quiz Mode ────────────────────────────────────────────────── */
#quiz { display: flex; flex-direction: column; gap: 16px; }

.quiz-header { display: flex; justify-content: space-between; align-items: center; }
.quiz-progress-bar {
  height: 4px; background: var(--bg3); border-radius: 2px; margin: 8px 0;
}
.quiz-progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width .3s ease;
}
.quiz-question { font-size: 1.25rem; font-weight: 700; margin-bottom: 16px; }
.quiz-options  { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quiz-option {
  padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg2);
  cursor: pointer; font-family: var(--font); font-size: .9rem;
  text-align: left; color: var(--text);
  transition: border-color var(--transition), background var(--transition);
}
.quiz-option:hover          { border-color: var(--accent); }
.quiz-option.correct-answer { background: #1e4d2e; border-color: var(--correct); color: var(--correct); }
.quiz-option.wrong-answer   { background: #4b1b1b; border-color: var(--wrong);   color: var(--wrong); }

.quiz-text-row { display: flex; gap: 8px; }
.quiz-text-row input { flex: 1; font-family: var(--mono); }
.quiz-feedback { font-size: 1rem; font-weight: 600; margin-top: 8px; }

.quiz-results { text-align: center; }
.quiz-score-big { font-size: 3rem; font-weight: 800; color: var(--accent); }
.quiz-review-list { text-align: left; margin-top: 16px; }
.quiz-review-item { border-bottom: 1px solid var(--border); padding: 10px 0; font-size: .9rem; }

/* ── Dashboard ────────────────────────────────────────────────── */
#dashboard { display: flex; flex-direction: column; gap: 20px; }
.stat-grid  { display: grid; grid-template-columns: repeat(auto-fill,minmax(160px,1fr)); gap: 12px; }
.stat-card  {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; text-align: center;
}
.stat-num  { font-size: 2rem; font-weight: 800; color: var(--accent); }
.stat-lbl  { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.bar-chart  { display: flex; align-items: flex-end; gap: 6px; height: 100px; margin-top: 8px; }
.bar-col    { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-fill   { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .4s ease; }
.bar-lbl    { font-size: .65rem; color: var(--muted); }

.category-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(200px,1fr)); gap: 10px; }
.category-row  { display: flex; align-items: center; gap: 10px; }
.cat-bar-bg    { flex: 1; height: 8px; background: var(--bg3); border-radius: 4px; }
.cat-bar-fill  { height: 100%; border-radius: 4px; background: var(--accent2); }
.cat-pct       { font-size: .8rem; color: var(--muted); min-width: 36px; text-align: right; }

.weakest-list { display: flex; flex-direction: column; gap: 8px; }
.weak-item    {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
}

/* ── Session summary ─────────────────────────────────────────── */
.session-summary {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; text-align: center; max-width: 460px;
  margin: 0 auto;
}
.summary-big { font-size: 2.5rem; font-weight: 800; color: var(--accent); }

/* ── Streak display ───────────────────────────────────────────── */
.streak-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 99px; padding: 4px 14px;
  font-size: .85rem; font-weight: 700;
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
.shake { animation: shake .35s ease; }

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}
.pop { animation: pop .25s ease; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  nav { gap: 2px; padding: 0 8px; }
  .nav-btn .label { display: none; }
  .nav-btn { padding: 8px; font-size: 1.2rem; }
  .quiz-options { grid-template-columns: 1fr; }
  .modal { padding: 18px; }
  .modal-word { font-size: 1.5rem; }
  main { padding: 14px 10px; }
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
