:root {
  --bg: #eef5fb; --panel: #ffffff; --ink: #17324a; --muted: #4a6580;
  --tankbench: #dcecfa; --capbench: #fdeccf; --water: #2b7fd4; --water2: #6db2ef;
  --amber: #e08a14; --plus: #d6402f; --minus: #2b6fc4; --glass: #9fb7cc;
  --btn: #ffd24a; --btn-ink: #3a2a00; --btn-edge: #c99a12; --chip: #ffffff; --chip-edge: #9fb7cc;
  --good: #1f8a4c; --soft: #fff6d8; --line: #c9d9e8;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1c2a; --panel: #172a3d; --ink: #eaf3fb; --muted: #a9c0d6;
  --tankbench: #14324d; --capbench: #3a2d16; --water: #4a9cf0; --water2: #8cc6ff;
  --amber: #f2b441; --plus: #ff7b66; --minus: #7db6ff; --glass: #5f7f9c;
  --btn: #ffd24a; --btn-ink: #2a1f00; --btn-edge: #e2b52b; --chip: #1f3850; --chip-edge: #5f7f9c;
  --good: #66d394; --soft: #2a3a22; --line: #2d465e;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 18px/1.45 ui-rounded, "Nunito", "Trebuchet MS", system-ui, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
header {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 56px;
  flex: none;
}
.brand { font-weight: 800; font-size: 18px; white-space: nowrap; }
.tools { display: flex; gap: 2px; margin-left: auto; }
#progress { display: flex; gap: 5px; align-items: center; flex: 1; max-width: 320px; }
#progress i {
  flex: 1; height: 14px; border-radius: 7px; background: var(--line);
  position: relative; overflow: hidden; min-width: 8px;
}
#progress i::after {
  content: ""; position: absolute; inset: 0; background: var(--water); transform: scaleY(0);
  transform-origin: bottom; transition: transform 0.5s cubic-bezier(.3,1.5,.5,1);
}
#progress i.done::after { transform: scaleY(1); }
#progress i.now { outline: 2px solid var(--amber); outline-offset: 1px; }
button {
  font: inherit; cursor: pointer; min-height: 48px; min-width: 48px; border-radius: 16px;
  color: var(--ink); border: 2px solid var(--chip-edge); background: var(--chip); padding: 8px 16px;
  transition: transform 0.2s cubic-bezier(.3,1.6,.5,1), box-shadow 0.2s;
}
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
button.icon { background: transparent; border-color: transparent; font-size: 20px; padding: 4px; }
#act, #next {
  background: var(--btn); color: var(--btn-ink); border-color: var(--btn-edge); font-weight: 800;
  font-size: 19px; box-shadow: 0 4px 0 var(--btn-edge); min-height: 56px; padding: 10px 28px;
}
#act:active, #next:active { transform: translateY(3px) scale(0.98); box-shadow: 0 1px 0 var(--btn-edge); }
#replay { background: transparent; border-color: transparent; color: var(--muted); font-size: 16px; text-decoration: underline; min-height: 44px; }
#lab { flex: 1; min-height: 0; display: grid; gap: 12px; padding: 0 12px 12px; }
#stage {
  position: relative; background: var(--panel); border-radius: 22px; border: 2px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
#scene { flex: 1; width: 100%; min-height: 0; display: block; }
#caption { margin: 0; padding: 8px 14px 0; font-size: 16px; color: var(--muted); text-align: center; min-height: 0; }
#caption:empty { display: none; }
#dock { display: flex; justify-content: center; padding: 8px 12px 12px; }
#guide {
  background: var(--panel); border-radius: 22px; border: 2px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
#sheet { flex: 1; overflow-y: auto; padding: 18px 18px 8px; display: flex; flex-direction: column; justify-content: center; gap: 12px; }
h1 { font-size: 22px; line-height: 1.3; margin: 0; outline: none; }
#copy, #feedback { margin: 0; font-size: 18px; }
#copy:empty, #feedback:empty { display: none; }
#copy strong { font-weight: 800; }
#answers { display: flex; flex-direction: column; gap: 10px; }
#answers button { text-align: left; font-size: 18px; line-height: 1.3; width: 100%; box-shadow: 0 3px 0 var(--chip-edge); }
#answers button.miss { opacity: 0.6; text-decoration: line-through; }
#answers button.hit { border-color: var(--good); box-shadow: 0 3px 0 var(--good); }
#answers button:active { transform: translateY(2px); }
#controls { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 18px 16px; }
#feedback.right { color: var(--good); }
[hidden] { display: none !important; }
.pop { animation: pop 0.45s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(0.94); opacity: 0.2; } to { transform: scale(1); opacity: 1; } }
#next.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 4px 0 var(--btn-edge), 0 0 0 0 rgba(255,210,74,0.7); } 50% { box-shadow: 0 4px 0 var(--btn-edge), 0 0 0 10px rgba(255,210,74,0); } }

