:root {
  /* palette from the Games Portal (game-portal/public/style.css) */
  --bg: #0f1020;
  --panel: #171933;
  --panel-2: #1d2040;
  --panel-3: #262a52;
  --line: #2c3060;
  --text: #eceefe;
  --muted: #9aa0c8;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --edge: #3a3f78;
  --on-accent: #fff;
  --body-bg: radial-gradient(1200px 600px at 10% -10%, #2a1f6b55, transparent), var(--bg);
  --hint-bg: linear-gradient(120deg, #3b2a9e, #1b4a7a 60%, #0f5b6b);
  --hint-line: #ffffff1a;
  --hint-text: #dfe3ff;
  --hint-strong: #fff;
  --tab-on-bg: var(--text);
  --tab-on-text: var(--bg);
  --scene-filter: none;
  /* derived from the colours above, so a theme only has to set those */
  --rail: var(--bg);
  --key: var(--panel-2);
  --key-hover: color-mix(in srgb, var(--panel-2), var(--text) 9%);
  --go: var(--accent);
  --go-dark: color-mix(in srgb, var(--accent), black 30%);
  --text-2: color-mix(in srgb, var(--text), var(--muted) 30%);
  --dim-bg: color-mix(in srgb, var(--panel-2), var(--bg) 55%);
  --dim-line: color-mix(in srgb, var(--line), var(--bg) 35%);
  --dim-name: color-mix(in srgb, var(--text), var(--muted) 45%);
  --short-bg: color-mix(in srgb, var(--bad) 20%, var(--panel-2));
  --short-line: color-mix(in srgb, var(--bad) 45%, var(--panel-2));
  --short-text: color-mix(in srgb, var(--bad), var(--text) 45%);
  --btn-dis-bg: color-mix(in srgb, var(--panel-3), var(--bg) 35%);
  --btn-dis-text: color-mix(in srgb, var(--muted), var(--bg) 40%);
  --owned-bg: color-mix(in srgb, var(--accent-2) 14%, transparent);
  --owned-line: color-mix(in srgb, var(--accent-2) 35%, transparent);
  --full-line: color-mix(in srgb, var(--warn) 55%, var(--panel-2));
  --topbar-bg: color-mix(in srgb, var(--bg) 95%, transparent);
  --float-bg: color-mix(in srgb, var(--panel-2) 93%, transparent);
  --log-bg: color-mix(in srgb, var(--bg) 88%, transparent);
  --tray: color-mix(in srgb, var(--panel), var(--bg) 35%);
  --tray-line: color-mix(in srgb, var(--line), var(--panel) 30%);
  /* section colours (bottom-table layout): muted hues, pulled toward the theme's own grey */
  --sec-1: color-mix(in srgb, #d6a85c 82%, var(--muted));
  --sec-2: color-mix(in srgb, #78acd6 82%, var(--muted));
  --sec-3: color-mix(in srgb, #8cc283 82%, var(--muted));
  --sec-4: color-mix(in srgb, #d08fb4 82%, var(--muted));
  --sec-5: color-mix(in srgb, #ad9be0 82%, var(--muted));
  --log-bg-solid: color-mix(in srgb, var(--bg) 97%, transparent);
  --panel-w: 400px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--body-bg); color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
.hidden { display: none !important; }

#app {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "main panel";
}

/* ---------- top bar ---------- */
#topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
#civBlock { min-width: 120px; max-width: 200px; flex: none; }
#civName { font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#civSize { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chips { flex: 1; display: flex; gap: 5px; flex-wrap: wrap; min-width: 0; }
.chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px 9px; min-width: 0;
}
.chip.big { min-width: 128px; }
.chip .ico { font-size: 17px; }
.chip .num { font-weight: 700; font-variant-numeric: tabular-nums; }
.chip .cap { color: var(--muted); font-size: 11px; }
.chip .rate { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--muted); }
.chip .rate.pos { color: var(--good); }
.chip .rate.neg { color: var(--bad); }
.chip .rate.flat { color: var(--muted); }
/* small chips: number above its rate, so more fit on one row; a steady width as numbers change */
.chip:not(.big) { display: grid; grid-template-columns: auto 1fr; column-gap: 5px; align-items: center; padding: 3px 7px; }
.chip:not(.big) .ico { grid-row: span 2; }
.chip:not(.big) .num { line-height: 1.2; }
.chip:not(.big) .rate { line-height: 1.2; min-width: 4.7em; white-space: nowrap; }
.chip.norate .ico { grid-row: auto; }
.chip.norate .num { min-width: 0; }
.chip .bar { height: 3px; background: #0006; border-radius: 2px; overflow: hidden; margin-top: 2px; }
.chip .bar i { display: block; height: 100%; width: 0; }
.chip .col { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chip .line { display: flex; gap: 4px; align-items: baseline; white-space: nowrap; }
.chip.danger { border-color: var(--bad); animation: pulse 1s infinite; }
.chip.full { border-color: var(--full-line); }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px #ff6b6b44; } }

.icon-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; font-size: 18px; flex: none;
}
.icon-btn:hover { background: var(--panel-3); }

/* ---------- main area ---------- */
#main {
  grid-area: main; position: relative; overflow: hidden;
  display: grid; grid-template-rows: 1fr auto;
}
#scene { position: relative; min-height: 0; overflow: hidden; }
#scene canvas { display: block; touch-action: manipulation; filter: var(--scene-filter); }

#gatherBar {
  position: absolute; left: 50%; bottom: 128px; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 3;
}
.gather {
  display: flex; flex-direction: column; align-items: center; gap: 0;
  background: var(--float-bg); border: 1px solid var(--edge); border-radius: 14px;
  padding: 6px 14px; min-width: 92px; user-select: none; -webkit-user-select: none;
  box-shadow: 0 4px 14px #0006; transition: transform .06s;
}
.gather:hover { background: var(--key-hover); border-color: var(--accent); }
/* taps are handled on pointerdown in main.js; no zoom delay, callout or selection on fast tapping */
.gather { touch-action: manipulation; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#gatherBar { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.gather .g-ico { font-size: 24px; line-height: 1.1; }
.gather .g-txt { font-weight: 700; }
.gather .g-amt { font-size: 11px; color: var(--muted); }
/* desktop: a small ✕ beside the gather buttons hides them; a small 🌾🪵🪨 pill brings them back */
.gather-tog {
  align-self: center; flex: none; border-radius: 999px; cursor: pointer;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--edge);
  box-shadow: 0 2px 0 #0004; font-size: 12px; line-height: 1;
}
.gather-tog:hover { color: var(--text); border-color: var(--accent); background: var(--key-hover); }
#gatherHide { width: 24px; height: 24px; padding: 0; opacity: .55; }
#gatherBar:hover #gatherHide, #gatherHide:focus-visible { opacity: 1; }
#gatherShow { display: none; padding: 5px 10px; font-size: 14px; letter-spacing: 2px; opacity: .8; }
html[data-gather="hidden"] .gather, html[data-gather="hidden"] #gatherHide { display: none; }
html[data-gather="hidden"] #gatherShow { display: block; }
/* phones: hidden, the gather bar's row shrinks to nothing so the village gets the space back,
   and the pill sits over the village's bottom-right corner */
@media (max-width: 800px) {
  #gatherHide { width: 30px; height: 30px; opacity: .7; }
  html[data-gather="hidden"] #gatherBar {
    height: 0; padding: 0; border: 0; background: none; overflow: visible;
    justify-content: flex-end;
  }
  html[data-gather="hidden"] #gatherShow { position: relative; top: -44px; margin-right: 10px; padding: 7px 12px; opacity: .9; }
}

#logBox {
  height: 118px; background: var(--bg); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
#logHead { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 5px 10px 2px; }
#log { list-style: none; margin: 0; padding: 0 10px 6px; overflow-y: auto; flex: 1; font-size: 12.5px; }
#log li { padding: 1px 0; color: var(--text-2); }
#log li.good { color: var(--good); }
#log li.bad { color: var(--bad); }
#log li.warn { color: var(--warn); }
#log li .tm { color: var(--muted); opacity: .75; margin-right: 6px; font-variant-numeric: tabular-nums; }

#alerts {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 4; align-items: center;
  max-width: calc(100% - 20px); pointer-events: none;
}
.alert {
  background: #000c; border: 1px solid var(--line); border-radius: 12px; padding: 7px 14px;
  text-align: center; pointer-events: auto;
}
.alert.bad { border-color: var(--bad); color: var(--short-text); background: var(--short-bg); animation: pulse 1.2s infinite; }
.alert.gold { border-color: var(--accent); color: var(--text); }
.alert .btn { margin-left: 8px; }

#toasts {
  position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 6px;
  z-index: 4; pointer-events: none; max-width: min(340px, calc(100% - 20px));
}
.toast {
  background: #000d; border-left: 3px solid var(--accent); border-radius: 8px;
  padding: 7px 11px; animation: toastIn .25s ease-out; transition: opacity .4s, transform .4s;
}
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }
.toast.warn { border-color: var(--warn); }
.toast.out { opacity: 0; transform: translateX(-12px); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-12px); } }

