:root {
  --bg: #0b1626;
  --panel: rgba(12, 26, 44, 0.94);
  --panel-2: rgba(20, 40, 64, 0.96);
  --line: rgba(120, 180, 220, 0.18);
  --text: #e8f1f8;
  --muted: #9bb3c7;
  --accent: #2ec4b6;
  --accent-2: #5fd7ff;
  --sand: #f4d58d;
  --good: #5ad17a;
  --warn: #ffb347;
  --bad: #ff6b5b;
  --info: #7fb4ff;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --ui-scale: 1;
  font-size: calc(15px * var(--ui-scale));
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; background: rgba(46, 196, 182, 0.12); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.45em 0.8em; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
button:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
button { transition: background 0.12s, border-color 0.12s, transform 0.06s; }
button:hover:not(:disabled) { background: rgba(46, 196, 182, 0.28); border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, #33d3c3, #1f9e93); color: #03201d; font-weight: 700; border-color: #52e0d2; }
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, #4de0d1, #25b3a6); }
button.danger { background: rgba(255, 107, 91, 0.18); border-color: rgba(255, 107, 91, 0.5); }
button.small { padding: 0.2em 0.55em; font-size: 0.85rem; }
button.big { padding: 0.8em 1.4em; font-size: 1.1rem; width: 100%; }
input, select { font: inherit; color: var(--text); background: #0e2034; border: 1px solid var(--line); border-radius: 7px; padding: 0.4em 0.6em; }
input[type=range] { padding: 0; accent-color: var(--accent); }
label { display: block; margin: 0.6em 0; color: var(--muted); }
label > input, label > select { display: block; width: 100%; margin-top: 0.3em; color: var(--text); }
h1, h2, h3, h4 { margin: 0.2em 0 0.5em; font-weight: 700; letter-spacing: 0.01em; }
.muted { color: var(--muted); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
kbd { font-family: ui-monospace, monospace; font-size: 0.75em; background: rgba(255,255,255,0.1); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3em; margin-left: 0.3em; color: var(--muted); }
.hidden, [hidden] { display: none !important; }

/* screens */
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }
#screen-title .title-bg { position: absolute; inset: 0; background: url(assets/title.png) center/cover no-repeat, linear-gradient(160deg, #0f3b5c, #0b1626 60%);
  filter: saturate(1.05); }
#screen-title .title-bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(6,16,30,0.92) 0%, rgba(6,16,30,0.55) 42%, rgba(6,16,30,0.05) 75%); }
.title-card { position: relative; width: min(440px, 90vw); margin-left: 7vw; padding-top: 12vh; }
.title-card h1 { font-size: 4.2rem; line-height: 0.95; margin: 0; letter-spacing: -0.02em; text-shadow: 0 4px 24px rgba(0,0,0,0.5); }
.title-card h1 span { display: block; font-size: 1.6rem; font-weight: 600; color: var(--sand); letter-spacing: 0.18em; text-transform: uppercase; margin-top: 0.4em; }
.tagline { color: #cfe3f1; font-size: 1.1rem; margin: 1em 0 1.6em; }
.title-menu { display: grid; gap: 0.55em; }
.title-menu button:not(.primary) { background: rgba(8, 20, 36, 0.72); backdrop-filter: blur(6px); }   /* legible over the busy key art */
.title-menu button:not(.primary):hover { background: rgba(20, 48, 72, 0.85); }
.fineprint { color: var(--muted); font-size: 0.85rem; margin-top: 1.4em; }
.sheet { position: absolute; inset: 4vh 5vw; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 1.4em 1.8em; overflow: auto; box-shadow: var(--shadow); }
.sheet header { display: flex; align-items: center; gap: 1em; }
.sheet header h2 { margin: 0; }
.sheet footer { margin-top: 1.2em; display: flex; justify-content: flex-end; }
.sheet footer button { width: auto; }
.setup-grid { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 2em; margin-top: 1em; }
.rivals { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1em; align-content: start; }
.rival { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.rival img { width: 100%; aspect-ratio: 5 / 4; object-fit: cover; object-position: center 20%; background: #123; display: block; }
.rival > div { padding: 0.8em 0.95em 1em; min-width: 0; }
.rival select { width: 100%; margin: 0.35em 0 0.2em; }
.rival h4 { margin: 0 0 0.2em; }
.rival p { margin: 0.2em 0; font-size: 0.9rem; color: var(--muted); }
.campaign-list { display: grid; gap: 0.9em; margin-top: 1em; }
.scenario { display: grid; grid-template-columns: 240px 1fr auto; gap: 1.1em; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8em; }
.scenario .num { font-size: 1.3rem; font-weight: 800; color: var(--accent); margin-right: 0.2em; }
.scenario .card-art { width: 240px; height: 135px; object-fit: cover; border-radius: 9px; box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.scenario.locked .card-art { filter: grayscale(0.8) brightness(0.7); }
.banner { height: 180px; border-radius: 12px; background: #123 center / cover no-repeat; margin: 0 0 0.9em; position: relative;
  box-shadow: inset 0 -80px 70px -30px rgba(6, 16, 30, 0.9); overflow: hidden; }
.banner span { position: absolute; left: 1em; bottom: 0.6em; font-weight: 800; font-size: 1.35rem; text-shadow: 0 2px 8px rgba(0,0,0,0.8); }
@media (max-width: 900px) { .scenario { grid-template-columns: 1fr; } .scenario .card-art { width: 100%; height: 160px; } }
.scenario.locked { opacity: 0.55; }
.scenario ul { margin: 0.4em 0 0; padding-left: 1.2em; color: var(--muted); font-size: 0.9rem; }
.badge { display: inline-block; font-size: 0.75rem; padding: 0.1em 0.5em; border-radius: 99px; background: rgba(90, 209, 122, 0.2); color: var(--good); margin-left: 0.5em; }

/* game layout */
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: default; }
#map, #minimap { touch-action: none; }
.resource-strip { display: contents; }
[data-touch-speed], #mobile-controls, #mobile-close, #touch-instruction { display: none; }
#map.placing { cursor: crosshair; }
#map.panning { cursor: grabbing; }
#topbar { position: absolute; top: 0; left: 0; right: 0; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: stretch; gap: 2px; padding: 0 8px; z-index: 10; box-shadow: 0 4px 18px rgba(0,0,0,0.35); }
.chip { display: flex; flex-direction: row; align-items: center; gap: 0.45em; padding: 0 0.6em 0 0.4em; min-width: 0; border-radius: 8px; cursor: pointer; background: none; border: 0; text-align: left; }
.chipbody { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.ico { width: 30px; height: 30px; object-fit: contain; pointer-events: none; }
.ico.sm { width: 18px; height: 18px; vertical-align: -4px; flex: none; }
.ico.chipico { width: 26px; height: 26px; flex: none; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }
#buildbar button .ico { width: 36px; height: 36px; }
@media (max-width: 1380px) { .chip .k { display: none; } .ico.chipico { width: 22px; height: 22px; } .chip:not([data-chip="treasury"]) small { display: none; } }   /* narrow: the icon names the chip; tooltip has the label */
.chip:hover { background: rgba(255,255,255,0.06); }
.chip .k { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
.chip .v { font-size: 1rem; font-weight: 700; white-space: nowrap; }
.chip .v small { font-weight: 500; font-size: 0.75rem; margin-left: 0.3em; }
.chip .bar { height: 4px; background: rgba(255,255,255,0.1); border-radius: 3px; margin-top: 3px; overflow: hidden; }
.chip .bar i { display: block; height: 100%; background: var(--good); }
.chip.alert .v { color: var(--bad); }
.chip.caution .v { color: var(--warn); }
.island-flag { display: flex; align-items: center; gap: 0.6em; padding: 0 0.8em 0 0.2em; border-right: 1px solid var(--line); margin-right: 0.3em; }
.island-flag .dot { width: 14px; height: 14px; border-radius: 4px; }
.island-flag b { display: block; }
.island-flag span { font-size: 0.75rem; color: var(--muted); white-space: nowrap; display: block; max-width: 11em; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.clock { display: flex; align-items: center; gap: 0.6em; padding: 0 0.6em; border-left: 1px solid var(--line); }
.clock .phase { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); }
.clock .when { font-weight: 700; }
.clock .yearbar { width: 110px; height: 5px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.clock .yearbar i { display: block; height: 100%; background: var(--accent); }
.speed { display: flex; gap: 3px; }
.speed button { padding: 0.25em 0.55em; min-width: 34px; }
.speed button.on { background: var(--accent); color: #032; border-color: var(--accent); font-weight: 700; }

#buildbar { position: absolute; left: 8px; top: 66px; width: 58px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: grid; gap: 6px; z-index: 9; }
#buildbar button { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; font-size: 1.25rem; position: relative; }
#buildbar button.on { background: var(--accent); color: #032; }
#buildbar hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
#buildmenu { position: absolute; left: 74px; top: 66px; width: 360px; max-height: calc(100% - 180px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0.8em; z-index: 9; box-shadow: var(--shadow); }
#buildmenu h3 { display: flex; justify-content: space-between; align-items: center; margin: 0 0 0.5em; }
.bcard { display: grid; grid-template-columns: 58px 1fr auto; gap: 0.6em; align-items: center; padding: 0.4em; border-radius: 9px; border: 1px solid transparent; cursor: pointer; width: 100%; text-align: left; background: none; margin-bottom: 3px; }
.bcard:hover:not(.off) { background: rgba(46,196,182,0.12); border-color: var(--line); }
.bcard.sel { border-color: var(--accent); background: rgba(46,196,182,0.18); }
.bcard img { width: 58px; height: 58px; object-fit: contain; }
.bcard .n { font-weight: 700; }
.bcard .d { font-size: 0.78rem; color: var(--muted); line-height: 1.25; }
.bcard .c { text-align: right; font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.bcard .c small { display: block; font-weight: 400; color: var(--muted); font-size: 0.75rem; }
.bcard.off { opacity: 0.5; cursor: help; }
.bcard .why { color: var(--warn); font-size: 0.75rem; }

#inspector { position: absolute; right: 8px; top: 66px; width: 340px; max-height: calc(100% - 350px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0.9em; z-index: 9; box-shadow: var(--shadow); }
#inspector h3 { margin: 0 0 0.2em; display: flex; align-items: center; gap: 0.5em; }
#inspector.collapsed > :not(h3) { display: none; }
#inspector.collapsed h3 { margin: 0; }
#inspector h3 [data-collapse] { margin-left: auto; padding: 0.1em 0.55em; }
#inspector h3 .count { font-size: 0.75rem; background: var(--warn); color: #1a1206; border-radius: 99px; padding: 0.05em 0.55em; }
#inspector .sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.6em; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 0.15em 0.8em; font-size: 0.9rem; margin: 0.4em 0; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.sect { border-top: 1px solid var(--line); margin-top: 0.7em; padding-top: 0.6em; }
.sect h4 { margin: 0 0 0.4em; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.reason { display: flex; gap: 0.5em; align-items: flex-start; font-size: 0.88rem; padding: 0.35em 0.5em; border-radius: 7px; background: rgba(255,255,255,0.04); margin: 0.25em 0; }
.reason.s2 { background: rgba(255,107,91,0.13); }
.reason.s1 { background: rgba(255,179,71,0.11); }
.issue { border: 1px solid var(--line); border-radius: 9px; padding: 0.55em 0.7em; margin: 0.4em 0; cursor: pointer; background: rgba(255,255,255,0.03); }
.issue:hover { border-color: var(--accent); }
.issue .t { font-weight: 700; display: flex; gap: 0.5em; align-items: center; }
.issue ul { margin: 0.4em 0 0.3em; padding-left: 1.1em; color: var(--muted); font-size: 0.85rem; }
.issue .acts { display: flex; flex-wrap: wrap; gap: 0.3em; margin-top: 0.3em; }
.sev { display: inline-grid; place-items: center; min-width: 1.4em; height: 1.4em; border-radius: 5px; font-size: 0.8rem; font-weight: 800; color: #111; }
.sev.s3 { background: var(--bad); } .sev.s2 { background: var(--warn); } .sev.s1 { background: var(--info); } .sev.s0 { background: #8aa; }
.meter { height: 7px; background: rgba(255,255,255,0.08); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.tabs { display: flex; gap: 4px; margin-bottom: 0.6em; flex-wrap: wrap; }
.tabs button.on { background: var(--accent); color: #032; font-weight: 700; }

#ticker { position: absolute; left: 74px; bottom: 8px; right: 230px; max-width: 760px; z-index: 8; display: flex; flex-direction: column-reverse; gap: 3px; pointer-events: none; }
#ticker .ev { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: pop 0.25s ease-out; pointer-events: auto; background: rgba(10, 22, 38, 0.82); border: 1px solid var(--line); border-radius: 7px; padding: 0.25em 0.7em; font-size: 0.85rem; cursor: pointer; width: fit-content; max-width: 100%; }
#ticker .ev.bad { border-color: rgba(255,107,91,0.6); } #ticker .ev.warn { border-color: rgba(255,179,71,0.6); } #ticker .ev.good { border-color: rgba(90,209,122,0.5); }
#mapctl { position: absolute; right: 8px; bottom: 8px; z-index: 9; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#overlays { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 330px; }
#overlays button { font-size: 0.8rem; padding: 0.25em 0.55em; background: var(--panel); }
#overlays button.on { background: var(--accent); color: #032; }
#overlays .ov-legend { flex-basis: 100%; text-align: right; font-size: 0.75rem; color: var(--muted); background: var(--panel); border-radius: 6px; padding: 0.2em 0.55em; }
#minimap { width: 200px; height: 200px; background: #0b2440; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; box-shadow: var(--shadow); }
#alerts { position: absolute; top: 66px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toasts { display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 9px; padding: 0.55em 0.9em; box-shadow: var(--shadow); max-width: 560px; font-size: 0.92rem; animation: pop 0.25s ease-out; cursor: pointer; }
.toast.bad { border-left-color: var(--bad); } .toast.warn { border-left-color: var(--warn); } .toast.good { border-left-color: var(--good); }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
/* finding 2: storms collapse into one pinned banner (most urgent + "N more") instead of stacking toasts */
.storm-pin { pointer-events: auto; display: flex; align-items: center; gap: 0.7em; background: #3a1620; border: 2px solid var(--bad); border-radius: 9px; padding: 0.55em 0.9em; box-shadow: 0 0 0 4px rgba(255,107,91,0.25), var(--shadow); font-size: 1rem; font-weight: 600; max-width: 620px; animation: pop 0.25s ease-out; }
.storm-pin .muted { font-weight: 400; white-space: nowrap; }
#tooltip { position: fixed; z-index: 50; background: #081322; border: 1px solid var(--line); border-radius: 8px; padding: 0.5em 0.7em; font-size: 0.85rem; max-width: 320px; pointer-events: none; box-shadow: var(--shadow); }
#phase-pill { position: absolute; top: 66px; left: 50%; transform: translateX(-50%); z-index: 15; background: var(--panel-2); border: 1px solid var(--accent); border-radius: 99px; padding: 0.4em 0.5em 0.4em 1em; display: flex; gap: 0.8em; align-items: center; box-shadow: var(--shadow); }
#leftstack { position: absolute; left: 74px; top: 66px; z-index: 8; display: flex; flex-direction: column; gap: 8px; max-width: 320px; max-height: calc(100vh - 66px - 112px); overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
#objectives { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.6em 0.8em; font-size: 0.85rem; }
#objectives h4 { margin: 0 0 0.3em; }
#objectives li { margin: 0.2em 0; }
#objectives .charter-row { display: flex; justify-content: space-between; gap: 0.5em; font-size: 0.85rem; }
#objectives .charter-row + p.muted { margin: 0.1em 0 0; font-size: 0.78rem; }

/* S4: decision events — a small pinned card, never a blocking modal */
#dilemmas { display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.dilemma-card { pointer-events: auto; background: var(--panel); border: 1px solid var(--warn); border-radius: 10px; padding: 0.65em 0.8em; font-size: 0.85rem; box-shadow: var(--shadow); animation: pop 0.25s ease-out; }
.dilemma-card h4 { margin: 0 0 0.3em; display: flex; align-items: center; gap: 0.4em; }
.dilemma-card .situation { color: var(--muted); margin: 0 0 0.5em; }
.dilemma-card .choices { display: flex; flex-direction: column; gap: 0.35em; }
.dilemma-card .choice-btn { display: block; width: 100%; text-align: left; padding: 0.4em 0.55em; }
.dilemma-card .choice-btn .consequence { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 400; margin-top: 0.1em; }
.dilemma-card .timeout { margin: 0.4em 0 0; font-size: 0.75rem; color: var(--muted); }

/* modals */
#modal-root { position: absolute; inset: 0; z-index: 40; pointer-events: none; }
.modal-back { position: absolute; inset: 0; background: rgba(3, 10, 20, 0.55); pointer-events: auto; display: grid; place-items: center; }
@keyframes modal-in { from { transform: translateY(10px) scale(0.985); opacity: 0; } to { transform: none; opacity: 1; } }
.modal { animation: modal-in 0.18s ease-out; width: min(920px, 94vw); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 1.2em 1.4em; box-shadow: var(--shadow); position: relative; }
.modal.wide { width: min(1120px, 96vw); }
.modal > header { display: flex; align-items: center; gap: 0.8em; margin-bottom: 0.6em; position: sticky; top: -1.2em; background: var(--panel); padding: 0.4em 0; z-index: 2; }
.modal > header h2 { margin: 0; flex: 1; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1em; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8em 0.9em; }
.card h3 { font-size: 1rem; margin: 0 0 0.5em; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.35em 0.5em; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: rgba(46,196,182,0.1); }
.policy { display: grid; grid-template-columns: 180px 1fr 70px; gap: 0.8em; align-items: center; padding: 0.35em 0; border-bottom: 1px solid var(--line); }
.policy .hint { grid-column: 1 / -1; font-size: 0.8rem; color: var(--muted); margin-top: -0.3em; }
.bigscore { font-size: 3.2rem; font-weight: 800; line-height: 1; }
.catrow { display: grid; grid-template-columns: 170px 1fr 60px 60px; gap: 0.6em; align-items: center; margin: 0.35em 0; font-size: 0.9rem; }
.catrow .why { grid-column: 1 / -1; color: var(--muted); font-size: 0.8rem; margin-top: -0.25em; }
.catnote { font-size: 0.8rem; margin: -0.2em 0 0.6em; line-height: 1.35; }
.portrait { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; }
.offer { display: flex; gap: 0.6em; align-items: center; justify-content: space-between; padding: 0.5em; border: 1px solid var(--line); border-radius: 8px; margin: 0.4em 0; }

/* research tree (S2): 3 branch columns, each stacking tier 1 → 3 top to bottom */
.res-tree { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1em; align-items: start; }
.res-col { display: flex; flex-direction: column; gap: 0.6em; min-width: 0; }
.res-branch { text-align: center; margin: 0 0 0.1em; color: var(--accent-2); }
.res-tier { display: flex; flex-direction: column; gap: 0.5em; padding-top: 0.5em; border-top: 1px dashed var(--line); }
.res-tier:first-of-type { padding-top: 0; border-top: none; }
.res-tier-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.res-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 0.5em 0.65em; font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.3em; }
.res-card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.4em; }
.res-card-head b { font-size: 0.92rem; }
.res-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5em; margin-top: 0.1em; }
.res-card.available { border-color: var(--accent-2); }
.res-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.res-card.done { border-color: var(--good); opacity: 0.8; }
.res-card.locked { opacity: 0.55; }
@media (max-width: 900px) { .res-tree { grid-template-columns: 1fr; } }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
#tutorial { position: absolute; z-index: 30; left: 50%; bottom: 90px; transform: translateX(-50%); width: min(520px, 92vw); background: #0d2742; border: 2px solid var(--accent); border-radius: 14px; padding: 1em 1.2em; box-shadow: var(--shadow); }
#tutorial h3 { margin: 0 0 0.3em; color: var(--accent); }
#tutorial .row { display: flex; justify-content: space-between; align-items: center; margin-top: 0.7em; gap: 1em; }
.flash { animation: flash 1.2s ease-in-out infinite; }
@keyframes flash { 50% { box-shadow: 0 0 0 3px var(--accent-2); } }
.chart { width: 100%; height: 220px; }
.chart-sm { width: 100%; height: 96px; }

/* Insights panel: small-multiples grid for the Trends card */
.ins-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.8em 1.2em; }
.ins-title { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.2em; }

/* Contextual tip card: bottom-right, clear of the top bar and the concerns panel (#inspector) at all times */
#tip-card { position: absolute; right: 250px; bottom: 110px; width: min(380px, 32vw); z-index: 25;
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 10px; padding: 0.6em 0.8em;
  box-shadow: var(--shadow); font-size: 0.85rem; pointer-events: auto; animation: pop 0.25s ease-out; }
#tip-card .tip-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 0.3em; }
#tip-card p { margin: 0; color: var(--text); }
@media (max-width: 900px) {
  #inspector { width: 280px; }
  .chip { padding: 0 0.4em; }
  .setup-grid { grid-template-columns: 1fr; }
  #tip-card { right: 8px; bottom: 8px; width: min(340px, 90vw); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
#inspector, #buildmenu, .modal { backdrop-filter: blur(6px); }   /* no ghosting of bright map labels through panels */

/* S5 dynasty mode: royal family, coronation card, chronicle */
.portrait.sm { width: 44px; height: 44px; border-radius: 8px; vertical-align: middle; }
.portrait.lg { width: 96px; height: 96px; }
.portrait.xl { width: 168px; height: 168px; border-radius: 14px; border: 2px solid #d9a93a; box-shadow: var(--shadow); }
.royal-head { display: flex; gap: 0.8em; align-items: center; }
.royal-actions { display: flex; gap: 0.5em; flex-wrap: wrap; margin-top: 0.8em; justify-content: flex-end; }
.traits { display: grid; gap: 0.25em; margin-top: 0.6em; font-size: 0.9rem; }
.trait { display: inline-block; padding: 0 0.45em; border-radius: 99px; background: rgba(226, 164, 43, 0.16); color: var(--warn); font-size: 0.8rem; }
.heirs { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0.5em; }
.heir { display: flex; gap: 0.6em; align-items: center; padding: 0.4em; border: 1px solid var(--line); border-radius: 8px; }
.heir > div { flex: 1; min-width: 0; }
.coronation { text-align: center; }
.coronation .crown-name { font-size: 1.7rem; font-weight: 800; margin-top: 0.4em; }
.coronation h3 { margin: 0.6em 0 0.2em; color: #e8b84a; }
.coronation .traits { text-align: left; max-width: 460px; margin: 0.6em auto; }
.coronation .royal-actions { justify-content: center; }
.compact .bigscore { font-size: 2.6rem; }
.compact table { width: 100%; }
.chronicle { max-height: 52vh; overflow: auto; }
.reign { display: flex; gap: 0.7em; align-items: flex-start; padding: 0.5em 0; border-bottom: 1px solid var(--line); }
.reign:last-child { border-bottom: 0; }
.reign ul { margin: 0.25em 0 0; padding-left: 1.1em; font-size: 0.82rem; color: var(--muted); }
#topbar [data-regent] { white-space: nowrap; }
#topbar [data-regent].on { background: #d9a93a; color: #231; border-color: #d9a93a; font-weight: 700; }
.ico.chipico.royal-ico { border-radius: 50%; object-fit: cover; border: 1px solid #d9a93a; }
.clock .when { white-space: nowrap; }
#topbar.royal .chip { gap: 0.3em; padding: 0 0.4em 0 0.3em; }
@media (max-width: 1380px) {
  #topbar.royal .chip small { display: none; }
  #topbar.royal .clock { gap: 0.4em; padding: 0 0.4em; }
  #topbar.royal .clock .yearbar { width: 84px; }
  #topbar.royal .speed button { min-width: 30px; padding: 0.25em 0.4em; }
  #topbar .rg-label { display: none; }
}

/* S11: plot cards share the left stack with the dilemma card and objectives (stacked, never overlapping) */
#plots { display: flex; flex-direction: column; gap: 8px; }
#plots[hidden] { display: none; }
.plot-card { background: var(--panel); border: 1px solid var(--bad); border-radius: 10px; padding: 0.6em 0.75em; font-size: 0.83rem; box-shadow: var(--shadow); animation: pop 0.25s ease-out; }
.plot-card h4 { margin: 0 0 0.3em; display: flex; align-items: center; gap: 0.35em; }
.plot-card .situation { color: var(--muted); margin: 0 0 0.45em; }
.plot-card .suspects { display: flex; flex-direction: column; gap: 3px; margin-bottom: 0.45em; }
.plot-card .suspect { display: flex; align-items: center; gap: 0.3em; }
.plot-card .suspect .link { flex: 1; text-align: left; background: none; border: none; padding: 0.1em 0; color: var(--text, #e8eef6); cursor: pointer; font-size: 0.83rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plot-card .suspect .link:hover { text-decoration: underline; }
.plot-card .suspect.guarded .link { color: #8fd3ff; }
.plot-card .tag { font-size: 0.72rem; padding: 0.05em 0.35em; border-radius: 5px; background: rgba(255,255,255,0.08); white-space: nowrap; }
.plot-card .tag.good { color: var(--good); } .plot-card .tag.warn { color: var(--warn); } .plot-card .tag.bad { color: var(--bad); }
.plot-card .plot-actions { display: flex; flex-wrap: wrap; gap: 0.4em; align-items: center; }
.plot-card .timeout { margin: 0.35em 0 0; font-size: 0.72rem; color: var(--muted); }
.plot-card.outcome h4 { margin: 0; font-weight: 600; }
.plot-card.outcome .x { margin-left: auto; }
.plot-card.outcome.good { border-color: var(--good); } .plot-card.outcome.warn { border-color: var(--warn); }
.teams-ctl { display: inline-flex; align-items: center; gap: 0.25em; white-space: nowrap; }
.teams-ctl button { min-width: 1.8em; padding: 0.1em 0.3em; }
.flag { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 2px; vertical-align: -0.05em; }
/* S10 titles */
.tbadges { font-size: 0.85em; letter-spacing: 0.05em; white-space: nowrap; }
.titles-table td { vertical-align: middle; }
.titles-table .holder { display: flex; align-items: center; gap: 0.4em; }
.titles-table .portrait.xs { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.titles-table .gap { font-size: 0.82rem; }

/* Phones and touch tablets: keep the island visible and open one panel at a time. */
#app { position: relative; height: 100%; height: 100dvh; overflow: hidden; }
#screen-title { overflow-y: auto; }
@media (max-width: 1200px), (pointer: coarse) {
  :root { --hud-height: calc(108px + env(safe-area-inset-top, 0px)); --tools-height: calc(68px + env(safe-area-inset-bottom, 0px)); --panel-top: calc(var(--hud-height) + 56px); }
  button, button.small, select { min-height: 44px; }
  button { touch-action: manipulation; }
  input, select { font-size: 16px; }
  .title-card { margin-left: max(20px, env(safe-area-inset-left)); width: min(440px, calc(100% - 40px)); padding-top: max(28px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .title-card h1 { font-size: clamp(3rem, 12vw, 4.2rem); }
  .title-card h1 span { font-size: clamp(1.05rem, 4vw, 1.6rem); }
  .sheet { 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)); padding: 16px; }
  .sheet header { gap: 12px; }
  .sheet header h2 { font-size: 1.35rem; }
  .setup-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .rivals { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
  .rival { flex-direction: row; }
  .rival img { width: 80px; height: 110px; align-self: center; object-fit: cover; }
  .rival > div { flex: 1; padding: 10px; }
  .sheet footer button { width: 100%; }
  .scenario { grid-template-columns: minmax(0, 1fr); }
  .scenario .card-art { width: 100%; }
  #topbar { height: var(--hud-height); padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left)); flex-direction: column; gap: 0; }
  #topbar .island-flag, #topbar > .spacer { display: none; }
  #topbar .clock { order: -1; flex: none; height: 52px; width: 100%; border: 0; padding: 0; gap: 6px; }
  #topbar .clock > div:first-child { flex: 1; min-width: 0; }
  #topbar .clock .phase { font-size: 0.65rem; letter-spacing: 0; }
  #topbar .clock .when { font-size: 0.82rem; }
  #topbar .clock .yearbar { display: none; }
  #topbar .clock .speed { flex: none; gap: 4px; }
  #topbar .speed [data-speed]:not([data-speed="0"]) { display: none; }
  #topbar .speed button, #topbar [data-menu], #topbar [data-regent] { min-width: 44px; padding: 4px 8px; }
  #topbar [data-regent] { font-size: 0; }
  #topbar [data-regent]::after { content: 'Regent'; font-size: 0.75rem; }
  #topbar [data-touch-speed] { display: block; width: 64px; padding: 4px; }
  .resource-strip { display: flex; overflow-x: auto; overflow-y: hidden; width: 100%; height: 56px; scrollbar-width: thin; gap: 8px; overscroll-behavior-x: contain; }
  #topbar .resource-strip .chip { flex: none; padding: 2px 6px; gap: 6px; }
  #topbar .resource-strip .chip .k { display: block; font-size: 0.65rem; letter-spacing: 0; }
  #topbar .resource-strip .chip .v { font-size: 0.9rem; }
  #topbar .resource-strip .chip small { display: none; }
  #mobile-controls { display: flex; position: absolute; top: calc(var(--hud-height) + 6px); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); gap: 4px; z-index: 11; overflow-x: auto; scrollbar-width: none; }
  #mobile-controls button { background: var(--panel); flex: none; padding: 6px 10px; }
  #mobile-controls button[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
  #mobile-controls [data-zoom] { min-width: 44px; }
  #buildbar { left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); top: auto; bottom: max(6px, env(safe-area-inset-bottom)); width: auto; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; border-radius: 12px; }
  #buildbar button { flex: none; }
  #buildbar hr { width: 1px; height: 32px; border: 0; background: var(--line); flex: none; align-self: center; margin: 0 4px; }
  #inspector, #buildmenu, #leftstack, #mapctl { display: none; top: var(--panel-top); bottom: calc(var(--tools-height) + 8px); left: auto; right: max(8px, env(safe-area-inset-right)); width: min(420px, calc(100% - max(16px, env(safe-area-inset-right)) - env(safe-area-inset-left))); max-width: none; max-height: none; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; z-index: 14; padding: 58px 12px 12px; overscroll-behavior: contain; }
  #screen-game[data-panel="inspector"] #inspector, #screen-game[data-panel="build"] #buildmenu { display: block; }
  #screen-game[data-panel="events"] #leftstack, #screen-game[data-panel="map"] #mapctl { display: flex; }
  #screen-game[data-panel="map"] #mapctl { align-items: center; }
  #buildmenu { padding-top: 12px; }
  #buildmenu h3 { position: sticky; top: -12px; padding: 8px 0; background: var(--panel); z-index: 1; }
  #mobile-close { position: absolute; top: calc(var(--panel-top) + 8px); right: max(20px, calc(env(safe-area-inset-right) + 12px)); z-index: 15; background: var(--panel-2); }
  #screen-game:is([data-panel="inspector"], [data-panel="events"], [data-panel="map"]) #mobile-close { display: block; }
  #inspector.collapsed > :not(h3) { display: block; }
  #inspector [data-collapse] { display: none; }
  #leftstack #objectives { display: block; }
  #leftstack #dilemmas, #leftstack #plots { display: flex; }
  #overlays { justify-content: center; }
  #overlays .ov-legend { text-align: center; }
  #minimap { flex: none; }
  #ticker { display: none; }
  #alerts { top: auto; bottom: calc(var(--tools-height) + 12px); max-width: calc(100% - 24px); width: 520px; z-index: 16; }
  #toasts, .toast, .storm-pin { max-width: 100%; }
  .storm-pin { flex-wrap: wrap; font-size: 0.85rem; }
  #tip-card { right: max(8px, env(safe-area-inset-right)); bottom: calc(var(--tools-height) + 12px); width: min(340px, calc(100% - 16px)); max-height: 25%; overflow: auto; }
  #screen-game[data-panel]:not([data-panel=""]) #tip-card { display: none; }
  #touch-instruction { display: block; position: absolute; top: var(--panel-top); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); width: fit-content; margin: 0; padding: 8px 12px; max-width: calc(100% - 16px); background: var(--panel); border-radius: 8px; z-index: 10; pointer-events: none; font-size: 0.85rem; }
  #phase-pill { top: auto; bottom: calc(var(--tools-height) + 8px); width: min(520px, calc(100% - 16px)); flex-wrap: wrap; border-radius: 12px; gap: 8px; }
  #tutorial { bottom: calc(var(--tools-height) + 12px); max-height: 40%; overflow: auto; }
  .modal, .modal.wide { width: calc(100% - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)); max-width: 1120px; max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding: 12px; }
  .modal-back { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .modal > header { top: -12px; gap: 8px; }
  .modal > header h2 { font-size: 1.25rem; overflow-wrap: anywhere; }
  .modal > header button { min-width: 44px; }
  .cols { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
  .cols > *, .card, .mbody { min-width: 0; }
  .mbody { overflow-x: auto; }
  .mbody table { display: block; overflow-x: auto; max-width: 100%; }
  .heirs { grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }
  .policy { grid-template-columns: minmax(100px, 1fr) minmax(60px, 1fr) 44px; gap: 8px; }
  .catrow { grid-template-columns: minmax(90px, 1fr) minmax(40px, 1fr) 44px 44px; gap: 6px; }
  .offer { flex-wrap: wrap; }
  .bcard { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 8px; }
  .bcard img { width: 44px; height: 44px; }
  .bcard .d { font-size: 0.85rem; }
  .royal-head { flex-wrap: wrap; }
  .kv { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); overflow-wrap: anywhere; }
  #tooltip { display: none; }
}
