:root {
  --ink: #12263a;
  --ink-soft: #3a5166;
  --mute: #6a7f90;
  --field: #cfd9d3;
  --field-deep: #b7c6bf;
  --sheet: #f8f6f2;
  --sheet-edge: #e6e1d8;
  --mark: #b11226;
  --mark-soft: rgba(177, 18, 38, 0.1);
  --line: rgba(18, 38, 58, 0.16);
  --focus: #1f6f6a;
  --ui: "Trebuchet MS", "Gill Sans", "Gill Sans MT", sans-serif;
  --display: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--ui);
  color: var(--ink);
  background-color: var(--field);
  background-image:
    linear-gradient(90deg, rgba(18, 38, 58, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(18, 38, 58, 0.035) 1px, transparent 1px),
    radial-gradient(ellipse 900px 420px at 12% -8%, #e4ece7 0%, transparent 60%),
    linear-gradient(165deg, var(--field) 0%, var(--field-deep) 100%);
  background-size: 28px 28px, 28px 28px, auto, auto;
  padding:
    max(24px, calc(var(--safe-top) + 18px))
    max(20px, calc(var(--safe-right) + 16px))
    max(32px, calc(var(--safe-bottom) + 18px))
    max(20px, calc(var(--safe-left) + 16px));
}

a {
  color: inherit;
}

/* ——— Home ——— */

.home {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.brand {
  margin-bottom: 28px;
  animation: rise 0.55s ease both;
}

.brand-kicker {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mark);
}

.brand-title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(48px, 12vw, 72px);
  font-weight: 700;
  line-height: 0.92;
  letter-spacing: -0.03em;
}

.brand-title span {
  display: block;
  font-size: 0.42em;
  font-family: var(--ui);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-top: 10px;
  color: var(--ink-soft);
}

.brand-lead {
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 16px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.brand-lead-meta {
  font-size: 13.5px;
  letter-spacing: 0.02em;
  color: var(--mute);
}

.section-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mute);
}

.deck-list {
  border-top: 2px solid var(--ink);
  animation: rise 0.55s ease 0.08s both;
}

.deck-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px 14px;
  align-items: start;
  padding: 18px 4px 18px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  transition: background 0.15s ease, padding-left 0.15s ease;
}

.deck-row:hover,
.deck-row:focus-visible {
  background: rgba(248, 246, 242, 0.55);
  padding-left: 8px;
  outline: none;
}

.deck-num {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--mark);
  padding-top: 2px;
}

.deck-copy h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.deck-copy .desc {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.deck-meta {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mute);
  text-align: right;
  white-space: nowrap;
  padding-top: 6px;
}

.deck-arrow {
  display: none;
}

.home-hint {
  margin: 22px 0 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--mute);
  max-width: 46ch;
}

@media (max-width: 520px) {
  .deck-row {
    grid-template-columns: 40px 1fr;
  }

  .deck-meta {
    grid-column: 2;
    text-align: left;
    padding-top: 0;
  }
}

/* ——— Trainer ——— */

body.page-trainer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.trainer {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.trainer-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  animation: rise 0.4s ease both;
}

.back-link {
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1.5px solid transparent;
  padding-bottom: 1px;
}

.back-link:hover,
.back-link:focus-visible {
  border-bottom-color: var(--ink);
  outline: none;
}

.deck-chip {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mark);
  text-align: right;
}

.lesson-bar {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  animation: rise 0.4s ease 0.05s both;
}

.lesson-bar label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mute);
}

.lesson-wrap {
  position: relative;
  min-width: 0;
}

.lesson-label {
  width: 100%;
  min-height: 44px;
  padding: 10px 28px 10px 0;
  border: none;
  border-bottom: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  text-align: left;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lesson-label::after {
  content: "";
  position: absolute;
  right: 2px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--ink);
  transform: translateY(-40%);
  pointer-events: none;
}

.lesson-wrap select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px;
}

.stage {
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  border: 1px solid var(--sheet-edge);
  border-left: 6px solid var(--ink);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  animation: rise 0.45s ease 0.1s both;
}

.stage:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.stage-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 240px;
  padding: 36px 28px 28px;
  text-align: left;
}

.stage-word {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(34px, 8vw, 52px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  word-break: break-word;
  animation: wordIn 0.28s ease both;
}

.stage.is-open .stage-word {
  color: var(--ink-soft);
}

.stage-hint {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--mute);
  transition: opacity 0.2s ease;
}

.stage.is-open .stage-hint {
  opacity: 0;
}

.stage-reveal {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease;
  background: var(--mark-soft);
  border-top: 1px solid transparent;
}

.stage-reveal > .stage-reveal-inner {
  overflow: hidden;
}

.stage.is-open .stage-reveal {
  grid-template-rows: 1fr;
  border-top-color: rgba(177, 18, 38, 0.18);
}

.stage-reveal-inner {
  padding: 0 28px;
}

.stage.is-open .stage-reveal-inner {
  padding: 18px 28px 20px;
}

.stage-ru {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: var(--mark);
}

.stage-example {
  margin: 0;
  font-family: var(--display);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink-soft);
  font-style: italic;
}

.controls {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  animation: rise 0.45s ease 0.16s both;
}

.ctrl-btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  min-height: 48px;
  padding: 0 16px;
  font-family: var(--ui);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ctrl-btn:hover,
.ctrl-btn:focus-visible {
  background: var(--ink);
  color: var(--sheet);
  outline: none;
}

.ctrl-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.ctrl-btn.primary {
  background: var(--ink);
  color: var(--sheet);
}

.ctrl-btn.primary:hover,
.ctrl-btn.primary:focus-visible {
  background: var(--mark);
  border-color: var(--mark);
}

.controls-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 88px;
}

.counter {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.speak-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--mute);
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 4px;
}

.speak-btn:hover,
.speak-btn:focus-visible {
  color: var(--ink);
  outline: none;
}

.status {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--mute);
  text-align: left;
}

/* Voice picker */

.voice-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 38, 58, 0.48);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.voice-overlay.show {
  display: flex;
}

.voice-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--sheet);
  border-left: 6px solid var(--mark);
  padding: 18px 16px max(16px, var(--safe-bottom));
}

.voice-sheet h3 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: 22px;
}

.voice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 40vh;
  overflow: auto;
}

.voice-item {
  width: 100%;
  text-align: left;
  border: 1.5px solid var(--line);
  background: transparent;
  padding: 12px 14px;
  font-size: 14px;
  font-family: var(--ui);
  color: var(--ink);
  cursor: pointer;
}

.voice-item.selected,
.voice-item:hover {
  border-color: var(--ink);
  background: rgba(18, 38, 58, 0.05);
}

.voice-close {
  margin-top: 12px;
  width: 100%;
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--sheet);
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--ui);
  cursor: pointer;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes wordIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 420px) {
  .stage-main,
  .stage.is-open .stage-reveal-inner {
    padding-left: 20px;
    padding-right: 20px;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "prev next"
      "mid mid";
  }

  #btnPrev { grid-area: prev; }
  #btnNext { grid-area: next; }
  .controls-mid { grid-area: mid; }
}