/* Wide screens: bench on the left, coach on the right, both visible. */
@media (min-width: 900px) and (min-height: 501px) {
  #lab { grid-template-columns: 1.25fr 1fr; padding: 0 20px 20px; gap: 18px; }
  h1 { font-size: 26px; }
  #sheet { padding: 28px 28px 8px; }
  #answers button, #copy, #feedback { font-size: 20px; }
}
/* Phones and short screens: one thing at a time. */
@media (max-width: 899px), (max-height: 500px) {
  #lab { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  #lab > section { grid-area: 1 / 1; }
  #lab[data-screen="intro"] #stage, #lab[data-screen="ask"] #stage, #lab[data-screen="result"] #stage { display: none; }
  #lab[data-screen="watch"] #guide { display: none; }
}
@media (max-width: 420px) { .brand { font-size: 15px; } header { gap: 6px; padding: 6px 8px; } #progress i { height: 12px; } h1 { font-size: 21px; } }
@media (max-height: 500px) {
  header { min-height: 44px; padding: 2px 10px; }
  #sheet { padding: 10px 16px 4px; gap: 8px; }
  h1 { font-size: 19px; } #copy, #feedback, #answers button { font-size: 16px; }
  #answers { flex-direction: row; flex-wrap: wrap; } #answers button { flex: 1 1 30%; min-height: 48px; padding: 6px 10px; }
  #controls { padding: 4px 12px 8px; flex-direction: row; justify-content: center; gap: 12px; }
  #act, #next { min-height: 48px; padding: 6px 22px; }
  #dock { padding: 4px 12px 8px; } #caption { padding-top: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 360px) { .brand { font-size: 14px; } button.icon { min-width: 44px; width: 44px; min-height: 44px; padding: 0; } header { gap: 4px; padding: 4px 6px; } }
@media (max-width: 420px) and (max-height: 640px) {
  #sheet { padding: 10px 14px 4px; gap: 8px; } h1 { font-size: 19px; } #copy, #feedback { font-size: 16px; }
  #answers { gap: 8px; } #answers button { font-size: 16px; padding: 6px 12px; min-height: 48px; }
  #controls { padding: 4px 14px 10px; }
}
@media (max-width: 360px) { #progress { gap: 3px; } #progress i { min-width: 6px; } .brand { font-size: 13px; } }
@media (max-height: 340px) {
  header { min-height: 40px; } #sheet { padding: 6px 14px 2px; gap: 5px; } h1 { font-size: 16px; line-height: 1.2; }
  #copy, #feedback, #answers button { font-size: 14px; line-height: 1.25; } #copy p { margin: 0 0 4px !important; }
  #answers button { min-height: 44px; padding: 4px 8px; } #controls { padding: 2px 12px 6px; } #act, #next { min-height: 46px; }
}
#side { display: flex; flex-direction: column; flex: none; }
@media (max-height: 500px) {
  #stage { flex-direction: row; }
  #scene { width: auto; flex: 1 1 0; min-width: 0; }
  #side { width: 190px; justify-content: center; padding: 6px 8px; }
  #caption { padding: 0 4px 8px; font-size: 14px; line-height: 1.3; }
  #dock { padding: 0; }
  #act { padding: 6px 14px; font-size: 17px; }
}

/* Wide screens: body text scales with the viewport height so nothing scrolls. */
@media (min-width: 900px) and (min-height: 501px) {
  #caption { display: none; }
  h1 { font-size: clamp(21px, 3.3vh, 32px); line-height: 1.25; }
  #copy, #feedback, #answers button { font-size: clamp(17px, 2.5vh, 23px); line-height: 1.35; }
  #copy p { margin: 0 0 clamp(6px, 1.2vh, 12px) !important; }
  #sheet { padding: clamp(16px, 3.4vh, 36px) clamp(24px, 3vw, 40px) 10px; gap: clamp(10px, 1.8vh, 18px); }
  #answers { gap: clamp(8px, 1.2vh, 12px); }
  #answers button { padding: clamp(8px, 1.4vh, 14px) 18px; }
  #act, #next { font-size: clamp(19px, 2.7vh, 24px); min-height: clamp(56px, 7.4vh, 68px); padding: 12px clamp(28px, 3vw, 44px); }
  #replay { font-size: clamp(16px, 2.1vh, 19px); }
  #controls { padding: 10px 40px clamp(14px, 3vh, 28px); gap: 6px; }
  #dock { padding: 12px 12px clamp(14px, 2.4vh, 22px); }
}
