/* Conveyor Captain. Hazard yellow on charcoal, big friendly type. */
#game-root {
  --page-safe-top: env(safe-area-inset-top, 0px);
  --st: env(safe-area-inset-top, 0px); --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px); --sl: env(safe-area-inset-left, 0px);
  --ink: #1d262b; --ink2: #27333a; --paper: #f7f2e6; --accent: #f2c94c; --muted: #a9b8bf; --good: #4be37a; --bad: #ff5a44;
  --ui: clamp(1px, calc(min(100vw, 100dvh) / 560), 2.4px);
  position: relative; isolation: isolate; overflow: hidden; width: 100%;
  height: calc(100vh - 48px - var(--page-safe-top)); height: calc(100dvh - 48px - var(--page-safe-top)); min-height: 280px;
  background: #3a4247; color: #fff; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
#game-root:fullscreen, #game-root.am-fullscreen { height: 100dvh; min-height: 0; width: 100%; padding: 0; }
#floor { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#safe-probe { position: absolute; visibility: hidden; pointer-events: none; padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#game-root button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#game-root button:focus-visible, #game-root input:focus-visible { outline: 3px solid #fff5b8; outline-offset: 3px; }

/* Switches and jams: transparent hit targets over the drawn floor. */
#controls { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#controls button { position: absolute; left: 0; top: 0; pointer-events: auto; border: 0; padding: 0; margin: 0; background: transparent; border-radius: 50%; min-width: 44px; min-height: 44px; }
#controls .sw:focus-visible { outline: 4px solid #fff5b8; outline-offset: -2px; box-shadow: 0 0 0 7px rgba(29, 38, 43, .7); }
#controls .jam { border-radius: 14px; }
#controls .jam:focus-visible { outline: 4px solid #fff5b8; outline-offset: -4px; }

/* The HUD: a bar across the top held upright, a column at the left held sideways. */
#hud { position: absolute; z-index: 3; display: flex; gap: 8px; pointer-events: none; font-variant-numeric: tabular-nums; }
#hud > * { pointer-events: auto; }
.hud-tools { display: flex; gap: 8px; }
.hud-tools button { width: calc(44px + 6 * var(--ui)); height: calc(44px + 6 * var(--ui)); border-radius: 12px; border: 2px solid rgba(255,255,255,.18); background: rgba(29,38,43,.92); display: grid; place-items: center; }
.hud-tools svg { width: 60%; height: 60%; fill: #fff; stroke: #fff; stroke-width: 0; }
#btn-sound .on, #btn-sound .off { fill: none; stroke-width: 2.2; stroke-linecap: round; }
#btn-sound .off, #btn-sound.muted .on { display: none; }
#btn-sound.muted .off { display: inline; }
.hud-meter, .hud-clock { background: rgba(29,38,43,.92); border: 2px solid rgba(255,255,255,.12); border-radius: 12px; padding: 4px 10px; box-sizing: border-box; }
.hud-label { font-size: calc(13px + 2 * var(--ui)); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); line-height: 1.15; }
.hud-value strong, .hud-clock strong { font-size: calc(17px + 7 * var(--ui)); font-weight: 900; line-height: 1.1; }
.hud-value span { font-size: calc(13px + 3 * var(--ui)); font-weight: 700; color: var(--muted); margin-left: 3px; }
.bar { position: relative; height: calc(5px + 2 * var(--ui)); border-radius: 4px; background: rgba(255,255,255,.14); margin: 3px 0 2px; }
.bar i { position: absolute; inset: 0 auto 0 0; width: calc(var(--fill, 0) * 100%); border-radius: inherit; background: var(--accent); transition: width .25s ease-out; }
.hud-stars { display: flex; gap: 3px; height: calc(13px + 3 * var(--ui)); }
.hud-stars svg { height: 100%; width: auto; fill: rgba(255,255,255,.2); }
.hud-stars svg.got { fill: var(--accent); }
#game-root[data-orient="landscape"] .hud-stars { justify-content: center; }
#game-root[data-orient="portrait"] .hud-meter { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; align-items: center; }
#game-root[data-orient="portrait"] .hud-label, #game-root[data-orient="portrait"] .hud-value { grid-column: 1 / -1; }
#game-root[data-orient="portrait"] .bar { grid-column: 1; margin: 0; }
#game-root[data-orient="portrait"] .hud-stars { grid-column: 2; height: calc(12px + 4 * var(--ui)); }
#hud.rush .hud-clock { background: #b3261b; border-color: var(--accent); }
#hud.hurry .hud-clock strong { color: #ffd0c8; }
#hud.rush .hud-clock strong { color: #fff; }

