:root {
  color-scheme: light;
  font-family: ui-rounded, "Nunito", "Avenir Next", system-ui, sans-serif;
  background: #e8e3d7;
  color: #22241f;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 18% 0%, #fffdf6 0 17%, transparent 42%),
    #e8e3d7;
}

button, a { font: inherit; }

button {
  min-height: 44px;
  border: 1px solid #c7c1b3;
  border-radius: 14px;
  padding: 9px 14px;
  color: inherit;
  background: #fffdf8;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible, a:focus-visible { outline: 3px solid #176e83; outline-offset: 3px; }
button:disabled { opacity: .42; cursor: not-allowed; }

.shell {
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(68px + env(safe-area-inset-top)) 12px calc(22px + env(safe-area-inset-bottom));
}

.topbar, .top-actions, .level-row, .map-heading, .controls, .result-actions {
  display: flex;
  align-items: center;
}

.topbar { min-height: 44px; justify-content: space-between; gap: 8px; }
.top-actions { gap: 5px; }

.lab-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: #31574b;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.quiet-button, .icon-button {
  min-height: 44px;
  border-color: transparent;
  padding: 7px 9px;
  background: transparent;
  color: #4c5148;
  font-size: 13px;
  font-weight: 750;
}

.icon-button { width: 44px; padding: 0; font-size: 21px; }

