:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1c2830;
  --muted: #5b6770;
  --line: #e4e0d6;
  --brand: #0f766e;
  --brand-ink: #0b5953;
  --brand-soft: #e3f2ef;
  --accent: #c2410c;
  --warn-bg: #fff6e8;
  --warn-line: #f0c27f;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 40, 48, 0.04), 0 6px 20px rgba(28, 40, 48, 0.06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body.in-session { overflow: hidden; }

a { color: var(--brand-ink); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin-top: 1.4em; }

.container { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: rgba(246, 244, 239, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--brand); text-decoration: none; font-weight: 700; font-size: 1.05rem;
}
.brand svg { width: 28px; height: 28px; }
.brand span { color: var(--ink); }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  padding: 6px 12px; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.92rem;
}
.nav a:hover { color: var(--ink); background: rgba(28, 40, 48, 0.05); }
.nav a.active { color: var(--brand-ink); background: var(--brand-soft); }

.icon-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  width: 38px; height: 38px; cursor: pointer; font-size: 1rem;
}
.icon-btn .sound-off { display: none; }
.icon-btn[aria-pressed="false"] .sound-on { display: none; }
.icon-btn[aria-pressed="false"] .sound-off { display: inline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: #cfc9bb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.big { width: 100%; padding: 14px; font-size: 1.1rem; }
.btn.danger { color: var(--danger); }
.btn:focus-visible, .icon-btn:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.45); outline-offset: 2px;
}
.link-btn {
  background: none; border: 0; padding: 0; color: var(--muted);
  font: inherit; font-size: 0.88rem; text-decoration: underline; cursor: pointer;
}

/* ---------- Home ---------- */
.hero { padding: 40px 0 24px; max-width: 760px; }
.hero p { font-size: 1.08rem; color: var(--muted); }

.callout {
  border: 1px solid var(--line); border-left: 4px solid var(--brand);
  background: var(--surface); border-radius: 10px; padding: 12px 16px; margin: 16px 0;
}
.callout.warn { border-color: var(--warn-line); border-left-color: #d97706; background: var(--warn-bg); }
.callout p { margin: 0.3em 0; }

.grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  margin: 8px 0 40px;
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
.ex-card {
  display: flex; flex-direction: column; gap: 6px;
  color: inherit; text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.ex-card:hover { transform: translateY(-2px); border-color: #b8ddd7; box-shadow: 0 10px 28px rgba(15, 118, 110, 0.12); }
.ex-card h2 { margin: 6px 0 0; font-size: 1.15rem; }
.ex-card p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.ex-card .go { margin-top: auto; padding-top: 10px; color: var(--brand-ink); font-weight: 600; font-size: 0.92rem; }
.ex-icon {
  width: 52px; height: 52px; border-radius: 12px;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center;
}
.ex-icon svg { width: 34px; height: 34px; }
.tag {
  display: inline-block; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--accent);
}

.section-title { margin-top: 8px; }

.how-grid {
  display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-bottom: 40px;
}
.how-grid .card h3 { margin-top: 0; }
.how-grid .card p { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* ---------- Exercise page ---------- */
.back { display: inline-block; margin: 22px 0 6px; color: var(--muted); text-decoration: none; font-weight: 600; }
.back:hover { color: var(--ink); }
.ex-header { margin-bottom: 18px; max-width: 780px; }
.ex-header .lede { color: var(--muted); font-size: 1.05rem; margin: 0; }

.ex-grid {
  display: grid; gap: 20px; align-items: start;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
  margin-bottom: 40px;
}
@media (max-width: 860px) { .ex-grid { grid-template-columns: 1fr; } }

.steps { padding-left: 1.3em; margin: 0; }
.steps li { margin: 0.45em 0; }
.tips { padding-left: 1.2em; margin: 0; color: var(--muted); }
.tips li { margin: 0.35em 0; }


.field { margin: 0 0 16px; }
.field > label, .field > .label {
  display: block; font-weight: 600; font-size: 0.92rem; margin-bottom: 6px;
}
.field select, .field textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px;
  font: inherit; background: #fff; color: var(--ink);
}
.field textarea { resize: vertical; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--brand); }
.range-row output {
  min-width: 68px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--brand-ink);
}
.toggle { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 0.92rem; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--brand); }
.field-hint { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

.divider { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.start-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 10px; flex-wrap: wrap; }
.kbd-hint { font-size: 0.82rem; color: var(--muted); margin: 10px 0 0; }
kbd {
  font-family: inherit; font-size: 0.8em; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line); border-bottom-width: 2px; background: #fff;
}

/* ---------- Log ---------- */
.log-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 16px; }
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat .num { font-size: 1.6rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 0.85rem; }
.table-wrap { overflow-x: auto; margin-bottom: 40px; padding: 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #faf9f6; }
tr:last-child td { border-bottom: 0; }
.sym { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sym .up { color: var(--danger); font-weight: 600; }
.sym .down { color: var(--brand-ink); font-weight: 600; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

/* ---------- About ---------- */
.prose { max-width: 780px; margin-bottom: 40px; }
.prose h2 { margin-top: 1.6em; }
.prose li { margin: 0.35em 0; }

.footer { padding: 24px 20px 40px; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); }

/* ---------- Stage (exercise runner) ---------- */
#stage {
  position: fixed; inset: 0; z-index: 100;
  background: #f4f1ea;
  user-select: none; -webkit-user-select: none;
}
#stage[hidden] { display: none; }
#canvas { display: block; width: 100%; height: 100%; }
#stage.idle { cursor: none; }

.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
#stage.idle .hud-left, #stage.idle .hud-right .hud-btn { opacity: 0.45; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; transition: opacity 0.4s ease; }
.hud-left { flex-direction: column; align-items: flex-start; gap: 0; }
.hud-title { font-weight: 700; font-size: 0.95rem; color: rgba(28, 40, 48, 0.75); }
.hud-stat { font-size: 0.85rem; color: rgba(28, 40, 48, 0.6); font-variant-numeric: tabular-nums; }
.hud-cue {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.85); color: var(--ink);
  font-weight: 600; font-size: 0.9rem; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.hud-time {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem;
  padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.8);
}
.hud-btn {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.85); border-color: rgba(0, 0, 0, 0.08);
  padding: 7px 14px;
}
.hud-btn.stop { color: var(--danger); }

.countdown, .paused {
  position: absolute; inset: 0; display: grid; place-items: center; align-content: center;
  pointer-events: none; text-align: center;
}
.countdown[hidden], .paused[hidden] { display: none; }
.countdown {
  font-size: clamp(5rem, 18vw, 11rem); font-weight: 800; color: rgba(15, 118, 110, 0.9);
  background: rgba(244, 241, 234, 0.55);
}
.paused {
  font-size: 2.4rem; font-weight: 800; color: var(--ink);
  background: rgba(244, 241, 234, 0.82);
}
.paused small { display: block; font-size: 1rem; font-weight: 500; color: var(--muted); margin-top: 6px; }

@media (max-width: 600px) {
  .hud-title { display: none; }
  .hud-cue { top: 58px; font-size: 0.82rem; }
  .nav a { padding: 6px 9px; }
  .brand span { display: none; }
}

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(460px, calc(100vw - 32px));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25); color: var(--ink);
}
dialog::backdrop { background: rgba(28, 40, 48, 0.45); }
.dialog-body { padding: 24px; }
.dialog-body h2 { margin-bottom: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

@media (prefers-reduced-motion: reduce) {
  .ex-card { transition: none; }
}