/* ---------- side panel ---------- */
#panel {
  grid-area: panel; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; z-index: 4;
}
#panelHead { display: flex; align-items: flex-start; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); }
#drawerToggle { display: none; }
.tabs { display: flex; gap: 5px; flex: 1; flex-wrap: wrap; }
.tab-btn {
  flex: 1 1 30%; padding: 7px 6px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; font-weight: 600; color: var(--muted); white-space: nowrap; font-size: 13px;
}
.tab-btn.active { background: var(--tab-on-bg); color: var(--tab-on-text); border-color: var(--tab-on-bg); }
.tab-btn .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--bad); margin-left: 4px; vertical-align: middle; }
#panelBody { overflow-y: auto; padding: 10px; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }

#hintCard:empty { display: none; }
#hintCard {
  background: var(--hint-bg); border: 1px solid var(--hint-line);
  border-radius: 12px; padding: 9px 12px; margin-bottom: 10px; color: var(--hint-text); font-size: 13px;
}
#hintCard b { color: var(--hint-strong); }

.section-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 14px 2px 6px; display: flex; justify-content: space-between; }
.section-title:first-child { margin-top: 2px; }
.card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 10px; margin-bottom: 7px; display: grid; grid-template-columns: 32px 1fr auto; gap: 3px 10px; align-items: center;
}
.card .big { font-size: 22px; text-align: center; grid-row: span 2; }
.card .name { font-weight: 700; }
.card .name .owned { color: var(--accent); font-weight: 700; margin-left: 4px; }
.card .name .sub { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.card .desc { color: var(--muted); font-size: 12.5px; grid-column: 2 / 4; }
.card .cost { grid-column: 2 / 4; display: flex; gap: 5px; flex-wrap: wrap; font-size: 12.5px; }
.card .acts { grid-column: 2 / 4; display: flex; gap: 5px; flex-wrap: wrap; margin-top: 3px; }
.card .effect { grid-column: 2 / 4; font-size: 12.5px; color: var(--good); }
.card .effect.off { color: var(--warn); }
.card.locked { opacity: .55; }
.card.plain { display: block; }
.cost span { background: #0004; border-radius: 6px; padding: 1px 6px; white-space: nowrap; }
.cost span { cursor: default; }
.cost .ci { font-style: normal; font-size: 1.15em; line-height: 1; vertical-align: -1px; }
.cost .cn { font-size: .92em; opacity: .85; }
.cost span.short { color: var(--short-text); background: var(--short-bg); }

.btn {
  background: var(--accent); color: var(--on-accent); font-weight: 700; border: 0;
  border-radius: 9px; padding: 7px 12px; min-height: 34px;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { background: var(--btn-dis-bg); color: var(--btn-dis-text); cursor: not-allowed; }
.btn.small { padding: 4px 9px; min-height: 30px; font-size: 13px; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:disabled { color: var(--btn-dis-text); }
.btn.danger { background: var(--short-bg); box-shadow: inset 0 0 0 1px var(--short-line); color: var(--short-text); }
.btn.wide { width: 100%; }

.job { grid-template-columns: 32px 1fr; }
.job .stepper { grid-column: 1 / 3; }
.stepper { display: flex; align-items: center; gap: 4px; justify-content: space-between; margin-top: 4px; }
.stepper button {
  flex: 1; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-3); font-weight: 700; font-size: 13px; min-width: 0; padding: 0 2px;
}
.stepper button:disabled { opacity: .3; cursor: not-allowed; }
.stepper .n { flex: 1.4; text-align: center; font-variant-numeric: tabular-nums; font-weight: 800; }
.stepper .n small { color: var(--muted); font-weight: 400; }
/* job buttons: minus buttons on top (−1 −10 −100 −all), plus buttons below (+1 +10 +100 +all) */
.stepper.s100 { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 30px; gap: 4px; }
.stepper.s100 button { height: auto; }
/* job counts live in the badge next to the job name, so the button row has no number in it */
.job .stepper { justify-content: stretch; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.stat { background: #0003; border-radius: 10px; padding: 6px 8px; }
.stat .k { color: var(--muted); font-size: 11px; }
.stat .v { font-weight: 800; font-variant-numeric: tabular-nums; }

.progress { height: 10px; background: #0007; border-radius: 6px; overflow: hidden; margin: 6px 0; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.textin {
  flex: 1; min-width: 120px; background: #0006; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px;
}
select.textin { flex: none; }
.note { color: var(--muted); font-size: 12.5px; }
.note b { color: var(--text); }
.tag { display: inline-block; background: #0005; border-radius: 6px; padding: 1px 7px; margin: 2px 3px 2px 0; font-size: 12px; }
.tag.learned { color: var(--good); }

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0; background: #000a; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 10px; font-size: 20px; }
.modal-card h3 { margin: 14px 0 4px; font-size: 15px; }
.modal-card p, .modal-card li { color: var(--text-2); }
.modal-card ul { padding-left: 20px; }
.modal-card textarea {
  width: 100%; height: 110px; background: #0006; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; font: 12px ui-monospace, monospace; resize: vertical;
}
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.ach { background: #0003; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-size: 12.5px; opacity: .45; }
.ach.got { opacity: 1; border-color: var(--accent); }
.ach b { display: block; }
.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-list .btn { text-align: left; }
.pace-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 4px; }
.pace-row input[type=range] { flex: 1; accent-color: var(--accent); }
.pace-row b { min-width: 7em; text-align: right; }

/* ---------- phones: panel becomes a bottom drawer ---------- */
@media (max-width: 800px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "top" "main";
  }
  #topbar { padding: 6px; gap: 6px; flex-wrap: wrap; padding-top: max(6px, env(safe-area-inset-top)); }
  #civBlock { order: 1; flex: 1; max-width: none; display: flex; gap: 8px; align-items: baseline; }
  #menuBtn, #muteBtn { order: 2; width: 34px; height: 34px; }
  .chips { order: 3; flex-basis: 100%; gap: 4px; }
  .chip { padding: 2px 6px; gap: 3px; border-radius: 8px; }
  .chip.big { min-width: 0; flex: 1; }
  .chip .ico { font-size: 14px; }
  .chip .num { font-size: 13px; }
  .chip .cap { display: none; }
  .chip .rate { font-size: 10px; }
  #logBox { display: none; }
  /* phones: Harvest / Chop / Quarry get their own bar under the village (desktop keeps them floating),
     and the village and that bar end where the drawer begins (closed or open) */
  #main { grid-template-rows: 1fr auto; padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  body.drawer-open #main { padding-bottom: 56vh; }
  #gatherBar {
    position: relative; left: auto; bottom: auto; transform: none; z-index: 3;
    justify-content: center; padding: 7px 10px; background: var(--rail); border-top: 1px solid var(--line);
  }
  .gather { min-width: 80px; padding: 5px 10px; }
  #panel {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: 56vh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px #0008;
    transition: transform .25s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #panel:not(.open) { transform: translateY(calc(100% - 56px - env(safe-area-inset-bottom))); }
  #drawerToggle { display: block; width: 36px; height: 36px; }
  #panel:not(.open) #drawerToggle { transform: rotate(180deg); }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tab-btn { flex: none; }
}

/* ---------- sound settings ---------- */
.snd-row { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.snd-row label { min-width: 6.5em; }
.snd-row input[type=range] { flex: 1; accent-color: var(--accent); }
.snd-row b { min-width: 3em; text-align: right; font-variant-numeric: tabular-nums; }
#muteBtn.muted { opacity: .7; }
/* ---------- seasons and choice events ---------- */
#seasonTag { color: var(--muted); font-size: 12px; white-space: nowrap; cursor: help; }
#seasonTag:empty { display: none; }
#seasonTag .fx { color: var(--accent); }
.evt-choice { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; background: var(--panel-2); }
.evt-choice .btn { margin-bottom: 6px; }
.evt-choice .cost span { margin-right: 8px; }
.evt-choice .cost .short { color: var(--bad); }
.evt-choice .why { color: var(--warn); font-size: 12px; }
.chk-row { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; }
.chk-row input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
@media (max-width: 800px) { #seasonTag { font-size: 11px; } }

/* population stats in the tab rail: only used by the "table" layout */
#railStats { display: none; }

/* resize grip: only used by the "table" controls layout (css/look-table.css) */
#dockGrip { display: none; }

/* instant hover tips (ui.js initTips), styled like the Chronicle box */
#tip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 260px;
  background: var(--log-bg-solid); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 18px #0007; padding: 4px 10px; font-size: 12.5px; line-height: 1.35;
  display: flex; flex-direction: column; align-items: center; white-space: nowrap;
}
#tip small { color: var(--muted); font-size: 11.5px; }

/* greyed-out buttons in cards pass clicks through to the card, so ui.js can flash what's missing */
.card button[data-act]:disabled { pointer-events: none; }

/* One-time "install the app" hint on phones (ui.js scheduleInstallHint) */
#installHint {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 8px); width: min(94vw, 460px); z-index: 15;
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--accent);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45); font-size: 14px;
}
#installHint span { flex: 1; }
#installHint .btn { flex: none; }
