:root { color-scheme: dark; font-family: ui-monospace, monospace; color: #f1dfb3; background: #20283c; }
* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; }
#game-shell { position: fixed; inset: 0; }
#board-stage { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; }
#game-shell #canvas { width: 100%; height: 100%; margin: 0; }
.mobile-only, .touch-intro { display: none; }
body.online #game-shell { top: 48px; }
#canvas { display: block; width: 100vw; height: 100dvh; image-rendering: pixelated; touch-action: none; outline: none; }
#welcome { position: fixed; inset: 0; display: grid; place-items: center; overflow-y: auto; padding: 24px; background: #20283c; }
#welcome[hidden] { display: none; }
#welcome { align-items: safe center; }
[hidden] { display: none !important; }
article { width: min(100%, 520px); padding: 32px; border: 4px solid #46516a; box-shadow: 8px 8px #171c2c; background: #2c354d; }
h1 { margin: 16px 0; font-size: clamp(48px, 10vw, 72px); line-height: 1; letter-spacing: .06em; }
p { line-height: 1.6; }
.eyebrow { color: #efb95b; font-size: 12px; letter-spacing: .1em; }
button { width: 100%; margin-top: 12px; padding: 16px; border: 0; border-top: 4px solid #e1edc4; box-shadow: 0 4px #171c2c; color: #20283c; background: #add2b2; font: bold 20px ui-monospace, monospace; cursor: pointer; }
button:hover { background: #f1dfb3; }
button:focus-visible { outline: 3px solid #efb95b; outline-offset: 5px; }
button:disabled { opacity: .6; cursor: wait; }
label { display: block; margin-top: 18px; margin-bottom: 8px; color: #b6c2d0; font-size: 13px; }
input { width: 100%; min-width: 0; padding: 12px; border: 2px solid #46516a; border-radius: 0; color: #f1dfb3; background: #20283c; font: 13px ui-monospace, monospace; }
input:focus-visible { outline: 2px solid #78c4d0; }
fieldset { margin: 18px 0 6px; padding: 12px; border: 2px solid #46516a; }
legend { color: #78c4d0; font-size: 12px; }
.setting-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.setting-controls label { margin: 0; }
select { width: 100%; margin-top: 8px; padding: 8px; color: #f1dfb3; background: #20283c; border: 2px solid #46516a; font: inherit; }
select:focus-visible { outline: 2px solid #78c4d0; }
#time-control-note { margin: 10px 0 0; color: #94a3b8; font-size: 12px; }
.join-controls { display: flex; gap: 10px; }
.join-controls button { width: auto; margin: 0; padding: 10px 18px; font-size: 14px; }
#host { background: #78c4d0; border-top-color: #c6f0e7; font-size: 17px; }
#share-room { padding-top: 8px; }
body[data-room-state="waiting"] #play,
body[data-room-state="waiting"] #tutorial,
body[data-room-state="waiting"] #match-settings,
body[data-room-state="waiting"] #solo-settings,
body[data-room-state="waiting"] #host,
body[data-room-state="waiting"] #join-form,
body[data-room-state="waiting"] .controls { display: none; }
#copy-room, #cancel-room { padding: 10px; font-size: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#network-bar { position: fixed; inset: 0 0 auto; height: 48px; display: flex; align-items: center; gap: 16px; padding: 6px 12px; border-bottom: 2px solid #46516a; background: #20283c; font-size: 12px; }
#player-role { color: #efb95b; white-space: nowrap; }
body[data-side="BLACK"] #player-role { color: #78c4d0; }
#network-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; color: #b6c2d0; }
#leave-room { width: auto; margin: 0; padding: 6px 12px; font-size: 12px; }
body.online #canvas { height: calc(100dvh - 48px); margin-top: 48px; }
#connection-failure { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: #141b2de8; }
#failure-title { font-size: clamp(18px, 5vw, 26px); color: #ed8c78; }
#status { min-height: 24px; color: #add2b2; font-size: 14px; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding-top: 4px; border-top: 2px solid #46516a; font-size: 12px; color: #b6c2d0; }
.controls strong { color: #efb95b; }
.controls p + p strong { color: #78c4d0; }
.note { color: #94a3b8; font-size: 12px; }
@media (max-height: 650px) { article { padding: 20px; } h1 { font-size: 42px; } }

/* The renderer crops to the square board; DOM controls keep their native size. */
body.mobile { --network-space: 0px; }
body.mobile.online { --network-space: calc(48px + env(safe-area-inset-top)); }
.mobile #game-shell {
  top: var(--network-space); bottom: auto; height: calc(100dvh - var(--network-space));
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.mobile.online #game-shell { padding-top: 0; }
.mobile .mobile-only { display: block; }
.mobile #canvas { pointer-events: none; }
.mobile #mobile-hud { position: relative; padding: 8px 12px 0; }
.mobile button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.game-toolbar { display: flex; gap: 8px; }
.game-toolbar button, .action-grid button {
  min-height: 44px; margin: 0; padding: 8px; border-top-width: 2px; font-size: 13px;
}
.game-toolbar button { background: #2c354d; color: #f1dfb3; border-top-color: #46516a; }
.mobile-clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.clock { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 9px; border: 2px solid #46516a; background: #2c354d; font-size: 12px; }
.clock.white { color: #efb95b; }
.clock.black { color: #78c4d0; }
.clock.active { border-color: currentColor; }
.clock strong { color: #f1dfb3; font-size: 20px; font-variant-numeric: tabular-nums; }
.clock.warning strong { color: #ed8c78; }
#mobile-turn { margin: 8px 0 0; font-size: 13px; font-weight: bold; }
#mobile-feedback { min-height: 18px; margin: 3px 0 5px; font-size: 11px; line-height: 1.4; color: #add2b2; }
#mobile-details { position: absolute; z-index: 5; left: 8px; right: 8px; top: 58px; max-height: calc(100dvh - 100px); overflow: auto; padding: 14px; border: 2px solid #78c4d0; box-shadow: 0 6px #171c2c; background: #20283c; }
#mobile-details p { margin: 0 0 12px; font-size: 12px; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#mobile-dialog { position: absolute; z-index: 3; inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: min(94%, 420px); max-height: 100%; overflow-y: auto; padding: 16px; border: 3px solid #efb95b; background: #20283cf5; box-shadow: 4px 4px #171c2c; }
#mobile-dialog h2 { margin: 0 0 10px; font-size: 20px; }
#mobile-dialog p { margin: 0 0 14px; font-size: 12px; }
#touch-controls { padding: 4px 12px 12px; background: #20283c; }
#touch-hint { margin: 0 0 6px; text-align: center; color: #94a3b8; font-size: 10px; line-height: 1.4; }
.touch-pad { margin-top: 8px; }
.touch-pad > strong { display: block; margin-bottom: 5px; font-size: 11px; color: #efb95b; }
.touch-pad[data-side="BLACK"] > strong { color: #78c4d0; }
.pad-buttons { display: grid; grid-template-columns: 1fr 1fr 1.3fr 1.7fr; gap: 8px; }
.pad-buttons button { min-width: 0; min-height: 52px; margin: 0; padding: 8px 4px; border-top-width: 3px; font-size: 15px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.pad-buttons .flap { background: #efb95b; border-top-color: #f1dfb3; }
.pad-buttons .carry { background: #78c4d0; border-top-color: #c6f0e7; font-size: 12px; }
.pad-buttons button.held { transform: translateY(3px); box-shadow: 0 1px #171c2c; filter: brightness(1.15); }
#mobile-review { grid-template-columns: repeat(3, 1fr); }
.mobile #welcome { padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.mobile article { padding: 20px; box-shadow: 4px 4px #171c2c; }
.mobile h1 { font-size: clamp(40px, 13vw, 64px); }
.mobile .tagline { color: #efb95b; margin-bottom: 6px; }
.mobile .touch-intro { display: block; margin-top: 0; color: #b6c2d0; font-size: 12px; }
.mobile input, .mobile select { font-size: 16px; min-height: 44px; }
.mobile .setting-controls { gap: 8px; }
.mobile fieldset { padding: 10px; }
.mobile .controls { display: none; }
.mobile #network-bar { height: var(--network-space); padding-top: calc(6px + env(safe-area-inset-top)); gap: 8px; }
.mobile .local-action:disabled { cursor: default; }
@media (max-width: 360px) {
  .mobile .setting-controls { grid-template-columns: 1fr; }
  .mobile article { padding: 16px; }
}
@media (orientation: portrait) and (max-height: 650px) {
  .mobile #mobile-hud { padding-top: 6px; }
  .mobile .clock { padding: 4px 6px; gap: 6px; }
  .mobile .clock span { font-size: 10px; white-space: nowrap; }
  .mobile .clock strong { font-size: 18px; }
  .mobile .pad-buttons button { min-height: 44px; }
  .mobile #touch-hint { display: none; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .mobile #game-shell { grid-template-columns: minmax(0, 1fr) minmax(260px, 38%); grid-template-rows: minmax(0, 1fr) auto; }
  .mobile #board-stage { grid-column: 1; grid-row: 1 / 3; }
  .mobile #mobile-hud { grid-column: 2; grid-row: 1; padding: 6px 10px 0; overflow: visible; }
  .mobile #touch-controls { grid-column: 2; grid-row: 2; padding: 4px 10px 8px; }
  .mobile-clocks { margin-top: 8px; gap: 6px; }
  .clock { display: block; padding: 4px 6px; }
  .clock strong { display: block; font-size: 18px; }
  #mobile-feedback { min-height: 15px; }
  .pad-buttons { gap: 6px; }
  .pad-buttons button { min-height: 44px; font-size: 13px; }
  .pad-buttons .carry { font-size: 11px; }
  #touch-hint { display: none; }
  #mobile-dialog { padding: 12px; }
}
