/* App foundation (lead-owned): tokens, reset, layout frame, shared primitives.
   Skin packs override the color/font tokens at runtime (skin.applyTheme). Component styles live in
   styles/<region>.css and must only use these tokens. */

:root {
  --bg: #0d151c;
  --surface: #162326;
  --surface-2: #1f3033;
  --ink: #f5f0df;
  --muted: #baa98e;
  --accent: #be9870;
  --danger: #ff7277;
  --ok: #7cdd8c;
  --font-display: Georgia, "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --player-0: #36a3ff; --player-1: #d34545; --player-2: #38b764; --player-3: #d6b13d;

  --line: color-mix(in srgb, var(--ink) 14%, transparent);
  --scrim: rgb(0 0 0 / 0.45);
  --radius: 10px;
  --radius-sm: 6px;
  --tap: 44px;
  --topbar-h: 44px;
  --dock-h: 112px;          /* HandDock sets this on .game when it changes size */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fx-scale: 1;            /* animation duration multiplier (settings.fxSpeed) */
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font: 14px/1.35 var(--font-body);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
img { display: block; max-width: 100%; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

#app, .app { position: fixed; inset: 0; overflow: hidden; }
.boot { display: grid; place-items: center; height: 100%; color: var(--muted); font-family: var(--font-display); }

/* Game frame ---------------------------------------------------------------- */
.game { position: absolute; inset: 0; padding: var(--safe-t) var(--safe-r) 0 var(--safe-l); }
.topbar { position: absolute; top: var(--safe-t); left: var(--safe-l); right: var(--safe-r); height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px; padding: 0 8px; z-index: 20; }
.board-area { position: absolute; top: calc(var(--safe-t) + var(--topbar-h)); left: var(--safe-l); right: var(--safe-r);
  bottom: 0; overflow: hidden; z-index: 1; }
.hand-dock { position: absolute; left: var(--safe-l); right: var(--safe-r); bottom: 0; z-index: 30;
  padding-bottom: var(--safe-b); }

/* Primitives ------------------------------------------------------------------ */
.btn { min-height: var(--tap); min-width: var(--tap); padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; }
.btn:disabled { opacity: .45; }
.btn-primary { background: var(--accent); color: var(--bg); border-color: transparent; font-weight: 700; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: var(--bg); }

.icon { display: inline-block; flex: none; vertical-align: middle; }
.amount { display: inline-flex; align-items: center; gap: 2px; font-variant-numeric: tabular-nums; }
.amount b { font-weight: 700; }
.rewards { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.player-dot { display: inline-block; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--bg); flex: none; }

.art { display: block; overflow: hidden; background: var(--surface-2); border-radius: var(--radius-sm); }
.art img { width: 100%; height: 100%; object-fit: cover; }

/* Card face (hand, market, lists) */
.card-face { position: relative; display: flex; flex-direction: column; padding: 0; border-radius: var(--radius-sm);
  border: 1.5px solid color-mix(in srgb, var(--card-accent, var(--accent)) 60%, transparent);
  background: var(--surface); overflow: hidden; text-align: left; transition: transform .15s var(--ease), opacity .15s; }
.card-face .art { border-radius: 0; }
.card-name { padding: 3px 6px 4px; font-size: 11px; font-weight: 600; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-cost { position: absolute; top: 3px; right: 3px; display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 5px 1px 2px; border-radius: 99px; background: rgb(0 0 0 / .65); font-weight: 700; font-size: 12px; }
.card-access { position: absolute; top: 3px; left: 3px; display: flex; gap: 2px; }
.card-sm { width: 84px; }
.card-md { width: 120px; }
.card-lg { width: 168px; }
.card-face.is-selected { transform: translateY(-10px); border-color: var(--ink); box-shadow: 0 6px 18px rgb(0 0 0 / .5); }
.card-face.is-dimmed { opacity: .45; }
.is-recommended { box-shadow: 0 0 0 2px var(--ok), 0 0 14px color-mix(in srgb, var(--ok) 60%, transparent); }

/* Sheets ------------------------------------------------------------------------ */
.sheet-host { position: absolute; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade .18s var(--ease); }
.sheet { position: relative; width: min(100%, 760px); max-height: min(88dvh, calc(100dvh - var(--safe-t) - 8px));
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0; padding-bottom: var(--safe-b);
  animation: rise .22s var(--ease); box-shadow: 0 -8px 30px rgb(0 0 0 / .4); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 6px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-close { width: var(--tap); height: var(--tap); border: 0; background: transparent; font-size: 26px; line-height: 1; }
.sheet-body { overflow: auto; padding: 10px 16px 14px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  user-select: text; -webkit-user-select: text; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 8px 16px; border-top: 1px solid var(--line); }
@media (min-width: 900px) and (min-height: 500px) {
  .sheet-host { justify-content: flex-end; align-items: stretch; }
  .sheet { width: 420px; max-height: none; border-radius: var(--radius) 0 0 var(--radius); animation-name: slide; }
  .sheet-wide { width: min(760px, 70vw); }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Choices */
.choice-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.choice-row { display: flex; align-items: center; gap: 10px; min-height: var(--tap); width: 100%; padding: 6px 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); text-align: left; }
.choice-row:disabled { opacity: .5; }
.choice-row.is-pass { background: transparent; }
.choice-text { display: flex; flex-direction: column; min-width: 0; }
.choice-text small { color: var(--muted); }
.choice-art { width: 54px; flex: none; }
.choice-group { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--surface-2); }
.choice-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.option-picker { display: flex; flex-direction: column; gap: 8px; }
.option-row { display: flex; flex-direction: column; gap: 4px; }
.option-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { min-height: 38px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: transparent;
  display: inline-flex; align-items: center; gap: 6px; }
.seg.is-on { background: var(--accent); color: var(--bg); border-color: transparent; font-weight: 700; }
.seg.is-far:not(.is-on) { opacity: .55; }
.search { width: 100%; min-height: 40px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); }

.leader-setup .faction-picks { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 8px 0 12px; }
.faction-pick { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 6px 10px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--surface-2); }
.faction-pick.is-on { border-color: var(--faction, var(--accent)); box-shadow: inset 0 0 0 1px var(--faction, var(--accent)); }
.snooper .art { max-width: 320px; margin-bottom: 8px; }
.placement-head { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 360px; margin-bottom: 10px; }

/* Primary action */
.primary-action { min-height: 52px; min-width: 120px; padding: 0 18px; border-radius: 99px; border: 0;
  background: var(--accent); color: var(--bg); font-weight: 800; font-size: 15px; letter-spacing: .02em;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 4px 14px rgb(0 0 0 / .45); }
.primary-action.is-waiting { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.primary-action.is-pass { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.primary-action.is-attention { animation: pulse 1.6s ease-in-out infinite; }
.primary-preview { display: inline-flex; align-items: center; gap: 2px; padding: 2px 8px 2px 4px; border-radius: 99px;
  background: rgb(0 0 0 / .2); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 35%, transparent); } }

/* Toasts */
.toasts { position: absolute; top: calc(var(--safe-t) + var(--topbar-h) + 6px); left: 50%; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { pointer-events: auto; border: 1px solid var(--line); background: var(--surface); padding: 10px 14px;
  border-radius: var(--radius-sm); text-align: left; box-shadow: 0 6px 20px rgb(0 0 0 / .45); animation: rise .2s var(--ease); }
.toast-error { border-color: var(--danger); }
.toast-warn { border-color: var(--accent); }

/* Stub layouts (replaced by region styles) */
.board-stub { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; overflow: auto; height: 100%; align-content: flex-start; }
.board-stub .space { min-height: var(--tap); padding: 4px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); }
.board-stub .is-legal { border-color: var(--ok); }
.board-stub .is-dim { opacity: .35; }
.hand-dock .hand { display: flex; gap: 6px; overflow-x: auto; padding: 14px 8px 6px; }
.start { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; height: 100%; padding: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
.primary-action.is-armed { background: var(--danger); color: var(--bg); }

/* Desktop sheet chrome (roadmap 3.9, agent:ui-desktop2). Fine pointer +
   large screen only. Short-content sheets become centred floating panels so
   they never read as half-empty stretched phone sheets; tall sheets keep
   their side-panel height and scroll with the wheel. */
@media (hover: hover) and (pointer: fine) and (min-width: 1200px) and (min-height: 760px) {
  .sheet-host-choice .sheet,
  .sheet-host-placement .sheet,
  .sheet-host-moves .sheet,
  .sheet-host-me .sheet,
  .sheet-host-conflict .sheet,
  .sheet-host-inspect .sheet,
  .sheet-host-settings .sheet {
    align-self: center;
    max-height: calc(100dvh - 64px);
    border-radius: var(--radius);
    box-shadow: 0 18px 60px rgb(0 0 0 / .55);
  }
  .sheet-host-choice .sheet { width: min(620px, 46vw); }
  .sheet-host-placement .sheet { width: min(580px, 44vw); }
  .sheet-host-moves .sheet { width: min(680px, 50vw); }

  .sheet-host .sheet-head { padding: 12px 12px 10px 20px; }
  .sheet-host .sheet-body { padding: 14px 20px 18px; }
  .sheet-host .sheet-actions { padding: 10px 20px; }

  /* Choice / composer controls: desktop type, still easy mouse targets. */
  .choice-list { gap: 10px; }
  .choice-row {
    min-height: 50px;
    padding: 8px 14px;
    font-size: 15px;
  }
  .choice-art { width: 64px; }
  .choice-group { padding: 10px 14px; }
  .choice-head { font-size: 15px; }
  .option-picker { gap: 10px; }
  .option-label { font-size: 12px; }
  .seg { min-height: 40px; padding: 0 16px; font-size: 14px; }
  .search { min-height: 44px; font-size: 14px; }
  .leader-setup .faction-picks { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .faction-pick { min-height: 60px; font-size: 14px; }
  .placement-head { max-width: none; gap: 12px; }
  .snooper .art { max-width: 420px; }
}
