:root {
  --bg: #12141b;
  --panel: #1c2030;
  --panel-2: #252a3d;
  --ink: #eef0f5;
  --muted: #a9b0c2;
  --line: #3a4158;
  --gold: #f3c74f;
  --good: #5fd39a;
  --bad: #ff7a6e;
  --accent: #6ea8ff;
  --font: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; }
button { font: inherit; }
[hidden] { display: none !important; }

#app { min-height: 100%; display: flex; flex-direction: column; }

#hud {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: #0c0e14; border-bottom: 2px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 1px; color: var(--gold); text-transform: uppercase; }
.stats { display: flex; gap: 14px; margin: 0; flex-wrap: wrap; flex: 1; }
.stats div { display: flex; flex-direction: column; }
.stats dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stats dd { margin: 0; font-weight: 700; font-size: 16px; }
.hud-buttons { display: flex; gap: 6px; }

.btn, button {
  background: var(--panel-2); color: var(--ink); border: 2px solid var(--line); border-bottom-width: 4px;
  padding: 6px 12px; border-radius: 4px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: #2f6b4f; border-color: #3f8f69; }
button.primary:hover:not(:disabled) { border-color: var(--good); }
button.gold { background: #8a6a1c; border-color: #c9a54a; }
button.danger { background: #6b2f2f; border-color: #a04545; }

#stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px 16px; gap: 10px; }
#canvas-wrap { position: relative; line-height: 0; border: 3px solid #0a0b10; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); }
#city { image-rendering: pixelated; image-rendering: crisp-edges; display: block; cursor: pointer; }
#prompt {
  position: absolute; transform: translate(-50%, 0); white-space: nowrap; z-index: 2; pointer-events: auto; cursor: pointer;
  background: rgba(12, 14, 20, 0.92); color: var(--ink); border: 2px solid var(--gold); border-radius: 4px;
  padding: 4px 8px; font-size: 14px; line-height: 1.3;
}
#prompt kbd, #hint kbd { background: var(--gold); color: #000; border-radius: 3px; padding: 0 5px; font-weight: 700; }
#playrow { display: flex; gap: 12px; align-items: flex-start; justify-content: center; flex-wrap: wrap; max-width: 100%; }
#playrow.docked { flex-wrap: nowrap; }
#daybar.docked { flex-direction: column; align-items: stretch; width: 348px; flex: 0 0 348px; }
#daybar.docked .live { grid-template-columns: repeat(2, auto); }
#daybar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center;
  background: #0c0e14; border: 2px solid var(--line); border-radius: 6px; padding: 8px 12px; max-width: 100%;
}
.day-clock { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.day-time { font-size: 20px; font-weight: 800; color: var(--gold); }
.day-time .sub { font-size: 13px; font-weight: 400; color: var(--muted); }
.day-clock .bar > span { transition: width 0.2s linear; background: var(--gold); }
.speed { display: flex; gap: 4px; }
.speed button { padding: 3px 8px; font-size: 13px; }
.speed button[aria-pressed="true"] { border-color: var(--gold); background: #3a3320; }
#interior { width: 320px; height: 128px; image-rendering: pixelated; border: 2px solid #0a0b10; }
.live { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 14px; margin: 0; font-size: 13px; }
.live dt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.live dd { margin: 0; font-weight: 700; font-size: 15px; }
#reason { margin: 0; font-size: 15px; font-weight: 700; color: var(--gold); text-align: center; }
.paused-banner { background: #3a3320; border: 2px solid var(--gold); border-radius: 4px; padding: 8px 12px; margin: 8px 0 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#daybar.flash { animation: flash 1.2s ease-out 1; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--gold); } 100% { box-shadow: 0 0 0 0 transparent; } }
#goalbar { font-size: 14px; color: var(--muted); text-align: center; }
#goalbar b { color: var(--ink); }
#places { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; align-items: center; font-size: 14px; color: var(--muted); }
#places button { font-size: 13px; padding: 4px 9px; }
#hint { color: var(--muted); font-size: 13px; margin: 0; text-align: center; max-width: 900px; }

#toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 50; pointer-events: none;
  background: #0c0e14; border: 2px solid var(--gold); border-radius: 4px; padding: 8px 14px; opacity: 0; transition: opacity 0.2s;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }

#overlay {
  position: fixed; inset: 0; background: rgba(5, 6, 10, 0.72); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 20;
}
#panel {
  background: var(--panel); border: 3px solid var(--line); border-radius: 6px; width: min(720px, 100%);
  max-height: calc(100vh - 32px); overflow: auto; padding: 18px 20px; box-shadow: 0 0 0 3px #0a0b10, 0 20px 50px rgba(0, 0, 0, 0.6);
}
#panel:focus { outline: none; }
#panel.wide { width: min(980px, 100%); }
#panel h2 { margin: 0 0 4px; color: var(--gold); font-size: 22px; text-transform: uppercase; letter-spacing: 1px; }
#panel h3 { margin: 18px 0 6px; font-size: 15px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.5px; }
#panel p { line-height: 1.5; margin: 6px 0; }
.sub { color: var(--muted); margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.note { background: var(--panel-2); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 3px; margin: 10px 0; line-height: 1.45; }
.note.warn { border-left-color: var(--bad); }
.note.good { border-left-color: var(--good); }
.err { color: var(--bad); min-height: 1.3em; }
.ok { color: var(--good); }
.neg { color: var(--bad); }
.pos { color: var(--good); }
input[type=number] {
  font: inherit; background: #0f1220; color: var(--ink); border: 2px solid var(--line); border-radius: 4px; padding: 5px 8px; width: 110px;
}
input[type=number]:focus { outline: 3px solid var(--gold); }

table.sheet { width: 100%; border-collapse: collapse; font-size: 14px; }
table.sheet td, table.sheet th { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.sheet td:first-child, table.sheet th:first-child { text-align: left; white-space: normal; }
table.sheet tr.total td { font-weight: 800; border-top: 2px solid var(--ink); }
table.sheet th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.ledger-wrap { overflow-x: auto; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.card { background: var(--panel-2); border: 2px solid var(--line); border-radius: 6px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.card canvas { width: 100%; image-rendering: pixelated; border: 2px solid #0a0b10; }
.card h3 { margin: 0 !important; }
.card ul { margin: 0; padding-left: 18px; line-height: 1.45; font-size: 14px; }
.card .nums { font-size: 13px; color: var(--muted); line-height: 1.5; }
.card button { margin-top: auto; }

.radio-row { display: flex; gap: 6px; flex-wrap: wrap; }
.radio-row label { background: var(--panel-2); border: 2px solid var(--line); border-radius: 4px; padding: 6px 10px; cursor: pointer; }
.radio-row input { margin-right: 6px; }
.radio-row label:has(input:checked) { border-color: var(--gold); }

.bar { height: 14px; background: #0f1220; border: 2px solid var(--line); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.done > span { background: var(--good); }
.req { display: grid; grid-template-columns: 1fr 160px 70px; gap: 10px; align-items: center; margin: 8px 0; }

.title-screen { text-align: center; }
.logo { font-size: 44px; font-weight: 900; color: var(--gold); letter-spacing: 3px; text-shadow: 4px 4px 0 #6b4f12; margin: 6px 0; }
.title-screen .actions { justify-content: center; }

@media (max-width: 640px) {
  .req { grid-template-columns: 1fr; }
  .stats dd { font-size: 14px; }
}

/* ---- Game Library home page ---- */
#lib-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; background: #0c0e14; border-bottom: 2px solid var(--line); }
#lib-head .brand { font-size: 22px; }
#lib-main { flex: 1; padding: 24px 16px; max-width: 1100px; width: 100%; margin: 0 auto; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.lib-card { background: var(--panel); border: 3px solid var(--line); border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; }
.lib-card:hover { border-color: var(--gold); }
.lib-preview img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; image-rendering: pixelated; border-bottom: 2px solid #0a0b10; }
.lib-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.lib-body h2 { margin: 0; color: var(--gold); font-size: 20px; text-transform: uppercase; letter-spacing: 1px; }
.lib-body p { margin: 0; line-height: 1.5; }
.lib-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.lib-tags span { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 1px 6px; }
.lib-save { color: var(--good); font-size: 14px; }
.lib-play { margin-top: auto; align-self: flex-start; text-decoration: none; color: var(--ink); background: #2f6b4f; border: 2px solid #3f8f69; border-bottom-width: 4px; border-radius: 4px; padding: 8px 18px; font-weight: 700; }
.lib-play:hover, .lib-play:focus-visible { border-color: var(--good); outline: none; }
.lib-foot { margin-top: 22px; text-align: center; }

/* Stop controls work only when the local launcher (serve.py) served the page. js/server-control.js sets
   html[data-server]; hide every Stop control elsewhere: public web host, other servers, file. */
html:not([data-server="owned"]) #lib-stop,
html:not([data-server="owned"]) #b-stop,
html:not([data-server="owned"]) [data-action="stop"] { display: none !important; }
