/* Emberhold — RS-ish dark UI (spec §4 / §14).
   The :root block below MIRRORS the Emberhold-22 palette frozen in js/data.js.
   These custom properties (plus --scrim, ink @ 85%) are the ONLY color literals
   allowed outside data.js — everything else must use var(). Keep in sync. */
:root {
  --ink: #140c1c;
  --plum: #442434;
  --navy: #30346d;
  --slate: #4e4a4e;
  --rust: #854c30;
  --moss: #346524;
  --ember: #d04648;
  --drab: #757161;
  --cornflower: #597dce;
  --amber: #d27d2c;
  --steel: #8595a1;
  --leaf: #6daa2c;
  --tan: #d2aa99;
  --sky: #6dc2ca;
  --gold: #dad45e;
  --bone: #deeed6;
  --ui-dark: #1a1614;
  --ui-brown: #4a3c2e;
  --parchment: #c9b78a;
  --arc: #2979FF;
  --boltglow: #9AB8FF;
  --frost: #7FD4FF;
  --scrim: rgba(20, 12, 28, 0.85);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--ink);
  color: var(--parchment);
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 14px;
  display: flex;
  justify-content: center;
  padding: 10px;
  user-select: none;
}

#app { display: flex; gap: 8px; align-items: stretch; }
#gameCol { display: flex; flex-direction: column; gap: 8px; }

/* ---- world canvas + HUD overlay ---- */
#canvasWrap {
  position: relative;
  width: 772px;
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  background: var(--ui-dark);
}
#world { display: block; background: var(--ui-dark); }

#hud {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

#minimap {
  display: block;
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  background: var(--ui-dark);
}

#goalTicker {
  max-width: 220px;
  min-height: 16px;
  padding: 2px 6px;
  background: var(--ui-dark);
  border: 1px solid var(--ui-brown);
  color: var(--gold);
  font-size: 12px;
  text-align: right;
}
#goalTicker:empty { display: none; }

/* ---- HP / mana orbs ---- */
#orbs { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.orb {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
#hpOrb { background: radial-gradient(circle at 35% 30%, var(--ember), var(--plum)); }
#mpOrb { background: radial-gradient(circle at 35% 30%, var(--cornflower), var(--navy)); }
.orb-num {
  color: var(--bone);
  font-size: 13px;
  font-weight: bold;
  text-shadow: 1px 1px 0 var(--ink);
}
.run-btn {
  width: 46px;
  padding: 3px 0;
  background: var(--ui-dark);
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  color: var(--drab);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}
.run-btn.active { color: var(--gold); border-color: var(--rust); }
.run-btn:hover { color: var(--bone); }

.orb.low { animation: orb-pulse 0.8s infinite; }
@keyframes orb-pulse {
  0%, 100% { outline-color: var(--ink); }
  50% { outline-color: var(--ember); }
}

/* §14: mana orb pulses while a cast winds up, flashes red when out of mana */
#mpOrb.casting { animation: orb-cast 0.7s infinite; }
@keyframes orb-cast {
  0%, 100% { outline-color: var(--ink); }
  50% { outline-color: var(--sky); }
}
#mpOrb.oom { animation: orb-oom 0.45s infinite; }
@keyframes orb-oom {
  0%, 100% { outline-color: var(--ember); border-color: var(--ember); }
  50% { outline-color: var(--ink); border-color: var(--ui-brown); }
}

/* ---- chat log ---- */
#chatBox {
  width: 772px;
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  background: var(--ui-dark);
  display: flex;
  flex-direction: column;
  position: relative;   /* anchors #newGameBtn */
}
#chatHeader {
  padding: 3px 8px;
  background: var(--ui-brown);
  color: var(--bone);
  font-size: 12px;
  font-weight: bold;
  text-shadow: 1px 1px 0 var(--ink);
}
#chatLog {
  height: 118px;
  overflow-y: auto;
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1.35;
}
.chat-line { color: var(--parchment); }
.chat-system { color: var(--sky); }
.chat-warn { color: var(--ember); }
.chat-gold { color: var(--gold); }

/* ---- right panel column ---- */
#panelCol {
  width: 242px;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  background: var(--ui-dark);
}
#tabBar { display: flex; }
.tab {
  flex: 1;
  padding: 6px 2px;
  background: var(--ui-brown);
  color: var(--parchment);
  border: 1px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}
.tab:hover { color: var(--bone); }
.tab.active {
  background: var(--rust);
  color: var(--bone);
  border-bottom-color: var(--rust);
}
#panelBody { flex: 1; position: relative; min-height: 420px; }
.panel { display: none; padding: 8px; height: 100%; }
.panel.active { display: block; }
.placeholder {
  color: var(--drab);
  text-align: center;
  margin-top: 40%;
  font-style: italic;
}

