:root {
    --bg: #0b1020; --panel: #141b33; --panel2: #1c2547; --line: #2b3763; --text: #e8ecff; --dim: #8c97c4;
    --violet: #8b6cff; --violet-lt: #d4c8ff; --teal: #2dd4bf; --orange: #fb923c; --green: #4ade80; --red: #f87171;
    --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
    /* Use almost the whole screen: only ~60% of the notch/corner insets are kept as padding, and every
       bar paints edge to edge behind them. */
    --pad-l: max(8px, calc(var(--safe-l) * .6)); --pad-r: max(8px, calc(var(--safe-r) * .6)); --pad-b: calc(var(--safe-b) * .5);
    /* Keep the top bar clear of the status bar / edge-swipe zone so its buttons can be tapped. */
    --pad-t: max(16px, var(--safe-t)); --hud-h: calc(46px + var(--pad-t));
    /* One card size everywhere: whatever lets 4+4 market cards fit across AND market + hand fit down. */
    --cardh: min(calc((100cqh - 84px - var(--hud-h) - var(--pad-b)) / 2), calc((100cqw - var(--pad-l) - var(--pad-r) - 46px - 16px - 10px - 42px) / 8 / .644));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
    font: 13px/1.25 -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; touch-action: manipulation; }
button { font: inherit; color: inherit; }

/* body is the size container: fixed to the visible viewport, so it is right with or without browser chrome. */
body { position: fixed; inset: 0; container-type: size; }
#app { display: grid; grid-template-rows: var(--hud-h) 44px minmax(0, 1fr) calc(var(--cardh) + 10px + var(--pad-b)); height: 100cqh; }
#rotate { display: none; position: fixed; inset: 0; z-index: 99; background: var(--bg); align-items: center; justify-content: center;
    text-align: center; font-size: 18px; }