#game-root[data-orient="portrait"] #hud {
  left: max(12px, calc(var(--sl) + 12px)); right: max(12px, calc(var(--sr) + 12px)); top: max(8px, calc(var(--st) + 8px));
  flex-direction: row; align-items: stretch;
}
#game-root[data-orient="portrait"] .hud-meter { flex: 1; min-width: 0; overflow: hidden; }
#game-root[data-orient="portrait"] .hud-clock { min-width: calc(60px + 16 * var(--ui)); text-align: center; }
#game-root[data-orient="portrait"] .hud-tools { order: 3; }
#game-root[data-orient="landscape"] #hud {
  left: max(12px, calc(var(--sl) + 12px)); top: max(8px, calc(var(--st) + 8px)); bottom: max(8px, calc(var(--sb) + 8px));
  width: calc(96px + 24 * var(--ui)); flex-direction: column; align-items: stretch;
}
@media (max-height: 520px) and (orientation: landscape) {
  #game-root[data-orient="landscape"] #hud { width: 96px; }
  #game-root[data-orient="landscape"] .hud-tools button { width: 44px; height: 44px; }
  #game-root[data-orient="landscape"] .am-fs-exit { left: calc(max(12px, var(--sl) + 12px) + 26px); }
}
#game-root[data-orient="landscape"] .hud-tools { justify-content: space-between; }
#game-root[data-orient="landscape"] .hud-clock { text-align: center; }
#game-root[data-orient="landscape"] .hud-meter { text-align: center; }

/* Full screen: the site's exit button sits in the HUD's own slot. */
#game-root:fullscreen[data-orient="portrait"] #hud, #game-root.am-fullscreen[data-orient="portrait"] #hud { right: max(64px, calc(var(--sr) + 64px)); }
#game-root[data-orient="portrait"] .am-fs-exit { left: auto; right: max(12px, calc(var(--sr) + 12px)); top: max(10px, calc(var(--st) + 10px)); }
#game-root:fullscreen[data-orient="landscape"] #hud, #game-root.am-fullscreen[data-orient="landscape"] #hud { bottom: max(64px, calc(var(--sb) + 64px)); }
#game-root[data-orient="landscape"] .am-fs-exit { top: auto; left: calc(max(12px, var(--sl) + 12px) + (52px + 24 * var(--ui)) / 2); bottom: max(10px, calc(var(--sb) + 10px)); }

/* Coach marks. */
#coach { position: absolute; left: 0; top: 0; z-index: 4; max-width: min(280px, 80%); padding: 10px 14px; border-radius: 12px; background: var(--paper); color: var(--ink); font-size: calc(13px + 2 * var(--ui)); font-weight: 700; line-height: 1.3; box-shadow: 0 6px 18px rgba(0,0,0,.35); pointer-events: none; }

/* Panels: title, map, brief, pause, results. */
.overlay { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; box-sizing: border-box;
  padding: max(16px, calc(var(--st) + 12px)) max(16px, calc(var(--sr) + 16px)) max(16px, calc(var(--sb) + 12px)) max(16px, calc(var(--sl) + 16px));
  background: linear-gradient(180deg, rgba(20,26,30,.55), rgba(20,26,30,.78)); touch-action: manipulation; }
