:root {
  color-scheme: dark;
  --ink: #f5efdf;
  --muted: #b1c2b7;
  --gold: #f8d387;
  --line: #ffffff22;
  --card: #1b2a27;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: #111e1c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; background: radial-gradient(ellipse at 25% 5%, #28433a 0, transparent 56%); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid #f8db9d; outline-offset: 4px; }
a { color: inherit; text-decoration: none; }
.top { min-height: 61px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 0 max(24px, calc((100vw - 1336px) / 2)); background: #10201dbb; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; }
.brand-icon { width: 32px; height: 32px; display: grid; place-items: center; color: #163329; background: var(--gold); border-radius: 10px; }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .83rem; }
.status i { width: 7px; height: 7px; background: var(--gold); border-radius: 50%; }
.status.online i { background: #a5e5a5; }
main { max-width: 1384px; margin: auto; padding: 29px 24px 36px; }
.intro, .actions, .board-top, .board-bottom, .score-heading, .side-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.intro { margin-bottom: 24px; align-items: end; }
h1 { margin: 0; font: 600 clamp(3rem, 7vw, 5.1rem)/.99 Georgia, serif; letter-spacing: -.067em; }
.intro p { margin: 12px 0 0; color: var(--muted); }
.primary, .secondary, .ar-top button, .ar-bottom button { border: 1px solid var(--line); border-radius: 11px; padding: 11px 15px; min-height: 44px; font-size: .89rem; font-weight: 750; color: var(--ink); background: #20322c; white-space: nowrap; }
.primary { color: #202317; background: var(--gold); border-color: var(--gold); }
.primary span { margin-right: 5px; }
button:hover, .side-actions a:hover { filter: brightness(1.12); }
.layout { display: grid; gap: 17px; grid-template-columns: minmax(0,1fr) 258px; align-items: start; }
.workbench, .side-card { border: 1px solid var(--line); border-radius: 16px; background: var(--card); overflow: hidden; }
.workbench { box-shadow: 0 18px 45px #07110c38; }
.board-top { min-height: 51px; padding: 0 16px; }
.board-top span { font-variant-numeric: tabular-nums; color: var(--gold); font-size: .85rem; }
#stage { position: relative; background: radial-gradient(ellipse at 49% 31%,#365b4c,#233f35 75%); aspect-ratio: 1040 / 645; }
#stage::before { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .15; background: repeating-linear-gradient(25deg, #d3e7cf30 0 1px, transparent 1px 5px); }
#desktopView { width: 100%; height: 100%; position: relative; }
canvas { display: block; touch-action: none; }
.board-bottom { padding: 13px 16px; min-height: 49px; color: var(--muted); font-size: .84rem; }
.text-button { padding: 4px 0; color: var(--gold); background: none; border: 0; font-size: .82rem; }
aside { display: grid; gap: 14px; }
.side-card { padding: 14px; }
h2 { font-size: .94rem; margin: 0; }
.reference img { width: 100%; height: auto; display: block; border-radius: 10px; margin-top: 10px; }
#scores, #arScores { list-style: none; padding: 0; margin: 9px 0 0; }
:is(#scores, #arScores) li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 8px 0; font-size: .85rem; border-top: 1px solid var(--line); }
:is(#scores, #arScores) li span:nth-child(2) { overflow-wrap: anywhere; }
:is(#scores, #arScores) li strong { color: var(--gold); font-variant-numeric: tabular-nums; }
:is(#scores, #arScores) li em { color: var(--muted); font-style: normal; font-size: .72rem; }
.avatar { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 8px; background: #405447; color: #fff2d1; font-weight: 800; }
.side-actions { padding: 0 4px; color: var(--gold); font-size: .82rem; }
dialog { width: min(410px, calc(100% - 30px)); color: var(--ink); padding: 20px; border-radius: 15px; border: 1px solid #789383; background: #1b2a27; }
dialog::backdrop { background: #071713c9; }
.dialog-head,.dialog-actions { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.dialog-head button { color: var(--ink); background: transparent; border: 0; font-size: 1.6rem; }
dialog p, dialog label { color: var(--muted); font-size: .9rem; line-height: 1.5; }
dialog label { display: grid; gap: 5px; margin: 14px 0; }
dialog input { width: 100%; padding: 10px; border: 1px solid #789383; color: var(--ink); background: #12211d; border-radius: 8px; }
.dialog-actions { justify-content: end; }
.dialog-actions a { color: var(--gold); margin-right: auto; font-size: .88rem; text-decoration: underline; }
#arView { display: block; position: fixed; inset: 0; z-index: 5; isolation: isolate; overflow: hidden; background: #0c1815; }
#arView video { position: absolute; }
#surfaceCanvas { display: block; position: absolute !important; inset: 0 !important; width: 100% !important; height: 100% !important; margin: 0; z-index: 1; }
.ar-top, .ar-bottom { z-index: 6; position: fixed; left: max(12px,env(safe-area-inset-left)); right: max(12px,env(safe-area-inset-right)); display: flex; align-items: center; justify-content: space-between; gap: 10px; pointer-events: none; }
.ar-top { top: max(12px,env(safe-area-inset-top)); }
.ar-bottom { bottom: max(12px,env(safe-area-inset-bottom)); }
.ar-top button, .ar-bottom button { pointer-events: auto; }
.ar-top span,.ar-bottom span { background: #0c1815e9; border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; color: var(--ink); font-size: .88rem; }
body.ar-active { overflow: hidden; }
@media (max-width: 760px) {
  .top { padding: 0 14px; min-height: 51px; }
  main { padding: 19px 12px 25px; }
  .intro { align-items: start; flex-direction: column; gap: 13px; margin-bottom: 15px; }
  h1 { font-size: clamp(2.8rem,11vw,4rem); }
  .intro p { margin-top: 8px; font-size: .92rem; }
  .layout { grid-template-columns: minmax(0,1fr); gap: 13px; }
  aside { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 9px; }
  .side-actions { grid-column: 1 / -1; }
  .side-card { padding: 10px; }
  .score-heading { flex-wrap: wrap; gap: 3px 8px; }
  .board-top, .board-bottom { padding-left: 10px; padding-right: 10px; }
  .board-bottom { min-height: 43px; padding-block: 8px; }
}

.ar-tools { display: flex; gap: 6px; }
.ar-tools button { padding-inline: 10px; }
#guide img { display: block; width: 100%; height: auto; border-radius: 10px; margin: 9px 0 14px; }
@media (max-width: 420px) {
  .ar-top span { padding-inline: 7px; font-size: .77rem; }
  .ar-tools button { padding-inline: 7px; font-size: .76rem; }
}

#arScan { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
.scan-target { position: absolute; top: 50%; left: 50%; translate: -50% -50%; width: min(54vw, 35dvh, 230px); aspect-ratio: 1; border: 2px dashed #fff5c8; border-radius: 18px; box-shadow: 0 0 0 1px #15231c, inset 0 0 0 1px #15231c; }
.scan-help { position: absolute; left: 50%; translate: -50% 0; bottom: max(12px, env(safe-area-inset-bottom)); width: min(calc(100% - 24px), 430px); padding: 13px; border-radius: 15px; background: #14221ff5; border: 1px solid #ffffff3b; pointer-events: auto; }
.scan-help p { margin: 6px 0 0; color: var(--muted); font-size: .85rem; line-height: 1.4; }
.scan-help button { width: 100%; margin-top: 12px; }
.surface-ready .scan-target { border-color: #a5e5a5; border-style: solid; }
@media (orientation: landscape) and (max-height: 475px) {
  .scan-target { width: min(36vw, 26dvh, 175px); }
  .scan-help { width: min(34%, 360px); left: auto; right: 12px; translate: none; }
}
@media (max-width: 420px) {
  .ar-bottom span { font-size: .76rem; padding-inline: 8px; }
  .ar-bottom button { font-size: .76rem; padding-inline: 8px; }
}

.brand-logo { display:block; max-width:120px; height:34px; object-fit:contain; }
.lobby-account, .collection-heading { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:12px; }
.lobby-account { padding:13px 15px; border:1px solid var(--line); border-radius:12px; background:var(--card); }
.lobby-account a { color:var(--gold); text-decoration:underline; font-size:.88rem; }
.collection-heading { margin:18px 0 13px; }
.collection-heading > span { color:var(--muted); font-size:.84rem; }
.level-switch { display:flex; gap:5px; padding:4px; border:1px solid var(--line); border-radius:12px; }
.level-switch button { border:0; border-radius:8px; padding:9px 14px; background:transparent; color:var(--ink); font-weight:720; }
.level-switch button[aria-pressed=true] { background:var(--gold); color:#202317; }
.puzzle-cards { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:12px; }
.puzzle-card-link { overflow:hidden; border-radius:12px; border:1px solid var(--line); background:var(--card); display:grid; align-content:start; transition:transform .15s ease; }
.puzzle-card-link:hover { transform:translateY(-2px); border-color:var(--gold); }
.puzzle-card-link img { width:100%; aspect-ratio:4/3; object-fit:cover; }
.puzzle-card-link strong { font-size:.9rem; padding:10px; }
.rankings { margin-top:20px; }
.rankings p { color:var(--muted); margin:6px 0 10px; font-size:.84rem; }
.rankings table { border-collapse:collapse; width:100%; text-align:left; font-size:.87rem; }
.rankings th,.rankings td { padding:9px 10px; border-top:1px solid var(--line); }
.rank-scroll { overflow:auto; }
.board-top strong { overflow-wrap:anywhere; }
.board-top > div { white-space:nowrap; }
@media(max-width:850px){.puzzle-cards{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media(max-width:520px){.puzzle-cards{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}.puzzle-card-link strong{padding:7px;font-size:.8rem}.rankings th,.rankings td{padding:7px}.ar-top{gap:5px}}

.game-head { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:12px; }
.game-head h1 { font:850 clamp(1.4rem,4vw,2.75rem)/1.05 system-ui,sans-serif; letter-spacing:-.045em; overflow-wrap:anywhere; }
.game-head > a { color:var(--gold); font-size:.86rem; font-weight:700; white-space:nowrap; }
.game-level { color:#a8e6ca; font-size:.8rem; font-weight:750; margin-bottom:5px; }
.game-modes { display:flex; gap:8px; margin-bottom:13px; flex-wrap:wrap; }
.game-modes .primary, .result-actions .primary { background:#ffdc74; color:#211b12; box-shadow:0 3px 0 #b68c3e; }
.workbench { border:2px solid #689483; border-radius:20px; }
.board-top { gap:16px; }
.game-progress { display:flex; align-items:center; flex:1; gap:10px; }
.game-progress label { font-size:.84rem; white-space:nowrap; }
.game-progress progress { width:min(100%,15rem); height:10px; accent-color:#87e7bf; }
.game-time { color:var(--gold); white-space:nowrap; font-weight:750; }
.board-bottom [role=status] { font-weight:750; color:#ecfff5; }
.game-steps { margin-top:14px; display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; }
.game-steps > div { display:flex; align-items:center; gap:9px; min-width:0; padding:11px; background:var(--card); border:1px solid var(--line); border-radius:12px; }
.game-steps > div > span { display:grid; place-items:center; width:33px; height:33px; flex:none; border-radius:10px; color:#142925; background:#a8e6ca; font-size:1.15rem; }
.game-steps strong { display:block; font-size:.86rem; }
.game-steps p { margin:4px 0 0; color:var(--muted); font-size:.75rem; }
#localResult { color:var(--muted); font-size:.8rem; }
.puzzle-card-link { position:relative; }
.card-play { align-self:end; justify-self:start; margin:0 10px 10px; padding:4px 8px; border-radius:7px; background:#a8e6ca; color:#142925; font-size:.77rem; font-weight:820; }
#results { width:min(460px,calc(100% - 24px)); max-height:calc(100dvh - 24px); padding:0; border:1px solid #acdbb9; border-radius:23px; overflow:auto; text-align:center; box-shadow:0 18px 100px #0009; }
#results::backdrop { background:#071713d9; }
.result-close { position:absolute; right:9px; top:9px; z-index:2; width:40px; height:40px; border:1px solid #ffffff55; border-radius:50%; background:#10281eed; color:#fff; font-size:1.45rem; }
.result-art { height:clamp(95px,23dvh,185px); overflow:hidden; }
.result-art img { display:block; width:100%; height:100%; object-fit:cover; }
.result-body { padding:15px; }
.result-body h2 { font-size:clamp(1.35rem,6vw,1.92rem); line-height:1.15; letter-spacing:-.04em; }
.result-stats { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:6px; margin:14px 0; }
.result-stats div { border:1px solid var(--line); border-radius:10px; padding:8px 3px; background:#294339; }
.result-stats strong { display:block; color:#ffdc74; font-size:1.35rem; font-variant-numeric:tabular-nums; }
.result-stats span { font-size:.7rem; color:#d3e9db; }
#resultScores { margin:8px 0; padding:0; list-style:none; }
#resultScores li { display:flex; align-items:center; gap:8px; text-align:left; padding:4px; border-bottom:1px solid var(--line); font-size:.83rem; }
#resultScores li strong { margin-left:auto; color:var(--gold); }
#saveStatus { margin:8px 0; color:var(--muted); font-size:.8rem; }
.result-actions { display:flex; align-items:stretch; justify-content:center; gap:8px; flex-wrap:wrap; }
.result-actions a,.result-actions button { display:inline-flex; justify-content:center; align-items:center; }
.result-actions .secondary:disabled { cursor:default; opacity:1; color:#b9f0d4; }
#roundMenu { display:inline-block; margin-top:12px; }
#confetti { position:absolute; inset:0; z-index:1; overflow:hidden; pointer-events:none; }
#confetti i { position:absolute; left:var(--x); top:-9px; width:7px; height:10px; border-radius:2px; animation:puzzle-celebration 1.3s var(--delay) ease-in both; }
@keyframes puzzle-celebration { from { transform:translateY(0) rotate(0); } to { transform:translateY(430px) rotate(var(--turn)); opacity:0; } }
@media (max-width: 760px) {
  .game-head { flex-wrap:wrap; gap:8px; }
  .game-head > div { order:3; flex-basis:100%; }
  #game .reference { display:none; }
  #game aside { grid-template-columns:1fr; }
  .game-steps { grid-template-columns:1fr; }
  .game-steps > div { padding:7px 10px; }
  .game-steps p { margin-top:1px; }
}

.prefer-ar #game { visibility:hidden; }
.ar-start { position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); z-index:7; width:min(410px,calc(100% - 28px)); padding:22px; border:1px solid #6f9e89; border-radius:18px; background:#1b3029; text-align:center; }
.ar-start h2 { font-size:1.4rem; }
.ar-start p { margin:9px 0 15px; color:var(--muted); line-height:1.45; }
.ar-start-actions { display:flex; justify-content:center; flex-wrap:wrap; gap:8px; }
.ar-start .text-button { display:inline-block; margin-top:13px; }

#lobby > .intro { margin-bottom:12px; }
#lobby > .intro h1 { font:850 clamp(1.6rem,6vw,2.4rem)/1.05 system-ui,sans-serif; letter-spacing:-.045em; }
#lobby > .intro p { margin-top:5px; font-size:.84rem; }
#game .game-head { margin-bottom:8px; }
#game .game-head h1 { font-size:clamp(1.15rem,4vw,1.7rem); }
#game .game-level { margin-bottom:2px; font-size:.73rem; }
@media(max-width:760px) { main { padding-top:12px; } .game-head > div { order:0; flex-basis:auto; flex:1; } .game-head > a { font-size:.75rem; } .game-head .secondary { padding:7px; font-size:.74rem; min-height:38px; } }

/* WebXR compositor supplies the camera and scene. DOM overlay contains only
   controls and a transparent touch surface, otherwise it hides passthrough. */
html.native-ar, body.native-ar { background: transparent !important; }
body.native-ar > main, body.native-ar > .top { display: none !important; }
body.native-ar #arView { background: transparent !important; }
body.native-ar #surfaceCanvas { opacity: 0; }

.ar-tracking { display:grid; gap:5px; }
.ar-tracking small { width:fit-content; padding:3px 6px; border-radius:5px; background:#0c1815e9; color:#c8e1d7; font-size:10px; }
.ar-tracking small:empty { display:none; }
