:root {
  color-scheme: dark;
  --arena: #163b3f;
  --text: #dce6d9;
  --muted: #96afa5;
  --line: #a6c7b52b;
  --panel: #143639b8;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--arena); color: var(--text); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .32; cursor: default; }
button:focus-visible { outline: 2px solid #e9b27b; outline-offset: 4px; }
button:hover:not(:disabled) { background-color: #42645c; border-color: #c4ddc870; }
[hidden] { display: none !important; }
.arena { position: relative; width: 100%; height: 100vh; height: 100dvh; overflow: hidden; isolation: isolate; }
#board { display: block; width: 100%; height: 100%; touch-action: none; }
#board:focus-visible { outline: 2px solid #c7b58c55; outline-offset: -3px; }
.arena-top, .arena-controls { position: absolute; left: max(32px, env(safe-area-inset-left)); right: max(32px, env(safe-area-inset-right)); z-index: 2; display: flex; justify-content: space-between; pointer-events: none; }
.arena-top { top: max(26px, env(safe-area-inset-top)); align-items: center; }
.arena-top button, .arena-controls button { pointer-events: auto; }
.level-badge { display: flex; align-items: center; gap: 9px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font-size: 11px; font-weight: 500; letter-spacing: 1.5px; }
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: #e4b78c; }
.level-heading { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; min-width: 0; }
.level-chevron { margin-left: 3px; color: #a6c2b1; font-size: 15px; line-height: .7; }
.level-seed { display: block; max-width: min(350px, 40vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #a4bca9; font-size: 9px; letter-spacing: 1px; padding-left: 3px; }
.hud-right { display: flex; align-items: center; gap: 28px; }
.arena-stats { display: flex; align-items: center; gap: 19px; }
.arena-stats > span { display: flex; align-items: baseline; gap: 10px; font-size: 10px; color: var(--muted); letter-spacing: 1.5px; }
.arena-stats strong { color: var(--text); font-size: 24px; font-weight: 450; font-variant-numeric: tabular-nums; letter-spacing: -.6px; }
.arena-stats i { width: 1px; height: 20px; background: var(--line); }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); }
.icon-button svg { width: 18px; height: 18px; }
.arena-controls { bottom: max(28px, env(safe-area-inset-bottom)); align-items: flex-end; gap: 24px; }
.actions { display: flex; align-items: center; gap: 10px; }
.actions button, .key, .switch-cube { border: 1px solid var(--line); border-radius: 7px; background: var(--panel); backdrop-filter: blur(8px); }
.actions button { min-height: 44px; padding: 10px 14px; display: flex; align-items: center; gap: 9px; font-size: 12px; white-space: nowrap; }
.actions button > span { font-size: 23px; line-height: 1; color: #b8d3b8; }
kbd { font-family: inherit; font-size: 9px; line-height: 1.2; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px; }
.controls-card { flex-shrink: 0; }
.controls-row { display: flex; align-items: center; gap: 18px; }
.controls-row p { margin: 0; color: #bbcec0; font-size: 11px; line-height: 1.9; }
.controls-row strong { display: block; margin-bottom: 5px; font-size: 9px; font-weight: 600; letter-spacing: 1.6px; color: #d5e1d1; }
.controls-row p span { display: block; font-size: 10px; color: var(--muted); }
.key-grid { display: grid; grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); gap: 5px; }
.key { padding: 0; font-size: 22px; line-height: 1; color: #d3e2cd; }
.key:active, .key.pressed { background: #547767; transform: translateY(1px); }
.up { grid-column: 2; grid-row: 1; }
.left { grid-column: 1; grid-row: 2; }
.down { grid-column: 2; grid-row: 3; }
.right { grid-column: 3; grid-row: 2; }
.switch-cube { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 40px; margin-top: 10px; padding: 8px; font-size: 11px; gap: 12px; }
.toast { position: absolute; top: 90px; left: 50%; z-index: 7; transform: translate(-50%, -8px); width: max-content; max-width: min(570px, calc(100% - 48px)); padding: 11px 17px; border: 1px solid #b7cdb545; border-radius: 8px; background: #15373bf2; color: #d8e5d6; box-shadow: 0 6px 24px #09232b35; font-size: 12px; line-height: 1.6; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.loading { position: absolute; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; background: var(--arena); color: #bfd0c0; }
.loading strong { font-size: 15px; font-weight: 450; }
.loader-cube { width: 30px; height: 30px; border-radius: 4px; background: #e4ab77; animation: tumble 1.4s infinite ease-in-out; }
@keyframes tumble { 50% { transform: rotate(90deg) translate(10px, -10px); } 100% { transform: rotate(180deg); } }
.result { position: absolute; inset: 0; z-index: 8; display: grid; grid-template-columns: minmax(0,1fr); place-items: center; padding: 20px; overflow-y: auto; background: #09272bb3; backdrop-filter: blur(7px); }
.result-card { width: 460px; max-width: 100%; padding: 34px 30px 30px; border: 1px solid #97c1a76b; border-radius: 22px; background: radial-gradient(ellipse at 50% 0%, #3a6253 0%, #214744 70%); text-align: center; box-shadow: 0 8px 0 #102f31, 0 22px 70px #031b2477, inset 0 1px 0 #d2e7b526; animation: result-in .35s cubic-bezier(.2,.8,.2,1) both; }
.result-card h1 { margin: 0 0 12px; font-size: clamp(24px, 4.5vw, 36px); line-height: 1.1; font-weight: 850; letter-spacing: -.8px; text-transform: uppercase; color: #f4f6e9; text-shadow: 0 3px 0 #143a38; }
#result-description { margin: 0; color: #f0f3df; font-size: 29px; line-height: 1.2; font-weight: 750; text-transform: uppercase; font-variant-numeric: tabular-nums; }
.result-card .result-detail { margin: 7px 0 0; color: #b8cdb6; font-size: 12px; line-height: 1.5; }
.stars { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 24px 0 30px; }
.stars svg { width: 64px; height: 64px; overflow: visible; fill: #f6ca60; stroke: #ffe8a0; stroke-width: 1.6; stroke-linejoin: round; filter: drop-shadow(0 4px 0 #a67837) drop-shadow(0 0 12px #ffd56a26); animation: star-in .4s cubic-bezier(.2,.8,.3,1.3) both; animation-delay: calc(.12s + var(--star) * .12s); }
.stars svg:nth-child(2) { width: 76px; height: 76px; }
.stars svg.dim { fill: #36584e; stroke: #638371; filter: none; }
.result-actions { display: grid; grid-template-columns: 76px minmax(0,1fr); gap: 12px; }
.result-actions button { height: 66px; display: flex; align-items: center; justify-content: center; border: 1px solid #bbd6a078; border-radius: 12px; box-shadow: 0 5px 0 #102f2d, inset 0 1px 0 #edffd12b; transition: transform .12s, filter .12s; }
.result-replay { background: #365e4e; color: #d8e9bc; }
.result-replay svg { width: 31px; height: 31px; }
.analytics-prompt { position: absolute; z-index: 10; top: 94px; left: 50%; transform: translateX(-50%); width: min(400px, calc(100% - 32px)); padding: 14px 17px; border: 1px solid #88aa8c70; border-radius: 12px; background: #214744f5; box-shadow: 0 8px 30px #08272b55; }
.analytics-prompt p { margin: 0 0 12px; font-size: 12px; line-height: 1.5; color: #c3d4c2; }
.analytics-prompt strong { display: block; margin-bottom: 3px; color: #edf2de; font-size: 14px; }
.analytics-prompt > div { display: flex; gap: 8px; }
.analytics-prompt button { padding: 8px 12px; border: 1px solid #a4bea45e; border-radius: 6px; background: #365e4e; font-size: 12px; }
.analytics-prompt .quiet-button { margin-left: auto; border-color: transparent; background: transparent; color: #bdcfb7; text-decoration: underline; }
.privacy-copy { font-size: 13px; line-height: 1.65; color: #bdd0c2; }
.privacy-copy p { margin: 18px 0; }
.privacy-actions { display: flex; gap: 10px; }
.privacy-actions .primary-button { justify-content: center; }
#analytics-status { color: #e5d6a3; }
.result-next { gap: 14px; background: linear-gradient(#94b278,#779c64); color: #faffea; font-size: 23px; font-weight: 800; text-transform: uppercase; letter-spacing: .2px; text-shadow: 0 2px 0 #4e714d; }
.result-next svg { width: 27px; height: 27px; flex-shrink: 0; }
.result-actions button:hover { filter: brightness(1.1); transform: translateY(-2px); }
.result-actions button:active { transform: translateY(3px); box-shadow: 0 2px 0 #102f2d; }
@keyframes result-in { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes star-in { from { opacity: 0; transform: translateY(10px) scale(.65); } to { opacity: 1; transform: none; } }
.primary-button { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 12px 16px; border: 1px solid #a4bea45e; border-radius: 6px; background: #74917c; color: #f5f4e9; font-size: 13px; }
.primary-button span { font-size: 19px; }
.text-button { border: 0; padding: 18px 8px 0; background: transparent; font-size: 11px; color: #baceb8; }
.no-script { position: absolute; inset: 40% 20px auto; padding: 20px; background: #335650; text-align: center; }
dialog { width: min(640px, calc(100% - 32px)); max-height: min(800px, calc(100dvh - 40px)); padding: 27px; border: 1px solid #739b845c; border-radius: 15px; background: #193f40; color: var(--text); box-shadow: 0 25px 80px #031a226b; overflow-y: auto; }
dialog::backdrop { background: #08272da8; backdrop-filter: blur(5px); }
.selector-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.selector-head h2 { margin: 0; font-size: 25px; font-weight: 550; letter-spacing: -.6px; }
.selector-head p { margin: 8px 0 0; color: #a5bfb0; font-size: 12px; line-height: 1.5; }
.dialog-close { width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: #254c48; font-size: 23px; line-height: 1; flex-shrink: 0; }
.selector-section { margin: 24px 0 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.selector-section > span { font-size: 11px; color: #b9cdbb; letter-spacing: 1px; text-transform: uppercase; }
.selector-section .text-button { padding: 4px; font-size: 11px; }
.level-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 9px; }
.level-choice { display: flex; flex-direction: column; align-items: flex-start; min-height: 89px; gap: 7px; padding: 12px; border: 1px solid #8cb49c38; border-radius: 8px; background: #214946; overflow: hidden; text-align: left; }
.level-choice.current { border-color: #e0b47c; background: #3c594b; }
.level-choice:disabled { opacity: .38; }
.level-choice strong { font-size: 13px; font-weight: 550; }
.level-choice small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; color: #aac5ad; }
.level-choice .level-score { font-size: 11px; letter-spacing: 2px; color: #e1b779; }
.level-score .dim { color: #587668; }
.selector-pages { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 16px 0 21px; }
.selector-pages button { min-width: 35px; height: 31px; border: 1px solid var(--line); border-radius: 5px; background: #254b46; }
.selector-pages span { font-size: 11px; color: #b2c7b5; }
.custom-level-form { border-top: 1px solid var(--line); padding-top: 20px; }
.custom-level-form label { display: block; margin-bottom: 10px; font-size: 13px; }
.seed-entry { display: flex; gap: 9px; }
.seed-entry input { min-width: 0; flex: 1; padding: 11px 12px; border: 1px solid #8bad934d; border-radius: 6px; background: #113438; color: #dce7d5; font: inherit; font-size: 13px; }
.seed-entry input:focus-visible { outline: 2px solid #e0b47c; outline-offset: 2px; }
.seed-entry .primary-button { width: 140px; flex-shrink: 0; }
.custom-level-form p { margin: 10px 0 0; font-size: 11px; line-height: 1.6; color: #a1b9a6; }
#seed-error { color: #efb79b; }
@media (min-width: 1600px) { .arena-top, .arena-controls { left: 44px; right: 44px; } .arena-top { top: 32px; } .arena-controls { bottom: 36px; } }
@media (max-width: 760px) {
  .arena-top, .arena-controls { left: max(20px, env(safe-area-inset-left)); right: max(20px, env(safe-area-inset-right)); }
  .arena-top { top: max(20px, env(safe-area-inset-top)); }
  .arena-controls { bottom: max(20px, env(safe-area-inset-bottom)); gap: 18px; }
  .hud-right { gap: 17px; }
  .arena-stats { gap: 12px; }
  .actions { gap: 7px; }
  .actions button { padding: 9px 11px; gap: 7px; }
  .actions kbd { display: none; }
  .controls-row p { display: none; }
}
@media (max-width: 480px) {
  .result-card { padding: 28px 21px 25px; border-radius: 18px; }
  .result-actions { grid-template-columns: 64px minmax(0,1fr); gap: 9px; }
  .result-actions button { height: 61px; }
  .result-next { font-size: 19px; gap: 9px; }
  .stars { gap: 8px; }
  .stars svg { width: 56px; height: 56px; }
  .stars svg:nth-child(2) { width: 67px; height: 67px; }
  .arena-top, .arena-controls { left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); }
  .level-badge { font-size: 9px; letter-spacing: 1px; padding: 10px; gap: 7px; }
  .hud-right { gap: 12px; }
  .arena-stats { gap: 10px; }
  .arena-stats > span { font-size: 8px; letter-spacing: .8px; gap: 6px; }
  .arena-stats strong { font-size: 21px; }
  .arena-stats i { height: 16px; }
  .icon-button { width: 34px; height: 34px; }
  .icon-button svg { width: 15px; height: 15px; }
  .arena-controls { align-items: flex-end; gap: 12px; }
  .actions { flex-direction: column; gap: 6px; align-items: stretch; }
  .actions button { min-height: 39px; padding: 8px 11px; font-size: 11px; }
  .actions button > span { font-size: 21px; }
  .key-grid { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); }
  .switch-cube { font-size: 10px; margin-top: 8px; }
  .switch-cube kbd { display: none; }
  .toast { top: 76px; max-width: calc(100% - 32px); font-size: 11px; padding: 10px 13px; }
  .level-seed { max-width: 135px; font-size: 8px; letter-spacing: .5px; }
  dialog { padding: 20px; max-height: calc(100dvh - 24px); }
  .selector-head h2 { font-size: 22px; }
  .level-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .level-choice { min-height: 80px; padding: 10px; }
  .seed-entry { flex-direction: column; }
  .seed-entry .primary-button { width: 100%; }
}
@media (max-height: 500px) and (min-width: 481px) {
  .result-card { padding: 22px 28px; }
  .result-card h1 { font-size: 30px; margin-bottom: 7px; }
  #result-description { font-size: 25px; }
  .stars { margin: 13px 0 21px; }
  .stars svg { width: 49px; height: 49px; }
  .stars svg:nth-child(2) { width: 58px; height: 58px; }
  .result-actions button { height: 54px; }
  .arena-top { top: max(12px, env(safe-area-inset-top)); }
  .arena-controls { bottom: max(12px, env(safe-area-inset-bottom)); }
  .controls-row p { display: none; }
  .key-grid { grid-template-columns: repeat(3, 36px); grid-template-rows: repeat(3, 36px); gap: 4px; }
  .key { font-size: 19px; }
  .switch-cube { position: absolute; bottom: 0; right: 132px; width: auto; min-height: 40px; margin: 0; }
  .switch-cube kbd { display: none; }
  .toast { top: 65px; padding: 7px 13px; font-size: 11px; }
}
@media (min-width: 481px) and (max-width: 620px) and (max-height: 500px) {
  .arena-controls:has(.switch-cube:not([hidden])) .actions { flex-direction: column; align-items: stretch; gap: 4px; }
  .arena-controls:has(.switch-cube:not([hidden])) .actions button { min-height: 34px; padding: 5px 10px; font-size: 11px; }
  .arena-controls:has(.switch-cube:not([hidden])) .actions button > span { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

