:root {
  --ink: #f2e2cf;
  --dim: #b79b80;
  --panel: rgba(24, 16, 14, 0.94);
  --panel-edge: #6b4326;
  --ember: #ff9a3c;
  --ember-dim: #b8642a;
  --slot: rgba(52, 34, 26, 0.9);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d0806;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
}

.hidden { display: none !important; }

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

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
}

#statusBar {
  display: flex;
  align-items: center;
  gap: 12px;
}

#healthBar {
  position: relative;
  width: 190px;
  height: 20px;
  background: rgba(10, 6, 5, 0.8);
  border: 2px solid var(--panel-edge);
  border-radius: 3px;
  overflow: hidden;
}

#healthFill {
  height: 100%;
  width: 100%;
  background: #4ad06a;
  transition: width 0.12s linear;
}

#healthText {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  text-shadow: 0 1px 2px #000;
}

#clock, #wallBadge {
  background: rgba(10, 6, 5, 0.8);
  border: 2px solid var(--panel-edge);
  border-radius: 3px;
  padding: 3px 10px;
  font-size: 12px;
}

#wallBadge {
  border-color: #3f7fa8;
  color: #9fd4ef;
}

#log {
  position: absolute;
  top: 52px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-line {
  background: rgba(10, 6, 5, 0.78);
  border-left: 3px solid var(--ember);
  padding: 4px 10px;
  font-size: 12px;
  max-width: 30rem;
  transition: opacity 0.7s;
}

.log-line.fade { opacity: 0; }

#bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#hotbar {
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

#hint {
  font-size: 11px;
  color: var(--dim);
  text-shadow: 0 1px 3px #000;
  text-align: center;
}

#hoverPrompt {
  background: rgba(10, 6, 5, 0.85);
  border: 2px solid var(--ember);
  border-radius: 3px;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--ink);
}

#hoverPrompt b { color: var(--ember); }

#dialogue {
  position: fixed;
  left: 50%;
  bottom: 130px;
  transform: translateX(-50%);
  z-index: 25;
  width: min(520px, 92vw);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-left: 4px solid var(--ember);
  border-radius: 5px;
  padding: 14px 18px;
}

#dialogueName {
  margin: 0 0 6px;
  color: var(--ember);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#dialogueText {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink);
}

#dialogueActions { margin-bottom: 0; }

/* ---------- slots ---------- */

.slot {
  position: relative;
  width: 44px;
  height: 44px;
  background: var(--slot);
  border: 2px solid #4a3226;
  border-radius: 3px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.slot:hover { border-color: #8a6a4a; }

.slot.selected {
  border-color: var(--ember);
  box-shadow: 0 0 0 1px var(--ember), 0 0 12px rgba(255, 154, 60, 0.45);
}

.slot img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  pointer-events: none;
}

.slot .count {
  position: absolute;
  right: 2px;
  bottom: 0;
  font-size: 11px;
  text-shadow: 0 1px 2px #000, 0 0 3px #000;
  pointer-events: none;
}

.slot .key {
  position: absolute;
  left: 3px;
  top: 0;
  font-size: 9px;
  color: var(--dim);
  font-weight: normal;
  pointer-events: none;
}

#cursorStack {
  position: fixed;
  z-index: 50;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#cursorStack img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

#cursorStack span {
  position: absolute;
  right: -4px;
  bottom: -4px;
  font-size: 11px;
  text-shadow: 0 1px 2px #000;
}

/* ---------- panels ---------- */

.panel {
  position: fixed;
  top: 50%;
  /* left/right:0 with auto margins rather than left:50% — a shrink-to-fit box
     anchored at 50% only gets half the viewport to lay out in, which forced
     the columns to wrap. */
  left: 0;
  right: 0;
  width: fit-content;
  margin: 0 auto;
  transform: translateY(-50%);
  display: flex;
  gap: 22px;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 6px;
  padding: 18px 20px;
  z-index: 20;
  flex-wrap: wrap;
  max-width: min(1010px, 96vw);
  max-height: 88vh;
  overflow: auto;
}

/* Both columns are explicitly sized so they sit side by side rather than
   wrapping: the inventory holds exactly ten 44px slots plus their gaps, and
   the pair still fits inside the panel's max-width. */
.panel-col { flex: 0 0 auto; width: 440px; }
.panel-col.inv { width: 476px; }

h1, h2, h3, h4 { margin: 0 0 10px; font-weight: normal; letter-spacing: 2px; }
h3 { font-size: 13px; color: var(--ember); text-transform: uppercase; }
h4 { font-size: 11px; color: var(--dim); text-transform: uppercase; margin: 12px 0 6px; }

.note {
  font-size: 11px;
  color: var(--dim);
  margin: 8px 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(10, 44px);
  gap: 4px;
}

/* ---------- crafting ---------- */

#craftList {
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 6px;
}

.recipe {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: rgba(52, 34, 26, 0.55);
  border: 1px solid #4a3226;
  border-radius: 3px;
  padding: 6px 8px;
  margin-bottom: 4px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.recipe:hover:not(:disabled) {
  border-color: var(--ember);
  background: rgba(80, 50, 30, 0.7);
}

.recipe.locked { opacity: 0.42; cursor: not-allowed; }

.recipe img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
}

.recipe strong { display: block; font-size: 12px; font-weight: normal; }
.recipe small { display: block; font-size: 10px; color: var(--dim); }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(8, 5, 4, 0.82);
  backdrop-filter: blur(2px);
}

.dialog {
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 6px;
  padding: 26px 30px;
  max-width: min(680px, 92vw);
  max-height: 90vh;
  overflow: auto;
  text-align: center;
}

.dialog.wide { max-width: min(760px, 94vw); text-align: left; }

.dialog h1 {
  font-size: 44px;
  letter-spacing: 10px;
  color: var(--ember);
  text-shadow: 0 0 26px rgba(255, 106, 0, 0.55);
  text-align: center;
}

.tagline { color: var(--dim); text-align: center; margin-top: -4px; }
.danger { color: #ff8a8a; }

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 16px 0;
}

.row.tight { margin: 12px 0; justify-content: flex-start; }
.row.tight button { padding: 6px 14px; font-size: 12px; }

button {
  font: inherit;
  padding: 9px 18px;
  color: #1b0d0a;
  background: var(--ember);
  border: 0;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 1px;
}

button:hover:not(:disabled) { background: #ffb96b; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.ghost {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--panel-edge);
}

button.ghost:hover { color: var(--ink); background: rgba(255, 154, 60, 0.12); }

input[type='text'] {
  font: inherit;
  padding: 9px 12px;
  min-width: 230px;
  color: var(--ink);
  background: rgba(10, 6, 5, 0.8);
  border: 2px solid var(--panel-edge);
  border-radius: 3px;
}

input[type='text']:focus { outline: none; border-color: var(--ember); }

/* ---------- save slots ---------- */

.slots { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }

.save-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(52, 34, 26, 0.5);
  border: 1px solid #4a3226;
  border-radius: 3px;
  padding: 8px 12px;
}

.save-label strong { display: block; font-size: 12px; font-weight: normal; }
.save-label small { font-size: 10px; color: var(--dim); }
.save-actions { display: flex; gap: 6px; }
.save-actions button { padding: 5px 12px; font-size: 11px; }

.how { border-top: 1px solid var(--panel-edge); margin-top: 14px; padding-top: 14px; }
.how ul { margin: 0; padding-left: 18px; }
.how li { font-size: 12px; color: var(--dim); line-height: 1.8; }
.how b { color: var(--ink); }
