* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #243022;
  --cream: #fff8ec;
  --sun: #ffb703;
  --leaf: #2f6b2a;
  --dock: rgba(255, 248, 236, 0.94);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #8ec8f5;
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

#view { position: fixed; inset: 0; }
#view canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#view-hint {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 248, 236, 0.88);
  font-size: 13px;
  font-weight: 700;
  color: #3d5a40;
  white-space: nowrap;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 28px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(142, 200, 245, 0.92), transparent);
}

header button, header a { pointer-events: auto; }

h1 {
  font-size: clamp(22px, 3vw, 34px);
  letter-spacing: -0.03em;
  color: var(--leaf);
}

#station-label {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #3d5a40;
}

.site-link {
  display: inline-block;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 800;
  color: var(--leaf);
  text-underline-offset: 3px;
}

.site-link:hover { color: #1d4d1a; }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  touch-action: manipulation;
}

#home, #show, #again, #summary-home, .card, .stepper button, #line-controls button {
  border-radius: 14px;
}

#home {
  padding: 10px 14px;
  background: var(--cream);
  color: var(--leaf);
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(36, 48, 34, 0.12);
}

#menu, #play, #summary {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 4;
  width: min(1080px, calc(100% - 24px));
}

#menu, #summary {
  padding: 18px;
  background: var(--dock);
  border-radius: 22px;
  box-shadow: 0 16px 40px rgba(36, 48, 34, 0.16);
}

.lead, #summary-copy, #help, #feedback {
  line-height: 1.35;
}

.lead { margin-bottom: 12px; font-size: 16px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 14px;
  background: #fff;
  color: var(--ink);
  border: 3px solid transparent;
  box-shadow: 0 4px 0 #e4d3b5;
}

.card:hover, .card:focus-visible { border-color: var(--sun); }

.card-kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a5a12;
}

.card-title { font-size: 22px; font-weight: 800; color: var(--leaf); }
.card-copy { font-size: 14px; }

#play {
  padding: 14px 16px 16px;
  background: var(--dock);
  border-radius: 22px;
  box-shadow: 0 16px 40px rgba(36, 48, 34, 0.16);
}

.play-top, .summary-actions, .controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

#progress, #stars { font-weight: 800; font-size: 14px; }
#stars { letter-spacing: 0.12em; color: #c47d09; }

#prompt {
  margin: 6px 0 2px;
  font-size: clamp(28px, 5vw, 46px);
  letter-spacing: -0.03em;
  line-height: 1.05;
}

#help { color: #4d5c46; font-size: 15px; }
#equation {
  margin: 6px 0 8px;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

[hidden] { display: none !important; }

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 16px;
  padding: 6px;
}

.stepper span { min-width: 7.5em; text-align: center; font-weight: 800; }

.stepper button, #line-controls button, #show, #again, #summary-home {
  min-width: 64px;
  min-height: 56px;
  padding: 8px 14px;
  font-size: 26px;
  font-weight: 800;
  background: #fff;
  color: var(--leaf);
  box-shadow: 0 4px 0 #d7c4a4;
}

#line-controls button { font-size: 22px; background: #fff7df; }
#jump-p10, #jump-p1 { background: #e5f6d4; }
#jump-m10, #jump-m1 { background: #ffe8c7; }
#fraction-controls { flex-wrap: wrap; justify-content: flex-start; }
#fraction-controls button { background: #f3d5a0; color: #5a3a16; }
#fraction-controls button.on { background: #c46a2c; color: #fff8ec; }

#show, #again, #summary-home {
  margin-top: 8px;
  font-size: 16px;
  background: var(--sun);
  color: #3d2a04;
}

button:disabled { opacity: 0.4; cursor: default; }

#feedback {
  min-height: 1.3em;
  margin-top: 8px;
  font-weight: 700;
}

#feedback.ok { color: var(--leaf); }
#feedback.nudge { color: #8a4b12; }

#summary { text-align: center; }
#summary h2 { font-size: 32px; color: var(--leaf); margin-bottom: 6px; }
.summary-actions { justify-content: center; margin-top: 12px; }

body.mode-menu #play, body.mode-menu #summary, body.mode-menu #home { display: none; }
body.mode-play #menu, body.mode-play #summary { display: none; }
body.mode-summary #menu, body.mode-summary #play { display: none; }

@media (max-width: 800px) {
  .cards { grid-template-columns: 1fr; }
  #menu, #play, #summary { bottom: 8px; width: calc(100% - 12px); }
  #menu { max-height: calc(100% - 96px); overflow: auto; }
  .controls { flex-wrap: wrap; }
  .stepper { flex: 1; }
  #prompt { font-size: 32px; }
  #view-hint { display: none; }
}
