/* ===== Tokens ===== */
:root {
  --bg: #F5EFE3;
  --grid: rgba(47, 107, 79, .07);
  --ink: #1E3A2F;
  --muted: #5E6F66;
  --card: #FFFDF8;
  --green: #2F6B4F;
  --green-l: #DCEBDD;
  --terra: #C65D3B;
  --terra-l: #F6DCCF;
  --tape: #F2C230;
  --tape-l: #FCEFC0;
  --oak: #C99A62;
  --oak-l: #F1E2CC;
  --sky: #3E7CB1;
  --sky-l: #DCE9F4;
  --red: #D64545;
  --red-l: #F9DADA;
  --line: 3px solid var(--ink);
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 4px 4px 0 var(--ink);
  --radius: 22px;
  --font: 'Rubik', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --nav-h: 64px;
  --tape-h: 22px;
  --scale: 1;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
mark { background: none; color: inherit; position: relative; z-index: 0; }
mark::after {
  content: ""; position: absolute; left: -4px; right: -4px; bottom: 6%; height: 36%;
  background: var(--tape); z-index: -1; border-radius: 6px; transform: rotate(-1deg);
}
sub { font-size: .6em; }
sup { font-size: .6em; line-height: 0; }
.muted { color: var(--muted); }
.ru { color: var(--muted); font-weight: 500; font-size: .78em; font-style: italic; }

/* ===== Tape-measure progress ===== */
.tape {
  position: fixed; top: 0; left: 0; right: 0; height: var(--tape-h); z-index: 30;
  background: rgba(30, 58, 47, .06); border-bottom: 1px solid rgba(30, 58, 47, .12);
}
.tape__bar {
  position: relative; height: 100%; width: 0;
  background-color: var(--tape);
  background-image:
    repeating-linear-gradient(90deg, rgba(30,58,47,.75) 0 2px, transparent 2px 40px),
    repeating-linear-gradient(90deg, rgba(30,58,47,.45) 0 1px, transparent 1px 8px);
  background-size: 100% 10px, 100% 5px;
  background-repeat: no-repeat;
  border-right: 3px solid var(--ink);
  transition: width .6s cubic-bezier(.2,.8,.2,1);
}
.tape__bar::after {
  content: ""; position: absolute; right: -14px; top: -3px; width: 22px; height: calc(var(--tape-h) + 4px);
  background: var(--ink); border-radius: 4px 8px 8px 4px;
}

/* ===== Viewport & scaled deck ===== */
.viewport { position: fixed; top: var(--tape-h); left: 0; right: 0; bottom: var(--nav-h); }
.deck {
  position: absolute; left: 50%; top: 50%;
  width: 1600px; height: 900px;
  transform: translate(-50%, -50%) scale(var(--scale));
  transform-origin: center center;
  font-size: 30px; line-height: 1.3;
}

.slide {
  position: absolute; inset: 0;
  padding: 36px 64px 32px;
  display: flex; flex-direction: column; gap: 22px;
  opacity: 0; visibility: hidden;
  transform: translateX(80px) scale(.98);
  transition: opacity .45s ease, transform .55s cubic-bezier(.2,.8,.2,1), visibility 0s linear .55s;
}
.slide.is-past { transform: translateX(-80px) scale(.98); }
.slide.is-active {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity .45s ease, transform .55s cubic-bezier(.2,.8,.2,1), visibility 0s;
}

/* entrance animations */
.pop { opacity: 0; }
.slide.is-active .pop { animation: popIn .6s cubic-bezier(.2,.9,.3,1.25) both; animation-delay: var(--d, 0s); }
@keyframes popIn {
  from { opacity: 0; transform: translateY(26px) scale(.96); }
  to { opacity: 1; }
}
.frag { opacity: 0; transform: translateY(18px) scale(.97); transition: opacity .4s ease, transform .45s cubic-bezier(.2,.9,.3,1.3); }
.frag.is-shown { opacity: 1; transform: none; }

/* ===== Slide header ===== */
.head { display: flex; flex-direction: column; gap: 10px; }
.head__row { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.head h2 { margin: 0; font-size: 54px; line-height: 1.08; font-weight: 800; letter-spacing: -.5px; }
.head h2 .muted { font-size: .58em; font-weight: 600; }
.chip {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 18px; border: var(--line); border-radius: 999px;
  background: var(--card); font-size: 21px; font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.chip--tape { background: var(--tape); }
.chip--green { background: var(--green-l); }
.chip--terra { background: var(--terra-l); }
.chip--sky { background: var(--sky-l); }
.chip--oak { background: var(--oak-l); }

/* 4-step lesson map shown in slide headers */
.steps { display: flex; gap: 6px; font-size: 18px; font-weight: 700; }
.steps span {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
  border: 2px solid rgba(30,58,47,.25); border-radius: 999px; color: var(--muted); background: var(--card);
}
.steps span.is-on { border: var(--line); color: var(--ink); background: var(--tape); box-shadow: 3px 3px 0 var(--ink); }
.steps span.is-done { color: var(--green); border-color: var(--green); }

/* ===== Layout helpers ===== */
.body { flex: 1; min-height: 0; display: flex; gap: 32px; }
.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.grow { flex: 1; }
.row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.center { align-items: center; justify-content: center; }
.w-40 { flex: 0 0 40%; }
.w-45 { flex: 0 0 45%; }
.w-50 { flex: 0 0 calc(50% - 16px); }
.w-55 { flex: 0 0 55%; }

/* ===== Navbar ===== */
.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h);
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: rgba(255, 253, 248, .92); backdrop-filter: blur(8px);
  border-top: 2px solid rgba(30, 58, 47, .12); z-index: 40;
}
.navbar__credit { font-size: 14px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.navbar__credit b { color: var(--ink); }
.navbar__credit:hover b { text-decoration: underline; }
.navbar__mid { flex: 1; display: flex; justify-content: center; align-items: center; gap: 12px; min-width: 0; }
.navbar__stage { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navbar__count { font-size: 18px; font-weight: 800; min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; }
.nbtn {
  height: 44px; min-width: 44px; padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 2px solid var(--ink); border-radius: 14px; background: var(--card);
  font-size: 18px; font-weight: 700; box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s, box-shadow .12s, background .2s;
}
.nbtn:hover { background: var(--tape-l); }
.nbtn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.nbtn--main { background: var(--tape); }
.nbtn.is-on { background: var(--green-l); }
.nbtn:disabled { opacity: .4; cursor: default; }

/* ===== Overlays: menu & scoreboard ===== */
.overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(30, 58, 47, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  position: relative;
  background: var(--card); border: var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(920px, 100%); max-height: 100%; overflow: auto; padding: 24px;
}
.sheet h3 { margin: 0 0 12px; font-size: 26px; }
.sheet__x { position: absolute; top: 10px; right: 14px; border: 0; background: none; font-size: 26px; }
.menu__group { margin: 14px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.menu__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.menu__item {
  display: flex; gap: 10px; align-items: center; text-align: left;
  padding: 10px 12px; border: 2px solid var(--ink); border-radius: 14px; background: var(--bg); font-size: 17px;
}
.menu__item:hover { background: var(--tape-l); }
.menu__item.is-current { background: var(--tape); }
.menu__item span { font-weight: 800; min-width: 28px; }
.menu__keys { margin-top: 16px; font-size: 14px; color: var(--muted); line-height: 2; }

kbd {
  display: inline-block; padding: 1px 8px; border: 2px solid var(--ink); border-bottom-width: 4px;
  border-radius: 8px; background: var(--card); font-family: var(--font); font-size: .85em; line-height: 1.3;
}

/* ===== Timer ===== */
.timer {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px); z-index: 50;
  background: var(--card); border: var(--line); border-radius: 22px; box-shadow: var(--shadow);
  padding: 14px 16px; width: 280px; text-align: center;
  animation: popIn .35s cubic-bezier(.2,.9,.3,1.3);
}
.timer__digits { font-size: 64px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; margin: 4px 0 10px; }
.timer.is-low .timer__digits { color: var(--red); animation: pulse 1s ease-in-out infinite; }
.timer.is-done { animation: shake .5s ease 3; background: var(--red-l); }
.timer__presets, .timer__ctrl { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.timer__ctrl { margin-top: 8px; }
.timer .nbtn { height: 38px; font-size: 16px; padding: 0 10px; }
.timer__close { position: absolute; top: 6px; right: 10px; border: 0; background: none; font-size: 22px; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ===== Confetti & toast ===== */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
.toast {
  position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 14px 26px; border-radius: 18px;
  font-size: 26px; z-index: 20; box-shadow: var(--shadow-sm); max-width: 80%; text-align: center;
  animation: toastIn .3s cubic-bezier(.2,.9,.3,1.3);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } }

/* ===== Small screens ===== */
@media (max-width: 960px) {
  .nx-label { display: none; }
}
@media (max-width: 760px) {
  .navbar__stage { display: none; }
  .navbar { gap: 6px; padding: 0 8px; }
  .nbtn { padding: 0 10px; min-width: 40px; }
  .navbar__credit { font-size: 12px; }
}
@media (max-width: 560px) {
  .navbar__credit span, .nx-label { display: none; }
  .navbar__credit { white-space: normal; line-height: 1.15; font-size: 11px; max-width: 96px; }
  .navbar__mid { gap: 6px; }
  .nbtn { padding: 0 8px; min-width: 38px; }
  #btn-sound, #btn-full, #btn-timer { display: none; }
  .navbar__count { min-width: 52px; font-size: 16px; }
}
@media (max-height: 520px) {
  :root { --nav-h: 48px; --tape-h: 12px; }
  .navbar { gap: 6px; padding: 0 8px; }
  .navbar__stage, .nx-label { display: none; }
  .nbtn { height: 36px; min-width: 36px; padding: 0 8px; font-size: 16px; box-shadow: 2px 2px 0 var(--ink); }
  .navbar__count { min-width: 52px; font-size: 15px; }
  .navbar__credit { font-size: 12px; }
}
.rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 700px) {
  .rotate-hint {
    display: block; position: fixed; top: calc(var(--tape-h) + 12px); left: 16px; right: 16px; z-index: 35;
    background: var(--ink); color: #fff; border-radius: 16px; padding: 10px 14px; font-size: 16px; text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