.title-screen { padding: clamp(58px, 13vh, 118px) 14px 32px; text-align: center; }
.eyebrow { margin: 0 0 7px; color: #757a70; font-size: 12px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(32px, 10vw, 45px); line-height: 1.05; letter-spacing: -.045em; }
.subtitle { max-width: 32ch; margin: 17px auto 25px; color: #5c6159; font-size: 16px; line-height: 1.45; }
.instruction { min-height: 1.4em; margin: 11px 2px; color: #62685d; font-size: 14px; line-height: 1.4; }
.title-screen .subtitle, .title-screen .instruction { display: none; }

.primary-button {
  border-color: #24645f;
  color: #fffdf8;
  background: #24645f;
  box-shadow: 0 4px 0 #174942;
  font-weight: 850;
}
.primary-button:active { transform: translateY(2px); box-shadow: 0 2px 0 #174942; }

#play-screen { padding: 12px 0 0; }
.level-row { justify-content: space-between; gap: 12px; padding: 0 3px; }
.level-name { margin: 0; font-size: 18px; font-weight: 850; }
.move-count { margin: 0; color: #686d63; font-size: 13px; font-variant-numeric: tabular-nums; }
.endless-bar { display: flex; justify-content: space-between; gap: 10px; margin: 8px 3px 3px; color: #3b2a1e; font-size: 13px; font-variant-numeric: tabular-nums; }
.endless-bar strong { font-weight: 850; }
.endless-bar span { color: #5d6259; }

.board-shell {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid #cfc7b7;
  border-radius: 22px;
  background: #fffdf8;
  box-shadow: 0 6px 20px rgb(62 51 30 / .10);
}

#board { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }
.message { min-height: 1.4em; margin: 11px 5px 6px; color: #51574e; font-size: 14px; line-height: 1.35; }
.message.refused { color: #9b3b31; }

.controls { justify-content: center; flex-wrap: wrap; gap: 8px; padding: 8px 0 11px; }
.controls button { min-width: 92px; font-weight: 750; }
#ring-button:not(:disabled) { color: #fffdf8; border-color: #24645f; background: #24645f; }
#listen-button[aria-pressed="true"] { background: #ede3c9; }

.result-card {
  margin: 4px 0 12px;
  padding: 20px 16px 16px;
  border: 1px solid #a7c7a6;
  border-radius: 20px;
  background: #f5fbef;
  text-align: center;
}
.result-title { margin: 0; color: #24594c; font-size: 24px; font-weight: 900; }
.result-marks { margin: 7px 0 5px; font-size: 16px; font-weight: 800; }
.share-line { min-height: 1.4em; margin: 0 auto 14px; color: #5a6758; font-size: 13px; line-height: 1.4; }
.result-actions { justify-content: center; flex-wrap: wrap; gap: 8px; }
.result-actions button { font-weight: 750; }

.map-heading { justify-content: space-between; gap: 15px; padding: 12px 4px 3px; }
.map-heading h1 { font-size: 32px; }
.level-map { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 18px; }
.level-tile { min-height: 76px; padding: 10px 7px; text-align: left; }
.level-tile strong, .level-tile small { display: block; }
.level-tile strong { font-size: 17px; }
.level-tile small { margin-top: 4px; color: #687067; font-size: 11px; line-height: 1.25; }
.level-tile.complete { border-color: #79a982; background: #f4fbef; }
.mode-picker { margin: 28px 0 8px; padding: 16px 10px 4px; border-top: 1px solid #8c6c3e; }
.mode-picker h2, .mode-picker h3 { font-family: "IM Fell English", Georgia, serif; font-weight: 400; }
.mode-picker h2 { margin: 0; font-size: 25px; }
.mode-picker > p, .mode-group p { margin: 5px 0 10px; color: rgb(59 42 30 / .8); font-size: 14px; line-height: 1.35; }
.mode-group { margin: 16px 0; }
.mode-group h3 { margin: 0; font-size: 20px; }
.difficulty-buttons { display: flex; gap: 8px; }
.difficulty-buttons button { flex: 1; min-width: 0; padding: 8px 4px; }
.difficulty-buttons button.selected { color: #f3ecda; background: #3b2a1e; }
.mode-group.endless-group .difficulty-buttons { display: block; }
.mode-group.endless-group .difficulty-buttons button { width: 100%; }

.hand-demo {
  position: absolute;
  z-index: 2;
  display: none;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border-radius: 50%;
  background: rgb(255 255 255 / .86);
  box-shadow: 0 2px 9px rgb(0 0 0 / .16);
  color: #24594c;
  font-size: 25px;
  line-height: 42px;
  text-align: center;
  pointer-events: none;
}
.hand-demo.running { display: block; animation: hand-pulse 1.8s ease-in-out infinite; }
@keyframes hand-pulse { 0%, 100% { transform: scale(.78); opacity: .15; } 42%, 60% { transform: scale(1); opacity: 1; } }

.success-effect { position: absolute; inset: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.success-effect i { position: absolute; top: 47%; left: 50%; width: 9px; height: 9px; border-radius: 2px; opacity: 0; background: #e5a52d; }
.success-effect.on i { animation: confetti .72s ease-out both; }
.success-effect i:nth-child(2) { background: #4d91ae; animation-delay: .05s; }
.success-effect i:nth-child(3) { background: #bb5f70; animation-delay: .1s; }
.success-effect i:nth-child(4) { background: #5d9663; animation-delay: .02s; }
.success-effect i:nth-child(5) { background: #9d71ad; animation-delay: .12s; }
@keyframes confetti { 0% { transform: translate(0, 0) rotate(0); opacity: 1; } 100% { transform: translate(var(--x, 0), var(--y, 0)) rotate(240deg); opacity: 0; } }
.success-effect i:nth-child(1) { --x: -112px; --y: -105px; }.success-effect i:nth-child(2) { --x: 106px; --y: -96px; }.success-effect i:nth-child(3) { --x: 130px; --y: 92px; }.success-effect i:nth-child(4) { --x: -126px; --y: 78px; }.success-effect i:nth-child(5) { --x: 8px; --y: -145px; }

.load-error { margin: 54px 8px; padding: 18px; border: 1px solid #c4695e; border-radius: 14px; background: #fff5f2; color: #742f27; line-height: 1.4; }
.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; } }
@media (min-width: 700px) { .shell { margin-top: 18px; min-height: calc(100dvh - 36px); border: 1px solid rgb(117 110 96 / .2); border-radius: 28px; background: rgb(255 253 248 / .62); box-shadow: 0 20px 60px rgb(58 48 30 / .12); } }

/* Overload bar (endless). Eight segments, one per unit of dye weight, the same weight that mutes the sound
   and ends the run at 8. Zones read by pattern and word as well as colour: Fine = plain, Hindering =
   diagonal stripes, Choked = cross-hatch. Palette: Okabe-Ito blue, yellow, vermilion. */
.load-bar { margin: 8px 3px 0; color: var(--ink, #3b2a1e); }
.load-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 20px; line-height: 1.45; }
.load-word { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.load-meter { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; height: 26px; }
.load-meter i { display: block; border: 2px solid var(--ink, #3b2a1e); border-radius: 3px; background: transparent; }
.load-meter i.on { background-color: #0072B2; }
.load-bar[data-zone="hinder"] .load-meter i.on { background-color: #F0E442; background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--ink, #3b2a1e) 4px 6px); }
.load-bar[data-zone="choked"] .load-meter i.on { background-color: #D55E00; background-image: repeating-linear-gradient(45deg, transparent 0 4px, var(--ink, #3b2a1e) 4px 6px), repeating-linear-gradient(135deg, transparent 0 4px, var(--ink, #3b2a1e) 4px 6px); }
.load-meter i.edge { box-shadow: 0 0 0 2px var(--cream, #f3ecda), 0 0 0 4px var(--ink, #3b2a1e); }
.load-cue { min-height: 1.45em; margin: 4px 0 0; font-size: 20px; line-height: 1.45; text-align: center; }
.reduced-motion .load-meter i { transition: none; }

/* Short phones: keep the bar on screen under the plate; the cue and the word say what the long instruction said. */
@media (max-height: 700px) {
  body.is-endless #instruction { display: none; }
  body.is-endless .load-label { display: none; }
  body.is-endless .load-top { justify-content: center; }
  body.is-endless .load-cue { margin-top: 2px; min-height: 0; line-height: 1.3; }
}
