:root {
  --bg: #15120f;
  --panel: #1f1b17;
  --line: #3a332c;
  --text: #e8dfd2;
  --muted: #9a8f80;
  --mana: #7fb3ff;
  --good: #7cc47c;
  --bad: #e06c5a;
  --warn: #e0b45a;
  --accent: #b388ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, sans-serif; }
button, .button {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 8px; font: inherit; cursor: pointer;
}
button:hover, .button:hover { border-color: var(--muted); }
button.active { border-color: var(--accent); background: #2b2238; }
button:disabled, button.locked { opacity: 0.45; cursor: not-allowed; }

#app { position: fixed; inset: 0; overflow: hidden; }
#map { display: block; width: 100%; height: 100%; cursor: crosshair; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mana { color: var(--mana); }
.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
inspector-card p { margin: 0 0 6px; }

/* Floating panels over the map */
status-corner, build-bar, inspector-card, #start-message {
  background: rgba(31, 27, 23, 0.94); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px #0008;
}

/* Status corner (DESIGN-v2 §5.1); the corner is a setting */
status-corner { position: absolute; width: 230px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
status-corner[data-corner="br"] { right: 12px; bottom: 12px; }
status-corner[data-corner="bl"] { left: 12px; bottom: 12px; }
status-corner[data-corner="tr"] { right: 12px; top: 12px; }
status-corner[data-corner="tl"] { left: 12px; top: 12px; }
status-corner .mana-value { font-size: 16px; }
status-corner .clock { font-variant-numeric: tabular-nums; }
status-corner .clock.night { color: #a9b4ff; }
status-corner .speed { display: grid; grid-template-columns: 40px 1fr 48px; align-items: center; gap: 6px; color: var(--muted); }
status-corner .speed.current { color: var(--text); }
status-corner .speed input { width: 100%; margin: 0; accent-color: var(--accent); }
status-corner .speed-value { text-align: right; font-variant-numeric: tabular-nums; }

/* Bottom bar (§5.2) */
build-bar { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; align-items: stretch; gap: 4px; padding: 4px; max-width: calc(100vw - 520px); overflow-x: auto; }
build-bar .entry { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 64px; padding: 4px 6px; }
build-bar .entry.fixed { cursor: default; border-style: dashed; }
build-bar .icon { font-size: 18px; line-height: 1.2; }
build-bar .label { font-size: 12px; white-space: nowrap; }
build-bar kbd { color: var(--muted); font-size: 10px; }
build-bar .sep { width: 1px; background: var(--line); margin: 2px 2px; }
build-bar .empty { align-self: center; padding: 0 10px; font-size: 12px; }
build-bar[data-mode="build"] { border-color: var(--accent); }

/* Inspector cards (§5.3): pin, move by the header, resize by the corner */
#cards { position: absolute; inset: 0; pointer-events: none; }
inspector-card { position: absolute; pointer-events: auto; display: flex; flex-direction: column; width: 280px; min-width: 200px; min-height: 80px; max-height: 70vh; resize: both; overflow: hidden; }
inspector-card header { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 10px; border-bottom: 1px solid var(--line); cursor: move; user-select: none; }
inspector-card header .spacer { flex: 1; }
inspector-card header button { padding: 0 6px; border-color: transparent; background: none; }
inspector-card .pin { opacity: 0.45; }
inspector-card.pinned { border-color: var(--accent); }
inspector-card.pinned .pin { opacity: 1; }
inspector-card .body { padding: 8px 10px; overflow: auto; flex: 1; }
inspector-card fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0 0 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; }

#start-message { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); padding: 8px 14px; max-width: min(560px, calc(100vw - 32px)); text-align: center; color: var(--warn); }
#start-message[hidden] { display: none; }

#toast { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); background: #000c; padding: 6px 12px; border-radius: 6px; pointer-events: none; }
#toast[hidden] { display: none; }

button.accent { border-color: var(--accent); }
.row.center { justify-content: center; }
#feedback, #new-world { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 16px; width: min(480px, calc(100vw - 32px)); }
#feedback::backdrop, #new-world::backdrop { background: #000a; }
#feedback h2 { margin: 0; font-size: 16px; }
#feedback h2 .muted { font-size: 12px; font-weight: normal; }
#feedback form { display: flex; flex-direction: column; gap: 10px; }
#feedback p { margin: 0; }
#feedback fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px 6px; }
#feedback label { display: flex; flex-direction: column; gap: 4px; }
#feedback fieldset label, #feedback label.check { flex-direction: row; align-items: center; gap: 4px; }
#feedback label.check { align-items: flex-start; }
#feedback textarea, #feedback input:not([type]) {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px; font: inherit; resize: vertical;
}

/* ---------- /admin (feedback reader) ---------- */
body.admin { height: auto; min-height: 100%; }
#admin { display: flex; height: 100vh; }
#admin-list { width: 360px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; padding: 10px; overflow: hidden; }
#admin-list h1 { margin: 0; font-size: 16px; }
#admin-list header button { margin-left: auto; }
#admin-search { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px; font: inherit; }
#admin-items { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#admin-items li { padding: 6px 8px; border: 1px solid transparent; border-bottom-color: var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
#admin-items li:hover { background: var(--panel); }
#admin-items li.active { border-color: var(--accent); background: #2b2238; }
#admin-items .snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.between { justify-content: space-between; }
#admin-detail { flex: 1; min-width: 0; overflow-y: auto; padding: 10px 16px; }
#admin-detail h2 { margin: 0; font-size: 16px; }
#admin-detail h2 .muted { font-size: 12px; font-weight: normal; }
#admin-detail h3 { margin: 14px 0 4px; font-size: 13px; color: var(--muted); }
#admin-detail blockquote { margin: 0; padding: 6px 10px; background: var(--panel); border-left: 3px solid var(--accent); white-space: pre-wrap; }
#admin-detail pre { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px; overflow-x: auto; font-size: 12px; }
a.button { text-decoration: none; display: inline-block; }
@media (max-width: 700px) {
  #admin { flex-direction: column; height: auto; }
  #admin-list { width: auto; border-right: none; border-bottom: 1px solid var(--line); max-height: 50vh; }
}

#new-world h2 { margin: 0 0 6px; font-size: 16px; }
#new-world p { margin: 0 0 12px; }

/* Custom tooltips (src/ui/tooltip.js) */
#tip { position: fixed; z-index: 10; max-width: 280px; background: #000e; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 12px; pointer-events: none; }
#tip[hidden] { display: none; }

/* Templates in the bar and in cards (step 2) */
build-bar .entry.active { border-color: var(--accent); background: #2b2238; }
build-bar .entry.template .label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
inspector-card table { width: 100%; border-collapse: collapse; margin: 4px 0; }
inspector-card td { padding: 1px 0; vertical-align: top; }
inspector-card td:first-child { color: var(--muted); padding-right: 8px; white-space: nowrap; }
inspector-card td.num { text-align: right; font-variant-numeric: tabular-nums; }
inspector-card .prices { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 4px 0; }
inspector-card .prices span[data-tip], inspector-card [data-tip] { cursor: help; }
inspector-card td.good { color: var(--good); } inspector-card td.bad { color: var(--bad); }

/* Adventurer cards (step 4): what they said, and the developer view of their emotions */
inspector-card ul.said { list-style: none; margin: 4px 0; padding: 0; color: var(--text); font-style: italic; }
.dev-label { font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
/* Anything only ?dev shows: a dashed accent border on a tinted background, so it never passes for player UI. */
.dev { margin-top: 6px; padding: 6px 8px; border: 1px dashed var(--accent); border-radius: 6px; background: rgba(179, 136, 255, 0.1); }
inspector-card table.moods td:first-child { width: 70px; }
inspector-card table.moods td.num { width: 40px; padding-right: 6px; }
.mood { position: relative; height: 6px; background: var(--line); border-radius: 3px; }
.mood > div { position: absolute; top: 0; height: 100%; border-radius: 3px; }
.mood > .pos { background: var(--good); }
.mood > .neg { background: var(--bad); }
.mood::after { content: ''; position: absolute; left: 50%; top: -2px; width: 1px; height: 10px; background: var(--muted); }

/* Step 5: the edit queue and the after-visit popups */
status-corner .queue { display: flex; justify-content: space-between; align-items: center; gap: 6px; color: var(--warn); }
status-corner .queue[hidden] { display: none; }
inspector-card .queued { margin-top: 6px; padding: 6px; border: 1px dashed var(--warn); border-radius: 6px; }
inspector-card .queued .row { margin-top: 4px; }
#popups { position: absolute; top: 70px; right: 12px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 300px); overflow-y: auto; width: 340px; }
visit-popup { display: block; background: rgba(31, 27, 23, 0.96); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 16px #0008; }
visit-popup h3 { margin: 0 0 2px; font-size: 13px; }
visit-popup table { width: 100%; border-collapse: collapse; margin: 4px 0; }
visit-popup td.num { text-align: right; }
visit-popup p { margin: 4px 0 6px; }

/* Step 6: the entrance card's tabs and the town news */
inspector-card .tabs { display: flex; gap: 4px; margin-bottom: 6px; }
inspector-card .tabs button.active { border-color: var(--accent); background: #2b2238; }
inspector-card ol.news { list-style: none; margin: 0; padding: 0; }
inspector-card ol.news li { padding: 2px 0; border-bottom: 1px solid var(--line); }
inspector-card .limit { min-width: 24px; text-align: center; }

/* Step 6b: game over */
#gameover { position: absolute; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 20; }
#gameover[hidden] { display: none; }
#gameover .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; max-width: 380px; text-align: center; }
