:root {
  color-scheme: dark;
  --ink: #ebe4d4;
  --muted: #a39886;
  --paper: #231f1b;
  --line: #1a120e;
  --rust: #e07a3d;
  --deep: #141210;
  --teal: #7fbfb2;
  --gold: #e0b15a;
  --danger: #e07058;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--deep); color: var(--ink); }
body { font-family: "Segoe UI", Tahoma, sans-serif; overflow: hidden; }
button, input { font: inherit; }
button { cursor: pointer; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#scrim { position: fixed; inset: 0; background: rgba(12, 10, 8, 0.5); pointer-events: none; }
.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  pointer-events: none;
  overflow: auto;
}
.card {
  pointer-events: auto;
  width: min(440px, 100%);
  background: var(--paper);
  border: 3px solid var(--line);
  box-shadow: 8px 8px 0 #0c0a08;
  padding: 22px 22px 18px;
}
.card.wide {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 18px;
}
h1, h2, h3 { font-family: Georgia, "Palatino Linotype", Palatino, serif; font-weight: 700; margin: 0; }
h1 { font-size: 48px; letter-spacing: 0.16em; line-height: 0.95; }
h1 span, h2 { color: var(--rust); }
h2 { font-size: 28px; letter-spacing: 0.04em; margin-bottom: 8px; }
.stamp { margin: 0; letter-spacing: 0.22em; font-size: 11px; color: var(--gold); }
.tag { font-family: Georgia, serif; font-style: italic; color: var(--muted); margin: 6px 0 14px; }
.fine { color: var(--muted); font-size: 13px; }
.error { min-height: 1.2em; color: var(--danger); font-size: 14px; }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 13px; }
input[type="text"], input[type="password"], input:not([type]) {
  width: 100%;
  background: var(--deep);
  color: var(--ink);
  border: 2px solid #3a3228;
  padding: 8px 10px;
}
input:focus, button:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.card > button, .card button[type="submit"], .panel button, .switch button, #conn button, #menu button {
  background: var(--rust);
  color: #1a120e;
  border: 0;
  font-weight: 700;
  padding: 9px 12px;
}
.card > button { margin-top: 8px; }
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.switch button { background: #3a3228; color: var(--ink); }
.switch button.on { background: var(--gold); color: #1a120e; }
button.ghost { background: #3a3228; color: var(--ink); }

.preview-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#preview { background: #1a1814; border: 2px solid #3a3228; image-rendering: pixelated; width: 180px; height: 200px; }
.cycler { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.cycler button { width: 32px; background: #3a3228; color: var(--ink); border: 0; font-weight: 700; }
.cycler span { flex: 1; }
.cycler i { width: 16px; height: 16px; border: 2px solid #1a120e; display: block; }
#origins { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.origin {
  text-align: left;
  background: #1a1814;
  color: var(--ink);
  border: 2px solid #3a3228;
  padding: 8px;
}
.origin.on { border-color: var(--gold); }
.origin b { display: block; color: var(--gold); font-size: 14px; }
.origin span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }

#hud { position: fixed; inset: 0; pointer-events: none; }
.paper {
  background: rgba(20, 16, 12, 0.82);
  border: 2px solid #3a3228;
  box-shadow: 3px 3px 0 #0c0a08;
  padding: 8px 10px;
  font-size: 14px;
}
/* ---- HUD ---- */
#plate { position: absolute; top: 12px; left: 12px; width: min(260px, calc(100vw - 24px)); display: grid; gap: 2px; }
#plate strong { font-family: Georgia, serif; font-size: 20px; letter-spacing: 0.04em; }
#tabs { color: var(--gold); font-weight: 700; align-self: center; }
#who-origin { color: var(--gold); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
#where { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
#where-tier { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.rowline { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rowline.tight { justify-content: flex-start; flex-wrap: wrap; }
kbd { font: 10px/1 inherit; color: var(--muted); border: 1px solid #3a3228; padding: 1px 3px; margin-left: 3px; }

#tracker { position: absolute; top: 152px; right: 12px; width: 190px; font-size: 12px; display: grid; gap: 6px; }
#tracker:empty { display: none; }
#quest { color: var(--ink); font-family: Georgia, serif; font-size: 13px; }
.track { border-top: 1px solid #3a3228; padding-top: 4px; }
.track b { color: var(--gold); font-weight: 600; }
.track.done b { color: var(--teal); }

#banner { position: absolute; top: 12%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; text-shadow: 2px 2px 0 #0c0a08; animation: bannerfade 2.8s ease-out forwards; }
#banner b { display: block; font-family: Georgia, serif; font-size: 34px; letter-spacing: 0.08em; }
#banner span { color: var(--gold); letter-spacing: 0.22em; font-size: 12px; text-transform: uppercase; }
@keyframes bannerfade { 0% { opacity: 0; } 12% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

#dock { position: absolute; left: 12px; bottom: 12px; width: min(340px, calc(50% - 200px)); min-width: 220px; display: grid; gap: 4px; }
#chat-log { max-height: 132px; overflow: hidden; font-size: 13px; color: var(--ink); text-shadow: 1px 1px 0 #0c0a08; }
#chat-log b { color: var(--gold); font-weight: 600; }
#chat-log .road b { color: #b48cdc; }
#chat-form { pointer-events: auto; }
#chat-input { width: 100%; background: rgba(20, 16, 12, 0.82); }

#bottom { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; align-items: flex-end; gap: 10px; pointer-events: auto; }
#hands { display: flex; gap: 4px; }
.hand { position: relative; width: 56px; height: 56px; background: rgba(20, 16, 12, 0.92); border: 2px solid #3a3228; display: grid; place-items: center; }
.hand.on { border-color: var(--gold); }
.hand .ico { width: 40px; height: 40px; }
.hand .key { position: absolute; left: 3px; top: 1px; font-size: 10px; color: var(--muted); }
.hand .cdv { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(12, 10, 8, 0.7); }
.hand .fists { font-size: 11px; color: var(--muted); }
#vitals { display: grid; gap: 4px; }
.hp { position: relative; height: 14px; background: #1a120e; border: 2px solid #3a3228; }
#hp-fill { display: block; height: 100%; width: 100%; background: linear-gradient(#e8894a, #a34532); transition: width 0.15s; }
#hp-text { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 10px; text-shadow: 1px 1px 0 #0c0a08; }
#hotbar { display: flex; gap: 4px; }
#hotbar button {
  position: relative;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: rgba(20, 16, 12, 0.92);
  color: var(--ink);
  border: 2px solid #3a3228;
  padding: 2px;
  font-size: 11px;
}
#hotbar button.on { border-color: var(--gold); color: var(--gold); }
#hotbar .idx { position: absolute; left: 3px; top: 1px; font-size: 10px; color: var(--muted); }
#hotbar .qty { position: absolute; right: 3px; bottom: 1px; font-size: 11px; text-shadow: 1px 1px 0 #0c0a08; }
#hotbar .ico { width: 32px; height: 32px; }
#menu-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
#menu-buttons button { background: rgba(20, 16, 12, 0.92); color: var(--ink); border: 2px solid #3a3228; padding: 4px 8px; font-size: 12px; text-align: left; }
#menu-buttons button:hover { border-color: var(--gold); }
#hint {
  position: absolute;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  margin: 0;
  width: max-content;
  max-width: calc(100% - 24px);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  text-shadow: 1px 1px 0 #0c0a08;
}

/* ---- Panels ---- */
.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  background: var(--paper);
  border: 3px solid var(--line);
  box-shadow: 8px 8px 0 #0c0a08;
  padding: 14px 16px;
  pointer-events: auto;
  z-index: 10;
}
.panel.big { width: min(860px, calc(100% - 24px)); }
.panel.huge { width: calc(100% - 48px); height: calc(100% - 48px); display: flex; flex-direction: column; }
.panel h4 { margin: 12px 0 6px; font-family: Georgia, serif; font-size: 14px; color: var(--gold); font-weight: 700; }
.panel button { background: var(--rust); color: #1a120e; border: 0; font-weight: 700; padding: 6px 10px; }
.panel button.ghost, .panel button.soft { background: #3a3228; color: var(--ink); }
.panel button:disabled { background: #2a241c; color: #6d6458; cursor: default; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
#talk-text { font-family: Georgia, serif; font-size: 17px; line-height: 1.4; }
#talk-choices, #fire-choices { display: flex; flex-wrap: wrap; gap: 8px; }
#talk-choices button, #fire-choices button { background: #1a1814; color: var(--ink); border: 2px solid #3a3228; font-weight: 400; }
#talk-choices button:hover, #fire-choices button:hover { border-color: var(--gold); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, 52px); gap: 4px; min-height: 56px; }
#bag.grid { grid-template-columns: repeat(6, 52px); }
.slot {
  position: relative;
  width: 52px;
  height: 52px;
  background: #1a1814;
  border: 2px solid #3a3228;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
}
.slot.empty { cursor: default; border-style: dashed; }
.slot:hover { filter: brightness(1.2); }
.slot.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
.slot .ico { width: 40px; height: 40px; object-fit: contain; pointer-events: none; }
.slot .price { position: absolute; right: 2px; bottom: 0; font-size: 10px; color: var(--gold); text-shadow: 1px 1px 0 #0c0a08; }
.slot .tier { position: absolute; left: 3px; top: 1px; font-size: 9px; color: var(--muted); }
.slot.worn::after { content: ''; position: absolute; right: 3px; top: 3px; width: 6px; height: 6px; background: var(--gold); }
.slot.r-odd { border-color: #3f7a70; box-shadow: inset 0 0 10px rgba(127, 191, 178, 0.25); }
.slot.r-wrong { border-color: #a07a30; box-shadow: inset 0 0 12px rgba(224, 177, 90, 0.3); }
.slot.r-relic { border-color: #b0552a; box-shadow: inset 0 0 14px rgba(224, 122, 61, 0.4); }
.slot.cant { opacity: 0.45; }
.slot.drag-over { border-color: var(--ink); }

#pack-layout { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: start; }
#doll { display: grid; grid-template-columns: repeat(3, 60px); grid-template-areas: '. head .' 'hand chest sling' 'hands legs charm'; gap: 6px; justify-content: center; }
.doll-slot { position: relative; width: 60px; height: 60px; background: #1a1814; border: 2px dashed #3a3228; display: grid; place-items: center; cursor: pointer; }
.doll-slot.full { border-style: solid; }
.doll-slot .lbl { position: absolute; left: 3px; top: 1px; font-size: 9px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; pointer-events: none; }
.doll-slot .ico { width: 44px; height: 44px; object-fit: contain; pointer-events: none; }
.doll-slot.r-odd { border-color: #3f7a70; }
.doll-slot.r-wrong { border-color: #a07a30; }
.doll-slot.r-relic { border-color: #b0552a; }
#doll-stats { margin-top: 10px; display: grid; gap: 2px; font-size: 12px; }
#doll-stats b { color: var(--ink); font-weight: 600; }
#pack-actions { min-height: 34px; margin: 8px 0; }
#pack-actions .sel-name { font-family: Georgia, serif; }

.line { display: flex; align-items: center; gap: 8px; border-top: 1px solid #3a3228; padding: 5px 0; font-size: 13px; }
.line .ico { width: 28px; height: 28px; object-fit: contain; }
.line .grow { flex: 1; }
.line .fine { font-size: 12px; }
.line button { padding: 3px 7px; font-size: 12px; background: #1a1814; color: var(--ink); border: 2px solid #3a3228; font-weight: 400; }
.line button:hover:not(:disabled) { border-color: var(--gold); }
.job { border-top: 1px solid #3a3228; padding: 8px 0; display: grid; gap: 4px; }
.job .meta { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.job .meta b { color: var(--gold); font-weight: 600; }

#map-layout { flex: 1; display: grid; grid-template-columns: 1fr 220px; gap: 12px; min-height: 0; }
#map-canvas { width: 100%; height: 100%; min-height: 0; background: #0c0a08; image-rendering: pixelated; cursor: crosshair; }
#map-marks { overflow: auto; display: grid; align-content: start; gap: 2px; }
#map-marks button { text-align: left; background: #1a1814; color: var(--ink); border: 2px solid #3a3228; font-weight: 400; font-size: 12px; padding: 4px 6px; }
#map-marks button.on { border-color: var(--gold); color: var(--gold); }

#sheet-body { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; font-size: 13px; }
#sheet-body div { display: flex; justify-content: space-between; border-top: 1px solid #2a241c; padding: 3px 0; }
#sheet-body b { color: var(--ink); font-weight: 600; }

#tip {
  position: fixed;
  z-index: 30;
  width: min(270px, calc(100% - 24px));
  background: #1c1916;
  border: 2px solid #3a3228;
  box-shadow: 4px 4px 0 #0c0a08;
  padding: 7px 9px;
  pointer-events: none;
  font-size: 13px;
}
#tip b { display: block; font-family: Georgia, serif; font-size: 15px; }
#tip .kind { color: var(--muted); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 4px; }
#tip .stat { color: var(--ink); }
#tip .affix { color: var(--teal); }
#tip .blurb { color: var(--muted); font-style: italic; margin-top: 4px; font-family: Georgia, serif; }
#tip .cmp { margin-top: 6px; border-top: 1px solid #3a3228; padding-top: 4px; font-size: 12px; }
#tip .up { color: #8fbf6a; }
#tip .down { color: var(--danger); }
#tip .price { color: var(--gold); margin-top: 4px; font-size: 12px; }
#tip span { display: block; }

#menu { display: none; flex-direction: column; gap: 8px; }
#menu:not(.hidden) { display: flex; }
#menu button { width: 100%; }

#toasts {
  position: fixed;
  bottom: 118px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  pointer-events: none;
  width: min(440px, calc(100% - 24px));
  z-index: 5;
}
.toast {
  background: rgba(20, 16, 12, 0.9);
  border-left: 4px solid var(--gold);
  padding: 7px 10px;
  font-family: Georgia, serif;
  font-size: 14px;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  background: rgba(12, 10, 8, 0.45);
  text-align: center;
  pointer-events: none;
}
.overlay p { font-family: Georgia, serif; font-size: 42px; margin: 0; }
.overlay span, #conn-text { color: var(--muted); font-family: Georgia, serif; font-style: italic; }
#conn { pointer-events: auto; gap: 8px; z-index: 40; }
#conn button { pointer-events: auto; }

@media (max-width: 900px) {
  .card.wide { grid-template-columns: 1fr; }
  h1 { font-size: 36px; }
  #pack-layout, .split { grid-template-columns: 1fr; }
  #hint, #tracker { display: none; }
  #menu-buttons { display: none; }
}
.grid > p { grid-column: 1 / -1; margin: 4px 0; }
.cycler[hidden] { display: none; }