/* ---- skills tab (§14: level + XP bar, hover = XP to next) ---- */
.skill-list { display: flex; flex-direction: column; gap: 3px; }
.skill-row {
  position: relative;
  padding: 2px 6px 5px;
  border: 1px solid var(--ui-brown);
  background: var(--ink);
}
.skill-top { display: flex; justify-content: space-between; font-size: 12px; }
.skill-lvl { color: var(--gold); }
.skill-bar { height: 4px; margin-top: 3px; background: var(--ui-brown); }
.skill-fill { height: 100%; background: var(--sky); }
.skill-hover {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--parchment);
  font-size: 11px;
}
.skill-row:hover .skill-hover { display: flex; }
.skill-total { margin-top: 6px; text-align: right; color: var(--drab); font-size: 12px; }

/* ---- combat tab (§14: attack-style radios + combat level + EK stub) ---- */
.cmb-level { text-align: center; font-size: 15px; color: var(--bone); padding: 6px 0 10px; }
.cmb-level span { color: var(--gold); font-weight: bold; }
.cmb-sec {
  color: var(--drab);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.style-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  margin-bottom: 4px;
  border: 1px solid var(--ui-brown);
  background: var(--ink);
  cursor: pointer;
}
.style-row:hover { border-color: var(--drab); }
.style-row.selected { border-color: var(--gold); }
.style-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--ui-brown);
  background: var(--ink);
  flex: none;
}
.style-row.selected .style-dot { background: var(--gold); border-color: var(--rust); }
.style-name { color: var(--bone); font-size: 13px; }
.style-row.selected .style-name { color: var(--gold); }
.style-desc { color: var(--sky); font-size: 11px; }
.cmb-weapon {
  margin-top: 8px;
  padding: 4px 6px;
  border: 1px solid var(--ui-brown);
  font-size: 12px;
  color: var(--parchment);
}
.cmb-ek {
  margin-top: 8px;
  padding: 4px 6px;
  border: 1px dashed var(--ui-brown);
  font-size: 12px;
  color: var(--drab);
}

/* ---- boss bar (block 13: shown while a boss is engaged) ---- */
#bossBar {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  padding: 3px 10px 6px;
  background: var(--ui-dark);
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  text-align: center;
  z-index: 20;
  pointer-events: none;
}
#bossName {
  color: var(--ember);
  font-weight: bold;
  font-size: 12px;
  text-shadow: 1px 1px 0 var(--ink);
  margin-right: 7px;
}
#bossHp { color: var(--bone); font-size: 11px; }
#bossBar .boss-track {
  height: 7px;
  margin-top: 3px;
  background: var(--ink);
  border: 1px solid var(--ui-brown);
}
#bossFill { height: 100%; background: var(--ember); }

/* ---- spellbook tab (block 10 magic core) ---- */
.spell-list { display: flex; flex-direction: column; gap: 4px; }
.spell-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid var(--ui-brown);
  background: var(--ink);
  cursor: pointer;
}
.spell-row:hover { border-color: var(--drab); }
.spell-row.active { border-color: var(--gold); outline: 1px solid var(--gold); }
.spell-row.locked .spell-icon,
.spell-row.locked .spell-name,
.spell-row.locked .spell-info,
.spell-row.locked .spell-max { opacity: 0.4; filter: grayscale(0.8); }
.spell-icon { image-rendering: pixelated; width: 24px; height: 24px; flex: none; }
.spell-main { flex: 1; min-width: 0; }
.spell-name { color: var(--bone); font-size: 13px; }
.spell-row.active .spell-name { color: var(--gold); }
.spell-info { color: var(--sky); font-size: 11px; }
.spell-sub { color: var(--ember); font-size: 11px; font-style: italic; }
.spell-max { color: var(--parchment); font-size: 12px; flex: none; }
.spell-hint { margin-top: 6px; color: var(--drab); font-size: 11px; text-align: center; }

/* ---- context menu (RS-style) ---- */
#contextMenu {
  position: fixed;
  z-index: 40;
  min-width: 130px;
  background: var(--ui-dark);
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  padding: 2px;
  font-size: 13px;
}
#contextMenu .cm-header {
  color: var(--gold);
  padding: 2px 6px;
  border-bottom: 1px solid var(--ui-brown);
}
#contextMenu .cm-item {
  color: var(--parchment);
  padding: 2px 6px;
  cursor: pointer;
  white-space: nowrap;
}
#contextMenu .cm-item:hover { background: var(--ui-brown); color: var(--bone); }
#contextMenu .cm-target { color: var(--sky); }

