/* Govori — a Russian exercise book (тетрадь): grid paper, violet ink, red teacher's corrections. */

:root {
  --paper: #F3F6FA;
  --sheet: #FDFEFF;
  --grid: #DCE5EF;
  --ink: #1E2740;
  --ink-soft: #5A6480;
  --violet: #4A3FA0;
  --violet-soft: #E9E6F7;
  --red: #C42537;
  --red-soft: #FBE7E9;
  --ok: #2E6B4E;
  --line: #C9D3DF;

  --serif: "PT Serif", Georgia, "Times New Roman", serif;
  --sans: "PT Sans", "Segoe UI", system-ui, sans-serif;
  --hand: "Caveat", "Segoe Print", cursive;

  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: 1.75rem;
  --step-4: 2.4rem;

  --cell: 22px;
  --radius: 10px;
  --nav-h: 62px;
  color-scheme: light;
}

:root[data-theme="dark"] .btn:not(.ghost):not(.quiet):not(.danger) { color: #14112E; }
:root[data-theme="dark"] {
  --paper: #121722;
  --sheet: #182030;
  --grid: #222C3E;
  --ink: #E5E9F3;
  --ink-soft: #9AA4BD;
  --violet: #A69CF5;
  --violet-soft: #2A2750;
  --red: #FF6B79;
  --red-soft: #3A1C24;
  --ok: #7CC9A2;
  --line: #2C374C;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.5 var(--sans);
}
[hidden] { display: none !important; }
a { color: var(--violet); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

/* ---------- shell ---------- */

.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 6px; max-width: 760px; margin: 0 auto;
}
.brand { font: 700 var(--step-2)/1 var(--serif); color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.top-right { display: flex; align-items: center; gap: 14px; }
.streak { font: 700 var(--step-1)/1 var(--hand); color: var(--red); }
.more-link { text-decoration: none; color: var(--ink-soft); font-size: 1.3rem; letter-spacing: 2px; padding: 4px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--sheet); border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-soft); font-size: .78rem;
}
.tabs .ico { font: 400 1.25rem/1 var(--serif); }
.tabs a[aria-current="page"] { color: var(--violet); font-weight: 700; }

main { max-width: 760px; margin: 0 auto; padding: 8px 14px 24px; outline: none; }

@media (min-width: 900px) {
  .shell { padding-bottom: 32px; }
  .tabs {
    position: fixed; top: 70px; left: max(16px, calc(50vw - 560px)); bottom: auto; right: auto;
    width: 150px; height: auto; display: flex; flex-direction: column; gap: 4px;
    background: transparent; border: 0; padding: 0;
  }
  .tabs a { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 1rem; padding: 8px 10px; border-radius: 8px; }
  .tabs a[aria-current="page"] { background: var(--violet-soft); }
}

/* ---------- the exercise-book page ---------- */

.page {
  position: relative;
  background-color: var(--sheet);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-position: -1px -1px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 22px 20px 22px 46px;
  margin: 12px 0;
}
.page::before { /* the red margin line */
  content: ""; position: absolute; top: 0; bottom: 0; left: 30px; width: 2px; background: var(--red); opacity: .55;
}
.page > :first-child { margin-top: 0; }
.page > :last-child { margin-bottom: 0; }
.page.plain { background-image: none; }

h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0 0 10px; }
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
p { margin: 0 0 10px; }
.muted { color: var(--ink-soft); }
.small { font-size: .9rem; }
.ru { font-family: var(--serif); }
.prompt-label { color: var(--ink-soft); font-size: .95rem; margin-bottom: 6px; }

