:root{color-scheme:light;--paper:#f2f0e7;--picker:#f8f7f0;--ink:#283b36;--muted:#69786b;--line:#d8dcd0;--sage:#70867b;--amber:#d88c58;--hover:#e5e7dc;--key:#e1e5d9;--key-hover:#dbe0d2;--utility:#e8e9df;--key-shadow:#cdd4c5;--focus:#ced5c7;--next-ink:#283b36;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:var(--ink);background:var(--paper)}
*{box-sizing:border-box}body{margin:0;min-width:280px;min-height:100svh;display:flex;flex-direction:column}button,a{-webkit-tap-highlight-color:transparent}button{font:inherit;cursor:pointer;color:inherit}button:disabled{cursor:default;opacity:.35}button:focus-visible,a:focus-visible{outline:2px solid var(--sage);outline-offset:5px}button[hidden],[hidden]{display:none!important}svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}a{color:inherit;text-decoration:none}
.topbar{width:min(1100px,100%);padding:28px 30px 22px;margin:0 auto;display:grid;grid-template-columns:1fr auto 1fr;align-items:center}.home{display:flex;align-items:center;gap:4px;font-size:12px;letter-spacing:.03em;width:fit-content;opacity:.65}.home:hover{opacity:1}.home img{width:20px;height:20px;flex-shrink:0}.wordmark{font-family:Georgia,"Times New Roman",serif;font-size:28px;letter-spacing:.28em;position:relative;padding-left:.28em}.brand-dot{position:absolute;background:var(--amber);width:5px;height:5px;border-radius:50%;right:-10px;top:3px}.fullscreen{justify-self:end}
main{width:min(900px,100%);margin:0 auto;flex:1;display:flex;flex-direction:column;align-items:center}
/* The selector has a fixed footprint; the paged list floats over the board. */
.room-selector{position:relative;z-index:2;display:flex;align-items:center;justify-content:center;gap:12px;height:62px;flex-shrink:0;width:100%}
.room-trigger{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-width:116px;min-height:44px;padding:8px 16px;border:1px solid var(--line);border-radius:24px;background:var(--paper);font-size:14px;font-variant-numeric:tabular-nums;letter-spacing:.05em}
.room-trigger:hover{background:var(--hover)}.room-trigger svg{width:16px;height:16px;transition:transform .15s}.room-trigger[aria-expanded=true] svg{transform:rotate(180deg)}.room-total{color:var(--muted);font-size:12px;letter-spacing:0}
.room-picker{position:absolute;top:58px;left:50%;transform:translateX(-50%);width:min(330px,calc(100% - 16px));padding:14px;background:var(--picker);border:1px solid var(--line);border-radius:20px;box-shadow:0 12px 36px #101b1726}
.room-groups{display:grid;grid-template-columns:repeat(auto-fit,minmax(44px,1fr));gap:4px;margin-bottom:10px}.room-groups button{min-height:44px;padding:6px 4px;background:transparent;border:0;border-radius:22px;color:var(--muted);font-size:12px;white-space:nowrap}.room-groups button:hover{background:var(--hover)}.room-groups button[aria-pressed=true]{color:var(--ink);background:var(--key)}
.rooms{display:grid;grid-template-columns:repeat(5,44px);justify-content:center;gap:6px 8px}
.rooms button{background:transparent;border:1px solid transparent;width:44px;height:44px;border-radius:50%;font-size:12px;letter-spacing:.04em;position:relative;transition:background .15s,border-color .15s}.rooms button:hover{background:var(--hover)}.rooms button[aria-pressed=true]{background:var(--ink);color:var(--paper);border-color:var(--ink)}.rooms button[data-solved=true]:after{content:"";position:absolute;bottom:4px;left:calc(50% - 2px);width:4px;height:4px;border-radius:50%;background:var(--sage)}.rooms button[aria-pressed=true][data-solved=true]:after{background:var(--paper)}
.room-progress{display:flex;align-items:center;justify-content:space-between;border-top:1px solid var(--line);margin-top:12px;padding-top:10px;color:var(--muted);font-size:11px}.room-legend{display:flex;align-items:center;gap:6px}.room-dot{width:4px;height:4px;border-radius:50%;background:var(--sage)}

.game-surface{position:relative;width:100%;height:clamp(120px,min(52svh,calc(100svh - 355px - env(safe-area-inset-top) - env(safe-area-inset-bottom))),500px)}canvas{width:100%;height:100%;display:block;touch-action:none}.launch{position:absolute;inset:0;background:var(--paper);display:grid;place-items:center}.launch-inner{display:grid;justify-items:center;gap:26px}.loading-mark{width:38px;height:38px;border:2px solid var(--sage);border-radius:50%;position:relative;animation:breath 1.6s ease-in-out infinite}.loading-mark:before{content:"";position:absolute;inset:8px;border:1px solid var(--sage);border-radius:50%}#loading-status{font-size:12px;color:var(--muted);max-width:280px;text-align:center;line-height:1.6}#retry{border:1px solid var(--line);background:transparent;border-radius:24px;padding:10px 22px}.toolbar{width:min(310px,calc(100% - 32px));height:48px;display:grid;grid-template-columns:1fr auto 1fr;align-items:center}.tools{display:flex;gap:2px}.icon-button{display:inline-grid;place-items:center;border:0;border-radius:50%;background:transparent;width:46px;height:46px;transition:background .15s,transform .15s}.icon-button:hover:not(:disabled){background:var(--hover)}.icon-button:active:not(:disabled){transform:scale(.94)}.move-meter{grid-column:2;display:flex;align-items:center;gap:8px;font-variant-numeric:tabular-nums;font-size:12px;color:var(--muted);min-width:42px;justify-content:center}.move-meter svg{width:18px;height:18px;color:var(--sage)}.next{grid-column:3;justify-self:end;background:#dfe7d9}.direction-pad{display:grid;grid-template-columns:repeat(3,56px);gap:7px;margin:0 0 16px}.direction-pad .icon-button{position:relative;background:var(--key);width:56px;height:54px;border-radius:12px;box-shadow:0 2px 0 var(--key-shadow)}.direction-pad .utility-key{background:var(--utility)}.shortcut{position:absolute;right:7px;bottom:4px;font-size:9px;color:var(--muted);line-height:1}.direction-pad .icon-button:hover:not(:disabled){background:var(--key-hover)}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
@keyframes breath{50%{opacity:.35;transform:scale(.92)}}@media(max-width:540px){.topbar{padding:18px 18px 12px}.home span{font-size:11px}.wordmark{font-size:25px}.room-selector{height:54px}.room-picker{top:52px}.game-surface{height:clamp(120px,min(52svh,calc(100svh - 340px - env(safe-area-inset-top) - env(safe-area-inset-bottom))),430px)}.direction-pad{margin-bottom:8px}}@media(max-height:500px) and (min-width:600px){.topbar{padding-top:10px;padding-bottom:4px}.game-surface{height:230px}.toolbar{height:50px}}@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important}}