/* ---- tooltip ---- */
#tooltip {
  position: fixed;
  z-index: 50;
  max-width: 240px;
  background: var(--ui-dark);
  border: 1px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  padding: 4px 7px;
  font-size: 12px;
  color: var(--parchment);
  pointer-events: none;
}
#tooltip .tt-name { color: var(--bone); font-weight: bold; }
#tooltip .tt-bonus { color: var(--sky); }
#tooltip .tt-value { color: var(--gold); }
#tooltip .tt-ex { color: var(--parchment); font-style: italic; }
#tooltip .tt-req-bad { color: var(--ember); }

/* ---- inventory tab (blocks 8+11) ---- */
.inv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.inv-slot {
  position: relative;
  height: 44px;
  border: 1px solid var(--ui-brown);
  background: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.inv-slot:hover { border-color: var(--drab); }
.inv-slot.empty { cursor: default; }
.inv-slot.use-selected { border-color: var(--gold); outline: 1px solid var(--gold); }
.item-icon { image-rendering: pixelated; width: 24px; height: 24px; }
.slot-qty {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 10px;
  color: var(--gold);
  text-shadow: 1px 1px 0 var(--ink);
  pointer-events: none;
}
.inv-coins { margin-top: 6px; text-align: right; color: var(--gold); font-size: 12px; }

/* ---- equipment tab ---- */
.eq-list { display: flex; flex-direction: column; gap: 4px; }
.eq-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border: 1px solid var(--ui-brown);
  background: var(--ink);
  cursor: pointer;
}
.eq-row:hover { border-color: var(--drab); }
.eq-row.empty { color: var(--drab); cursor: default; }
.eq-slotname { width: 52px; font-size: 11px; color: var(--drab); }
.eq-bonuses {
  margin-top: 10px;
  padding: 6px 8px;
  border: 1px solid var(--ui-brown);
  font-size: 12px;
}
.eq-bonuses div { display: flex; justify-content: space-between; }
.eq-bonuses .pos { color: var(--sky); }
.eq-bonuses .neg { color: var(--ember); }

/* ---- shop / bank overlays ---- */
.ov {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ov-card {
  width: 640px;
  max-width: 94vw;
  max-height: 88vh;
  background: var(--ui-dark);
  border: 3px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  display: flex;
  flex-direction: column;
}
.ov-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--ui-brown);
  color: var(--bone);
  font-weight: bold;
  text-shadow: 1px 1px 0 var(--ink);
}
.ov-coins { margin-left: auto; color: var(--gold); font-size: 12px; font-weight: normal; }
.ov-close {
  background: var(--ui-dark);
  border: 1px solid var(--ink);
  color: var(--bone);
  font-family: inherit;
  font-size: 12px;
  padding: 1px 8px;
  cursor: pointer;
}
.ov-close:hover { background: var(--rust); }
.shop-tabs { display: flex; }
.shop-tab {
  flex: 1;
  padding: 5px 2px;
  background: var(--ui-brown);
  color: var(--parchment);
  border: 1px solid var(--ink);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.shop-tab:hover { color: var(--bone); }
.shop-tab.active { background: var(--rust); color: var(--bone); }
.ov-cols { display: flex; gap: 8px; padding: 8px; min-height: 0; }
.ov-col { flex: 1; border: 1px solid var(--ui-brown); overflow-y: auto; max-height: 54vh; }
.ov-col-head {
  padding: 3px 6px;
  background: var(--ink);
  color: var(--drab);
  font-size: 11px;
  border-bottom: 1px solid var(--ui-brown);
}
.ov-row { display: flex; align-items: center; gap: 6px; padding: 2px 6px; cursor: pointer; }
.ov-row:hover { background: var(--ui-brown); }
.ov-price { margin-left: auto; color: var(--gold); font-size: 12px; white-space: nowrap; }
.ov-price.na { color: var(--drab); }
.ov-hint { padding: 4px 10px 8px; color: var(--drab); font-size: 11px; text-align: center; }
.bank-grid {
  flex: 1.3;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 6px;
  overflow-y: auto;
  max-height: 54vh;
  border: 1px solid var(--ui-brown);
  align-content: start;
}

/* ---- dialogue overlay (spec §13: bottom, numbered options, 1-4 keys) ---- */
#dialogueOverlay {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 30;
  background: var(--ui-dark);
  border: 2px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  padding: 8px 12px 6px;
}
#dlgName {
  color: var(--gold);
  font-weight: bold;
  font-size: 13px;
  text-shadow: 1px 1px 0 var(--ink);
}
#dlgText {
  color: var(--parchment);
  font-size: 13px;
  line-height: 1.4;
  margin: 4px 0 8px;
}
#dlgOptions { display: flex; flex-direction: column; }
.dlg-opt {
  color: var(--sky);
  font-size: 13px;
  padding: 2px 6px;
  cursor: pointer;
}
.dlg-opt:hover { background: var(--ui-brown); color: var(--bone); }
.dlg-opt .dlg-num { color: var(--drab); margin-right: 7px; }

