:root {
  --bg: rgba(30, 24, 18, 0.93);
  --bg2: rgba(48, 38, 27, 0.95);
  --line: #6b5636;
  --text: #f1e6cf;
  --dim: #b9a888;
  --accent: #e8b84f;
  --good: #8fcf6a;
  --bad: #e2725b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0a0c0f; color: var(--text);
  font: 13px/1.4 -apple-system, "Segoe UI", system-ui, sans-serif; user-select: none; }
canvas#game, canvas#terrain { position: fixed; inset: 0; display: block; cursor: default; }
button { font: inherit; color: var(--text); background: #4a3a26; border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; }
button:hover:not(:disabled) { background: #5d4a30; border-color: #8f7448; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.on { background: #7a5b25; border-color: var(--accent); color: #fff6dc; }
button.danger { background: #5a2a20; border-color: #8a4433; }
button.danger:hover { background: #73352a; }
button.danger.confirm { background: #a33a26; border-color: #e2725b; }

#topbar { position: fixed; top: 0; left: 0; right: 0; height: 44px; display: flex; align-items: center; gap: 8px;
  padding: 0 10px; background: linear-gradient(#2c2218f2, #1f1812f2); border-bottom: 1px solid var(--line); z-index: 5; }
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 19px; font-weight: bold; color: var(--accent);
  letter-spacing: .5px; margin-right: 8px; text-shadow: 0 1px 0 #000; }
.res { display: flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; }
.res .r { display: flex; align-items: center; gap: 3px; padding: 2px 7px 2px 3px; background: #00000040; border-radius: 12px;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.res .r img { width: 22px; height: 22px; }
.res .pop { background: #3a5a2a80; font-weight: 600; }
.res .pop.full { background: #7a3a1c90; }
.grow { flex: 1; }
.speed { display: flex; }
.speed button { border-radius: 0; margin-left: -1px; min-width: 34px; }
.speed button:first-child { border-radius: 6px 0 0 6px; }
.speed button:last-child { border-radius: 0 6px 6px 0; }

#goals { position: fixed; top: 54px; left: 10px; width: 270px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; z-index: 4; }
#goals h3 { margin: 0 0 4px; font: bold 13px Georgia, serif; color: var(--accent); display: flex; justify-content: space-between; cursor: pointer; }
#goals.collapsed ul { display: none; }
#advisor { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
#advisor h3 { cursor: pointer; }
#advisor li { padding: 3px 0 3px 18px; font-size: 12px; line-height: 1.3; color: var(--text); }
#advisor li[data-n] { cursor: pointer; }
#advisor li[data-n]:hover { color: #fff; }
#advisor li::before { left: 2px; }
#advisor li.sev3::before { content: "⚠"; color: #f2a04e; }
#advisor li.sev2::before { content: "●"; color: #e8c86a; font-size: 9px; top: 6px; }
#advisor li.sev1::before { content: "ℹ"; color: #8ab0d8; }
#advisor li.calm::before { content: "✓"; color: var(--good); }
#goals ul { list-style: none; margin: 0; padding: 0; }
#goals li { padding: 2px 0 2px 20px; position: relative; color: var(--dim); }
#goals li::before { content: "○"; position: absolute; left: 3px; color: var(--dim); }
#goals li.done { color: #9a8f7a; text-decoration: line-through; }
#goals li.done::before { content: "✓"; color: var(--good); }
#goals li.cur { color: var(--text); }
#goals li.cur::before { content: "▸"; color: var(--accent); }

#panel { position: fixed; top: 54px; right: 10px; width: 320px; max-height: calc(100vh - 64px); overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; z-index: 5;
  box-shadow: 0 8px 30px #0008; }
.ph { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.ph h2 { margin: 0; font: bold 16px Georgia, serif; color: var(--accent); }
.ph .sub { color: var(--dim); font-size: 12px; }
.ph .x { margin-left: auto; align-self: flex-start; padding: 0 8px; background: none; border: none; font-size: 18px; color: var(--dim); }
.bicon { width: 64px; height: 56px; background: #00000030; border-radius: 6px; object-fit: contain; }
.tabs { display: flex; gap: 3px; margin: 6px 0; }
.tabs button { flex: 1; padding: 4px 2px; font-size: 12px; }
.bgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.bbtn { display: flex; flex-direction: column; align-items: center; padding: 4px 2px 5px; gap: 1px; min-height: 96px; }
.bbtn img { width: 60px; height: 52px; object-fit: contain; }
.bbtn .nm { font-size: 11.5px; font-weight: 600; text-align: center; line-height: 1.15; }
.cost { display: flex; gap: 4px; font-size: 11px; color: var(--dim); align-items: center; }
.cost img { width: 15px; height: 15px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.actions button { flex: 1 1 auto; }
.dyn .row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.dyn .lbl { color: var(--dim); min-width: 74px; }
.dyn .status { padding: 5px 8px; border-radius: 6px; background: #00000035; margin: 4px 0; }
.dyn .warn { background: #6a3a1c80; border-left: 3px solid var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 1px 6px 1px 2px; border-radius: 10px; background: #00000040;
  font-variant-numeric: tabular-nums; font-size: 12px; }
.chip img { width: 20px; height: 20px; }
.chip.zero { opacity: .45; }
.bar { height: 10px; background: #00000060; border-radius: 5px; overflow: hidden; flex: 1; border: 1px solid #00000080; }
.bar > div { height: 100%; background: linear-gradient(90deg, #c08a2c, #f0c45a); }
.note { color: var(--dim); font-size: 12px; margin: 6px 0; }
.sect { font: bold 12px Georgia, serif; color: var(--accent); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .5px; }

#hint { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--bg2); border: 1px solid var(--accent);
  border-radius: 20px; padding: 7px 16px; z-index: 6; pointer-events: none; max-width: calc(100vw - 20px); text-align: center; }
#toasts { position: fixed; bottom: 160px; left: 10px; display: flex; flex-direction: column-reverse; gap: 6px; z-index: 6; width: 300px; }
.toast { background: var(--bg2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 6px;
  padding: 6px 10px; cursor: pointer; animation: tin .25s ease-out; transition: opacity .5s; }
.toast.out { opacity: 0; }
@keyframes tin { from { transform: translateX(-20px); opacity: 0; } }
#minimap { position: fixed; left: 10px; bottom: 10px; width: 240px; height: 134px; border: 1px solid var(--line);
  border-radius: 6px; background: #000; z-index: 4; cursor: crosshair; image-rendering: auto; }

#modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 10; }
#modal .card { background: #2a2017; border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; width: min(760px, 94vw);
  max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px #000c; }
#modal h1 { margin: 0 0 6px; font: bold 26px Georgia, serif; color: var(--accent); }
#modal h3 { font: bold 14px Georgia, serif; color: var(--accent); margin: 14px 0 4px; }
#modal p, #modal li { color: #e8dcc2; }
#modal ul { padding-left: 20px; margin: 4px 0; }
#modal kbd { background: #4a3a26; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 12px; }
#modal .close { margin-top: 14px; }
.chain { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 3px 0; }
.chain img { width: 22px; height: 22px; }
.chain .ar { color: var(--dim); }
.stockgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 5px; }
.stockgrid .chip { font-size: 13px; padding: 3px 8px 3px 3px; }

@media (max-width: 900px) {
  #goals { display: none; }
  .brand { display: none; }
  #panel { width: calc(100vw - 20px); top: auto; bottom: 10px; max-height: 50vh; }
  #toasts { bottom: auto; top: 54px; }
}

#sound-panel { position: fixed; top: 50px; right: 150px; z-index: 7; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 24px #0009; min-width: 220px; }
.sp-row { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.sp-row label { min-width: 70px; color: var(--dim); }
.sp-row input[type=range] { flex: 1; accent-color: var(--accent); }
#btn-sound.muted { opacity: .5; text-decoration: line-through; }

#btn-clock { font-variant-numeric: tabular-nums; min-width: 128px; white-space: nowrap; }
#btn-clock.off { opacity: .6; }

.ngrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin: 10px 0; }
.ng { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 10px 12px; text-align: left; }
.ng b { font: bold 14px Georgia, serif; color: var(--accent); }
.ng span { color: var(--dim); font-size: 12px; }

.stance { margin-top: 6px; width: 100%; }
.attack { align-items: center; }
.attack .atkn { min-width: 26px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.attack button[data-a="atk-"], .attack button[data-a="atk+"] { flex: 0 0 34px; }

#econ { position: fixed; top: 54px; left: 10px; width: 360px; max-height: calc(100vh - 210px); overflow-y: auto; z-index: 5;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: 0 8px 30px #0008; }
#econ h2 { margin: 0 0 2px; font: bold 16px Georgia, serif; color: var(--accent); display: flex; justify-content: space-between; }
#econ .x { background: none; border: none; color: var(--dim); font-size: 18px; padding: 0 4px; }
.erow { display: grid; grid-template-columns: 26px 1fr 54px 54px 44px; gap: 4px; align-items: center; padding: 3px 4px; border-radius: 6px;
  cursor: pointer; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.erow:hover { background: #ffffff10; }
.erow.sel { background: #e8b84f22; outline: 1px solid #e8b84f66; }
.erow img { width: 22px; height: 22px; }
.erow .nm { display: flex; flex-direction: column; line-height: 1.15; }
.erow .nm small { color: var(--dim); font-size: 11px; }
.erow .num { text-align: right; color: var(--dim); }
.erow .num b { color: var(--text); font-weight: 600; }
.ehead { display: grid; grid-template-columns: 26px 1fr 54px 54px 44px; gap: 4px; padding: 0 4px; color: var(--dim); font-size: 11px; margin-top: 6px; }
.ehead span { text-align: right; } .ehead span:nth-child(2) { text-align: left; }
.badge { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; padding: 1px 5px; border-radius: 8px; justify-self: end; }
.badge.shortage { background: #a33a26; color: #fff; } .badge.tight { background: #a8762a; color: #fff; }
.badge.ok { background: #3a5a2a; color: #cfe8b8; } .badge.surplus { background: #2a4a6a; color: #cfe0f4; }
.edetail { margin: 2px 0 8px 30px; padding: 6px 8px; border-left: 2px solid var(--accent); background: #00000025; border-radius: 0 6px 6px 0; font-size: 12px; }
.edetail .who { display: flex; align-items: center; gap: 6px; margin: 2px 0; cursor: pointer; }
.edetail .who:hover { color: var(--accent); }
.edetail .who img { width: 26px; height: 22px; object-fit: contain; }
.edetail .who .st { color: var(--dim); }
.edetail h4 { margin: 6px 0 2px; font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: .4px; }

.goto { color: var(--accent); text-decoration: underline dotted; cursor: pointer; }
body.econ-open #toasts { left: 382px; }

.bbtn.locked { opacity: .5; }
.bbtn.locked img { filter: grayscale(1); }
#goals li.ms { padding: 4px 0; color: var(--text); }
#goals li.ms::before { content: none; }
#goals .unl img, .mscard .unl img { width: 26px; height: 22px; object-fit: contain; vertical-align: middle; }
.perk { font-size: 11px; color: var(--accent); margin-left: 3px; white-space: nowrap; }
.msbar { position: relative; height: 15px; background: #00000055; border-radius: 4px; margin-top: 3px; overflow: hidden; }
.msbar > div { height: 100%; background: linear-gradient(90deg, #6a8a3a, #9ac45a); }
.msbar span { position: absolute; inset: 0; font-size: 10.5px; line-height: 15px; padding-left: 5px; color: #f4ecd8; text-shadow: 0 1px 1px #000; }
.eras { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.era h3 { margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin-bottom: 10px; }
.chart { position: relative; background: #00000026; border: 1px solid #4a3a26; border-radius: 8px; padding: 6px 8px 2px; }
.chart .ch { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 12px; }
.chart .now { display: flex; gap: 8px; font-variant-numeric: tabular-nums; color: #e8dcc4; }
.chart .now i, .legend i, .chart .tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #ffffff14; stroke-width: 1; }
.chart .ax { fill: #a89878; font-size: 8.5px; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: #2a2017; stroke-width: 2; }
.chart .cross { stroke: #e8dcc480; stroke-width: 1; opacity: 0; pointer-events: none; }
.chart .tip { position: absolute; top: 26px; background: #1a140e; border: 1px solid #5a4a36; border-radius: 6px; padding: 4px 7px; font-size: 11px; pointer-events: none; white-space: nowrap; color: #e8dcc4; }
.legend { display: flex; gap: 14px; font-size: 12px; margin: -2px 0 6px; color: #e8dcc4; }
.bcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; margin-bottom: 6px; }
.bcard { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; grid-template-rows: auto auto; align-items: center; column-gap: 6px; text-align: left; padding: 4px 6px; min-height: 48px; }
.bcard img { grid-row: 1 / 3; width: 38px; height: 34px; object-fit: contain; }
.bcard .nm { font-size: 12px; font-weight: 600; line-height: 1.1; overflow-wrap: break-word; }
.bcard .n { font-size: 16px; grid-row: 1 / 3; grid-column: 3; }
.bcard .sub { font-size: 10.5px; opacity: .8; line-height: 1.15; }
.bcard .sub .warn { color: #f2c14e; }
.bcard.none { opacity: .75; border-style: dashed; }
.bcard.none .sub { color: #9fd08a; opacity: 1; }
.bcard.locked { opacity: .45; }
.bcard.locked img { filter: grayscale(1); }
.bcard:disabled { cursor: default; }
.mscard { background: #00000030; border: 1px solid #4a3a26; border-radius: 8px; padding: 6px 8px; margin-bottom: 8px; }
.mscard.got { border-color: #6a8a3a; background: #3a5a2a40; }
.mstitle { font-weight: 700; margin-bottom: 2px; }
.mscard .unl { margin-top: 4px; }
.toast.milestone { border-left-color: #9ac45a; background: #2a3a1ef2; font-weight: 600; }