@media(max-height:650px) and (max-width:540px){.game-surface{height:40svh;min-height:200px}.topbar{padding-top:10px}}


canvas:focus-visible{outline:1px solid var(--focus);outline-offset:-1px;border-radius:8px}

/* Keep touch targets distinct without changing the keyboard layout. */
body{padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)}
button{touch-action:manipulation;user-select:none;-webkit-user-select:none}
@media(pointer:coarse){
  .direction-pad{grid-template-columns:repeat(3,60px);gap:8px}
  .direction-pad .icon-button{width:60px;height:56px}
  .shortcut{display:none}
}
@media(max-width:540px) and (max-height:650px){
  .topbar{padding:6px 18px 4px}
  .topbar .fullscreen{width:32px;height:32px}

  .toolbar{height:44px;flex-shrink:0}
  .game-surface{height:clamp(120px,calc(100svh - 292px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),320px);min-height:0;flex-shrink:0}

}
/* Landscape keeps the board and controls visible together, including 568×320. */
@media(orientation:landscape) and (max-height:500px) and (min-width:480px){
  .topbar{height:36px;padding:0 18px}
  main{display:grid;grid-template-columns:minmax(0,1fr) 196px;grid-template-rows:54px minmax(0,1fr);height:calc(100svh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom));flex:none;align-items:center}
  .room-selector{grid-area:1/1/2/3;height:54px}
  .room-picker{top:50px}
  .game-surface{grid-area:2/1;height:100%;min-height:0;align-self:stretch}
  .toolbar{grid-area:2/2;width:180px;height:48px;justify-self:center;align-self:start}
  .direction-pad{grid-area:2/2;grid-template-columns:repeat(3,56px);gap:8px;margin:0 0 8px;justify-self:center;align-self:end}
  .direction-pad .icon-button{width:56px;height:54px}

}

