:root {
  color-scheme: dark;
  --ink: #f7edd4;
  --muted: #aac7c6;
  --panel: rgba(5, 32, 42, .96);
  --line: rgba(210, 237, 225, .18);
  --gold: #ebba5e;
  --coral: #ef785e;
  --green: #6bd6a5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body, #app { width: 100%; height: 100%; min-height: 100dvh; margin: 0; overflow: hidden; }
body { color: var(--ink); background: #052a36; }
button, input, select { font: inherit; }
button { touch-action: manipulation; }

#app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: radial-gradient(circle at 10% 5%, rgba(47, 145, 145, .27), transparent 32%), linear-gradient(145deg, #092f3c, #031b24);
}

.topbar { display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center; padding: 4px 4px 13px; }
.topbar h1, .control-panel h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; }
.topbar h1 { font-size: clamp(1.35rem, 2.5vw, 2.15rem); letter-spacing: .015em; }
.eyebrow { margin: 0 0 3px; color: var(--gold); font-size: .68rem; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
.back-link { display: grid; width: 42px; height: 42px; place-items: center; color: var(--ink); border: 1px solid var(--line); border-radius: 50%; text-decoration: none; font-size: 1.4rem; }
.connection { display: flex; gap: 8px; align-items: center; margin: 0; padding: 8px 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; font-size: .8rem; }
.connection span { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--gold); box-shadow: 0 0 12px currentColor; }
.connection[data-state="online"] span { background: var(--green); }
.connection[data-state="offline"] span { background: var(--coral); }
.top-actions { display: flex; gap: 5px; }
.top-actions button, .mobile-dock button { min-width: 40px; min-height: 40px; color: var(--ink); background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 850; }

