/* Carved Kingdoms — diagnostic v0.4. Tokens from design-assets-v1/ui/tokens.json. */
:root {
  --deep: #172C30;
  --panel: #21383B;
  --panel-a: rgba(23, 44, 48, 0.95);
  --dark: #102326;
  --gold: #D3AB70;
  --bone: #ECE4D3;
  --cool: #BDD0D3;
  --muted: #AAB6B2;
  --warn: #D9976E;
  --disabled: #768682;
  --line: rgba(211, 171, 112, 0.28);
  --line-soft: rgba(236, 228, 211, 0.1);
  --good: #9fc39a;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --sans: Arial, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --tap: 48px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: radial-gradient(ellipse 120% 90% at 50% 42%, #1c3a40 0%, #13282c 55%, var(--dark) 100%);
  color: var(--bone); font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; }
#board { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; cursor: grab; z-index: 1; background: transparent; }
canvas.layer { position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
#water { z-index: 0; }
#clouds { z-index: 1; }
#overlay { z-index: 1; }
#board.dragging { cursor: grabbing; }
#board:focus-visible { box-shadow: inset 0 0 0 2px var(--gold); }
.ico { flex: none; display: block; }

/* ---------- buttons */
.btn {
  appearance: none; border: 1px solid var(--gold); background: var(--deep); color: var(--bone);
  font: 700 14.5px/1 var(--sans); padding: 0 16px; min-height: var(--tap); border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: #1d363a; }
.btn:active { background: #2a4448; box-shadow: inset 0 -2px 0 var(--gold); }
.btn:focus-visible, .iconbtn:focus-visible, .tab:focus-visible, .chip:focus-visible, .step button:focus-visible, .seg button:focus-visible { outline: 2px solid var(--cool); outline-offset: 2px; }
.btn[disabled] { border-color: rgba(118, 134, 130, .6); color: var(--disabled); cursor: not-allowed; background: rgba(23, 44, 48, .6); }
.btn.primary { background: var(--gold); color: #1a1408; border-color: var(--gold); }
.btn.primary:hover { background: #dfb87d; }
.btn.warn { border-color: var(--warn); color: var(--warn); }
.btn.ghost { border-color: rgba(236, 228, 211, .22); background: transparent; }
.btn.small { min-height: 40px; font-size: 13.5px; padding: 0 12px; }
.btn.block { width: 100%; }
.iconbtn {
  appearance: none; width: var(--tap); height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--panel-a);
  display: inline-grid; place-items: center; cursor: pointer; color: var(--gold); font-size: 22px; font-weight: 500; flex: none;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.iconbtn.round { border-radius: 50%; }
.iconbtn.small { font: 700 12.5px/1 var(--sans); }

/* ---------- HUD */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 4; pointer-events: none;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 8px calc(10px + var(--safe-l));
  background: linear-gradient(180deg, rgba(16, 35, 38, .95) 0%, rgba(16, 35, 38, .82) 70%, rgba(16, 35, 38, 0) 100%);
}
.hud > * { pointer-events: auto; }
.hud-row { display: flex; align-items: center; gap: 8px; }
.turnbox { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.eyebrow { font: 700 10px/1.2 var(--sans); letter-spacing: .18em; text-transform: uppercase; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turnline { font: 600 18px/1.2 var(--serif); color: var(--bone); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turnline small { font: 500 12.5px var(--sans); color: var(--muted); margin-left: 4px; }
.coin {
  appearance: none; display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-a); cursor: pointer; font: 700 16px var(--sans); color: var(--bone);
}
.coin small { font: 600 11.5px var(--sans); color: var(--muted); }
.coin small.neg { color: var(--warn); }
.coin small.pos { color: var(--good); }
.strip { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.chip {
  appearance: none; flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; gap: 5px; min-height: 44px; padding: 4px 6px 4px 5px;
  border-radius: 22px; border: 1px solid var(--line); background: var(--panel-a); cursor: pointer; text-align: left;
}
.chip .med { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--gold); display: grid; place-items: center; color: var(--gold); flex: none; }
.chip .v { display: flex; flex-direction: column; line-height: 1.1; }
.chip b { font: 700 15px var(--sans); }
.chip small { font: 600 10.5px var(--sans); color: var(--muted); white-space: nowrap; }
.chip small.neg { color: var(--warn); }
.chip small.pos { color: var(--good); }
.chip.warn { border-color: var(--warn); }
.chip.warn .med { border-color: var(--warn); color: var(--warn); }
.townbtn { appearance: none; border: 0; background: transparent; padding: 0; text-align: left; cursor: pointer; min-height: 18px; }
.townbtn:focus-visible { outline: 2px solid var(--cool); }

/* ---------- zoom */
.zoom { position: fixed; z-index: 2; right: calc(12px + var(--safe-r)); display: flex; flex-direction: column; gap: 8px;
  bottom: calc(var(--sheet-h, 200px) + 12px); transition: bottom .2s ease; }
.zoom .iconbtn { width: 44px; height: 44px; }

/* ---------- sheet: phone = bottom sheet */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; flex-direction: column;
  background: var(--panel-a); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .35); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 0 calc(12px + var(--safe-r)) var(--safe-b) calc(12px + var(--safe-l));
  height: 52vh; transition: height .22s ease; user-select: text; -webkit-user-select: text;
}
.sheet.peek { height: 138px; }
.sheet.closed { height: 104px; }
.grab { appearance: none; border: 0; background: transparent; width: 100%; height: 22px; display: grid; place-items: center; cursor: pointer; flex: none; }
.grab span { width: 40px; height: 4px; border-radius: 2px; background: rgba(236, 228, 211, .3); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-soft); flex: none; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer; flex: 1 0 auto; min-width: 48px; min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted);
  font: 500 11.5px/1.1 var(--sans); padding: 4px 6px; border-bottom: 2px solid transparent; position: relative;
}
.tab[aria-selected="true"] { color: var(--bone); font-weight: 700; border-bottom-color: var(--gold); }
.tab .dot { position: absolute; top: 6px; right: calc(50% - 16px); width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.sheet-body { flex: 1; overflow: auto; padding: 12px 2px 16px; overscroll-behavior: contain; }

/* ---------- contextual hint (first district, first scout move, threat) */
.hint {
  position: fixed; z-index: 3; left: calc(10px + var(--safe-l)); right: calc(66px + var(--safe-r)); bottom: calc(var(--sheet-h, 138px) + 10px);
  display: flex; align-items: center; gap: 10px; padding: 8px 6px 8px 12px; border-radius: 14px; border: 1px solid var(--gold);
  background: rgba(16, 35, 38, .95); box-shadow: 0 8px 24px rgba(0, 0, 0, .4); font-size: 13.5px; line-height: 1.35; transition: bottom .2s ease;
}
.hint[hidden] { display: none; }
.hint > .ico { color: var(--gold); }
.hint span { flex: 1; }
.hint .btn.small { min-height: 40px; flex: none; }
.hint .hintx { width: 40px; height: 40px; flex: none; border: 0; background: transparent; }
.peekline { display: flex; align-items: center; gap: 8px; min-height: 30px; font-size: 14px; color: var(--bone); }
.peekline .ico { color: var(--gold); }
.small { font-size: 13px; }

/* ---------- content */
h2.title { margin: 0; font: 600 21px/1.15 var(--serif); color: var(--bone); }
h3 { margin: 18px 0 8px; font: 700 10.5px/1.3 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
h3:first-child { margin-top: 2px; }
.role { font: 700 10.5px/1.3 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.sub { font-size: 12.5px; color: var(--muted); }
.head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.thumb { width: 52px; height: 52px; flex: none; border-radius: 10px; background: rgba(255, 255, 255, .04) center/contain no-repeat; border: 1px solid var(--line-soft); display: grid; place-items: center; color: var(--gold); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.note { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.warnline { color: var(--warn); }
.goodline { color: var(--good); }
.card { border: 1px solid var(--line-soft); border-radius: 14px; background: rgba(16, 35, 38, .5); padding: 10px 12px; margin-bottom: 10px; }
.card.gold { border-color: var(--line); }
.card.warn { border-color: rgba(217, 151, 110, .7); }
.card.dim { opacity: .62; }
.row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.row + .row { border-top: 1px solid var(--line-soft); }
.row .lbl { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.row .lbl span { overflow: hidden; text-overflow: ellipsis; }
.row .lbl small { display: block; color: var(--muted); font-size: 12px; }
.row .val { font-weight: 700; text-align: right; white-space: nowrap; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 700; }
.cost { display: inline-flex; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--bone); align-items: center; }
.cost span { display: inline-flex; gap: 3px; align-items: center; }
.cost .short { color: var(--warn); }
.bar { height: 8px; border-radius: 4px; background: rgba(236, 228, 211, .14); overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; background: var(--gold); border-radius: 4px; }
.bar.warn i { background: var(--warn); }
.step { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; }
.step button { appearance: none; width: 44px; height: 44px; border: 0; background: transparent; color: var(--gold); font-size: 22px; cursor: pointer; }
.step button:disabled { color: var(--disabled); cursor: not-allowed; }
.step button:active:not(:disabled) { background: rgba(211, 171, 112, .16); }
.step output { min-width: 34px; text-align: center; font-weight: 700; font-size: 16px; }
.step.small button { width: 38px; height: 38px; font-size: 19px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 10px; }
.seg button { flex: 1; appearance: none; border: 0; background: transparent; min-height: 44px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: rgba(211, 171, 112, .16); color: var(--bone); box-shadow: inset 0 -2px 0 var(--gold); }
table.ledger { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ledger th { font: 700 10.5px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--gold); text-align: right; padding: 4px 4px 6px; }
table.ledger th:first-child, table.ledger td:first-child { text-align: left; color: var(--muted); }
table.ledger td { text-align: right; padding: 4px; border-top: 1px solid var(--line-soft); }
table.ledger tr.total td { font-weight: 700; color: var(--bone); border-top: 1px solid var(--line); }
table.ledger td.neg { color: var(--warn); }
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 14px; }
.notes li:first-child { border-top: 0; }
.notes li .ico { margin-top: 1px; }
.notes li.bad { color: var(--bone); }
.notes li.bad .ico, .notes li.warn .ico { color: var(--warn); }
.notes li.info { color: var(--muted); }
.notes li.good .ico { color: var(--good); }
.log-turn { font: 600 15px var(--serif); margin: 14px 0 4px; color: var(--bone); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font: 700 10.5px/1.5 var(--sans); letter-spacing: .08em; text-transform: uppercase; border: 1px solid var(--line); color: var(--gold); }
.pill.warn { border-color: var(--warn); color: var(--warn); }
.pill.good { border-color: var(--good); color: var(--good); }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }

/* ---------- modal */
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(6, 14, 16, .6); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.dialog {
  width: 100%; max-height: 86vh; overflow: auto; background: var(--deep); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 16px calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); box-shadow: 0 -16px 40px rgba(0, 0, 0, .5);
  user-select: text; -webkit-user-select: text;
}
.dialog h2 { margin: 0 0 4px; font: 600 22px/1.2 var(--serif); }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.toast {
  position: fixed; z-index: 11; left: 50%; transform: translateX(-50%); top: calc(118px + var(--safe-t)); max-width: min(92vw, 520px);
  background: var(--dark); border: 1px solid var(--gold); color: var(--bone); padding: 10px 14px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45); display: flex; gap: 10px; align-items: center;
}
.toast.warn { border-color: var(--warn); }
.toast[hidden] { display: none; }
.perf { position: fixed; left: calc(10px + var(--safe-l)); top: calc(124px + var(--safe-t)); z-index: 2; font: 11.5px/1.35 ui-monospace, Menlo, monospace;
  color: #cfe3d0; background: rgba(0, 0, 0, .6); padding: 6px 8px; border-radius: 6px; pointer-events: none; white-space: pre; }
.loading { position: fixed; inset: 0; display: grid; place-items: center; font: 600 15px var(--serif); color: var(--muted); pointer-events: none; transition: opacity .3s; z-index: 20; }
.loading.done { opacity: 0; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
label.check input { width: 20px; height: 20px; accent-color: var(--gold); }

/* ---------- tablet landscape / wide: side panel */
@media (min-width: 900px) and (min-height: 520px) and (orientation: landscape) {
  .hud { right: calc(400px + var(--safe-r)); background: linear-gradient(180deg, rgba(16, 35, 38, .92), rgba(16, 35, 38, 0)); }
  .strip .chip { flex: 0 0 auto; }
  .sheet, .sheet.peek, .sheet.closed {
    left: auto; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); bottom: calc(12px + var(--safe-b)); width: 380px; height: auto;
    border: 1px solid var(--line); border-radius: 16px; padding: 0 12px; box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
  }
  .grab { display: none; }
  .zoom { bottom: calc(18px + var(--safe-b)); right: calc(408px + var(--safe-r)); }
  .hint { right: calc(470px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); max-width: 560px; }
  .modal { align-items: center; }
  .dialog { max-width: 620px; border-radius: 18px; }
  .toast { top: calc(124px + var(--safe-t)); left: calc(50% - 200px); }
}
/* tablet portrait: centred, width-limited sheet */
@media (min-width: 600px) and (orientation: portrait) {
  .sheet { left: 50%; right: auto; width: min(680px, calc(100% - 32px)); transform: translateX(-50%); bottom: calc(14px + var(--safe-b));
    border: 1px solid var(--line); border-radius: 18px; height: 42vh; }
  .sheet.peek { height: 150px; }
  .hint { left: 50%; right: auto; width: min(640px, calc(100% - 32px)); transform: translateX(-50%); bottom: calc(var(--sheet-h, 150px) + 12px); }
  .modal { align-items: center; }
  .dialog { max-width: 640px; border-radius: 18px; }
  .strip .chip { flex: 0 0 auto; }
}
/* phone landscape: narrow side panel */
@media (max-height: 519px) and (orientation: landscape) {
  .hud { right: calc(330px + var(--safe-r)); padding-top: calc(6px + var(--safe-t)); }
  .strip { margin-top: 6px; }
  .chip { min-height: 40px; }
  .sheet, .sheet.peek, .sheet.closed { left: auto; top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r)); bottom: calc(8px + var(--safe-b)); width: 318px; height: auto;
    border: 1px solid var(--line); border-radius: 14px; padding: 0 10px; }
  .grab { display: none; }
  .zoom { bottom: calc(10px + var(--safe-b)); right: auto; left: calc(10px + var(--safe-l)); flex-direction: row; }
  .hint { right: calc(340px + var(--safe-r)); left: calc(170px + var(--safe-l)); bottom: calc(10px + var(--safe-b)); }
  .modal { align-items: center; }
  .dialog { max-width: 600px; max-height: 92vh; border-radius: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- v0.4 units */
.unit-card .mission { padding: 6px 0 2px; border-top: 1px solid var(--line-soft); font-size: 14px; }
.unit-actions { gap: 6px; margin-top: 8px; }
.unit-actions .btn { flex: 1 1 calc(33% - 6px); min-height: 44px; padding: 0 8px; }
.seg.radius { margin: 8px 0 0; align-items: center; }
.seg.radius .seglabel { padding: 0 10px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.seg.radius button { min-height: 44px; }
.hint.alert { border-color: var(--warn); }
.hint.alert > .ico { color: var(--warn); }
.card.debug { border: 1px dashed #ff4fd8; }