.overlay.title { background: linear-gradient(180deg, rgba(20,26,30,.15), rgba(20,26,30,.5)); }
.overlay[hidden] { display: none; }
.sheet { width: min(calc(520px + 160 * var(--ui)), 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain; box-sizing: border-box;
  background: var(--ink); border: 3px solid var(--accent); border-radius: 18px; padding: calc(16px + 8 * var(--ui)); box-shadow: 0 14px 40px rgba(0,0,0,.45);
  user-select: text; -webkit-user-select: text; font-size: calc(14px + 2 * var(--ui)); }
.sheet::before { content: ""; display: block; height: 10px; margin: calc(-16px - 8 * var(--ui)) calc(-16px - 8 * var(--ui)) 14px; border-radius: 14px 14px 0 0;
  background: repeating-linear-gradient(135deg, var(--accent) 0 14px, #1a1a1a 14px 28px); }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: calc(12px + 2 * var(--ui)); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sheet h2 { margin: 0 0 10px; font-size: calc(26px + 10 * var(--ui)); line-height: 1.05; font-weight: 900; letter-spacing: -.01em; }
.sheet h2 b { color: var(--accent); }
.sheet h2.logo { font-size: calc(36px + 18 * var(--ui)); text-transform: uppercase; letter-spacing: .02em; line-height: .95; }
.sheet h2.logo b { display: block; }
.lede { margin: 0 0 14px; color: #dfe7ea; }
.sheet p { margin: 0 0 12px; line-height: 1.4; }
.tip { background: var(--ink2); border-left: 4px solid var(--accent); padding: 10px 12px; border-radius: 8px; }
.tip.small { color: #cfdade; }
.idea { color: #dfe7ea; }
.goals { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-weight: 800; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.bay-icon { display: inline-block; vertical-align: middle; }
.best { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions button, .sound-row .toggle, .tabs button, .shift {
  min-height: calc(44px + 4 * var(--ui)); padding: 8px 16px; border-radius: 12px; border: 2px solid rgba(255,255,255,.22); background: var(--ink2); font-weight: 800; }
#game-root .actions button.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); box-shadow: 0 4px 0 #9b7a18; }
.actions button:hover, .tabs button:hover, .shift:hover:not([disabled]) { filter: brightness(1.15); }
.sound-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.12); color: #cfdade; font-weight: 700; }
.sound-row .hint { font-size: 13px; font-weight: 600; color: var(--muted); }
.sound-row label { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
.sound-row input[type="range"] { width: calc(90px + 30 * var(--ui)); height: 44px; accent-color: var(--accent); touch-action: pan-x; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tabs button { flex: 1; min-width: 44px; padding: 6px; }
#game-root .tabs button[aria-selected="true"] { background: var(--accent); color: #1a1a1a; border-color: var(--accent); }
.tabs button[disabled], .shift[disabled] { opacity: .45; cursor: default; }
.shift-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.shift { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 4px; }
.shift .n { font-size: calc(16px + 4 * var(--ui)); font-weight: 900; }
.shift .lock { font-size: 13px; color: var(--muted); }
.stars { display: inline-flex; gap: 2px; vertical-align: middle; }
.stars svg { width: 1.1em; height: 1.1em; fill: rgba(255,255,255,.18); }
.stars svg.on { fill: var(--accent); }
.stars.small { font-size: 13px; }
.stars.big { font-size: calc(34px + 14 * var(--ui)); gap: 8px; margin: 2px 0 8px; }
.results .stars.big svg.on { animation: star-in .45s cubic-bezier(.2, 1.6, .4, 1) backwards; }
.results .stars.big svg:nth-child(2) { animation-delay: .22s; }
.results .stars.big svg:nth-child(3) { animation-delay: .44s; }
@keyframes star-in { from { transform: scale(0) rotate(-40deg); } }
.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 6px 0 12px; }
.tally div { background: var(--ink2); border-radius: 10px; padding: 8px 10px; }
.tally dt { font-size: calc(12px + 1 * var(--ui)); color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.tally dd { margin: 0; font-size: calc(20px + 6 * var(--ui)); font-weight: 900; }
.tally small { font-size: .6em; color: var(--muted); }
.note { color: #dfe7ea; }

/* Tablets and up: the platform minimum is 15 px. */
@media (min-width: 600px) and (min-height: 600px) { .hud-label, .hud-value span { font-size: max(15px, calc(13px + 2 * var(--ui))); } }

/* Short sideways screens: two columns so nothing scrolls. */
@media (max-height: 520px) and (orientation: landscape) {
  .sheet { width: min(860px, 100%); padding: 12px 16px; }
  .sheet::before { margin: -12px -16px 10px; height: 8px; }
  .sheet h2 { font-size: 26px; margin-bottom: 6px; }
  .sheet h2.logo { font-size: 34px; }
  .sheet p { margin-bottom: 8px; }
  .actions { margin-top: 10px; }
  .sound-row { margin-top: 10px; padding-top: 8px; }
  .title .sheet, .brief .sheet, .results .sheet, .pause .sheet { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; align-content: start; }
  .sheet::before { grid-column: 1 / -1; }
  .sheet > * { grid-column: 1; }
  .title .sheet, .brief .sheet, .results .sheet, .pause .sheet { align-items: start; }
  .title .actions, .title .sound-row, .brief .tip, .brief .legend, .brief .best, .results .tally, .results .note, .pause .tip, .pause .sound-row { grid-column: 2; }
  .title .actions, .brief .tip, .results .tally, .pause .tip { grid-row: 2 / span 3; }
  .title .sound-row, .brief .legend, .results .note, .pause .sound-row { grid-row: 5; }
  .brief .best { grid-row: 6; }
  .pause .tip { display: none; }
  .pause .sound-row { grid-row: 2 / span 3; }
  .map .sheet { padding-bottom: 10px; }
  .map h2 { display: inline-block; margin: 0 12px 6px 0; }
  .map .idea { display: inline-block; margin: 0 0 6px; }
  .map .tabs { margin-bottom: 6px; }
  .map .actions { margin-top: 8px; }
  .title .actions { margin-top: 0; }
  .sheet > .actions { margin-top: 8px; }
  .sound-row { margin-top: 0; padding-top: 0; border-top: 0; }
  .results .tally { margin: 0 0 8px; }
  .shift-grid { grid-template-columns: repeat(10, 1fr); gap: 6px; }
  .tally { grid-template-columns: 1fr 1fr; gap: 6px; }
  .tally div { padding: 4px 8px; }
  .stars.big { font-size: 30px; }
}
@media (max-width: 380px) {
  .sheet { padding: 14px; }
  .sheet::before { margin: -14px -14px 10px; }
  .actions button { padding: 8px 12px; }
}

.about { max-width: 760px; margin: 24px auto; padding: 0 16px; line-height: 1.55; }

/* Reduced motion keeps every action; it only calms the decoration. */
@media (prefers-reduced-motion: reduce) {
  .bar i { transition: none; }
}