/* ---- quest-log tab (spec §13/§14: journal text + checkmarks) ---- */
.quest-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 100%;
}
.quest-entry {
  border: 1px solid var(--ui-brown);
  background: var(--ink);
  padding: 5px 7px;
}
.quest-title { font-weight: bold; font-size: 13px; }
.quest-title.q-locked { color: var(--ember); }
.quest-title.q-active { color: var(--gold); }
.quest-title.q-done { color: var(--leaf); }
.quest-step {
  font-size: 12px;
  color: var(--parchment);
  margin-top: 3px;
  padding-left: 13px;
  text-indent: -13px;
  line-height: 1.35;
}
.quest-step.done { color: var(--drab); }
.quest-progress { font-size: 11px; color: var(--sky); margin-top: 3px; }

/* ---- character-creation overlay ---- */
#charCreate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
}
#ccCard {
  width: 600px;
  max-width: 92vw;
  background: var(--ui-dark);
  border: 3px solid var(--ui-brown);
  outline: 1px solid var(--ink);
  padding: 24px 28px;
  text-align: center;
}
#ccCard h1 {
  color: var(--gold);
  font-size: 30px;
  letter-spacing: 2px;
  text-shadow: 2px 2px 0 var(--ink);
}
.cc-sub { color: var(--parchment); font-style: italic; margin: 4px 0 14px; }
.cc-name { margin-bottom: 14px; }
.cc-name label { color: var(--parchment); font-size: 13px; margin-right: 8px; }
#ccName {
  background: var(--ink);
  border: 1px solid var(--ui-brown);
  color: var(--bone);
  font-family: inherit;
  font-size: 14px;
  padding: 5px 8px;
  width: 220px;
}
#ccName:focus { outline: 1px solid var(--gold); }
.cc-archrow { display: flex; gap: 10px; margin-bottom: 14px; }
.arch-card {
  flex: 1;
  border: 2px solid var(--ui-brown);
  background: var(--ink);
  padding: 10px 8px;
  cursor: pointer;
}
.arch-card:hover, .arch-card.selected { border-color: var(--gold); }
.arch-card h2 { color: var(--bone); font-size: 16px; margin-bottom: 4px; }
.arch-card p { color: var(--parchment); font-size: 12px; min-height: 44px; }
.cc-preview {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  margin-bottom: 4px;
}
.arch-card.selected .cc-preview { filter: drop-shadow(0 0 3px var(--gold)); }
.cc-levels { color: var(--sky); font-size: 11px; margin-top: 4px; white-space: pre; }
.cc-kit { color: var(--drab); font-size: 11px; margin-top: 4px; line-height: 1.4; }
.cc-bonus { margin-bottom: 12px; }
.cc-bonus-head { color: var(--parchment); font-size: 13px; margin-bottom: 6px; }
#ccPoints { color: var(--gold); font-weight: bold; }
.cc-dim { color: var(--drab); font-size: 11px; }
.cc-step-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 3px;
}
.cc-skill { color: var(--parchment); font-size: 13px; width: 90px; text-align: right; }
.cc-step-btn {
  width: 22px;
  height: 22px;
  background: var(--ui-brown);
  color: var(--bone);
  border: 1px solid var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.cc-step-btn:hover:not(:disabled) { background: var(--rust); }
.cc-step-btn:disabled { opacity: 0.35; cursor: default; }
.cc-step-val { color: var(--bone); font-size: 13px; width: 58px; text-align: center; }
.cc-step-val.boosted { color: var(--gold); }
.cc-note { color: var(--drab); font-size: 12px; margin-bottom: 14px; }
.cc-note.warn { color: var(--ember); }

#newGameBtn {
  position: absolute;
  top: 2px;
  right: 4px;
  background: none;
  border: 1px solid var(--ui-brown);
  color: var(--drab);
  font-family: inherit;
  font-size: 10px;
  padding: 1px 6px;
  cursor: pointer;
}
#newGameBtn:hover { color: var(--ember); border-color: var(--ember); }

.btn {
  background: var(--ui-brown);
  color: var(--bone);
  border: 1px solid var(--ink);
  padding: 8px 26px;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  text-shadow: 1px 1px 0 var(--ink);
}
.btn:hover { background: var(--rust); }

.hidden { display: none !important; }