.rotate-icon { font-size: 56px; color: var(--teal); }
@media (orientation: portrait) { #rotate { display: flex; } #app, #overlay { display: none; } }

/* HUD */
#hud { display: flex; align-items: center; gap: 10px; padding: var(--pad-t) var(--pad-r) 8px var(--pad-l); background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.side { display: flex; gap: 6px; align-items: baseline; white-space: nowrap; padding: 3px 9px; border: 2px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, .04); }
.side b { font-size: 12px; } .side-0 { border-color: var(--teal); } .side-0 b { color: var(--teal); } .side-1 { border-color: var(--orange); } .side-1 b { color: var(--orange); }
.vp { color: var(--violet-lt); font-weight: 800; } .cash { color: var(--green); font-weight: 700; }
.hint { flex: 1; text-align: center; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turnno { color: var(--dim); }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; min-height: 40px; cursor: pointer; white-space: nowrap; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.primary { background: var(--violet); border-color: var(--violet); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .4; }

/* Console bar */
#console { display: flex; align-items: center; gap: 8px; padding: 2px var(--pad-r) 2px var(--pad-l); background: #10172c; border-bottom: 1px solid var(--line); min-width: 0; }
.track { display: flex; gap: 2px; flex: none; }
.step { padding: 4px 6px; font-size: 10px; font-weight: 700; color: var(--dim); border-radius: 6px; background: var(--panel); white-space: nowrap; }
.step.on { background: var(--teal); color: #04221e; }
.bar { display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; padding: 2px 0; scrollbar-width: none; }

/* Main pane */
#main { display: grid; grid-template-columns: calc(46px + var(--pad-l)) minmax(0, 1fr); min-height: 0; padding-right: var(--pad-r); }
#tabs { display: flex; flex-direction: column; gap: 4px; padding: 4px 4px 4px var(--pad-l); background: #0e1428; }
.tab { flex: 1; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; font-size: 11px; padding: 0; }
.tab.on { background: var(--violet); border-color: var(--violet); color: #fff; }
.pane { display: flex; gap: 12px; padding: 4px 8px; overflow: auto hidden; min-height: 0; align-items: stretch; }
.pane h3 { margin: 0 0 2px; font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.line, .group { display: flex; flex-direction: column; min-height: 0; flex: none; }
.row { display: flex; gap: 6px; flex: 1; min-height: 0; }
.empty { color: var(--dim); margin: 4px 0; font-size: 12px; white-space: nowrap; }
.contract { display: flex; gap: 8px; align-items: flex-start; height: 100%; }
.contract .row { flex: none; }
.xe { color: var(--teal); font-size: 12px; white-space: nowrap; }
.pips { display: flex; gap: 3px; margin-top: 4px; flex-wrap: wrap; width: 90px; }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--teal); } .pip.on { background: var(--teal); }
.stats { display: flex; flex-direction: column; gap: 4px; color: var(--dim); }

/* Cards: portrait, ~0.64 aspect; height comes from the row they sit in. */
.card { --ch: var(--cardh); position: relative; padding: 0; border: 2px solid transparent; border-radius: 8px;
    background: none; cursor: pointer; height: var(--ch); width: calc(var(--ch) * .644); flex: none; }
.ppe .card { --ch: 140px; }
/* Market: 4 + 4 cards across the pane; height is the smaller of what the pane or the width allows. */
.market { gap: 10px; }
.card.act { border-color: var(--teal); box-shadow: 0 0 8px rgba(45, 212, 191, .55); }
.tokens { position: absolute; left: 0; right: 0; bottom: 14%; display: flex; justify-content: center; gap: 4px; pointer-events: none; }
.tok { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; border: 3px solid #fff;
    background: var(--teal); color: #04221e; font-size: 13px; font-weight: 800; box-shadow: 0 1px 6px rgba(0, 0, 0, .7); }
.tok-1 { background: var(--orange); color: #2a1200; }
.tokcount .tok { width: 18px; height: 18px; border-width: 2px; }

/* Hand */
#hand { display: flex; gap: 6px; padding: 4px var(--pad-r) var(--pad-b) var(--pad-l); background: var(--panel); border-top: 1px solid var(--line); min-height: 0; }
.piles { display: flex; flex-direction: column; justify-content: center; gap: 6px; width: 74px; color: var(--dim); font-size: 11px; flex: none; }
.tokcount { display: flex; align-items: center; gap: 4px; color: var(--text); }
#hand .cards { display: flex; gap: 6px; overflow: auto hidden; flex: 1; min-width: 0; }

/* Sheets */
#overlay:empty { display: none; }
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 20, .78); display: flex; align-items: center; justify-content: center;
    padding: 6px var(--pad-r) 6px var(--pad-l); }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; max-height: 100%; max-width: 100%; overflow: auto; }
.sheet h2 { margin: 0 0 6px; font-size: 17px; }
.zoom { display: flex; gap: 16px; align-self: stretch; }
.zoom .card.big { height: 100%; width: auto; aspect-ratio: .644; flex: none; cursor: default; border: 0; padding: 0; }
.zoom .info { display: flex; flex-direction: column; gap: 6px; min-width: 0; overflow: auto; width: 360px; }
.facts { color: var(--dim); margin: 0; }
.acts { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.acts .btn { text-align: left; white-space: normal; padding: 6px 12px; }
.recap ol { margin: 0 0 10px; padding-left: 20px; display: flex; flex-direction: column; gap: 3px; }
.ppe .row { height: 150px; margin: 8px 0; justify-content: center; }
.pick { height: 100%; border: 3px solid transparent; border-radius: 10px; } .pick.on { border-color: var(--green); }
.gameover table { border-collapse: collapse; margin: 6px 0 10px; min-width: 300px; }
.gameover td, .gameover th { padding: 3px 12px; border-bottom: 1px solid var(--line); text-align: right; } .gameover td:first-child { text-align: left; }
.gameover .total td { font-weight: 800; color: var(--violet-lt); }
.menu { display: flex; flex-direction: column; gap: 8px; min-width: 240px; }
.levels { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.dim { color: var(--dim); }
.btn.current { border-color: var(--teal); }
/* With a big hand the cards overlap a little instead of scrolling. */
#hand .cards.tight { gap: 0; }
#hand .cards.tight .card + .card { margin-left: -16px; }
.turnno { white-space: nowrap; color: var(--text); font-weight: 600; }
.help { display: flex; flex-direction: column; width: min(100%, 820px); }
.help-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.help-body { overflow: auto; column-width: 300px; column-gap: 22px; }
.help section { break-inside: avoid; margin-bottom: 10px; }
.help h3 { margin: 0 0 2px; font-size: 13px; color: var(--teal); }
.help p { margin: 0; font-size: 12.5px; line-height: 1.35; }

/* ---- Card faces: drawn from data (ui/cardface.js), sized entirely in container units ---- */
.card { container-type: size; }
.face { --h: 220; position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; border-radius: 7cqw; text-align: left;
    color: hsl(var(--h) 30% 94%); border: 1.6cqw solid hsl(var(--h) 60% 62%);
    background: radial-gradient(120% 70% at 50% 28%, hsl(var(--h) 55% 30%), hsl(var(--h) 55% 14%) 75%), hsl(var(--h) 50% 12%); }
.face::before { content: ''; position: absolute; inset: 0; opacity: .16; pointer-events: none;
    background: repeating-linear-gradient(0deg, hsl(var(--h) 80% 80%) 0 .5cqw, transparent .5cqw 6cqw); }
.glyph { display: block; color: hsl(var(--h) 40% 92%); }
.glyph svg { display: block; width: 100%; height: 100%; }
.glyph .a { fill: hsl(var(--h) 85% 62%); } .glyph .b { fill: hsl(var(--h) 45% 34%); }
.top { position: relative; display: flex; align-items: center; gap: 2.4cqw; padding: 3cqw 3.4cqw 0; min-height: 25cqw; }
.name { font-size: 10.6cqw; line-height: 1.05; font-weight: 800; letter-spacing: -.01em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 900; }
.badge.cost { width: 15cqw; height: 15cqw; font-size: 9.5cqw; background: hsl(var(--h) 85% 66%); color: hsl(var(--h) 60% 12%); border: .9cqw solid #fff; }
.badge.cost::before { content: '$'; font-size: 6cqw; margin-right: .3cqw; }
.badge.install { width: 13cqw; height: 13cqw; font-size: 8cqw; background: transparent; color: hsl(var(--h) 40% 94%); border: 1cqw solid hsl(var(--h) 60% 70%); }
.glyph.corner { width: 15cqw; height: 15cqw; flex: none; }
.art { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 1cqw 6cqw; }
.art .glyph { height: 100%; aspect-ratio: 1; max-width: 100%; filter: drop-shadow(0 .8cqw 1.2cqw rgba(0, 0, 0, .5)); }
.rules { display: none; margin: 0; padding: 0 5cqw 2cqw; font-size: 5.6cqw; line-height: 1.22; color: hsl(var(--h) 25% 90%); }
.card.big .rules { display: block; }
.foot { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 2cqw; padding: 0 4cqw 3.6cqw; min-height: 15cqw; }
.phase { display: inline-flex; align-items: center; gap: 1.4cqw; font-size: 5.2cqw; font-weight: 800; color: hsl(var(--h) 60% 78%); }
.phase em { font-style: normal; }
.phase .glyph.tiny { width: 8cqw; height: 8cqw; }
.glyph.tiny { width: 11cqw; height: 11cqw; }
.xe-need { display: inline-flex; gap: 1cqw; flex-wrap: nowrap; align-items: center; }
.xe-need::before { content: 'Xe'; font-size: 5.4cqw; font-weight: 800; color: hsl(186 85% 70%); margin-right: .6cqw; }
.xe-dot { width: 5cqw; height: 5cqw; border-radius: 50%; background: hsl(186 85% 60%); border: .8cqw solid #fff; }
.pay { font-size: 12cqw; font-weight: 900; color: hsl(120 70% 72%); }
/* Victory points: a round gold medal with the number centred and a small star on its rim. */
.vp-star { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 16cqw; height: 16cqw; border-radius: 50%; font-size: 10.5cqw; font-weight: 900; line-height: 1;
    color: hsl(40 100% 12%); background: radial-gradient(circle at 35% 30%, hsl(48 100% 78%), hsl(42 95% 56%)); border: 1cqw solid #fff; box-shadow: 0 .6cqw 1.6cqw rgba(0, 0, 0, .55); }
.vp-star::after { content: '★'; position: absolute; top: -5.2cqw; right: -3cqw; font-size: 7cqw; color: hsl(48 100% 70%); text-shadow: 0 0 1cqw rgba(0, 0, 0, .8); }
.plus { font-size: 7cqw; font-weight: 800; color: hsl(var(--h) 60% 80%); }
/* elements */
.kind-element { align-items: center; justify-content: center; }
.kind-element .ring { position: absolute; inset: 36% 4% 10%; opacity: .9; }
.kind-element .ring svg { width: 100%; height: 100%; }
.ename { position: absolute; bottom: 6cqw; font-size: 9cqw; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: hsl(var(--h) 60% 84%); }
.ptable { position: absolute; top: 3cqw; left: 3cqw; right: 3cqw; opacity: .95; }
.ptable svg { display: block; width: 100%; }
.ptable .zsym { font-size: 24px; font-weight: 900; fill: #fff; stroke: hsl(var(--h) 70% 16%); stroke-width: .8px; paint-order: stroke; letter-spacing: -.5px; }
.el-Xe .ptable .zsym { fill: hsl(48 100% 88%); filter: drop-shadow(0 0 2px hsl(186 100% 60%)); }
.ptable .cell { fill: hsl(var(--h) 45% 52% / .75); }
.ptable .lit { fill: #fff; stroke: hsl(var(--h) 100% 60%); stroke-width: 1.6; filter: drop-shadow(0 0 3px hsl(var(--h) 100% 75%)); }
.el-Xe .kind-pipeline .glyph { color: hsl(var(--h) 50% 90%); }

.costs { position: relative; display: inline-flex; flex: none; width: 21cqw; height: 18cqw; }
.costs .badge.cost { position: absolute; left: 0; top: 0; }
.costs .later { position: absolute; right: -.5cqw; bottom: -1cqw; width: 11.5cqw; height: 11.5cqw; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
    font-size: 6.6cqw; font-weight: 900; background: hsl(var(--h) 60% 14%); color: #fff; border: .9cqw solid hsl(var(--h) 85% 72%); }

.log { display: flex; flex-direction: column; width: min(100%, 560px); }
.log-body { overflow: auto; }
.log-turn { margin: 0 0 8px; padding: 6px 10px; border-left: 4px solid var(--line); background: rgba(255, 255, 255, .03); border-radius: 0 8px 8px 0; }
.log-turn.by-0 { border-left-color: var(--teal); } .log-turn.by-1 { border-left-color: var(--orange); }
.log-turn h3 { margin: 0 0 3px; font-size: 13px; } .log-turn.by-0 h3 { color: var(--teal); } .log-turn.by-1 h3 { color: var(--orange); }
.log-turn ul { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.35; }

/* ---- animation layer (ui/fx.js) ---- */
#fx { position: fixed; inset: 0; z-index: 90; pointer-events: none; overflow: hidden; }
#toasts { position: absolute; top: calc(var(--hud-h) + 52px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; align-items: center; width: min(92%, 520px); }
.toast { padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; background: rgba(12, 18, 40, .94); border: 2px solid var(--line); box-shadow: 0 4px 14px rgba(0, 0, 0, .5); text-align: center; }
.toast.by-0 { border-color: var(--teal); } .toast.by-1 { border-color: var(--orange); }
.float { position: fixed; font-size: 15px; font-weight: 900; text-shadow: 0 1px 4px #000; white-space: nowrap; }
.float.gain { color: #86efac; } .float.loss { color: #fca5a5; } .float.vp { color: var(--violet-lt); }
.chip { position: fixed; min-width: 30px; height: 30px; padding: 0 6px; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-weight: 900; font-size: 14px;
    background: hsl(var(--h, 190) 70% 24%); border: 2px solid hsl(var(--h, 190) 90% 70%); color: #fff; box-shadow: 0 0 10px hsl(var(--h, 190) 100% 60% / .8); }
.confetti { position: fixed; width: 8px; height: 12px; border-radius: 2px; }
body[data-busy] #console .bar { opacity: .5; }
.rival-banner { display: flex; align-items: center; gap: 10px; color: var(--orange); font-weight: 800; }
.rival-banner .dots::after { content: '…'; animation: blink 1s steps(3) infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---- start screen ---- */
.start { height: 100cqh; display: grid; grid-template-columns: minmax(0, 34%) minmax(0, 1fr); align-items: center; gap: 12px; padding: var(--pad-t) var(--pad-r) var(--pad-b) var(--pad-l); overflow: auto;
    background: radial-gradient(120% 90% at 20% 30%, #1b2a5a 0%, var(--bg) 60%); }
.start-art { display: flex; justify-content: center; }
.ring-big { display: block; width: min(36cqh, 100%); aspect-ratio: 1; color: var(--teal); filter: drop-shadow(0 0 18px rgba(45, 212, 191, .55)); animation: spin-slow 40s linear infinite; }
.ring-big svg { width: 100%; height: 100%; }
@keyframes spin-slow { to { transform: rotate(360deg); } }
.start-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.start h1 { margin: 0; font-size: clamp(26px, 9cqh, 44px); line-height: 1; letter-spacing: -.02em; } .start h1 span { color: var(--teal); }
.start .tag { margin: 0; color: var(--dim); font-size: 13px; }
.levels-pick { display: flex; gap: 6px; }
.level { flex: 1; min-width: 0; text-align: left; padding: 6px 9px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.level small { color: var(--dim); font-size: 10.5px; line-height: 1.2; } .level.on { border-color: var(--teal); background: var(--panel2); }
.start-actions, .start-links { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.big { min-height: 46px; font-size: 16px; padding: 0 18px; }
.start .last { margin: 0; color: var(--dim); font-size: 12px; }

/* ---- stats & achievements ---- */
.stats { display: flex; flex-direction: column; width: min(100%, 760px); }
.tabs-row { display: flex; gap: 6px; margin-bottom: 6px; } .tabs-row .btn { min-height: 34px; }
.stats-body { overflow: auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; margin-bottom: 8px; }
.tile { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; display: flex; flex-direction: column; gap: 1px; }
.tile b { font-size: 18px; color: var(--teal); } .tile span { font-size: 10.5px; color: var(--dim); }
.level-table { border-collapse: collapse; width: 100%; font-size: 13px; } .level-table th, .level-table td { text-align: left; padding: 3px 8px; border-bottom: 1px solid var(--line); }
.res-win td:first-child { color: #86efac; } .res-loss td:first-child { color: #fca5a5; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.ach { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); }
.ach b { display: block; font-size: 13px; } .ach small { color: var(--dim); font-size: 11px; line-height: 1.2; display: block; }
.ach-icon { width: 36px; height: 36px; flex: none; }
.ach.got { border-color: hsl(46 90% 60%); } .ach.got .ach-icon { color: hsl(46 100% 76%); } .ach.got .ach-icon .a { fill: hsl(46 95% 58%); }
.ach.locked { opacity: .55; filter: grayscale(.8); }
.ach-count { margin: 0 0 6px; }
.toast.by-2 { border-color: hsl(46 95% 60%); color: hsl(46 100% 82%); }
.new-ach { margin: 6px 0; padding: 6px 10px; border: 2px solid hsl(46 95% 60%); border-radius: 10px; }
.new-ach h3 { margin: 0 0 3px; font-size: 13px; color: hsl(46 100% 76%); } .new-ach li { font-size: 12.5px; }
