:root {
  --slate: #17262b;
  --slate-2: #1f3238;
  --slate-3: #2c444b;
  --chalk: #e7e2d4;
  --chalk-dim: #a9b2ab;
  --ochre: #c99a2e;
  --malachite: #3f8f6b;
  --cinnabar: #b5432f;
  --azurite: #4a78a8;
  --line: rgba(231, 226, 212, 0.16);
  --display: 'IM Fell English SC', 'Iowan Old Style', Georgia, serif;
  --ui: 'Barlow Semi Condensed', 'Avenir Next Condensed', 'Arial Narrow', sans-serif;
  --r: 3px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #122025; color: var(--chalk); font: 15px/1.4 var(--ui); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ochre); outline-offset: 2px; }
.screen { position: fixed; inset: 0; }
.muted { color: var(--chalk-dim); }

/* plates: instrument-panel surfaces with an engraved inner rule */
.plate { background: linear-gradient(180deg, rgba(31, 50, 56, 0.96), rgba(23, 38, 43, 0.97)); border: 1px solid #0d1a1e; box-shadow: inset 0 0 0 1px var(--line), 0 6px 18px rgba(0, 0, 0, 0.35); border-radius: var(--r); }
fieldset.plate { margin: 0; padding: 14px 16px 16px; }
legend { font-family: var(--display); font-size: 19px; color: var(--ochre); padding: 0 6px; }

.btn { background: var(--slate-3); border: 1px solid #0d1a1e; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08); color: var(--chalk); padding: 7px 14px; border-radius: var(--r); cursor: pointer; font-weight: 600; letter-spacing: 0.02em; }
.btn:hover { background: #36525a; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--ochre); color: #1a1405; }
.btn.primary:hover { background: #dbad44; }
.btn.danger { background: var(--cinnabar); }
.btn.ghost { background: transparent; box-shadow: none; border-color: var(--line); }
.btn.icon { padding: 4px 10px; font-size: 18px; }
.btn.small { padding: 3px 8px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field span { color: var(--chalk-dim); font-size: 13px; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
input, select { background: #0f1c20; border: 1px solid var(--line); border-radius: var(--r); padding: 7px 9px; }

/* ---------------- lobby */
#lobby { display: grid; grid-template-columns: 1fr minmax(360px, 520px); }
.lobby-map { position: relative; overflow: hidden; }
.lobby-map canvas { width: 100%; height: 100%; display: block; filter: saturate(0.9); }
.lobby-panel { overflow: auto; padding: 40px 36px; background: var(--slate); border-left: 1px solid #0b161a; box-shadow: -12px 0 30px rgba(0, 0, 0, 0.35); }
.title { font-family: var(--display); font-weight: 400; margin: 0 0 12px; line-height: 0.88; color: var(--chalk); }
.title span { display: block; font-size: 64px; }
.title span:last-child { font-size: 78px; color: var(--ochre); padding-left: 0.6em; transform: rotate(-2.2deg) translateY(-4px); transform-origin: left; text-shadow: 3px 3px 0 #0b161a; }
.tagline { color: var(--chalk-dim); max-width: 46ch; margin: 18px 0 20px; }
.lobby-actions { display: grid; gap: 14px; }
.advanced { margin: 14px 0; color: var(--chalk-dim); }
.open-matches h2, .room-card h2 { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 20px 0 8px; }
#matchList { list-style: none; padding: 0; margin: 0 0 10px; }
#matchList li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
#matchList li.empty { color: var(--chalk-dim); border: 0; }
.join { display: flex; gap: 8px; }
.join input { flex: 1; text-transform: lowercase; }
.status { color: var(--ochre); min-height: 1.4em; }
#room { display: grid; place-items: center; background: radial-gradient(ellipse at 30% 20%, #23393f, #10191c); }
.room-card { padding: 24px 28px; width: min(460px, 92vw); }
.code { font-size: 22px; color: var(--ochre); letter-spacing: 0.08em; }
#roomSlots { list-style: none; padding: 0; }
#roomSlots li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
@media (max-width: 860px) { #lobby { grid-template-columns: 1fr; } .lobby-map { display: none; } .lobby-panel { padding: 28px 16px; } .title span { font-size: 48px; } .title span:last-child { font-size: 58px; } }

/* ---------------- game HUD */
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; }
#topbar { position: absolute; left: 0; right: 0; top: 0; height: 46px; display: flex; align-items: center; gap: 18px; padding: 0 12px; background: linear-gradient(180deg, rgba(16, 29, 33, 0.97), rgba(16, 29, 33, 0.88)); border-bottom: 1px solid #0a1417; box-shadow: inset 0 -1px 0 var(--line); z-index: 5; }
.realm { display: flex; flex-direction: column; line-height: 1.05; min-width: 150px; }
.civ-name { font-family: var(--display); font-size: 19px; }
.age { font-size: 12px; color: var(--ochre); }
.resources { display: flex; gap: 14px; list-style: none; margin: 0; padding: 0; flex: 1; overflow: hidden; }
.resources li { display: flex; flex-direction: column; line-height: 1.05; min-width: 56px; }
.resources b { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.resources small { font-size: 11px; color: var(--chalk-dim); font-variant-numeric: tabular-nums; }
.resources small.neg { color: #e0846f; }
.resources .k { font-size: 11px; color: var(--chalk-dim); }
.seismo { display: flex; align-items: center; gap: 8px; background: #0c171a; border: 1px solid #08100f; box-shadow: inset 0 0 0 1px var(--line); padding: 2px 8px 2px 2px; border-radius: var(--r); }
.seismo canvas { display: block; }
#seismoLabel { font-size: 12px; min-width: 64px; color: var(--chalk-dim); }
#seismoLabel.alert { color: #f0b54a; }
#seismoLabel.shock { color: #ff7a5c; }
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; font-variant-numeric: tabular-nums; }
.net { font-size: 11px; color: var(--chalk-dim); }

#toasts { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 6; pointer-events: none; }
.toast { pointer-events: auto; background: rgba(15, 28, 32, 0.95); border: 1px solid #0a1417; box-shadow: inset 0 0 0 1px var(--line); border-left: 3px solid var(--azurite); padding: 7px 12px; border-radius: var(--r); max-width: 560px; cursor: pointer; animation: toastIn 0.25s ease-out; }
.toast.quake, .toast.eruption, .toast.rift, .toast.uplift, .toast.drought, .toast.river { border-left-color: var(--ochre); }
.toast.warning { border-left-color: #f0b54a; }
.toast.war, .toast.loss, .toast.error, .toast.fall { border-left-color: var(--cinnabar); }
.toast.peace, .toast.tech, .toast.age, .toast.city, .toast.build { border-left-color: var(--malachite); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

#selection { position: absolute; left: 10px; bottom: 10px; width: 330px; max-height: 46vh; overflow: auto; padding: 12px 14px; z-index: 4; }
#selection h3 { font-family: var(--display); font-weight: 400; font-size: 21px; margin: 0 0 2px; }
#selection .sub { color: var(--chalk-dim); font-size: 13px; margin-bottom: 8px; }
.bar { height: 6px; background: #0c171a; border-radius: 2px; overflow: hidden; margin: 3px 0 8px; }
.bar > i { display: block; height: 100%; background: var(--malachite); }
.bar.hp > i { background: #6db36a; }
.bar.sup > i { background: var(--azurite); }
.bar.stab > i { background: linear-gradient(90deg, var(--cinnabar), var(--ochre) 50%, var(--malachite)); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14px; margin: 6px 0; }
.kv dt { color: var(--chalk-dim); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.trainbtn { display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: 5px 9px; min-width: 96px; }
.trainbtn small, .buildbtn small { color: var(--chalk-dim); font-weight: 400; font-size: 11px; }
.queue { display: flex; gap: 4px; flex-wrap: wrap; font-size: 12px; color: var(--chalk-dim); }
.queue span { background: #0c171a; padding: 1px 6px; border-radius: 2px; }
.warn { color: #f0b54a; }
.bad { color: #e0846f; }
.good { color: #8fd19e; }

#buildbar { position: absolute; left: 350px; right: 230px; bottom: 10px; display: flex; gap: 4px; padding: 6px; overflow-x: auto; z-index: 4; }
.buildbtn { display: flex; flex-direction: column; align-items: center; gap: 0; min-width: 74px; padding: 4px 6px; background: transparent; border: 1px solid transparent; border-radius: var(--r); cursor: pointer; color: var(--chalk); }
.buildbtn .g { font-size: 20px; line-height: 1.2; }
.buildbtn .n { font-size: 12px; font-weight: 600; white-space: nowrap; }
.buildbtn:hover { background: var(--slate-3); }
.buildbtn.active { border-color: var(--ochre); background: #2f3a2c; }
.buildbtn.poor .n { color: var(--chalk-dim); }
.buildbtn.tool { border-left: 1px solid var(--line); border-radius: 0; }

#drawer { position: absolute; right: 10px; top: 56px; width: 340px; bottom: 238px; display: flex; flex-direction: column; z-index: 4; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 8px 4px; color: var(--chalk-dim); cursor: pointer; font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button[aria-selected='true'] { color: var(--chalk); border-bottom-color: var(--ochre); }
#drawerBody { overflow: auto; padding: 10px 12px; flex: 1; }
#drawer.collapsed { bottom: auto; }
#drawer.collapsed #drawerBody { display: none; }
.resources { scrollbar-width: none; overflow-x: auto; }
#drawerBody h4 { font-family: var(--display); font-weight: 400; font-size: 18px; margin: 12px 0 6px; color: var(--ochre); }
#drawerBody h4:first-child { margin-top: 0; }
.tech { display: block; width: 100%; text-align: left; background: #13232a; border: 1px solid var(--line); border-radius: var(--r); padding: 6px 9px; margin: 0 0 5px; cursor: pointer; color: var(--chalk); }
.tech small { display: block; color: var(--chalk-dim); font-size: 12px; }
.tech.done { border-color: rgba(63, 143, 107, 0.6); background: rgba(63, 143, 107, 0.14); cursor: default; }
.tech.current { border-color: var(--ochre); }
.tech.locked { opacity: 0.45; cursor: default; }
.tech .prog { height: 3px; background: #0c171a; margin-top: 4px; }
.tech .prog i { display: block; height: 100%; background: var(--ochre); }
.gov, .policy { display: block; width: 100%; text-align: left; background: #13232a; border: 1px solid var(--line); border-radius: var(--r); padding: 6px 9px; margin-bottom: 5px; cursor: pointer; color: var(--chalk); }
.gov.on, .policy.on { border-color: var(--malachite); background: rgba(63, 143, 107, 0.16); }
.gov small, .policy small { display: block; color: var(--chalk-dim); font-size: 12px; }
.seg { display: flex; gap: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { flex: 1; background: #13232a; border: 0; border-right: 1px solid var(--line); padding: 5px 2px; cursor: pointer; color: var(--chalk-dim); font-size: 13px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--slate-3); color: var(--chalk); }
.civrow { border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; margin-bottom: 8px; }
.civrow .hd { display: flex; align-items: center; gap: 8px; }
.swatch { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.state { margin-left: auto; font-size: 13px; }
.state.war { color: #ff8a70; } .state.peace { color: var(--chalk-dim); } .state.alliance { color: #8fd19e; } .state.unmet { color: #6b7a78; }
.log li { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; list-style: none; }
.log { padding: 0; margin: 0; }
.log time { color: var(--chalk-dim); margin-right: 6px; font-variant-numeric: tabular-nums; }

#minimapWrap { position: absolute; right: 10px; bottom: 10px; padding: 6px; z-index: 4; width: 206px; }
#minimap { display: block; width: 192px; height: 168px; cursor: crosshair; background: #10181b; }
.lenses { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 5px; gap: 2px; }
.lenses button { background: #13232a; border: 1px solid var(--line); color: var(--chalk-dim); font-size: 11px; padding: 3px 0; cursor: pointer; border-radius: 2px; }
.lenses button.on { color: var(--chalk); border-color: var(--ochre); }
.hint { position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%); background: rgba(12, 23, 26, 0.92); padding: 6px 12px; border-radius: var(--r); font-size: 13px; z-index: 4; pointer-events: none; box-shadow: inset 0 0 0 1px var(--line); }
.hint:empty { display: none; }
.tooltip { position: absolute; pointer-events: none; background: rgba(12, 23, 26, 0.95); border: 1px solid #0a1417; box-shadow: inset 0 0 0 1px var(--line); padding: 6px 9px; border-radius: var(--r); font-size: 13px; z-index: 7; max-width: 260px; }
.tooltip b { font-weight: 600; }
.modal { position: absolute; inset: 0; background: rgba(6, 12, 14, 0.6); display: grid; place-items: center; z-index: 10; }
.modal .plate { padding: 22px 26px; width: min(480px, 92vw); display: flex; flex-direction: column; gap: 10px; }
.modal h2 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 0; }
#goStats { border-collapse: collapse; width: 100%; font-size: 14px; }
#goStats td, #goStats th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; }
#goStats td:first-child, #goStats th:first-child { text-align: left; }
@media (max-width: 1100px) { #drawer { width: 300px; } #buildbar { left: 10px; right: 10px; bottom: auto; top: 56px; } #drawer { top: 128px; } #selection { width: 280px; max-height: 38vh; } .seismo canvas { width: 140px; } }
@media (max-width: 700px) { .realm { min-width: 0; } #minimapWrap { transform: scale(0.8); transform-origin: bottom right; } #selection { width: calc(100% - 200px); } }