/* Very narrow phones keep the compact picker and at least 120px for the board. */
@media(max-width:375px){.home span{display:none}}
@media(max-width:319px) and (max-height:650px){
  .game-surface{height:clamp(120px,calc(100svh - 292px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),320px)}
}
@media(max-width:319px) and (max-height:540px){
  .topbar{height:28px;padding:0 10px}
  .topbar .fullscreen{width:28px;height:28px}
  .toolbar{height:32px}
  .direction-pad{grid-template-columns:repeat(3,56px);gap:6px;margin-bottom:4px}
  .direction-pad .icon-button{width:56px;height:48px}
}

/* A readable step count and a persistent, high-contrast completion action. */
.move-meter{gap:6px;color:var(--ink);white-space:nowrap}
#move-count{font-size:22px;font-weight:650;letter-spacing:.02em}
#move-unit{font-size:12px}
.next{background:#d99b55;color:var(--next-ink);border:2px solid var(--next-ink);box-shadow:0 0 0 4px #d99b5530}
.next:hover:not(:disabled){background:#e8ad6c}
body[data-completed=true] .next{animation:next-cue .9s ease-out 3}
@keyframes next-cue{50%{box-shadow:0 0 0 8px #d99b5530;transform:scale(1.06)}}

/* Disabled ads reserve no space; the existing PC/mobile game stays centered. */
.home-links{display:flex;align-items:center;gap:4px;min-width:0}
.privacy-link{display:grid;place-items:center;min-width:28px;min-height:32px;color:var(--muted)}
.privacy-link:hover{color:var(--ink)}
.privacy-link svg{width:16px;height:16px}
.page-layout{width:min(900px,100%);flex:1;display:flex;margin:0 auto}
.ad-rail{display:none;width:160px;padding-top:9px}
.ad-label{display:block;text-align:center;font-size:10px;color:var(--muted);margin-bottom:8px}
.ad-preview{width:160px;height:600px;display:grid;place-items:center;border:1px dashed var(--line);color:var(--muted);font-size:12px}
.ad-rail:has([data-ad-status="unfilled"]){visibility:hidden}
@media(min-width:1568px) and (min-height:740px){
  body[data-side-ads] .page-layout{width:1520px;display:grid;grid-template-columns:160px 900px 160px;column-gap:150px;align-items:start}
  body[data-side-ads] .ad-rail{display:block}
}

/* Mobile banners stay in document flow, outside the complete game and controls.
   Keep 150px clearance from interactive content; short landscape stays ad-free. */
.ad-banner{display:none;width:320px;flex:none;align-self:center}
.ad-banner .ad-preview{width:320px;height:50px}
.ad-banner:has([data-ad-status="unfilled"]){visibility:hidden}
@media(min-width:360px) and (max-width:767px) and (orientation:portrait){
  body[data-mobile-ads] .ad-banner{display:block}
  body[data-mobile-ads] [data-ad-side="top"]{margin:12px 0 150px}
  body[data-mobile-ads] [data-ad-side="bottom"]{margin:150px 0 12px}
  body[data-mobile-ads] .topbar,body[data-mobile-ads] .page-layout{flex-shrink:0}
}

/* Match the OS before scripts or the engine load, and on live changes. */
@media(prefers-color-scheme:dark){
  :root{color-scheme:dark;--paper:#18231f;--picker:#24362c;--ink:#e5e9df;--muted:#a6b3a4;--line:#465b4e;--sage:#a3b5a4;--hover:#34483f;--key:#2c3d34;--key-hover:#3b5145;--utility:#26372e;--key-shadow:#101b17;--focus:#a3b5a4}
}

@media(max-width:319px){.rooms{column-gap:2px}}

.unlock-balance,.unlock-prompt{display:flex;align-items:center;justify-content:center;gap:10px;margin-top:10px;font-size:13px;color:var(--muted)}.unlock-balance svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round}.unlock-prompt button{min-width:44px;min-height:44px}.rooms button[data-locked=true]{color:var(--muted)}.rooms button[data-locked=true]:before{content:"";position:absolute;top:3px;right:3px;width:8px;height:9px;background:currentColor;mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 14'%3E%3Cpath d='M3 6V4a3 3 0 0 1 6 0v2M2 6h8v7H2z' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center/contain no-repeat}

.unlock-balance{margin-top:0}.unlock-prompt{margin-top:0}.room-picker:has(.unlock-prompt:not([hidden])) .room-progress{display:none}

/* Sound settings use a modal so arrows adjust volume without moving the board. */
.header-tools{display:flex;justify-self:end;gap:0}
#sound-dialog{width:min(340px,calc(100% - 24px));max-height:calc(100svh - 24px);overflow:auto;padding:20px;border:1px solid var(--line);border-radius:20px;background:var(--picker);color:var(--ink);box-shadow:0 12px 36px #101b1733}
#sound-dialog::backdrop{background:#101b1740}
.sound-heading{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;gap:12px}
.sound-heading h2{font-size:16px;font-weight:550;margin:0}
.sound-heading button{font-size:24px;flex-shrink:0}
.sound-row{display:flex;justify-content:space-between;gap:12px;font-size:14px}
.sound-row output{color:var(--muted);font-variant-numeric:tabular-nums}
#sound-dialog input[type=range]{display:block;width:100%;height:40px;margin:0 0 14px;accent-color:var(--sage);cursor:pointer}
#sound-dialog input:focus-visible{outline:2px solid var(--sage);outline-offset:3px;border-radius:6px}
.sound-mute{display:flex;align-items:center;gap:10px;min-height:44px;font-size:14px;cursor:pointer}
.sound-mute input{width:18px;height:18px;accent-color:var(--sage)}
@media(max-width:540px){.header-tools .icon-button{width:36px;height:36px}.topbar{padding-left:12px;padding-right:12px}}
@media(max-height:500px){#sound-dialog{padding:12px 20px}.sound-heading{margin-bottom:4px}#sound-dialog input[type=range]{height:28px;margin-bottom:4px}}

/* Mobile header actions keep separate finger-sized targets, even on short phones. */
@media(pointer:coarse){
  .topbar{height:auto;min-height:60px;padding:8px 12px;grid-template-columns:minmax(88px,1fr) auto minmax(88px,1fr)}
  .home-links{gap:0}
  .home,.privacy-link{min-width:44px;min-height:44px;justify-content:center}
  .wordmark{display:flex;align-items:center;min-height:44px}
  .header-tools .icon-button,.topbar .fullscreen{width:44px;height:44px;flex-shrink:0}
  .room-picker{max-height:calc(100svh - 126px - env(safe-area-inset-top) - env(safe-area-inset-bottom));overflow-y:auto;overscroll-behavior:contain}
  #sound-dialog input[type=range]{min-height:44px}
}
@media(pointer:coarse) and (max-width:540px){.home span{display:none}}
@media(pointer:coarse) and (max-width:319px){
  .topbar{min-height:52px;padding:4px 6px}
  .wordmark{font-size:22px;letter-spacing:.16em;padding-left:.16em}
}
@media(pointer:coarse) and (orientation:landscape) and (max-height:500px) and (min-width:480px){
  .topbar{height:44px;min-height:44px;padding:0 12px}
  main{height:calc(100svh - 44px - env(safe-area-inset-top) - env(safe-area-inset-bottom))}
  .room-picker{max-height:calc(100svh - 102px - env(safe-area-inset-top) - env(safe-area-inset-bottom))}
}
