:root {
  --bg: #0d1012;
  --panel: #2b2520;
  --panel-hi: #3a3129;
  --edge: #14100d;
  --rim: #6b5a44;
  --text: #f1e9d6;
  --muted: #b3a68c;
  --gold: #f2c94c;
  --hp: #5fd35a;
  --hp-mid: #f2c94c;
  --hp-low: #e8503d;
  --xp: #5ab4f2;
  font-family: "Pixelify Sans", ui-monospace, monospace;
}

* { box-sizing: border-box; }
img, canvas { max-width: 100%; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

#world { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }

.px { image-rendering: pixelated; }

.panel {
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 3px solid var(--edge);
  box-shadow: inset 0 0 0 2px var(--rim), inset 0 0 0 4px var(--edge), 0 6px 18px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
  padding: 14px;
}

.hidden { display: none !important; }

/* --- Title and login ----------------------------------------------------- */

#title {
  position: fixed;
  top: 12%;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  z-index: 9;
}
#title h1 {
  margin: 0;
  font-size: clamp(48px, 10vw, 104px);
  font-weight: 700;
  letter-spacing: 4px;
  color: #ffe08a;
  text-shadow: 0 4px 0 #b0452f, 0 8px 0 #4a1e14, 0 12px 24px rgba(0, 0, 0, 0.6);
}
#title p { margin: 18px 0 0; font-size: 20px; text-shadow: 0 2px 0 #000; }

.modal {
  position: fixed;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100% - 32px));
  text-align: center;
  z-index: 10;
}
#starter { top: 50%; width: min(520px, calc(100% - 32px)); }

h2 { margin: 0 0 14px; color: var(--gold); font-weight: 600; }

form { display: flex; flex-direction: column; gap: 10px; }