.game-shell { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(330px, 390px); gap: 12px; }
.world-frame, .control-panel { border: 1px solid var(--line); border-radius: 22px; overflow: hidden; box-shadow: 0 25px 70px rgba(0, 0, 0, .26); }
.world-frame { position: relative; display: grid; min-height: 0; background: #0b5263; cursor: grab; }
.world-frame.is-dragging { cursor: grabbing; }
#game-world { width: 100%; height: 100%; min-height: 0; touch-action: none; user-select: none; }

.routes polyline { fill: none; stroke: rgba(246, 225, 173, .62); stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 3 24; filter: drop-shadow(0 2px 2px rgba(3,27,36,.28)); }
.sectors .sector-shadow { fill: rgba(2,24,31,.38); }
.sectors .sector-rim { fill: #8b6b3c; stroke: #f0d28a; stroke-width: 2; }
.sectors .sector-disc { fill: url(#sector-parchment); stroke: #594224; stroke-width: 2; transition: filter .15s, stroke .15s, transform .15s; }
.sectors .sector-tick { fill: none; stroke: #6d522d; stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.sectors text { fill: #173842; text-anchor: middle; dominant-baseline: central; pointer-events: none; font-family: ui-sans-serif, system-ui; }
.sectors .sector-symbol { font-size: 22px; font-weight: 950; }
.sectors .sector-number { fill: #654c2d; font-size: 10px; font-weight: 900; letter-spacing: .05em; }
.ports .island-shadow { fill: rgba(2,24,31,.36); }
.ports .island { fill: url(#island-sand); stroke: #f5dfa0; stroke-width: 4; }
.ports .island-green { fill: url(#island-green); stroke: #31573c; stroke-width: 2; }
.ports .island-shore { fill: none; stroke: rgba(255,244,204,.65); stroke-width: 3; stroke-linecap: round; }
.ports .palm-trunk { fill: none; stroke: #5b3e26; stroke-width: 5; stroke-linecap: round; }
.ports .palm-leaf { fill: none; stroke: #274e38; stroke-width: 5; stroke-linecap: round; }
.ports .port-dot { fill: #3b2d21; stroke: #f7d77c; stroke-width: 4; }
.ports .port-name { fill: #fff2cf; paint-order: stroke; stroke: #263228; stroke-width: 6; stroke-linejoin: round; text-anchor: middle; pointer-events: none; font: 700 18px Georgia, serif; }
.ports .port-used { fill: #ef785e; stroke: #3b211b; stroke-width: 3; text-anchor: middle; dominant-baseline: central; font: 950 22px ui-sans-serif, system-ui; }
.markers .beacon-ring { fill: none; stroke-width: 8; stroke-opacity: .95; pointer-events: none; }
.markers .beacon-ring.is-secured { stroke-width: 11; stroke-dasharray: 7 5; }
.markers .secured-mark { fill: #fff4d2; stroke: #173842; stroke-width: 2; text-anchor: middle; dominant-baseline: central; pointer-events: none; font: 900 18px ui-sans-serif, system-ui; }
.markers .blockade-mark { fill: #f07461; stroke: #351c19; stroke-width: 3; text-anchor: middle; dominant-baseline: central; pointer-events: none; font: 950 34px ui-sans-serif, system-ui; }
.markers .fortification-mark { fill: #f5d57e; stroke: #372d19; stroke-width: 3; text-anchor: middle; dominant-baseline: central; pointer-events: none; font: 950 23px ui-sans-serif, system-ui; }
.markers .beacon { stroke: #fff4d2; stroke-width: 4; }
.markers .beacon-pole { stroke: #fff4d2; stroke-width: 5; stroke-linecap: round; }
.ships .ship-hull { stroke: #fff4d2; stroke-width: 5; stroke-linejoin: round; }
.ships .ship-sail { stroke: #fff4d2; stroke-width: 4; }
.effects .legal-ring { fill: #6bd6a5; fill-opacity: .18; stroke: #75e1b2; stroke-width: 8; stroke-dasharray: 10 8; animation: legal-pulse 1.1s ease-in-out infinite alternate; pointer-events: none; }
.effects .joker-ring { fill: #f2c35d; fill-opacity: .22; stroke: #ffd87b; stroke-width: 9; stroke-dasharray: 3 6; animation: legal-pulse 1.1s ease-in-out infinite alternate; pointer-events: none; }
.effects .joker-mark { fill: #ffe69b; stroke: #173842; stroke-width: 4; paint-order: stroke; text-anchor: middle; pointer-events: none; font: 950 24px ui-sans-serif, system-ui; }
.effects .retreat-mark { fill: #fff4d2; stroke: #173842; stroke-width: 4; paint-order: stroke; text-anchor: middle; pointer-events: none; font: 950 25px ui-sans-serif, system-ui; }
.effects .target-ring { fill: #ef9f5e; fill-opacity: .22; stroke: #ffc178; stroke-width: 9; stroke-dasharray: 5 7; animation: legal-pulse 1.1s ease-in-out infinite alternate; pointer-events: none; }
.hitboxes .sector-hitbox { fill: #ffffff; fill-opacity: 0; pointer-events: all; cursor: pointer; outline: none; }
.hitboxes .sector-hitbox:focus-visible { fill: rgba(255,255,255,.18); stroke: white; stroke-width: 5; }
.debug-layer { display: none; pointer-events: none; }
.debug-mode .debug-layer { display: block; }
.debug-mode .debug-world-frame { fill: none; stroke: #ff6bd6; stroke-width: 6; stroke-dasharray: 20 10; }
.debug-mode .debug-anchor line { stroke: #ffef78; stroke-width: 4; }
.debug-mode .debug-anchor text, .debug-mode .debug-layer-label {
  fill: #fff; stroke: #17232b; stroke-width: 5; paint-order: stroke; font: 800 17px ui-monospace, monospace;
}
.debug-mode .hitboxes .sector-hitbox { fill: #58b8d4; fill-opacity: .13; stroke: #58b8d4; stroke-width: 3; stroke-dasharray: 7 5; }
.safe-area-debug { display: none; position: absolute; z-index: 7; inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); border: 2px dashed #ff6bd6; pointer-events: none; }
.debug-mode .safe-area-debug { display: block; }
.debug-hud { position: absolute; z-index: 8; left: 12px; top: 12px; max-width: calc(100% - 170px); padding: 7px 9px; color: #fff; background: rgba(19, 28, 34, .86); border: 1px solid #ff6bd6; border-radius: 8px; font: 700 11px/1.4 ui-monospace, monospace; pointer-events: none; }

@keyframes legal-pulse { to { stroke-width: 13; opacity: .72; } }

.camera-controls { position: absolute; top: 13px; right: 13px; display: flex; gap: 5px; padding: 5px; background: rgba(3, 27, 36, .76); border: 1px solid var(--line); border-radius: 13px; }
.camera-controls button { display: grid; width: 38px; height: 38px; place-items: center; color: var(--ink); background: rgba(255,255,255,.06); border: 0; border-radius: 9px; cursor: pointer; font-size: 1.1rem; font-weight: 900; }
.camera-controls button:hover { background: rgba(255,255,255,.14); }
.mobile-map-toggle { display: none !important; }
.map-hint { position: absolute; left: 14px; bottom: 12px; max-width: min(75%, 560px); margin: 0; padding: 7px 11px; color: #d7e7e1; background: rgba(3, 27, 36, .78); border: 1px solid var(--line); border-radius: 999px; font-size: .72rem; pointer-events: none; }

.control-panel { min-height: 0; overflow-y: auto; padding: clamp(17px, 2.5vw, 26px); background: var(--panel); scrollbar-color: rgba(255,255,255,.24) transparent; }
.setup-panel, .play-panel, .lobby-panel { display: grid; gap: 17px; }
.control-panel h2 { font-size: clamp(1.55rem, 2.8vw, 2.15rem); }
.control-panel h3 { margin: 0; font-size: .88rem; }
.control-panel p { color: var(--muted); line-height: 1.48; }
.telemetry { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: var(--line); }
.telemetry div { display: grid; gap: 4px; padding: 10px; background: #082f3c; }
.telemetry dt { color: var(--muted); font-size: .67rem; }
.telemetry dd { margin: 0; font-size: .82rem; font-weight: 850; }
.demo-form { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.demo-form label { display: grid; gap: 6px; color: var(--muted); font-size: .73rem; font-weight: 750; }
.demo-form label small { color: var(--muted); font-size: .62rem; font-weight: 500; line-height: 1.35; }
.demo-form input, .demo-form select { min-width: 0; width: 100%; height: 43px; padding: 0 10px; color: var(--ink); background: #082f3c; border: 1px solid var(--line); border-radius: 10px; }
.demo-form .primary { grid-column: 1 / -1; }
.setup-separator { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .7rem; text-transform: uppercase; }
.setup-separator::before, .setup-separator::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.join-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.join-form label, .lobby-panel > label { display: grid; gap: 6px; color: var(--muted); font-size: .73rem; font-weight: 750; }
.join-form input, .lobby-panel select { width: 100%; height: 43px; padding: 0 10px; color: var(--ink); background: #082f3c; border: 1px solid var(--line); border-radius: 10px; text-transform: uppercase; }
.lobby-code-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lobby-code-row h2 { color: var(--gold); letter-spacing: .18em; }
.lobby-panel > p { margin: 0; }
.lobby-players { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.lobby-players li { display: flex; gap: 9px; align-items: center; min-height: 44px; padding: 8px 10px; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; }
.lobby-players .player-color { flex: 0 0 auto; }
.lobby-players small { margin-left: auto; color: var(--muted); }
.primary { min-height: 47px; padding: 11px 15px; color: #273325; background: linear-gradient(135deg, #f0c66c, #dc9e3f); border: 0; border-radius: 12px; font-weight: 850; cursor: pointer; box-shadow: 0 10px 24px rgba(233, 183, 90, .18); }
.primary:hover { filter: brightness(1.07); }
.primary:disabled { cursor: wait; opacity: .58; }
.text-button { min-height: 38px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }

.turn-heading, .section-title, .player-strip { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.phase-pill { padding: 6px 9px; color: var(--gold); background: rgba(235,186,94,.1); border: 1px solid rgba(235,186,94,.35); border-radius: 999px; font-size: .7rem; font-weight: 850; }
.player-strip { justify-content: flex-start; padding: 10px 12px; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 12px; font-size: .8rem; }
.player-strip > :last-child { margin-left: auto; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-color { width: 13px; height: 13px; border: 2px solid white; border-radius: 50%; }
.player-status-list { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px; margin: 0; padding: 0; list-style: none; }
.player-status-list li { display: flex; gap: 6px; align-items: center; min-width: 0; padding: 6px 8px; color: var(--muted); background: rgba(255,255,255,.035); border-radius: 9px; font-size: .67rem; }
.player-status-list strong { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.player-status-list .presence { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--coral); }
.player-status-list .presence.is-online { background: var(--green); }
.player-status-list button { margin-left: auto; padding: 4px 6px; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: .62rem; }
.danger-button { min-height: 38px; color: #ffb0a2; background: rgba(239,120,94,.07); border: 1px solid rgba(239,120,94,.35); border-radius: 10px; cursor: pointer; }
.draw-panel, .hand-panel, .port-choice, .contracts-panel, .contract-route-choice, .reaction-panel, .journal-panel, .port-power-panel, .team-panel { display: grid; gap: 10px; }
.section-title span { color: var(--muted); font-size: .7rem; }
.visible-cards, .player-hand { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.player-hand { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.card-actions > :only-child { grid-column: 1 / -1; }
.card { position: relative; isolation: isolate; min-width: 0; min-height: 86px; display: grid; align-content: space-between; gap: 7px; padding: 11px 10px 9px; overflow: hidden; color: #173842; background: linear-gradient(145deg, #fff2cd 0%, #ead59c 68%, #cfaf6c 100%); border: 2px solid #9a7741; border-radius: 12px; text-align: left; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(255,255,255,.2), 0 7px 16px rgba(0,0,0,.22); transition: transform .14s ease, box-shadow .14s ease, filter .14s ease; }
.card::before { content: ""; position: absolute; z-index: -1; inset: 4px; border: 1px solid rgba(102,76,40,.35); border-radius: 8px; pointer-events: none; }
.card::after { content: "⚓"; position: absolute; z-index: -1; right: -7px; bottom: -15px; color: rgba(85,64,35,.10); font-size: 3.6rem; line-height: 1; transform: rotate(-12deg); pointer-events: none; }
.card[data-card-type="special"] { color: #f7edd4; background: linear-gradient(145deg, #315d66 0%, #153f4c 58%, #0a2c38 100%); border-color: #d1ae61; box-shadow: inset 0 0 0 2px rgba(235,186,94,.18), 0 7px 16px rgba(0,0,0,.28); }
.card[data-card-type="special"]::before { border-color: rgba(235,186,94,.46); }
.card[data-card-type="special"]::after { color: rgba(235,186,94,.12); }
.card strong { overflow: hidden; font-family: Georgia, serif; font-size: .78rem; line-height: 1.08; text-overflow: ellipsis; }
.card-symbol { width: 29px; height: 29px; display: grid; place-items: center; color: #513c22; background: rgba(255,250,229,.55); border: 1px solid rgba(102,76,40,.3); border-radius: 50%; font-size: 1.3rem; font-weight: 950; line-height: 1; box-shadow: 0 2px 5px rgba(67,49,25,.13); }
.card[data-card-type="special"] .card-symbol { color: #ffe4a0; background: rgba(235,186,94,.12); border-color: rgba(235,186,94,.4); }
.card-type { opacity: .72; font-size: .56rem; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.card:hover:not([aria-disabled="true"]) { transform: translateY(-3px) rotate(-.35deg); box-shadow: inset 0 0 0 2px rgba(255,255,255,.22), 0 11px 22px rgba(0,0,0,.27); }
.card.is-selected { border-color: #6bd6a5; box-shadow: 0 0 0 3px rgba(107,214,165,.22), 0 10px 22px rgba(0,0,0,.28); }
.card[aria-disabled="true"] { cursor: default; filter: saturate(.45); opacity: .56; }
.card-tooltip { position: fixed; z-index: 1000; max-width: min(320px, calc(100vw - 20px)); padding: 8px 10px; pointer-events: none; color: var(--ink); background: rgba(3,27,36,.97); border: 1px solid rgba(235,186,94,.45); border-radius: 9px; box-shadow: 0 8px 24px rgba(0,0,0,.38); font-size: .72rem; line-height: 1.35; }
.card-tooltip[hidden] { display: none; }
.deck-button { min-height: 43px; color: var(--ink); background: #0c4050; border: 1px solid var(--line); border-radius: 11px; cursor: pointer; font-weight: 780; }
.deck-button:disabled, .deck-button[aria-disabled="true"] { opacity: .45; cursor: default; }
.port-choice { padding: 12px; background: rgba(107,214,165,.07); border: 1px solid rgba(107,214,165,.28); border-radius: 12px; }
.port-choice p, .contract-route-choice p { margin: -5px 0 0; font-size: .75rem; }
.port-choice-actions, .contract-route-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.port-choice-actions button, .contract-route-actions button { min-height: 39px; flex: 1 1 110px; padding: 7px 9px; color: var(--ink); background: #0c4050; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.contracts-panel { padding: 11px; background: rgba(235,186,94,.06); border: 1px solid rgba(235,186,94,.22); border-radius: 12px; }
.contract-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.contract { min-width: 0; padding: 9px; color: #ecdcae; background: #0a3744; border: 1px solid rgba(235,186,94,.2); border-radius: 10px; }
.contract strong, .contract span { display: block; }
.contract strong { margin-bottom: 5px; color: var(--ink); font: 700 .76rem Georgia, serif; }
.contract span { color: var(--muted); font-size: .65rem; line-height: 1.35; }
.contract.is-completed { border-color: var(--green); background: rgba(107,214,165,.11); }
.contract.is-completed strong::before { content: "✓ "; color: var(--green); }
.team-panel { padding: 11px; background: rgba(88,184,212,.07); border: 1px solid rgba(88,184,212,.25); border-radius: 12px; }
.tactical-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.tactical-actions button { min-height: 34px; flex: 1 1 95px; padding: 5px 7px; color: var(--ink); background: #0c4050; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: .66rem; }
.team-messages { max-height: 72px; margin: 0; padding-left: 21px; overflow-y: auto; color: var(--muted); font-size: .67rem; }
.contract-route-choice { padding: 12px; background: rgba(235,186,94,.1); border: 1px solid rgba(235,186,94,.38); border-radius: 12px; }
.reaction-panel { padding: 12px; background: rgba(239,120,94,.11); border: 1px solid rgba(239,120,94,.42); border-radius: 12px; }
.reaction-panel p { margin: -5px 0 0; font-size: .75rem; }
.reaction-countdown { min-width: 46px; padding: 4px 7px; color: var(--ink) !important; background: rgba(239,120,94,.2); border-radius: 999px; text-align: center; font-weight: 850; }
.reaction-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.reaction-actions button { min-height: 39px; flex: 1 1 120px; padding: 7px 9px; color: var(--ink); background: #0c4050; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.port-power-panel { padding: 12px; background: rgba(88,184,212,.09); border: 1px solid rgba(88,184,212,.35); border-radius: 12px; }
.port-power-panel > p { margin: -4px 0 0; font-size: .75rem; }
.port-power-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.port-power-actions button { min-height: 39px; min-width: 0; padding: 7px 9px; color: var(--ink); background: #0c4050; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.port-power-actions button.is-selected { border-color: var(--green); background: rgba(107,214,165,.19); box-shadow: inset 0 0 0 2px rgba(107,214,165,.2); }
.port-power-actions button:disabled { cursor: default; opacity: .48; }
.port-power-actions .wide { grid-column: 1 / -1; }
.player-tokens { margin-left: 0 !important; color: var(--gold) !important; font-weight: 850; }
.card.is-reserved { border-color: var(--gold); }
.journal-panel { padding-top: 3px; }
.game-journal { max-height: 112px; margin: 0; padding: 0 0 0 23px; overflow-y: auto; color: var(--muted); font-size: .68rem; line-height: 1.45; }
.game-journal li + li { margin-top: 3px; }
.game-journal .journal-meta { color: var(--gold); font: 700 .58rem ui-monospace, monospace; }
.end-game-panel { padding: 18px; text-align: center; background: radial-gradient(circle at top, rgba(235,186,94,.22), rgba(107,214,165,.08)); border: 1px solid rgba(235,186,94,.46); border-radius: 15px; }
.end-game-panel p:last-child { margin-bottom: 0; }
.feedback { min-height: 1.35em; margin: 14px 0 0; color: var(--muted); font-size: .78rem; }
.feedback[data-kind="error"] { color: #ff9d8c; }
.feedback[data-kind="success"] { color: #86dfb6; }
.feedback[data-kind="warning"] { color: #ffd27a; }

.loading-screen { position: fixed; z-index: 100; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 24px; color: var(--ink); text-align: center; background: #052a36; transition: opacity .18s ease; }
.loading-screen.is-ready { opacity: 0; pointer-events: none; }
.loading-screen small { color: var(--muted); }
.loading-compass { color: var(--gold); font-size: 3rem; animation: compass-turn 1.3s ease-in-out infinite alternate; }
@keyframes compass-turn { to { transform: rotate(135deg) scale(1.08); } }
.info-dialog { width: min(92vw, 560px); max-height: min(82dvh, 720px); padding: 24px; overflow-y: auto; color: var(--ink); background: #082f3c; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 28px 90px rgba(0,0,0,.6); }
.info-dialog::backdrop { background: rgba(0,18,25,.74); backdrop-filter: blur(3px); }
.info-dialog h2 { margin: 0 42px 16px 0; font-family: Georgia, serif; }
.info-dialog h3 { margin: 18px 0 4px; color: var(--gold); font-size: .9rem; }
.info-dialog p { color: var(--muted); line-height: 1.5; }
.reference-list { display: grid; gap: 7px; margin: 0; }
.reference-list div { padding: 9px 10px; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 9px; }
.reference-list dt { color: var(--ink); font-weight: 800; }
.reference-list dd { margin: 3px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.42; }
.analysis-dialog { width: min(96vw, 920px); }
.analysis-actions { display: flex; gap: 8px; }
.analysis-actions button { flex: 1; }
.analysis-dialog pre { min-height: 260px; max-height: 52dvh; margin: 12px 0 0; padding: 12px; overflow: auto; color: #d7e7e1; background: #031b24; border: 1px solid var(--line); border-radius: 10px; font: 600 11px/1.5 ui-monospace, monospace; white-space: pre-wrap; }
.turn-summary-list { display: grid; gap: 9px; max-height: 46dvh; margin: 16px 0 20px; padding: 0; overflow-y: auto; list-style: none; }
.turn-summary-list li { padding: 11px 13px; background: rgba(255,255,255,.045); border: 1px solid var(--line); border-left: 6px solid var(--player-color, var(--gold)); border-radius: 10px; line-height: 1.45; }
.turn-summary-list .journal-meta { color: var(--gold); font-size: .72rem; font-weight: 800; }
.turn-summary-dialog form:last-child { float: none; }
.turn-summary-dialog form:last-child button { width: 100%; }
.info-dialog form { float: right; }
.dialog-close { width: 38px; height: 38px; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 50%; cursor: pointer; font-size: 1.4rem; }
.settings-dialog label { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.settings-dialog input { width: 20px; height: 20px; accent-color: var(--gold); }
.state-flash { animation: state-confirmed .22s ease-out; }
@keyframes state-confirmed { from { filter: brightness(1.25); } }
.mobile-dock { display: none; }
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }

button:focus-visible, input:focus-visible, select:focus-visible, .back-link:focus-visible { outline: 3px solid white; outline-offset: 3px; }

@media (max-width: 900px) {
  #app { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .topbar { padding-bottom: 8px; }
  .connection { padding: 8px; font-size: 0; gap: 0; }
  .game-shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .control-panel { max-height: 42dvh; padding: 13px 13px calc(13px + env(safe-area-inset-bottom)); border-radius: 16px; transition: max-height .18s ease; }
  .control-panel.is-expanded { max-height: 72dvh; }
  .world-frame { border-radius: 16px; }
  .mobile-map-toggle { display: grid !important; }
  .game-shell.is-map-priority { grid-template-rows: minmax(0, 1fr) auto; }
  .game-shell.is-map-priority .control-panel { max-height: 58px; overflow: hidden; padding-top: 9px; padding-bottom: 9px; }
  .game-shell.is-map-priority .control-panel > :not(.feedback) { display: none !important; }
  .game-shell.is-map-priority .feedback { min-height: 38px; margin: 0; display: flex; align-items: center; }
  .setup-panel, .play-panel { gap: 11px; }
  .setup-panel > div:first-child p { display: none; }
  .control-panel h2 { font-size: 1.25rem; }
  .player-hand { grid-template-columns: repeat(6, minmax(72px, 1fr)); overflow-x: auto; padding-bottom: 4px; }
  .card { min-height: 76px; padding: 9px 8px 8px; }
  .card-symbol { width: 27px; height: 27px; font-size: 1.18rem; }
  .mobile-dock:not([hidden]) { position: fixed; z-index: 20; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); display: flex; gap: 5px; padding: 5px; background: rgba(3,27,36,.9); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
  .mobile-dock button { min-width: 52px; padding: 5px; font-size: .67rem; }
  .mobile-section.is-mobile-target { padding: 10px; border: 1px solid rgba(107,214,165,.42); border-radius: 12px; animation: state-confirmed .22s ease-out; }
}

@media (max-width: 520px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 7px; }
  .topbar .connection { display: none; }
  .top-actions { gap: 3px; }
  .top-actions button { min-width: 36px; min-height: 36px; }
  .brand .eyebrow { display: none; }
  .topbar h1 { font-size: 1.08rem; }
  .back-link { width: 37px; height: 37px; }
  .camera-controls button { width: 34px; height: 34px; }
  .map-hint { display: none; }
  .demo-form { grid-template-columns: 1fr; }
  .demo-form .primary { grid-column: auto; }
  .visible-cards { grid-template-columns: repeat(3, minmax(78px, 1fr)); overflow-x: auto; }
  .player-hand { grid-template-columns: repeat(6, 82px); }
  .card-actions { grid-template-columns: 1fr; }
  .mobile-dock button { min-width: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