/* the teacher's red ink */
.mark {
  display: inline-grid; place-items: center; min-width: 2.2em; height: 2.2em; padding: 0 .3em;
  border: 2.5px solid var(--red); border-radius: 50%;
  font: 700 var(--step-3)/1 var(--hand); color: var(--red); transform: rotate(-6deg);
}
.hand { font-family: var(--hand); color: var(--red); font-size: 1.45rem; line-height: 1.1; }
.struck { text-decoration: line-through; text-decoration-color: var(--red); text-decoration-thickness: 2px; color: var(--ink-soft); }
.marked b, .marked u { font-weight: inherit; }
.marked u { text-decoration: underline wavy var(--red); text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
.tick { color: var(--ok); font-weight: 700; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: var(--radius);
  border: 1.5px solid var(--violet); background: var(--violet); color: #fff;
  font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .45; cursor: default; }
:root[data-theme="dark"] .btn:not(.ghost):not(.quiet):not(.danger) { color: #121722; }
.btn.ghost { background: transparent; color: var(--violet); }
.btn.quiet { background: transparent; border-color: var(--line); color: var(--ink); font-weight: 400; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.wide { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

.line-input {
  width: 100%; border: 0; border-bottom: 2px solid var(--violet); background: transparent;
  padding: 8px 2px; font: 400 var(--step-1)/1.4 var(--serif); color: var(--violet); outline: none;
}
.line-input:focus { border-bottom-width: 3px; }
textarea.note-area {
  width: 100%; min-height: 220px; resize: vertical; border: 1px solid var(--line); border-radius: 6px;
  background: transparent; padding: 10px; font: 400 var(--step-0)/var(--cell) var(--serif); color: var(--violet);
}
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: .9rem; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field textarea, .search {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--sheet); padding: 10px 12px;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chip {
  border: 1px solid var(--line); background: var(--sheet); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .92rem;
}
.chip[aria-pressed="true"] { border-color: var(--violet); background: var(--violet-soft); color: var(--violet); font-weight: 700; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }

/* ---------- home ---------- */

.today-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.today-head h1 { margin: 0; }
.tasks { list-style: none; margin: 14px 0 0; padding: 0; }
.tasks li { border-bottom: 1px dashed var(--line); }
.tasks a {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px;
  padding: 13px 0; color: var(--ink); text-decoration: none;
}
.tasks .box { width: 20px; height: 20px; border: 1.5px solid var(--ink-soft); border-radius: 3px; display: grid; place-items: center; }
.tasks .done .box { border-color: var(--red); }
.tasks .done .box::after { content: "✓"; font: 700 1.3rem/1 var(--hand); color: var(--red); transform: translateY(-2px); }
.tasks .count { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.streak-note { margin-top: 14px; }

/* ---------- review ---------- */

.progress { height: 4px; background: var(--grid); border-radius: 2px; overflow: hidden; margin: 6px 0 2px; }
.progress > i { display: block; height: 100%; background: var(--violet); }
.card-front { font: 400 var(--step-2)/1.45 var(--serif); margin: 6px 0 18px; word-break: break-word; }
.correction { margin: 8px 0 14px; }
.correction .answer { font: 700 var(--step-2)/1.3 var(--serif); }
.note { border-left: 3px solid var(--violet); padding: 4px 0 4px 12px; color: var(--ink); margin: 12px 0; }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.ratings button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px;
  border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--sheet); cursor: pointer;
}
.ratings button small { color: var(--ink-soft); font-size: .78rem; }
.ratings button.suggest { border-color: var(--violet); background: var(--violet-soft); }
.ratings button[data-r="1"] strong { color: var(--red); }
.kbd-hint { margin-top: 10px; font-size: .82rem; color: var(--ink-soft); }
@media (hover: none) { .kbd-hint { display: none; } }

/* ---------- reader ---------- */

.lib { list-style: none; padding: 0; margin: 0; }
.lib a { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px 0; border-bottom: 1px dashed var(--line); color: var(--ink); text-decoration: none; }
.lib .title { font-family: var(--serif); font-size: var(--step-1); }
.lib .done .title::after { content: " ✓"; font-family: var(--hand); color: var(--red); font-size: 1.4rem; }
.reading { font: 400 1.18rem/1.75 var(--serif); }
.w { cursor: pointer; border-radius: 3px; }
.w:hover { background: var(--violet-soft); }
.w.on { background: var(--violet-soft); color: var(--violet); }
.q { margin: 18px 0; }
.q legend { font-weight: 700; margin-bottom: 8px; }
.q label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; cursor: pointer; background: var(--sheet); }
.q label.right { border-color: var(--ok); }
.q label.wrong { border-color: var(--red); background: var(--red-soft); }

/* ---------- dictation ---------- */

.play {
  width: 74px; height: 74px; border-radius: 50%; border: 2px solid var(--violet); background: var(--sheet);
  color: var(--violet); font-size: 1.7rem; cursor: pointer; display: grid; place-items: center;
}
.play[aria-busy="true"] { opacity: .5; }
.hidden-text { filter: blur(7px); cursor: pointer; user-select: none; transition: filter .2s; }
.hidden-text.shown { filter: none; }
.dots { display: flex; gap: 6px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink-soft); }
.dots i.ok { background: var(--ok); border-color: var(--ok); }
.dots i.bad { background: var(--red); border-color: var(--red); }
.dots i.now { border-color: var(--violet); background: var(--violet-soft); }

/* ---------- writing ---------- */

.wordcount { font-variant-numeric: tabular-nums; }
.history details { border-bottom: 1px dashed var(--line); padding: 10px 0; }
.history summary { cursor: pointer; }

/* ---------- cards ---------- */

.card-list { list-style: none; padding: 0; margin: 0; }
.card-list li { border-bottom: 1px dashed var(--line); }
.card-list button { all: unset; display: block; width: 100%; padding: 12px 0; cursor: pointer; }
.card-list button:focus-visible { outline: 2px solid var(--violet); }
.card-list .front { font-family: var(--serif); }
.card-list .meta { font-size: .85rem; color: var(--ink-soft); }

/* ---------- stats ---------- */

.bars { display: grid; grid-template-columns: repeat(30, 1fr); gap: 3px; align-items: end; height: 120px; margin: 10px 0 4px; }
.bars i { display: block; background: var(--violet); border-radius: 2px 2px 0 0; min-height: 2px; }
.bars i.hit { background: var(--violet); }
.bars i.miss { background: var(--grid); }
.bars i.today { outline: 2px solid var(--red); outline-offset: 1px; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-top: 14px; }
.figures div strong { display: block; font: 700 var(--step-3)/1.1 var(--serif); }
.figures div span { color: var(--ink-soft); font-size: .9rem; }

/* ---------- sheet + toast ---------- */

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 20, 35, .45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow: auto;
  background: var(--sheet); border-radius: 16px 16px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 22px); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--sheet); padding: 10px 16px; border-radius: 8px; max-width: 90vw;
}
.labels { margin: 10px 0; padding-left: 18px; }
.labels li { margin-bottom: 3px; }

.center { text-align: center; }
.spacer { height: 10px; }
.loading { color: var(--ink-soft); padding: 30px 0; text-align: center; }
.error { color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