input, button, select {
  font: inherit;
  font-size: 16px;
  padding: 9px 12px;
  border-radius: 3px;
  border: 2px solid var(--edge);
  color: var(--text);
}
input, select { background: #1a1612; }
input:focus { outline: 2px solid var(--gold); outline-offset: -2px; }

button {
  cursor: pointer;
  background: linear-gradient(180deg, #6b5338, #4f3d2a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 2px 0 var(--edge);
}
button:hover:not(:disabled) { filter: brightness(1.15); }
button:active:not(:disabled) { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: linear-gradient(180deg, #d9a43c, #a8742a); color: #2b1a0a; font-weight: 700; }
button small { display: block; font-size: 12px; opacity: 0.8; }

.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.error { color: var(--hp-low); min-height: 1em; margin: 6px 0 0; }

.cards { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.card { width: 140px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; }
.card canvas { width: 96px; height: 96px; image-rendering: pixelated; }

.type {
  display: inline-block;
  padding: 0 6px;
  border-radius: 3px;
  font-size: 11px;
  text-transform: uppercase;
  color: #1a1c2c;
  background: #e8e2d0;
}
.type-grass { background: #6cc94c; }
.type-fire { background: #ff8a2a; }
.type-water { background: #4aa8e0; }
.type-rock { background: #b08a5a; }
.type-bug { background: #a8c83a; }

/* --- HUD ----------------------------------------------------------------- */

/* The right side, top down: the map, where you are, your quest, and the
   action buttons. */
#right-col { position: fixed; top: 12px; right: 12px; z-index: 9; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
#right-col > * { pointer-events: auto; }
#minimap-wrap {
  position: relative;
  width: 162px;
  height: 162px;
  border-radius: 50%;
  padding: 6px;
  background: radial-gradient(circle, #3a3129 60%, #14100d 61%, #6b5a44 64%, #14100d 68%);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
#minimap { border-radius: 50%; display: block; }


/* The map is top right, chat bottom left, the sidebar a wide strip filling
   the rest of the bottom, and the action buttons middle right. */
:root { --chat-w: 440px; --bottom-h: 204px; }
/* Numbers use a font whose digits can't be mistaken for letters. */
.stat-orb span, .stat-orb.cb { font-size: 21px; font-weight: 400; }
.num, #pouch-n, .qty, .hk .n, .stat-orb span, .stat-orb.cb, .shop-item small, .tip-price, #scores-table td { font-family: 'VT323', monospace; letter-spacing: 0.5px; }
#chat, #sidebar { height: var(--bottom-h); }
#vsplit {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--bottom-h) + 8px);
  height: 8px;
  z-index: 9;
  cursor: ns-resize;
}
#vsplit::after { content: ''; position: absolute; left: calc(50% - 32px); top: 2px; width: 64px; height: 4px; border-radius: 2px; background: var(--rim); opacity: 0.5; }
#vsplit:hover::after { opacity: 1; }
#split {
  position: fixed;
  bottom: 12px;
  left: calc(var(--chat-w) + 12px);
  width: 12px;
  height: var(--bottom-h);
  z-index: 9;
  cursor: ew-resize;
}
#split::after { content: ''; position: absolute; left: 4px; top: 70px; width: 4px; height: 64px; border-radius: 2px; background: var(--rim); opacity: 0.6; }
#split:hover::after { opacity: 1; }
#sidebar {
  position: fixed;
  bottom: 12px;
  left: calc(var(--chat-w) + 24px);
  right: 12px;
  font-size: 15px;
  padding: 10px;
  display: flex;
  gap: 10px;
}
#tab-body { flex: 1; overflow-y: auto; padding-right: 4px; }
#tabs { display: grid; grid-template-columns: repeat(2, 36px); grid-auto-rows: 36px; gap: 3px; align-content: start; }
#tabs button { padding: 4px 0; background: #3a2e22; display: grid; place-items: center; }
#tabs button img { width: 24px; height: 24px; }
#tabs button.active { background: linear-gradient(180deg, #8a6a44, #6b5338); box-shadow: inset 0 0 0 2px var(--gold); }
.tab-title { text-align: center; color: var(--gold); font-weight: 700; font-size: 17px; margin-bottom: 4px; }
.tab-title small { color: var(--muted); font-weight: 400; }
.center { text-align: center; }
.muted { color: var(--muted); }

.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row span:last-child { color: var(--muted); }

.bar { height: 7px; background: #120f0c; border: 1px solid var(--edge); border-radius: 2px; overflow: hidden; flex: 1; }
.bar > div { height: 100%; background: var(--hp); transition: width 0.5s ease-out; box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3); }
.bar.mid > div { background: var(--hp-mid); }
.bar.low > div { background: var(--hp-low); }
.bar.xp > div { background: var(--xp); }

.styles { display: grid; gap: 5px; margin: 10px 0; }
.styles button { text-align: left; }
.styles button.active { background: linear-gradient(180deg, #a83a2a, #7a2a1e); box-shadow: inset 0 0 0 2px var(--gold); }

.skill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 5px; }
.skill {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 2px 6px;
  background: #1a1612;
  border: 2px solid var(--edge);
  border-radius: 3px;
  padding: 4px 6px;
}
.skill img { width: 30px; height: 30px; grid-row: span 2; }
.skill .lvl { font-size: 17px; font-weight: 700; color: var(--gold); }
.skill .lvl small { font-size: 12px; color: var(--muted); font-weight: 400; }
.total { text-align: center; color: var(--muted); margin-top: 8px; }

.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 4px; }
.inv-slot {
  position: relative;
  aspect-ratio: 1;
  background: #1a1612;
  border: 2px solid var(--edge);
  border-radius: 3px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.inv-slot:hover { border-color: var(--rim); }
.inv-slot.drop { border-color: var(--gold); background: #2a2218; }
.inv-slot img { width: 34px; height: 34px; }
.inv-slot .qty { position: absolute; top: 0; left: 3px; font-size: 17px; color: #ffe04a; text-shadow: 1px 1px 0 #000; pointer-events: none; }
.buttons { display: flex; gap: 6px; margin-top: 10px; }
.buttons button { flex: 1; padding: 6px; font-size: 14px; }

.equip-grid {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-areas: ". head ammo" "weapon body shield" "hands legs feet";
  gap: 6px;
  justify-content: center;
  margin: 6px 0 12px;
}
.equip-slot {
  width: 56px;
  height: 56px;
  background: #1a1612;
  border: 2px solid var(--edge);
  border-radius: 3px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.equip-slot img { width: 40px; height: 40px; }
.equip-slot span { color: #4a3e32; font-size: 11px; text-transform: uppercase; }
.slot-head { grid-area: head; } .slot-body { grid-area: body; } .slot-legs { grid-area: legs; }
.slot-weapon { grid-area: weapon; } .slot-shield { grid-area: shield; }
.slot-hands { grid-area: hands; } .slot-feet { grid-area: feet; }
.mon.pet button { margin-top: 4px; padding: 3px 6px; font-size: 13px; }
.mon.pet.active { box-shadow: inset 0 0 0 2px var(--gold); }
.waystone-list { display: grid; gap: 6px; }
.bonuses .row { padding: 2px 0; }

.quest { padding: 5px 6px; border-radius: 3px; cursor: pointer; font-size: 15px; }
.quest:hover { background: rgba(255, 255, 255, 0.05); }
.quest p { margin: 4px 0 2px; color: var(--text); font-size: 13px; line-height: 1.35; }
.q-new > div { color: #ff5a4a; }
.q-active > div { color: #ffe04a; }
.q-done > div { color: #5fd35a; }
.q-locked > div { color: #8a8070; }
.q-meta { color: var(--muted); font-size: 12px; font-weight: 400; }
.quest .q-unlocks { color: #c8a8ff; }

.mon {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #1a1612;
  border: 2px solid var(--edge);
  border-radius: 3px;
  padding: 6px;
  margin-bottom: 6px;
}
.mon canvas { width: 40px; height: 40px; image-rendering: pixelated; flex: none; }
.mon-info { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.mon.fainted { opacity: 0.5; }

#chat {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: min(var(--chat-w), calc(100% - 24px));
  font-size: 15px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(58, 49, 41, 0.88), rgba(43, 37, 32, 0.88));
}
#chat.talking #chat-log, #chat.talking #chat-input { display: none; }
#chat-log { height: calc(var(--bottom-h) - 72px); overflow-y: auto; margin-bottom: 6px; }
#chat-log div { padding: 1px 2px; }
#chat-log .sys { color: var(--muted); }
#chat-log .news { color: #7fd0ff; }
#chat-log .trade-link { color: #d880ff; }
#chat-log b { color: var(--gold); }
#chat-input { width: 100%; padding: 6px 8px; font-size: 15px; }

/* --- Battle -------------------------------------------------------------- */

#battle {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 20;
  padding: 16px;
  animation: battle-in 0.5s steps(6);
}
@keyframes battle-in {
  from { clip-path: inset(50% 0 50% 0); }
  to { clip-path: inset(0 0 0 0); }
}

#battle-stage {
  position: relative;
  width: min(720px, 100%, calc((100vh - 230px) * 1.667));
  aspect-ratio: 240 / 144;
  border: 3px solid var(--edge);
  box-shadow: 0 0 0 2px var(--rim), 0 0 0 5px var(--edge);
  border-radius: 4px;
  overflow: hidden;
}
#battle-canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }

.hpbox {
  position: absolute;
  width: 42%;
  background: rgba(241, 233, 214, 0.95);
  color: #1a1c2c;
  border: 3px solid var(--edge);
  border-radius: 4px 14px 4px 14px;
  padding: 6px 10px;
  font-size: clamp(12px, 2.2vw, 17px);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.3);
}
.hpbox .row span:last-child { color: #4a4a5a; }
.hpbox .hpline { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.hpbox .hp-label { font-size: 11px; font-weight: 700; background: #1a1c2c; color: #ffe08a; padding: 0 4px; border-radius: 2px; }
.hpbox .bar { height: 9px; }
#hp-wild { top: 6%; left: 4%; }
#hp-mine { bottom: 5%; right: 4%; }

#battle-box { width: min(720px, 100%); }
#battle-text { min-height: 48px; font-size: 19px; line-height: 1.35; margin-bottom: 10px; }
#battle-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }
#battle-actions .moves { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#battle-actions .side { display: grid; gap: 6px; }
#battle-actions .wide { grid-column: 1 / -1; }
#battle-actions .move { text-align: left; border-left: 6px solid #e8e2d0; }
#battle-actions .move.type-grass { border-left-color: #6cc94c; }
#battle-actions .move.type-fire { border-left-color: #ff8a2a; }
#battle-actions .move.type-water { border-left-color: #4aa8e0; }
#battle-actions .move.type-rock { border-left-color: #b08a5a; }
#battle-actions .move.type-bug { border-left-color: #a8c83a; }
#battle-actions .move:not(:disabled) { background-color: initial; }

/* --- HUD extras ------------------------------------------------------------ */

.slot-ammo { grid-area: ammo; position: relative; }
.equip-slot .qty { position: absolute; top: 1px; left: 3px; font-size: 16px; color: #ffe04a; text-shadow: 1px 1px 0 #000; }
/* The orbs sit evenly on the minimap's rim, bottom left to bottom right. */
#mana-orb { left: 58px; top: 136px; }
#mana-orb .orb-fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(180deg, #5a8aff, #1a2a8a); transition: height 0.4s; }
#mana-orb span { position: relative; }
.bar.mana > div { background: #5a8aff; }
.spell { display: flex; gap: 8px; align-items: center; padding: 4px; border-radius: 3px; cursor: pointer; position: relative; }
.spell:hover { background: rgba(255, 255, 255, 0.06); }
.spell img { width: 28px; height: 28px; }
.spell b { font-size: 15px; }
.spell small { display: block; color: var(--muted); font-size: 12px; }
.spell kbd { font: inherit; font-size: 12px; color: var(--gold); width: 10px; }
.spell.locked { opacity: 0.4; cursor: default; }
.spell.auto { box-shadow: inset 0 0 0 2px #c88aff; }

#win-guide h3 { color: var(--gold); margin: 12px 0 4px; font-size: 16px; }
.guide-rows { display: grid; gap: 2px; }
.guide-row { display: grid; grid-template-columns: 26px 1fr 110px; gap: 2px 8px; align-items: center; padding: 3px 6px; background: #1a1612; border-radius: 3px; opacity: 0.55; }
.guide-row.ok { opacity: 1; }
.guide-row img { width: 24px; height: 24px; grid-row: span 2; }
.guide-row span { color: var(--gold); text-align: right; font-size: 13px; }
.guide-row small { grid-column: 2 / 4; color: var(--muted); font-size: 12px; }

#goal {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 5px 12px 6px;
  min-width: 300px;
  background: rgba(20, 16, 12, 0.85);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 1px var(--rim);
  border-radius: 4px;
  font-size: 14px;
}
#goal canvas { width: 24px; height: 24px; image-rendering: pixelated; }
#goal .goal-body { flex: 1; }
#goal .goal-text { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; line-height: 1.2; }
#goal .goal-text > span { display: flex; align-items: baseline; gap: 6px; }
#goal .goal-text small { color: var(--muted); }
#goal .bar { height: 6px; margin-top: 3px; }

#task-hud {
  position: fixed;
  top: 12px;
  right: 196px;
  z-index: 8;
  padding: 4px 10px;
  background: rgba(20, 16, 12, 0.85);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 1px var(--rim);
  font-size: 14px;
  max-width: 190px;
}
#task-hud b { color: var(--gold); }

#toasts {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.toast {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 280px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #4a3b2b, #2b2520);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 2px var(--gold), 0 6px 18px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  animation: toast-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1), toast-out 0.4s ease-in 3.6s forwards;
}
.toast img { width: 32px; height: 32px; }
.toast b { color: var(--gold); display: block; font-size: 16px; }
.toast small { color: var(--text); }
.toast.rare { box-shadow: inset 0 0 0 2px #c88aff, 0 0 18px rgba(200, 138, 255, 0.6); }
@keyframes toast-in { from { transform: translateY(-30px) scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateY(-20px); opacity: 0; } }

#combo {
  position: fixed;
  left: calc(50% - 150px);
  top: 42%;
  z-index: 7;
  font-size: 30px;
  font-weight: 700;
  color: #ffd23a;
  text-shadow: 0 3px 0 #8a3a14, 0 0 12px rgba(255, 160, 40, 0.6);
  pointer-events: none;
}
#combo.pop { animation: combo-pop 0.18s ease-out; }
@keyframes combo-pop { from { transform: scale(1.5); } to { transform: scale(1); } }

#daily-ladder { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin: 10px 0; }
.day img { width: 36px; height: 36px; margin-top: 4px; }
.day { background: #1a1612; border: 2px solid var(--edge); border-radius: 3px; padding: 6px 2px; font-size: 12px; }
.day b { display: block; color: var(--gold); }
.day.done { opacity: 0.5; }
.day.today { box-shadow: inset 0 0 0 2px var(--gold); background: #3a2e22; }
#win-daily { z-index: 35; width: min(520px, calc(100% - 32px)); }

#scores-table { width: 100%; border-collapse: collapse; font-size: 15px; }
#scores-table th { color: var(--gold); text-align: left; font-weight: 600; }
#scores-table td, #scores-table th { padding: 3px 6px; border-bottom: 1px solid #3a3129; }
#scores-table tr.me td { color: #ffe08a; }

.achv { display: flex; gap: 8px; align-items: center; padding: 4px; border-radius: 3px; }
.achv img { width: 22px; height: 22px; }
.achv.locked { opacity: 0.4; }
.achv b { font-size: 14px; }
.achv small { display: block; color: var(--muted); font-size: 12px; }
.collection { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 4px; margin: 6px 0 10px; }
.collection .inv-slot.missing img { filter: brightness(0) opacity(0.35); }

/* Quick actions on top, everything else under a divider. */
#hotbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9;
}
.hk-group { display: grid; grid-template-columns: repeat(4, auto); gap: 6px; }
.hk-divider { height: 2px; margin: 0 8px; background: linear-gradient(90deg, transparent, var(--rim), transparent); opacity: 0.7; }

.hk {
  position: relative;
  width: 62px;
  height: 66px;
  padding: 4px 2px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  overflow: hidden;
  background: linear-gradient(180deg, #4a3b2b, #2b2520);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 2px var(--rim), 0 4px 10px rgba(0, 0, 0, 0.45);
}
.hk canvas { width: 28px; height: 28px; image-rendering: pixelated; }
.hk span { font-size: 12px; color: var(--muted); }
.hk kbd {
  position: absolute;
  top: 2px;
  left: 4px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
}
.hk .n { position: absolute; top: 1px; right: 5px; font-size: 16px; color: #ffe04a; text-shadow: 1px 1px 0 #000; }
.hk .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.6); pointer-events: none; }
.hk.flash { box-shadow: inset 0 0 0 2px #fff6c0, 0 0 12px rgba(255, 230, 140, 0.7); }
.hk.on { box-shadow: inset 0 0 0 2px var(--gold), 0 4px 10px rgba(0, 0, 0, 0.45); }
.hk .energy { width: 22px; height: 22px; margin-top: 8px; border: 2px solid var(--edge); background: #120f0c; display: flex; align-items: flex-end; }
.hk .energy > div { width: 100%; background: linear-gradient(180deg, #f2d64a, #c88a1a); }
.hk.empty { opacity: 0.5; }

#wild-hud {
  position: fixed;
  top: 60px;
  right: 196px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(40, 8, 8, 0.85);
  border: 2px solid #000;
  box-shadow: 0 0 0 2px #8a1a14;
  color: #ffe08a;
  font-weight: 700;
}
#wild-hud .skull { font-size: 20px; color: #f2f2f2; }

#hover-text {
  position: fixed;
  top: 8px;
  left: 14px;
  z-index: 8;
  font-size: 16px;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  pointer-events: none;
}
.tgt, .npc-tgt { color: #ffff40; }
.mon-tgt { color: #ffff40; }
.item-tgt { color: #ff9040; }
.obj-tgt { color: #40e0ff; }
.player-tgt { color: #ffffff; }

.stat-orb {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--edge);
  box-shadow: 0 0 0 2px var(--rim);
  background: #1a1612;
  overflow: hidden;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
#hp-orb { left: 3px; top: 113px; }
#hp-orb .orb-fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(180deg, #e0403a, #8a1a14); transition: height 0.4s; }
#hp-orb span { position: relative; }
.stat-orb.cb { left: 113px; top: 113px; color: var(--gold); background: radial-gradient(circle, #4a3a2a, #1a1612); font-size: 15px; }

#context-menu {
  position: fixed;
  z-index: 50;
  background: #5d5447;
  border: 2px solid #000;
  min-width: 160px;
  font-size: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.menu-title { background: #000; color: #5d5447; padding: 2px 6px; font-size: 14px; }
.menu-row { padding: 3px 8px; color: #fff; cursor: pointer; white-space: nowrap; }
.menu-row:hover { background: rgba(0, 0, 0, 0.3); color: #ffff40; }

#dialogue {
  height: 100%;
  overflow-y: auto;
  display: flex;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 3px;
  background: linear-gradient(180deg, #e9dcc0, #d4c4a2);
  color: #2a1e14;
}
#dialogue.hidden { display: none; }
#dialogue-portrait { width: 72px; height: 56px; image-rendering: pixelated; flex: none; background: #c9b88a; border: 2px solid var(--edge); border-radius: 3px; }
.dialogue-body { flex: 1; display: flex; flex-direction: column; }
#dialogue-name { color: #8a1a14; font-weight: 700; font-size: 17px; }
#dialogue-text { font-size: 16px; line-height: 1.35; margin: 2px 0 6px; }
#dialogue-options { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#dialogue-options button { text-align: left; background: none; box-shadow: none; border: none; color: #1a3a8a; padding: 2px 4px; font-size: 16px; }
#dialogue-options button:hover { color: #8a1a14; filter: none; }
/* "Press Space to continue" sits at the bottom middle of the box. */
#dialogue-options button.continue { color: #1a3a8a; text-align: center; margin-top: auto; align-self: center; }

/* Every popup (shops, bank, crafting, gear, spells...) takes the same shape:
   most of the middle of the screen, between the map, the action buttons and
   the bottom panels. The title bar and close button stay put while the
   contents scroll. */
.window {
  position: fixed;
  top: 60px;
  bottom: calc(var(--bottom-h) + 28px);
  left: 24px;
  right: 292px;
  max-width: 1040px;
  margin: 0 auto;
  overflow-y: auto;
  padding: 0 16px 16px;
  font-size: 15px;
  z-index: 12;
}
.win-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.window > .win-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 -16px 12px;
  padding: 12px 16px 10px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border-bottom: 2px solid var(--edge);
}
.win-title { color: var(--gold); font-weight: 700; font-size: 22px; }
.win-close { padding: 4px 12px; font-size: 18px; }
.bank-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; min-height: 60px; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shop-item, .recipe {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #1a1612;
  border: 2px solid var(--edge);
  border-radius: 3px;
  padding: 6px;
  cursor: pointer;
}
.shop-item:hover, .recipe:hover { border-color: var(--rim); }
.shop-item img, .recipe img { width: 34px; height: 34px; }
.shop-item small, .recipe small { display: block; color: var(--muted); font-size: 12px; }
#make-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 6px; }
.recipe.cant { opacity: 0.55; }
.recipe.locked b { color: #ff6a5a; }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trade-cols h3 { margin: 0 0 6px; color: var(--gold); font-size: 15px; }
.trade-box { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; min-height: 120px; background: #120f0c; border: 2px solid var(--edge); padding: 4px; align-content: start; }
.trade-box .hint { grid-column: 1 / -1; }
#trade-status { color: var(--gold); min-height: 1.2em; }
.quest-scroll { background: linear-gradient(180deg, #f2e6c4, #d8c49a); color: #2a1e14; top: 50%; z-index: 30; }
.quest-scroll h2 { color: #8a1a14; }
.quest-scroll ul { text-align: left; display: inline-block; margin: 0 0 14px; }
.quest-scroll .muted { color: #6b5a44; }

@media (max-width: 1000px) {
  #sidebar { left: 12px; bottom: 228px; height: 180px; }
  #split { display: none; }
  .window { bottom: 420px; right: 24px; }
  #god-panel { bottom: 420px; }
}

@media (max-width: 760px) {
  #hotbar { top: auto; right: auto; left: 12px; bottom: 210px; transform: none; flex-direction: row; }
  .hk { width: 48px; height: 54px; }
  .hk span { display: none; }
  #hover-text { font-size: 13px; }
  .window { top: 120px; bottom: 470px; left: 12px; right: 12px; }
  #sidebar { left: 12px; bottom: 280px; height: 170px; }
  #minimap-wrap { transform: scale(0.7); transform-origin: top right; }
  #task-hud, #wild-hud { right: 130px; }
  #god-panel { top: 40px; bottom: 280px; }
  #battle-actions { grid-template-columns: 1fr; }
}

/* --- God mode ------------------------------------------------------------ */

#god-panel {
  position: fixed;
  top: 40px;
  left: 12px;
  bottom: calc(var(--bottom-h) + 18px);
  width: min(330px, calc(100% - 24px));
  padding: 10px;
  display: flex;
  flex-direction: column;
  z-index: 8;
}
#god-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 6px; }
#god-tabs button { padding: 5px 2px; font-size: 13px; }
#god-tabs button.sel { background: linear-gradient(180deg, #8a6a3a, #6b5030); box-shadow: inset 0 0 0 2px var(--gold); }
#god-search { padding: 5px 8px; font-size: 14px; margin-bottom: 6px; }
#god-grid { flex: 1; min-height: 120px; overflow-y: auto; display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: max-content; gap: 4px; align-content: start; }
.god-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; font-size: 11px; line-height: 1.1; background: #1f1a15; min-width: 0; }
.god-cell span { max-width: 100%; overflow-wrap: anywhere; }
.god-cell img { width: 42px; height: 42px; object-fit: contain; }
#god-grid.skills { grid-template-columns: 1fr; }
.god-skill { display: flex; align-items: center; gap: 6px; padding: 4px 6px; background: #1f1a15; border-radius: 3px; font-size: 13px; }
.god-skill img { width: 24px; height: 24px; }
.god-skill span { flex: 1; }
.god-skill input { width: 54px; padding: 3px 4px; font-size: 14px; }
#god-hint kbd { color: var(--gold); font: inherit; font-weight: 700; }
.god-cell.sel { box-shadow: inset 0 0 0 2px #7fe0ff; background: #2a3a40; }
#god-item-opts { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 14px; }
#god-item-opts input { width: 72px; padding: 4px 6px; font-size: 14px; }
#god-item-opts button { padding: 4px 10px; font-size: 14px; }
#god-hint { margin-top: 6px; font-size: 12px; }
#god-npc-opts { margin-top: 6px; }
#god-npc-opts input { width: 100%; padding: 5px 8px; font-size: 14px; }
#god-panel .win-head { margin-bottom: 6px; }

/* --- Coin pouch, tooltips, settings, character creator ----------------------- */

#topleft { position: fixed; top: 12px; left: 12px; z-index: 9; display: flex; gap: 8px; align-items: center; }
#zoom { display: flex; gap: 4px; }
#zoom button { width: 34px; height: 34px; padding: 0; font-size: 20px; font-weight: 700; line-height: 1; display: grid; place-items: center; }
#settings-btn { font-family: system-ui, sans-serif; font-size: 20px; }
#pouch {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 6px;
  background: rgba(20, 16, 12, 0.85);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 1px var(--rim);
  border-radius: 18px;
  color: #ffe04a;
  text-shadow: 1px 1px 0 #000;
  cursor: default;
}
#pouch-n { font-size: 24px; line-height: 1; }
/* The coin art sits low in its square (and its shadow lower), so lift it to look centred. */
#pouch canvas { width: 30px; height: 30px; margin-top: -4px; }
#hover-text { left: 0; top: 0; transform: translate(14px, 18px); max-width: 360px; font-size: 14px; }
#hints { position: fixed; left: 12px; top: 58px; z-index: 8; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; pointer-events: none; }
.hint-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  font-size: 16px;
  line-height: 1;
  background: rgba(20, 16, 12, 0.75);
  border-radius: 4px;
  text-shadow: 1px 1px 0 #000;
}
.hint-line kbd { font: inherit; font-weight: 700; color: var(--gold); }
.hint-line.hidden { display: none; }
#god-panel { top: 92px; }

#item-tip {
  position: fixed;
  z-index: 60;
  max-width: 260px;
  padding: 7px 10px;
  background: rgba(20, 16, 12, 0.96);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 1px var(--rim), 0 4px 12px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
}
#item-tip b { color: var(--gold); font-size: 15px; display: block; margin-bottom: 2px; }
#item-tip .muted { margin-top: 4px; }
.tip-price { margin-top: 5px; color: #7fe07f; font-weight: 600; }
.tip-price.no { color: #ff8a7a; }

#win-bank .bank-grid { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); }
#win-shop .shop-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
#win-shop .shop-item img, #make-list .recipe img { width: 40px; height: 40px; }
.gear-layout { display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.gear-layout .equip-grid { grid-template-columns: repeat(3, 72px); }
.gear-layout .equip-slot { width: 72px; height: 72px; }
.gear-layout .equip-slot img { width: 54px; height: 54px; }
.gear-layout .bonuses { min-width: 280px; }

.settings { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; padding: 6px; }
.setting { display: flex; gap: 6px; align-items: center; font-size: 16px; cursor: pointer; }
.setting input { width: 18px; height: 18px; }

#win-look { z-index: 50; width: min(560px, calc(100% - 32px)); }
.look-preview { display: flex; justify-content: center; gap: 18px; margin: 6px 0 10px; }
.look-preview canvas { width: 80px; height: 92px; image-rendering: pixelated; background: radial-gradient(circle, #4a6a3a, #2a3a22); border: 2px solid var(--edge); border-radius: 6px; }
.look-row { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: center; margin: 5px 0; }
.look-row > span { color: var(--muted); }
.look-row > div { display: flex; flex-wrap: wrap; gap: 4px; }
.look-row button { padding: 4px 9px; font-size: 14px; }
.look-row button.sel { box-shadow: inset 0 0 0 2px var(--gold); background: linear-gradient(180deg, #8a6a44, #6b5338); }
.look-row .swatch { width: 26px; height: 26px; padding: 0; border: 2px solid var(--edge); }
.look-row .swatch.sel { box-shadow: 0 0 0 2px var(--gold); }
#look-save { display: block; margin: 12px auto 0; min-width: 160px; }

#area-name {
  width: 266px;
  z-index: 8;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  color: #ffe680;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  pointer-events: none;
}
#quest-hud {
  width: 266px;
  padding: 6px 10px;
  background: rgba(20, 16, 12, 0.88);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 1px var(--rim);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.35;
}
#quest-hud b { display: block; color: var(--gold); font-size: 14px; margin-bottom: 2px; }

#area-banner {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  max-width: min(560px, calc(100% - 480px));
  text-align: center;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(0, 0, 0, 0.8);
}
#area-banner b { display: block; font-size: 30px; color: #ffe680; letter-spacing: 1px; }
#area-banner span { font-size: 15px; color: #f1e9d6; }
#area-banner.show { animation: area-in 9s ease-out forwards; }
@keyframes area-in { 0% { opacity: 0; transform: translate(-50%, -8px); } 6% { opacity: 1; transform: translate(-50%, 0); } 85% { opacity: 1; } 100% { opacity: 0; } }

.world-map { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.world-map canvas { image-rendering: pixelated; border: 2px solid var(--edge); border-radius: 4px; max-width: 100%; }
#map-info { min-height: 2.6em; text-align: center; font-size: 15px; color: var(--text); }
#map-info b { color: var(--gold); }

/* A footer that stays at the bottom of a popup while its contents scroll. */
.win-foot {
  position: sticky;
  bottom: -16px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px -16px -16px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--panel), var(--panel-hi));
  border-top: 2px solid var(--edge);
}
.win-foot .hint { margin: 0; }
.inv-slot.empty { cursor: default; opacity: 0.55; }
#bank-space { margin: 0 0 8px; }
#win-bank:not(.hidden) { display: flex; flex-direction: column; overflow: hidden; }
#win-bank #bank-grid { flex: 1; align-content: start; overflow-y: auto; }
#win-bank .win-foot { margin-top: 12px; bottom: auto; }
