* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #000; }
body { color: #ff0000; font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace; }
main { -webkit-touch-callout: none; position: relative; width: 100%; height: 100%; min-height: 100%; background: #000; overflow: hidden; }
[hidden] { display: none !important; }
.sr-only, #private-message, #command-input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#private-message, #command-input { opacity: 0; border: 0; padding: 0; font-size: 16px; pointer-events: none; }
#word {
  position: absolute; top: 50%; left: 50%; display: inline-flex; align-items: baseline; justify-content: center;
  white-space: nowrap; padding: 22px; min-height: 78px; color: var(--buddy-color, #ff4d4d);
  font: 400 clamp(24px, 4vw, 42px)/1.4 ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
  user-select: none; -webkit-user-select: none; caret-color: transparent; touch-action: none; cursor: pointer; outline: none;
  transform: translate(-50%, -50%) translate(var(--x, 0px), var(--y, 0px)) scale(var(--scale, 1));
  text-shadow: 0 0 var(--glow, 0px) var(--buddy-color, #ff4d4d); will-change: transform;
  animation: blink 3.4s ease-in-out infinite; opacity: var(--music-alpha, 1);
}
#letters, #dots { display: inline-flex; }
#letters button, #dots button {
  appearance: none; border: 0; background: transparent; color: inherit; font: inherit; line-height: inherit;
  padding: 0; margin: 0; min-width: .61em; outline: none; cursor: inherit; touch-action: none;
  -webkit-tap-highlight-color: transparent; -webkit-text-fill-color: currentColor; caret-color: transparent;
  box-shadow: none; border-radius: 0; text-emphasis: none; transition: color .25s, text-shadow .3s, opacity .2s;
}
#word:focus-visible { text-decoration: underline; text-underline-offset: .18em; }
#letters button:focus-visible, #dots button:focus-visible { text-decoration: underline; color: var(--buddy-color, #ff4d4d); }
#dots button { animation: period 2.7s ease-in-out infinite; }
#dots button:nth-child(2) { animation-delay: .35s; }
#dots button:nth-child(3) { animation-delay: .7s; }
#word.reward { color: var(--buddy-color, #ff4d4d); animation: none; }
#word .touched { color: var(--buddy-color, #ff4d4d); }
#word.has-roam { cursor: grab; }
#word.dragging { cursor: grabbing; animation: none; }
#word.has-light { animation: none; }
#word.has-light #dots button { animation: none; opacity: .78; }
#word.has-light #dots button.pulse { opacity: 1; color: var(--buddy-color, #ff4d4d); text-shadow: 0 0 12px var(--buddy-color, #ff4d4d); }
#word.needs-left #letters button:first-child { animation: reach-left 2.8s ease-in-out infinite; }
#word.needs-right #letters button:last-child { animation: reach-right 2.8s ease-in-out infinite; animation-delay: 1.4s; }
#word.has-training.reward #letters button { animation: nod .6s ease-in-out; }
#word.has-training.reward #letters button:nth-child(even) { animation-delay: .08s; }
#word.has-training .echo-cue { color: var(--buddy-color, #ff4d4d); text-shadow: 0 0 9px var(--buddy-color, #ff4d4d); }
#word .echo-answer { text-decoration: underline; text-decoration-color: var(--buddy-color, #ff4d4d); text-underline-offset: .2em; }
#word.unlock { color: var(--buddy-color, #ff4d4d); }
#word.has-roam.unlock { animation: greet .9s ease-in-out; }
#word.holding { color: var(--buddy-color, #ff4d4d); animation: none; }
#word.listening { animation: none; color: var(--buddy-color, #ff4d4d); }
#word.listening #dots button { animation-duration: 1.4s; }
#word.paused, #word.paused * { animation-play-state: paused !important; }
#word.paused { opacity: .8; }
#word.retry { opacity: 1; color: var(--buddy-color, #ff4d4d); }
#word.steady, #word.steady * { animation: none !important; transition: none !important; }
#word.warmup, #word.warmup * { transform: none; }
#word.warmup { transform: translate(-50%, -50%); }
#word.exploding { animation: none; text-decoration: none; }
#word.exploding button { animation: burst 1s ease-out forwards; }
#word.steady.exploding { opacity: .35; }
#ending { position: absolute; inset: 0; padding: clamp(24px, 8vw, 100px); overflow: auto; line-height: 1.65; outline: none; }
#ending h1 { font: inherit; font-size: clamp(22px, 4vw, 34px); font-weight: 700; line-height: 1.3; }
#ending p { max-width: 65ch; }
#ending button, #ending a { display: inline-block; color: inherit; font: inherit; border: 1px solid currentColor; background: transparent; padding: 10px 18px; margin: 20px 15px 10px 0; cursor: pointer; text-decoration: none; }
#ending button:focus-visible, #ending a:focus-visible { outline: 3px solid currentColor; outline-offset: 5px; }
body.win, body.win main { color: #fff; background: #0000a8; }
.error-label { display: inline-block; background: #ddd; color: #0000a8; padding: 2px 12px; letter-spacing: .06em; }
.ending-note { font-size: .8rem; opacity: .8; margin-top: 32px; }
body.loss #ending { display: flex; flex-wrap: wrap; align-content: center; justify-content: center; text-align: center; }
body.loss #loss-ending { flex-basis: 100%; }
body.loss #loss-ending p { margin-left: auto; margin-right: auto; }
body.loss h1 { letter-spacing: .18em; }
@keyframes blink { 0%, 35%, 100% { opacity: 1; } 65% { opacity: .78; } }
@keyframes period { 0%, 100% { opacity: 1; } 50% { opacity: .78; } }
@keyframes reach-left { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-9px); color: var(--buddy-color, #ff4d4d); } }
@keyframes reach-right { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(9px); color: var(--buddy-color, #ff4d4d); } }
@keyframes nod { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-5px); } }
@keyframes greet { 0%, 100% { color: var(--buddy-color, #ff4d4d); } 40% { color: var(--buddy-color, #ff4d4d); text-shadow: 0 0 18px var(--buddy-color, #ff4d4d); } }
@keyframes burst { to { transform: translate(var(--burst-x), var(--burst-y)) rotate(var(--burst-r)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #word, #word * { animation: none !important; transition: none !important; } }

/* The requested rules are the only optional on-screen help. Loading stays reachable. */
#rules { position: absolute; z-index: 2; top: max(16px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); max-height: calc(50% - 70px); overflow-y: auto; overscroll-behavior: contain; border: 1px solid #a00; background: #080000; color: #ff7777; padding: clamp(14px, 3vw, 24px); font-size: clamp(13px, 1.8vw, 15px); line-height: 1.5; outline: none; -webkit-touch-callout: default; }
#rules h2 { font: inherit; font-size: 1.2em; font-weight: 700; color: #ff9999; margin: 0 0 10px; }
#rules p { margin: 10px 0; } #rules ol { padding-left: 1.4em; } #rules li { margin: 8px 0; }
#rules .rules-keys { font-size: .9em; } #rules .rules-dismiss { border-top: 1px solid #600; padding-top: 12px; color: #ff9999; }
#word.rules-open { transform: translate(-50%, -50%); animation: none; opacity: 1; cursor: pointer; }
#word.rules-open * { animation-play-state: paused !important; }

/* The companion is revealed only on request after earning level three. */
#dj-panel { position:absolute; z-index:4; inset:auto 12px max(12px, env(safe-area-inset-bottom)); margin:0 auto; width:min(520px, calc(100% - 24px)); max-height:65%; overflow:auto; background:#080000; border:1px solid #900; color:#ff8888; padding:18px; font-size:14px; line-height:1.45; touch-action:pan-y; }
#dj-panel header { display:flex; align-items:center; justify-content:space-between; gap:12px; }
#dj-panel h2 { margin:0; font:inherit; font-weight:bold; color:#f99; }
#dj-panel button, #dj-panel input { font:inherit; color:inherit; border:1px solid #900; background:#000; padding:9px 10px; border-radius:0; }
#dj-panel button { cursor:pointer; min-height:40px; } #dj-panel button:disabled { opacity:.5; cursor:default; }
#dj-panel input { min-width:0; width:100%; font-size:16px; } #dj-panel form { display:flex; gap:6px; }
#dj-panel :focus-visible { outline:2px solid #f44; outline-offset:2px; }
#dj-panel #dj-close { border:0; font-size:24px; padding:2px 10px; }
#dj-panel #dj-mode, #dj-panel #dj-level { font-size:12px; color:#d66; }
#dj-panel #dj-reply { min-height:3em; overflow-wrap:anywhere; white-space:pre-wrap; }
.dj-actions { display:flex; gap:6px; flex-wrap:wrap; margin-top:12px; }.dj-note { font-size:11px; color:#c66; }
@media (max-width:480px) { #dj-panel { max-height:70%; padding:12px; } .dj-actions button { flex:1; } }

#word .learned-cue { color:var(--buddy-color, #ff4d4d); text-shadow:0 0 12px var(--buddy-color, #ff4d4d); text-decoration:underline; text-underline-offset:.2em; }

/* Optional controls leave the actual play surface as one red word. */
#dj-panel #dj-next { margin:4px 0; font-size:12px; color:#f99; }
#dj-progress { width:100%; height:5px; accent-color:#e33; }
.dj-pads { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:6px; margin:12px 0; }
#dj-panel .dj-pads button { min-height:48px; padding:9px 3px; border-color:#d44; color:#faa; }
#dj-panel form { margin-top:14px; }
.dj-settings { display:flex; gap:10px; margin-top:14px; }.dj-settings label { flex:1; font-size:12px; }
#dj-panel select { display:block; width:100%; margin-top:4px; background:#000; color:#faa; border:1px solid #900; padding:10px 6px; font:inherit; font-size:16px; }
#dj-panel .dj-safety { border-top:1px solid #600; padding-top:12px; }
#dj-panel summary { cursor:pointer; padding:12px 0; color:#f99; }
#dj-upgrades { padding-left:24px; font-size:12px; }#dj-upgrades li { margin:8px 0; }#dj-upgrades li[data-earned="true"] { color:#faa; }
#word.happy #letters button { animation:buddy-five .7s ease-out; }
#word.calm #letters button { animation:buddy-breathe 1.2s ease-in-out; }
#word.curious #letters button:nth-child(odd) { animation:buddy-peek .8s ease-in-out; }
@keyframes buddy-five { 40% { transform:translateY(-9px) rotate(-4deg); } }
@keyframes buddy-breathe { 50% { transform:translateY(3px); opacity:.8; } }
@keyframes buddy-peek { 45% { transform:rotate(8deg); } }
#dj-panel header { position:sticky; top:-18px; z-index:1; background:#080000; padding:8px 0; }
@media(max-width:480px) { #dj-panel header { top:-12px; } }

/* The manual is the only optional overlay. The live word stays reachable below it. */
#rules { z-index:5; width:min(660px,calc(100% - 24px)); max-height:calc(100% - 135px); }
#rules h3 { color:#faa; font-size:1em; margin:24px 0 8px; }
#rules ul { padding-left:1.4em; }
#rules .manual-header { position:sticky; top:-24px; z-index:3; background:#080000; display:flex; align-items:center; justify-content:space-between; gap:12px; padding:8px 0; }
#rules-close { color:#faa; border:1px solid #a33; background:#080000; min-width:44px; min-height:44px; font:24px monospace; cursor:pointer; }
#rules-close:focus-visible, #rules summary:focus-visible { outline:2px solid #faa; outline-offset:2px; }
#rules summary { cursor:pointer; color:#faa; font-weight:bold; padding:12px 0; }
#word.rules-open { top:auto; bottom:8px; transform:translate(-50%,0); }
#rules #dj-panel { position:static; inset:auto; transform:none; width:100%; max-height:none; overflow:visible; border:0; border-top:1px solid #600; padding:12px 0; }
#rules #dj-panel header { position:static; padding:0; }
#rules #dj-panel h3 { margin:0; }
#rules #dj-close { font-size:13px; border:1px solid #900; padding:10px; }
@media(max-width:480px) { #rules { padding:14px; } #rules .manual-header { top:-14px; } }

/* Precise input acknowledgement, including warmup and reduced-motion play. */
#word .tap-feedback { text-decoration: underline; text-decoration-thickness: .08em; text-underline-offset: .18em; }

/* Phone gestures never scroll the play surface; the manual remains scrollable. */
#stage { height: var(--viewport-height, 100dvh); min-height: 0; touch-action: none; }
#rules, #ending { touch-action: pan-y pinch-zoom; -webkit-overflow-scrolling: touch; }
.phone-controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.phone-controls button, #phone-command-form button { min-height: 44px; padding: 10px; background: #080000; color: #faa; border: 1px solid #a33; font: inherit; cursor: pointer; }
.phone-controls :focus-visible, #phone-command-form :focus-visible { outline: 2px solid #faa; outline-offset: 2px; }
#phone-command-form label { display: block; margin-bottom: 8px; }
#phone-command-form > div { display: flex; gap: 8px; }
#phone-command { min-width: 0; width: 100%; min-height: 44px; padding: 10px; background: #000; color: #faa; border: 1px solid #a33; font: 16px ui-monospace, monospace; }
#word.rules-open { bottom: max(8px, env(safe-area-inset-bottom)); }
#rules { max-height: calc(100% - 135px - env(safe-area-inset-bottom)); }
#dj-panel button { min-height: 44px; }
@media (pointer: coarse), (max-width: 600px) {
  #word { padding: 12px; font-size: clamp(24px, 5vw, 32px); }
  #letters button, #dots button { min-width: clamp(28px, 7.2vw, 36px); min-height: 44px; }
  .dj-settings { flex-wrap: wrap; }
  .dj-settings label { min-width: 130px; }
}

/* Progress stays inside requested help, never on the one-word play surface. */
.play-goal { border-block: 1px solid #600; padding: 4px 0; margin: 14px 0; }
#manual-progress { color: #faa; font-weight: 700; }
#manual-goal { overflow-wrap: anywhere; }

/* Rally cues stay on the word and remain legible with all motion disabled. */
#word .rally-cue { text-decoration: underline double; text-underline-offset: .2em; }
#word .rally-answer, #word .rally-ready { text-decoration: underline double; text-underline-offset: .2em; }
#word.rally-playing, #word.rally-playing * { animation: none !important; }
#word.rally-playing { opacity: 1; }

/* Reviews live inside help/endings: the playing surface stays word-only. */
#ending { max-height: 100dvh; overflow-y: auto; padding-bottom: max(28px, env(safe-area-inset-bottom)); touch-action: pan-y pinch-zoom; }
#play-review { max-width: 38rem; margin: 1.2rem auto; text-align: left; font-size: .9rem; line-height: 1.5; }
#play-review p { font-size: inherit; line-height: 1.5; }
#play-review select { display: block; width: 100%; min-height: 44px; font: inherit; font-size: 16px; background: #111; color: #fff; border: 1px solid #777; padding: .65rem; }
#play-review summary { cursor: pointer; min-height: 44px; }
#dj-advanced button { min-height: 44px; }

/* Scale the ink independently of a minimum 48px invisible interaction target. */
#word.custom-size { padding: 3px; min-height: 0; }
#word.custom-size #letters button, #word.custom-size #dots button { min-width: .61em; min-height: 0; }
#word::before { content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: max(100%, var(--hit-size, 48px)); height: max(100%, var(--hit-size, 48px)); z-index: -1; }
#word.warmup::before { width: 100%; height: 100%; }
#word.rules-open::before { width: max(100%, 48px); height: max(100%, 48px); }
#word.tiny:not(.rules-open) { text-shadow: none; }
#word.tiny:not(.rules-open) * { animation: none !important; text-shadow: none !important; }
.size-controls { border-block: 1px solid #600; margin: 14px 0; padding: 12px 0; }
.size-controls label { display: block; font-weight: bold; color: #faa; }
#buddy-size { display: block; width: 100%; min-height: 44px; accent-color: #f88; }
.size-controls .phone-controls { margin: 4px 0; }
.size-controls button:disabled, #buddy-size:disabled { opacity: .5; }

/* Requests briefly show only while typing or acknowledging a command. */
#command-feedback { position: absolute; z-index: 4; bottom: max(12px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); margin: 0; max-width: calc(100% - 32px); padding: 8px 12px; color: #f99; background: #000; font-size: 13px; line-height: 1.5; text-align: center; overflow-wrap: anywhere; pointer-events: none; }

#stage { --safe-left: env(safe-area-inset-left, 0px); --safe-right: env(safe-area-inset-right, 0px); --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px); }

/* A quiet, clock-driven count-in uses only the existing three periods. */
#word .rally-count-in { text-decoration: underline double; text-underline-offset: .2em; opacity: 1; }

/* The play surface remains just Loading. Touching empty space explicitly opens
   the same native form used by help, without making players find a disclosure. */
.keyboard-access:focus-visible { position: fixed; z-index: 8; top: 12px; left: 12px; width: auto; height: auto; clip-path: none; white-space: normal; padding: 12px; background: #080000; color: #faa; border: 1px solid #a33; font: 16px ui-monospace, monospace; }
.request-actions, .request-note { display: none; }
#rules.request-mode { position: fixed; top: calc(var(--viewport-top, 0px) + max(12px, env(safe-area-inset-top))); width: min(480px, calc(100% - 24px)); max-height: calc(var(--viewport-height, 100dvh) - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding: 16px; scroll-padding-block: 12px; }
#rules.request-mode > :not(.manual-header):not(#phone-commands), #rules.request-mode #phone-commands > summary, #rules.request-mode .request-examples { display: none; }
#rules.request-mode .manual-header { position: static; padding: 0; margin-bottom: 12px; }
#rules.request-mode .manual-header h2 { margin: 0; }
#rules.request-mode .request-actions { display: flex; margin-bottom: 0; }
#rules.request-mode .request-note { display: block; font-size: 12px; }
#phone-command { touch-action: manipulation; -webkit-user-select: text; user-select: text; }

#rules.request-mode.keyboard-tight { padding: 12px; }
#rules.request-mode.keyboard-tight .request-note, #rules.request-mode.keyboard-tight #phone-command-form label { display: none; }
#rules.request-mode.keyboard-tight .manual-header { margin-bottom: 4px; }
#rules.request-mode.keyboard-tight .request-actions { margin-top: 8px; }
