:root {
  --bg: #0b0f1a;
  --bg2: #121828;
  --panel: #182033;
  --panel2: #1f2a42;
  --line: #2c3a58;
  --text: #e7ecf6;
  --dim: #94a0b8;
  --faint: #5d6984;
  --accent: #6ee7ff;
  --good: #49d17d;
  --warn: #ffbf3c;
  --bad: #ff6b6b;
  --C: #9aa4b2;
  --U: #3fd1a0;
  --R: #ffbf3c;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --head: 'Chakra Petch', 'Segoe UI', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 var(--body); overscroll-behavior: none; }
body { background: radial-gradient(1200px 600px at 70% -10%, #1a2550 0%, transparent 60%), radial-gradient(800px 500px at -10% 110%, #2a1640 0%, transparent 55%), var(--bg); }
button { font: inherit; color: inherit; touch-action: manipulation; }
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; position: relative; overflow: hidden; }
.boot { margin: auto; color: var(--dim); }
h1, h2, h3 { font-family: var(--head); margin: 0; letter-spacing: .02em; }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-height: 42px; cursor: pointer; font-weight: 600; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #2fd0f0, #1a8fbf); border-color: #5fe3ff; color: #031018; }
.btn.danger { border-color: #7a2d36; color: #ffb3b3; }
.btn.small { padding: 6px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.block { width: 100%; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); font-size: 12px; white-space: nowrap; }
.tag { display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 4px; background: #ffffff12; color: var(--dim); margin: 0 2px 2px 0; }
.pill-C { color: var(--C); } .pill-U { color: var(--U); } .pill-R { color: var(--R); }

/* ---------- title */
.title { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px calc(24px + var(--safe-b)); gap: 12px; }
.logo { font-family: var(--head); font-size: 40px; line-height: 1; letter-spacing: .06em; text-transform: uppercase; background: linear-gradient(90deg, #9cf6ff, #c7a6ff 60%, #ffd27a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo small { display: block; font-size: 15px; letter-spacing: .3em; margin-top: 8px; color: var(--dim); -webkit-text-fill-color: var(--dim); }
.title p { color: var(--dim); margin: 4px 0 18px; }
.planet { width: 160px; height: 160px; border-radius: 50%; margin: 0 auto 10px; background: radial-gradient(circle at 35% 30%, #ffe3a3, #e08b3a 35%, #6b2a52 70%, #1b1030 100%); box-shadow: 0 0 60px #e08b3a55, inset -20px -24px 40px #0008; position: relative; }
.planet::after { content: ''; position: absolute; inset: 40% -30%; border: 2px solid #c7a6ff66; border-radius: 50%; transform: rotate(-14deg); }

/* ---------- headers */
.topbar { padding: calc(8px + var(--safe-t)) 12px 8px; background: linear-gradient(180deg, #0b0f1aee, #0b0f1acc); border-bottom: 1px solid var(--line); z-index: 3; }
.topbar h2 { font-size: 17px; }
.res { display: flex; gap: 6px; flex-wrap: wrap; }
.res .chip { font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 4px; background: #ffffff14; overflow: hidden; position: relative; }
.meter > i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #2fd0f0, #a68cff); border-radius: 4px; }
.meter.danger > i { background: linear-gradient(90deg, #ffbf3c, #ff6b6b); }

/* ---------- clan select */
.page { flex: 1; overflow-y: auto; padding: 12px 12px calc(90px + var(--safe-b)); }
.clan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.clan-card { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: left; cursor: pointer; }
.clan-card.on { border-color: var(--cc); box-shadow: 0 0 0 1px var(--cc), 0 6px 24px -10px var(--cc); }
.clan-card .ic { font-size: 22px; }
.clan-card h3 { font-size: 14px; color: var(--cc); }
.clan-card p { margin: 4px 0 0; font-size: 12px; color: var(--dim); }
.bottombar { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + var(--safe-b)); background: linear-gradient(0deg, var(--bg) 70%, transparent); display: flex; gap: 8px; z-index: 4; }

/* ---------- colony */
.hud { padding: calc(6px + var(--safe-t)) 10px 6px; display: grid; gap: 5px; background: #0b0f1ad9; border-bottom: 1px solid var(--line); z-index: 3; }
.hud .l1 { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.hud .name { font-family: var(--head); font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.hud .inf { font-family: var(--head); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud .cp { font-size: 12px; color: var(--dim); }
.mapwrap { flex: 1; position: relative; min-height: 0; touch-action: manipulation; }
.mapwrap svg { width: 100%; height: 100%; display: block; }
.hex-base { stroke: #0b0f1a; stroke-width: .6; }
.hex-hit { fill: transparent; cursor: pointer; }
.legal { fill: #6ee7ff22; stroke: #6ee7ffaa; stroke-width: .9; pointer-events: none; }
.legal.top { fill: #ffbf3c33; stroke: #ffbf3c; stroke-width: 1.4; }
.picked { fill: none; stroke: #fff; stroke-width: 1.6; pointer-events: none; }
.target-ring { fill: none; stroke: #ff6b6b; stroke-width: 1.1; stroke-dasharray: 2 1.4; pointer-events: none; animation: spin 6s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.float { font-family: var(--head); font-weight: 700; font-size: 6.5px; fill: #fff; stroke: #000a; stroke-width: .6; paint-order: stroke; pointer-events: none; animation: floatUp 1.1s ease-out forwards; opacity: 0; }
@keyframes floatUp { 0% { opacity: 0; transform: translateY(2px); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-12px); } }
.flash { animation: flash .7s ease-out forwards; pointer-events: none; opacity: 0; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
.badge { font: 700 4.6px var(--body); fill: #031018; pointer-events: none; }
.badge-bg { fill: #6ee7ff; pointer-events: none; }
.badge-bg.top { fill: #ffbf3c; }
.maptools { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; }
.maptools .btn { width: 40px; height: 40px; padding: 0; min-height: 0; border-radius: 50%; font-size: 17px; background: #182033dd; }
.compass { position: absolute; left: 10px; bottom: 10px; width: 46px; height: 46px; border-radius: 50%; border: 1px dashed var(--line); pointer-events: none; }
.compass .sun { position: absolute; transform: translate(-50%, -50%); font-size: 15px; transition: left .4s, top .4s; }
.compass .rock { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; transform: translate(-50%, -50%); border-radius: 50%; background: linear-gradient(90deg, #2b3652 50%, #0e1320 50%); border: 1px solid var(--line); }
.turnsum { position: absolute; left: 64px; right: 8px; bottom: 8px; max-width: 340px; margin-left: auto; max-height: calc(100% - 16px); display: flex; flex-direction: column; background: #0b0f1aee; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; font-size: 11.5px; z-index: 2; cursor: pointer; }
.turnsum[hidden], .turnsum [hidden] { display: none; }
.turnsum .ts-head { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--head); font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.turnsum .ts-head .faint { font-family: inherit; font-weight: 400; font-size: 10px; }
.turnsum .ts-lines { overflow-y: auto; min-height: 0; flex: 0 1 auto; max-height: 180px; border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 4px; }
.turnsum .ts-row { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
.turnsum .ts-total, .turnsum .ts-level { font-size: 13px; }
.turnsum .ts-level { border-bottom: 1px solid var(--line); padding-bottom: 5px; margin-bottom: 3px; }
.turnsum .ts-target { color: var(--accent); }
.turnsum .ts-tail .ts-row span { color: var(--dim); }
.turnsum .pts { color: #ffd166; }
.legend { position: absolute; left: 8px; top: 8px; font-size: 11px; color: var(--dim); background: #0b0f1acc; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); }

.tray { border-top: 1px solid var(--line); background: #0d1220; padding: 6px 0 calc(6px + var(--safe-b)); z-index: 3; }
.hand { display: flex; gap: 8px; overflow-x: auto; padding: 2px 10px 6px; scroll-snap-type: x proximity; }
.hand::-webkit-scrollbar { display: none; }
.actions { display: flex; gap: 6px; padding: 0 10px; }
.actions .btn { flex: 1; padding: 6px 4px; min-height: 36px; font-size: 12px; }

.card { flex: 0 0 132px; height: 176px; border-radius: 10px; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1.5px solid var(--line); position: relative; overflow: hidden; padding: 0; text-align: left; cursor: pointer; scroll-snap-align: start; display: flex; flex-direction: column; }
.card.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent), 0 8px 26px -8px var(--accent); transform: translateY(-4px); }
.card .art { position: relative; flex: none; height: 58px; border-top: 3px solid var(--cc); background: radial-gradient(120% 90% at 50% 30%, color-mix(in srgb, var(--cc) 35%, transparent), transparent 70%), #0a0e18; display: flex; flex-direction: column; justify-content: space-between; }
.card .art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card .art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, #0008 0%, transparent 32%, transparent 48%, var(--panel2) 100%); pointer-events: none; }
.card .band { position: relative; z-index: 1; display: flex; align-items: center; padding: 4px 5px 0; }
.card .band .chip { background: var(--cc); color: #071018; font-weight: 700; font-size: 10px; line-height: 1; padding: 3px 5px; border-radius: 5px; white-space: nowrap; }
.card .band .gem { margin-left: auto; width: 10px; height: 10px; transform: rotate(45deg); border: 1.5px solid #071018; box-shadow: 0 0 0 1px #fff6; }
.card .nm { position: relative; z-index: 1; font-family: var(--head); font-weight: 700; font-size: 13px; line-height: 1.1; padding: 0 6px 3px; text-shadow: 0 1px 2px #000, 0 0 8px #000c; }
.card .meta { font-size: 10px; color: var(--dim); padding: 0 6px; }
.card .tx { flex: 1; min-height: 0; font-size: 10.5px; line-height: 1.25; color: #c9d2e3; padding: 3px 6px; overflow: hidden; -webkit-mask-image: linear-gradient(180deg, #000 80%, transparent); mask-image: linear-gradient(180deg, #000 80%, transparent); }
.tx .tl + .tl { margin-top: 3px; }
.tx .trg { display: inline-block; font-size: .85em; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; }
.tx .pts { color: #ffd166; font-weight: 700; white-space: nowrap; }
.card .rar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.card.big { flex: none; width: 100%; height: auto; cursor: default; }
.card.big .tx { -webkit-mask-image: none; mask-image: none; font-size: 13px; }
.card.big .tx .tl + .tl { margin-top: 6px; }
.card.big .nm { font-size: 17px; padding-bottom: 6px; }
.card.big .art { height: auto; aspect-ratio: 16 / 10; }
.card.big .band .chip { font-size: 12px; padding: 4px 7px; }

/* ---------- sheets */
.overlay { position: fixed; inset: 0; background: #0009; z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 720px; max-height: 86dvh; background: var(--bg2); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet .sh-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 8px; }
.sheet .sh-head h3 { flex: 1; font-size: 18px; }
.sheet .sh-body { padding: 4px 16px 12px; overflow-y: auto; }
.sheet .sh-actions { display: flex; gap: 8px; padding: 10px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet .sh-actions .btn { flex: 1; }
.x { background: none; border: 0; font-size: 22px; color: var(--dim); width: 40px; height: 40px; cursor: pointer; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv b { color: var(--dim); font-weight: 600; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.item h4 { margin: 0 0 4px; font-size: 14px; }
.sect { font-family: var(--head); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin: 14px 0 6px; }
.logline { font-size: 12.5px; padding: 3px 0; border-bottom: 1px solid #ffffff08; display: flex; gap: 6px; }
.logline .pts { margin-left: auto; font-weight: 700; color: var(--good); font-variant-numeric: tabular-nums; }
.logline.sys { color: var(--warn); }
.logline.rep { padding-left: 14px; color: #c7b8ff; }

#toast-root { position: fixed; left: 0; right: 0; bottom: calc(222px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 30; pointer-events: none; }
.toast { background: #182033f2; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 13px; box-shadow: 0 10px 30px #0008; animation: toast 2.6s forwards; max-width: 90vw; text-align: center; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-10px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- chart */
.chartwrap { flex: 1; overflow-y: auto; position: relative; }
.chartwrap svg { width: 100%; display: block; }
.node-c { cursor: pointer; }
.node-ring { fill: var(--panel); stroke: var(--line); stroke-width: 2; }
.node-ring.reach { stroke: var(--accent); stroke-width: 3; animation: pulse 1.6s ease-in-out infinite; }
.node-ring.claimed { stroke: var(--good); }
.node-ring.stranded { stroke: var(--bad); }
.node-ring.here { stroke: #fff; stroke-width: 4; }
@keyframes pulse { 50% { stroke-opacity: .35; } }
.lane { stroke: #3a4868; stroke-width: 2; }
.lane.lat { stroke-dasharray: 5 5; }
.lane.reach { stroke: var(--accent); stroke-width: 3; }
.lane.trail { stroke: #ffffff70; stroke-width: 3; }
.lane.built { stroke: #49d17d; stroke-width: 5; stroke-opacity: .85; }
.sector-label { font: 700 11px var(--head); fill: var(--faint); letter-spacing: .2em; text-transform: uppercase; }
.node-name { font: 600 9.5px var(--body); fill: var(--dim); }
.tabs { display: flex; border-top: 1px solid var(--line); background: #0d1220; padding-bottom: var(--safe-b); z-index: 3; }
.tabs button { flex: 1; background: none; border: 0; padding: 8px 2px 10px; color: var(--dim); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabs button span { font-size: 19px; }
.tabs button.on { color: var(--accent); }
.pips { display: inline-flex; gap: 2px; vertical-align: middle; }
.pips i { width: 7px; height: 7px; border-radius: 2px; background: #ffffff1c; }
.pips i.on { background: var(--accent); }
.prof { display: grid; grid-template-columns: auto auto; gap: 3px 10px; font-size: 12px; align-items: center; justify-content: start; }

.codex-card { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.pp { font-family: var(--head); font-weight: 700; font-variant-numeric: tabular-nums; }
.seg { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.seg .btn { flex: none; }
.seg .btn.on { border-color: var(--accent); color: var(--accent); }
.big-result { text-align: center; padding: 20px 0 10px; }
.big-result .em { font-size: 54px; }
.stamp { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
.stamp .ok { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; background: #ffffff10; border: 1px solid var(--line); }
.stamp .ok.y { background: #49d17d33; border-color: var(--good); }
.charter { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; background: var(--panel); cursor: pointer; text-align: left; width: 100%; }
.charter.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

@media (min-width: 560px) {
  .card { flex-basis: 150px; height: 190px; }
  .card .art { height: 64px; }
  .clan-grid { grid-template-columns: 1fr 1fr 1fr; }
}
