* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100svh; background: #201c14; color: var(--ink); font-family: var(--body-font); display: grid; place-items: center; padding: 18px; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button { border: 3px solid var(--ink); border-radius: 3px; min-height: 44px; padding: 9px 16px; font-weight: 800; box-shadow: 0 3px 0 #1c140c; }
button:hover { filter: brightness(1.13); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 #1c140c; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
.primary { background: var(--forest); color: var(--paper); letter-spacing: .045em; }
.board-button { background: var(--forest); color: var(--paper); }
.paper-button { background: var(--paper); color: var(--ink); }
.shop { width: min(1280px, 100%, calc((100svh - 36px) * 1.5)); aspect-ratio: 3 / 2; position: relative; background-image: var(--shop-image); background-size: 100% 100%; border: 5px solid #4b2c15; box-shadow: 0 14px 50px #0007; isolation: isolate; }
.shop-sign { position: absolute; top: 2.3%; left: 26.4%; width: 47%; height: 9.7%; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--paper); border: 4px solid #4b2c15; box-shadow: inset 0 0 0 3px #e4b06d, 0 4px 0 #25180d; }
.shop-sign h1 { font: 700 clamp(17px, 2.7vw, 36px)/1 var(--pixel-font); margin: 0; white-space: nowrap; letter-spacing: -.025em; }
.shop-sign h1 span { color: var(--forest); }.shop-sign h1 em { font-style: normal; color: #b84c18; }
.shop-sign p { font-size: clamp(12px, 1.3vw, 18px); font-weight: 800; margin: 3px 0 0; }
.hud { position: absolute; left: 28.2%; top: 14%; width: 44.6%; height: 10.5%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.hud div { background: #26381feb; border: 4px solid #b07b40; outline: 2px solid #493019; box-shadow: inset 0 0 0 2px #172715; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.hud span { color: var(--paper); font: 800 clamp(12px, 1.3vw, 17px)/1.2 var(--display-font); }
.hud strong { color: var(--orange); font: 950 clamp(23px, 3.2vw, 43px)/1.1 var(--display-font); text-shadow: 2px 3px #141a11; }
.audio-controls { position: absolute; left: 74.5%; top: 14%; width: 13%; display: grid; gap: 5px; }
.audio-controls button { min-height: 38px; padding: 5px 8px; font-size: 14px; }
.music-volume { display: flex; align-items: center; gap: 5px; padding: 5px; background: #20351fe8; color: var(--paper); font-size: 12px; }
.music-volume input { width: 100%; min-width: 0; accent-color: var(--leaf); }
.shop-sign.has-logo { padding-left: 124px; padding-right: 10px; }
.brand-logo { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 104px; height: calc(100% - 12px); max-height: 60px; padding: 6px; object-fit: contain; background: #fff; border: 2px solid #4b2c15; border-radius: 0; box-shadow: 2px 2px 0 #c5995c; }
.course-tag { position: absolute; left: 29%; top: 26.2%; width: 43%; color: var(--paper); font: 800 clamp(12px, 1.15vw, 15px)/1.3 var(--display-font); text-align: center; background: #271b10d9; padding: 5px 8px; }
#device-label { display: none; }
.conveyor { position: absolute; left: 0; top: 47%; width: 100%; height: 20.5%; }
.supply { position: absolute; left: 2%; top: 0; width: 22%; height: 100%; }
.supply img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.tray { position: absolute; bottom: 0; }
.active-tray { left: 36.5%; width: 32.5%; height: 113%; }
.next-tray { left: 73%; width: 23%; height: 91%; }
.tray-base { width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; }
.gear { position: absolute; object-fit: contain; image-rendering: pixelated; left: 19%; top: 10%; width: 62%; height: 68%; }
.next-tray .gear { left: 24%; top: 8%; width: 52%; height: 57%; }
.tray-label { position: absolute; z-index: 1; top: -13%; left: 50%; transform: translateX(-50%); padding: 4px 12px; background: var(--paper); border: 2px solid var(--wood); font: 800 clamp(12px, 1.2vw, 16px)/1.1 var(--display-font); white-space: nowrap; }
.active-tray .tray-label { color: var(--paper); background: var(--forest); border-color: var(--leaf); }
.next-word { position: absolute; bottom: 30%; left: 12%; width: 76%; text-align: center; font: 700 clamp(12px, 1.2vw, 16px)/1.1 var(--display-font); color: var(--ink); }
.word-board { position: absolute; top: 68.5%; left: 20%; width: 60%; height: 15.5%; padding: 8px 17px 8px; border: 4px solid #694422; box-shadow: 0 3px 0 #25170b, inset 0 0 0 3px #e5bd7b; background: var(--paper); display: flex; flex-direction: column; align-items: center; }
.word-top,.word-bottom { display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: clamp(12px, 1.1vw, 15px); font-weight: 700; line-height: 1.2; }
.word-top { color: #61421f; }.word-bottom { margin-top: auto; }
#combo { color: #467634; }.word { margin: auto 0; white-space: pre; font: 700 clamp(25px, 4.1vw, 56px)/1 var(--display-font); letter-spacing: .02em; text-transform: uppercase; flex-shrink: 1; }
.word.long { font-size: clamp(20px, 3.3vw, 44px); }
.word .typed { color: var(--green); }.word .cursor { text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 5px; }
.lifetime { position: absolute; width: calc(100% - 14px); height: 5px; left: 7px; bottom: 1px; background: #d8b984; }
.lifetime span { display: block; width: 100%; height: 100%; background: var(--green); transform-origin: left; }
.start-controls,.typing-controls { position: absolute; top: 85.5%; left: 20%; width: 60%; height: 6.5%; display: flex; align-items: center; gap: 10px; }
.start-controls label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
select { min-width: 0; width: 55%; padding: 10px; border: 3px solid var(--wood); min-height: 44px; background: var(--paper); color: var(--ink); font-weight: 700; }
.start-controls .primary { flex: 1; white-space: nowrap; }
.typing-controls input { min-width: 0; width: 63%; height: 46px; padding: 10px 14px; background: var(--paper); color: var(--ink); border: 3px solid var(--wood); border-radius: 0; }
.typing-controls button { flex: 1; padding: 8px; }
.shop-footer { position: absolute; left: 2%; bottom: 1%; width: 96%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.shop-footer p { margin: 0; padding: 7px 10px; background: #26190ee6; color: var(--paper); font-size: clamp(12px, 1.05vw, 14px); }
.shop-footer div { display: flex; gap: 8px; }.shop-footer button { min-height: 38px; padding: 6px 10px; font-size: 14px; }
.feedback { position: absolute; top: 37%; left: 30%; width: 40%; text-align: center; background: #20351fec; color: var(--paper); font-weight: 800; font-size: 16px; padding: 8px; margin: 0; border: 2px solid var(--leaf); pointer-events: none; }
.feedback:empty { display: none; }.shop.mistake .word-board { border-color: var(--danger); }.shop.mistake #word-status { color: var(--danger); }
.storage-note { position: absolute; top: 31%; left: 28%; width: 44%; text-align: center; margin: 0; padding: 4px; color: var(--paper); background: #44241ce6; font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
dialog { padding: 0; max-width: min(620px, calc(100% - 32px)); max-height: calc(100svh - 32px); background: var(--paper); color: var(--ink); border: 5px solid var(--wood); box-shadow: 0 8px 0 #2b1c10, 0 25px 80px #0008; }
dialog::backdrop { background: #152315ae; }
.dialog-content { padding: 28px; }.dialog-content h2 { font: 900 32px/1.15 var(--display-font); margin: 4px 0 16px; }
.eyebrow { color: var(--green); font: 800 14px/1.3 var(--display-font); letter-spacing: .12em; margin: 0; }
.dialog-content p,.dialog-content li { font-size: 16px; line-height: 1.5; }.dialog-content li { margin-bottom: 10px; }.dialog-content ul { padding-left: 21px; }
.dialog-content button { margin: 12px 6px 0 0; }.dialog-content details { margin: 18px 0; }.dialog-content summary { cursor: pointer; font-weight: 800; }
.dialog-content .small { font-size: 14px; }.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }.result-grid div { background: #233b21; padding: 15px; color: var(--paper); }.result-grid dt { font-size: 14px; }.result-grid dd { margin: 4px 0 0; font: 900 30px/1 var(--display-font); color: var(--orange); }
.glossary-content { width: 580px; max-width: 100%; }.glossary-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }.glossary-item { display: grid; grid-template-columns: 55px 1fr; align-items: center; background: #efd3a0; padding: 8px; gap: 9px; }.glossary-item img { width: 55px; height: 55px; object-fit: contain; image-rendering: pixelated; }.glossary-item strong { font-size: 16px; }.glossary-item span { display: block; font-size: 14px; line-height: 1.3; margin-top: 4px; }
@media (max-width: 850px), (max-height: 600px) {
  body { padding: 10px; }.shop { width: min(1100px, 100%); }.shop-sign h1 { font-size: clamp(17px, 2.55vw, 26px); }.hud { gap: 5px; }.hud div { border-width: 2px; }.word-board { padding: 7px 12px 5px; }.word { font-size: clamp(25px, 4.3vw, 44px); }.word-top,.word-bottom { font-size: 12px; }.typing-controls,.start-controls { left: 14%; width: 72%; }.shop-footer p { max-width: 54%; }.shop-footer button { padding: 5px 8px; font-size: 12px; }.course-tag { top: 26%; font-size: 12px; }
}
@media (max-width: 640px) {
  body { display: block; padding: 0; background: #362619; }.shop { width: 100%; min-height: 720px; aspect-ratio: auto; border-width: 0; background-size: auto 720px; background-position: center top; background-repeat: no-repeat; padding: 20px 14px 18px; display: flex; flex-direction: column; align-items: center; }
  .shop-sign { position: relative; inset: auto; width: 100%; height: 74px; flex-shrink: 0; }.shop-sign h1 { font-size: clamp(21px, 5.5vw, 32px); }.shop-sign p { font-size: 14px; }
  .shop-sign.has-logo { padding-left: 90px; }.brand-logo { left: 8px; width: 72px; height: 48px; padding: 4px; }
  .hud { position: relative; inset: auto; width: 100%; height: 80px; margin-top: 17px; flex-shrink: 0; gap: 8px; }.hud span { font-size: 14px; }.hud strong { font-size: 32px; }
  .audio-controls { position: relative; inset: auto; width: 100%; margin-top: 10px; grid-template-columns: 1fr 1fr; gap: 7px; }.audio-controls button { min-height: 40px; font-size: 14px; }.music-volume { grid-column: 1 / -1; font-size: 14px; padding: 5px 12px; }.music-volume input { min-height: 26px; }
  .course-tag { position: relative; inset: auto; width: 100%; margin-top: 6px; padding: 6px; font-size: 12px; }#device-label { display: block; color: var(--leaf); margin-top: 2px; }
  .conveyor { position: relative; inset: auto; width: 100%; height: 150px; margin-top: 20px; flex-shrink: 0; }.supply { display: none; }.active-tray { left: 0; width: 62%; height: 95%; }.next-tray { left: 64%; width: 36%; height: 67%; bottom: 13px; }.tray-label { font-size: 12px; padding: 4px 8px; top: -14px; }.next-word { font-size: 12px; bottom: 20%; }.gear { height: 62%; top: 11%; }
  .word-board { position: relative; inset: auto; width: 100%; height: 128px; flex-shrink: 0; margin-top: 12px; padding: 12px; }.word { font-size: clamp(27px, 7.8vw, 45px); }.word.long { font-size: clamp(21px, 5.7vw, 32px); }.word-top,.word-bottom { font-size: 14px; }#word-count { font-size: 12px; }
  .start-controls,.typing-controls { position: relative; inset: auto; width: 100%; height: auto; margin-top: 16px; flex-wrap: wrap; gap: 8px; }.start-controls select { width: 100%; font-size: 16px; }.start-controls .primary { flex: auto; width: 100%; }.typing-controls input { width: 100%; height: 48px; font-size: 16px; }.typing-controls button { flex: 1; }
  .shop-footer { position: relative; inset: auto; width: 100%; margin-top: 17px; flex-direction: column; gap: 10px; }.shop-footer p { font-size: 12px; max-width: 100%; width: 100%; text-align: center; line-height: 1.4; }.shop-footer button { font-size: 14px; padding: 8px 12px; min-height: 44px; }
  .feedback { position: absolute; top: 256px; width: calc(100% - 28px); left: 14px; z-index: 3; font-size: 14px; }.storage-note { position: relative; inset: auto; width: 100%; order: 12; margin-top: 10px; }
  .dialog-content { padding: 21px; }.dialog-content h2 { font-size: 28px; }.glossary-list { grid-template-columns: 1fr; }.glossary-item { grid-template-columns: 60px 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .active-tray.catch { animation: catch .22s ease-out; }@keyframes catch { 50% { transform: translateY(-7px); } }
}
/* Mobile play fits above the software keyboard. Setup and desktop keep the shop. */
@media (max-width: 640px) {
  body.mobile-playing { overflow: hidden; }
  .shop.mobile-play { position: fixed; top: var(--play-top, 0px); left: 0; height: var(--play-height, 100dvh); min-height: 0; width: 100%; padding: 10px 10px 18px; gap: 8px; overflow-y: auto; background-size: auto 720px; background-position: center top; }
  .mobile-play .shop-sign, .mobile-play .audio-controls, .mobile-play .course-tag, .mobile-play .shop-footer, .mobile-play .feedback { display: none; }
  .mobile-play .hud { height: 44px; margin: 0; grid-template-columns: 1fr 1fr; gap: 8px; }
  .mobile-play .hud div:last-child { display: none; }
  .mobile-play .hud span { font-size: 11px; }
  .mobile-play .hud strong { font-size: 23px; line-height: 1; }
  .mobile-play .conveyor { width: 90%; height: min(90px, calc(var(--play-height, 400px) * .2)); margin: 14px 0 0; }
  .mobile-play .active-tray { height: 100%; }
  .mobile-play .next-tray { height: 80%; bottom: 0; }
  .mobile-play .tray-label { font-size: 10px; padding: 3px 7px; top: -13px; }
  .mobile-play .next-word { font-size: 10px; }
  .mobile-play .word-board { height: 106px; min-height: 106px; margin: 0; padding: 9px; }
  .mobile-play .word { font-size: clamp(30px, 8vw, 42px); }
  .mobile-play .word.long { font-size: clamp(21px, 5.4vw, 30px); }
  .mobile-play .word-top, .mobile-play .word-bottom { font-size: 12px; }
  .mobile-play .typing-controls { margin: 0; flex-wrap: nowrap; gap: 6px; flex-shrink: 0; }
  .mobile-play .typing-controls input { flex: 1; width: 0; height: 46px; padding: 8px; font-size: 16px; }
  .mobile-play .typing-controls button { flex: 0 0 64px; padding: 8px 4px; min-height: 46px; font-size: 13px; }
  .mobile-play.mobile-tight .conveyor { display: none; }
  .mobile-play.mobile-tight .word-board { height: 92px; min-height: 92px; }
  body.mobile-playing dialog[open] { position: fixed; top: var(--play-top, 0px); bottom: auto; margin: 8px auto; max-height: calc(var(--play-height, 100svh) - 16px); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; } }

/* Shared ranking stays outside the gameplay HUD and never substitutes for LOCAL BEST. */
.ranking-submit { margin: 1.25rem 0; padding: 1rem; border: 1px solid #aab797; border-radius: 8px; background: #eaf0df; }
.ranking-submit h3 { margin: 0 0 .5rem; }
.ranking-submit form > label:first-child { display: block; margin-bottom: .35rem; font-weight: 700; }
.ranking-submit input[type="text"] { width: 100%; font: inherit; color: #203720; padding: .65rem; border: 2px solid #6a7f57; border-radius: 5px; background: #fffdf4; }
.ranking-submit .consent { display: flex; align-items: flex-start; gap: .5rem; margin: .8rem 0; font-size: .9rem; }
.ranking-submit .consent input { flex: 0 0 auto; margin-top: .2rem; }
.ranking-submit .primary { width: 100%; }
.ranking-environment { padding: .55rem .75rem; background: #e7ecd8; color: #26442a; border-radius: 5px; font-size: .85rem; font-weight: 800; }
.ranking-content { max-width: 560px; }
#ranking-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: .9rem; }
#ranking-table th { color: #385038; text-align: left; }
#ranking-table th, #ranking-table td { padding: .55rem .3rem; border-bottom: 1px solid #c9ceb5; }
#ranking-table th:nth-child(n+3), #ranking-table td:nth-child(n+3) { text-align: right; }
#ranking-table td:nth-child(2) { overflow-wrap: anywhere; max-width: 190px; }
#ranking-table td:nth-child(n+3) { font-variant-numeric: tabular-nums; white-space: nowrap; }
button:disabled { cursor: default; opacity: .65; }
@media (max-width: 400px) { #ranking-table { font-size: .78rem; } #ranking-table th, #ranking-table td { padding: .45rem .15rem; } }
