* { box-sizing: border-box; }

/* The game commits to one dark, sun-baked look in every theme. */
:root { color-scheme: dark; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a120b;
  color: #f2e6cc;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  user-select: none;
}

canvas#canvas {
  display: block;
  cursor: crosshair;
  outline: none;
}

.hidden { display: none !important; }

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid rgba(240, 210, 160, 0.4);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  font: 600 11px system-ui, sans-serif;
  color: #f6e2b8;
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding-block: 16px;
  background: radial-gradient(ellipse at center, rgba(40, 22, 10, 0.55), rgba(10, 5, 2, 0.85));
  z-index: 20;
}

.card {
  margin: auto;
  width: min(560px, calc(100vw - 32px));
  padding: 28px 32px 22px;
  background: linear-gradient(180deg, rgba(52, 34, 20, 0.96), rgba(30, 19, 11, 0.96));
  border: 1px solid rgba(230, 190, 130, 0.35);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 230, 180, 0.12);
  text-align: center;
}
.small-card { width: min(360px, calc(100vw - 32px)); }

.card h1 {
  margin: 0 0 6px;
  font: 700 46px Georgia, 'Times New Roman', serif;
  letter-spacing: 1px;
  color: #f6d48a;
  text-shadow: 0 2px 0 #6b3d14, 0 6px 24px rgba(255, 170, 60, 0.25);
}
.card h2 {
  margin: 0 0 14px;
  font: 700 28px Georgia, serif;
  color: #f6d48a;
}
.death h2 { color: #ff7a5a; }

.tag { margin: 0 0 18px; line-height: 1.5; color: #e8d3aa; font-style: italic; }
.hint { margin: 14px 0 16px; font-size: 13px; color: #ffb48a; }
.small { margin: 10px 0 0; font-size: 12px; color: rgba(240, 225, 195, 0.6); min-height: 1em; }

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 22px;
  text-align: left;
  font-size: 13px;
}
.controls div { display: flex; align-items: center; gap: 10px; }
.controls kbd { min-width: 78px; text-align: center; }
.controls span { color: #e8d8b8; }

@media (max-width: 480px) {
  .card { padding: 22px 18px 18px; }
  .card h1 { font-size: 36px; }
  .controls { grid-template-columns: 1fr; }
}

button {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  padding: 11px 16px;
  font: 700 15px system-ui, sans-serif;
  color: #2a1606;
  background: linear-gradient(180deg, #f6d48a, #d9a24a);
  border: 1px solid #f9e2a8;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
button:hover { filter: brightness(1.08); }
button:focus-visible { outline: 2px solid #f6d48a; outline-offset: 3px; }
button:active { transform: translateY(1px); }
button.secondary {
  color: #f2e6cc;
  background: rgba(255, 230, 180, 0.08);
  border-color: rgba(230, 190, 130, 0.35);
}
button.danger:hover { color: #ffb0a0; border-color: #ff7a5a; }

/* ---------- Inventory ---------- */
.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 16px 20px 18px;
  background: linear-gradient(180deg, rgba(44, 29, 17, 0.97), rgba(26, 17, 10, 0.97));
  border: 1px solid rgba(230, 190, 130, 0.35);
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  z-index: 10;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { margin: 0; font: 700 24px Georgia, serif; color: #f6d48a; }
.key-hint { font-size: 12px; color: rgba(240, 225, 195, 0.55); }

.inv-body { display: flex; gap: 22px; flex-wrap: wrap; }
.inv-left { flex: 0 0 250px; }
.inv-right { flex: 1 1 360px; }
.inv-right h3 { margin: 0 0 8px; font: 600 14px system-ui, sans-serif; color: #e8c88a; letter-spacing: 0.5px; text-transform: uppercase; }

.paperdoll {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(3, 72px);
  grid-template-areas: ". head ." "w1 body w2" ". feet .";
  gap: 8px;
  justify-content: center;
  padding: 10px 0 14px;
  background: radial-gradient(ellipse at center, rgba(255, 210, 140, 0.07), transparent 70%);
}

.slot {
  position: relative;
  width: 72px;
  height: 72px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(230, 190, 130, 0.2);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
}
.slot:hover { background: rgba(255, 220, 160, 0.1); }
.slot.filled:active { transform: scale(0.96); }
.slot .icon { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.slot-label {
  position: absolute;
  left: 0; right: 0; bottom: 4px;
  text-align: center;
  font-size: 10px;
  color: rgba(240, 225, 195, 0.45);
  pointer-events: none;
}
.slot.filled .slot-label { color: rgba(240, 225, 195, 0.65); }
.slot.active-weapon { outline: 2px solid #f2c66d; outline-offset: 2px; }
.slot.active-weapon .slot-label::after { content: ' ★'; color: #f2c66d; }

.bag {
  display: grid;
  grid-template-columns: repeat(6, 64px);
  gap: 6px;
}
.bag .slot { width: 64px; height: 64px; }

.inv-help { margin: 12px 0 0; font-size: 12px; color: rgba(240, 225, 195, 0.55); }

.stats {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  font-size: 13px;
}
.stat { display: flex; align-items: baseline; gap: 6px; }
.stat span { flex: 1; color: rgba(240, 225, 195, 0.7); }
.stat b { color: #f6e2b8; }
.stat em { font-style: normal; font-size: 11px; color: rgba(240, 225, 195, 0.45); }

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed;
  z-index: 30;
  width: 260px;
  padding: 10px 12px;
  background: rgba(16, 10, 6, 0.96);
  border: 1px solid rgba(230, 190, 130, 0.4);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  font-size: 13px;
  line-height: 1.45;
}
.tt-name { font: 700 16px Georgia, serif; }
.tt-type { font-size: 12px; color: rgba(240, 225, 195, 0.55); margin-bottom: 6px; }
.tt-main { font-weight: 700; font-size: 15px; color: #fff; }
.tt-line { color: #e8d8b8; }
.tt-bonus { color: #8fd3ff; }
.tt-bonus.venom { color: #b6ff5a; }
.tt-attacks { margin: 6px 0 2px; padding: 6px 8px; background: rgba(255, 230, 180, 0.06); border-radius: 6px; color: #e8d8b8; }
.tt-attacks kbd { min-width: 36px; text-align: center; margin-right: 4px; }
.tt-desc { margin-top: 6px; font-style: italic; color: #d4bf98; }
.tt-hint { margin-top: 8px; font-size: 11px; color: rgba(240, 225, 195, 0.45); }
.up { color: #7ee07e; font-weight: 700; margin-left: 4px; font-size: 12px; }
.down { color: #ff7a6a; font-weight: 700; margin-left: 4px; font-size: 12px; }
.tt-price { margin-top: 8px; font-weight: 700; color: #ffd76a; }
.tt-price.short { color: #ff8a6a; }

/* ---------- Gold, shop ---------- */
.gold { margin-left: auto; margin-right: 14px; font-weight: 700; color: #ffd76a; }
.panel-head { gap: 8px; }
.close-btn {
  width: auto;
  margin: 0;
  padding: 6px 12px;
  font-size: 13px;
}
#shop { width: min(900px, calc(100vw - 32px)); }
.shop-col { flex: 1 1 410px; min-width: 0; }
.shop-col h3 { margin: 0 0 8px; font: 600 14px system-ui, sans-serif; color: #e8c88a; letter-spacing: 0.5px; text-transform: uppercase; }
.shop-col .bag + h3 { margin-top: 14px; }
.slot .price {
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  text-align: center;
  font: 700 11px system-ui, sans-serif;
  color: #ffd76a;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
.slot .price.short { color: #ff8a6a; }
.shop-note { min-height: 1.2em; margin: 12px 0 0; font-size: 13px; font-weight: 600; color: #9fe07a; }
.shop-note.bad { color: #ff8a6a; }

.slot .count {
  position: absolute;
  top: 3px; right: 5px;
  font: 800 12px system-ui, sans-serif;
  color: #fff3d8;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

/* ---------- Materials ---------- */
.mats-head { margin: 14px 0 8px; font: 600 14px system-ui, sans-serif; color: #e8c88a; letter-spacing: 0.5px; text-transform: uppercase; }
.journal { max-height: min(62vh, 560px); overflow-y: auto; padding-right: 6px; }
.journal-intro { margin: 0 0 10px; font-size: 12px; color: rgba(240, 225, 195, 0.65); }
.biome { margin-bottom: 14px; }
.biome h3 { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 6px; font: 600 14px system-ui, sans-serif; color: #e8c88a; letter-spacing: 0.5px; text-transform: uppercase; }
.biome h3 small { font-weight: 600; letter-spacing: 0; text-transform: none; color: rgba(240, 225, 195, 0.6); }
.biome.unknown h3 { color: rgba(240, 225, 195, 0.45); }
.journal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.jm { display: flex; align-items: center; gap: 8px; padding: 5px 8px; background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(230, 190, 130, 0.16); border-radius: 6px; font-size: 13px; }
.jm canvas { width: 26px; height: 26px; flex: none; }
.jm span { flex: 1; min-width: 0; color: #f6e2b8; }
.jm b { color: #fff3d8; font-variant-numeric: tabular-nums; }
.jm.trophy { border-color: rgba(255, 180, 70, 0.5); }
.jm.unknown span, .jm.unknown b { color: rgba(240, 225, 195, 0.4); }
.jm .q { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgba(255, 255, 255, 0.06); color: rgba(240, 225, 195, 0.45); font-weight: 700; }
.rep-row { margin-bottom: 8px; font-size: 13px; }
.rep-row div { display: flex; justify-content: space-between; gap: 8px; }
.rep-row span { color: rgba(240, 225, 195, 0.8); }
.rep-bar { position: relative; height: 4px; margin-top: 4px; background: linear-gradient(90deg, rgba(255, 122, 90, 0.35) 0 37.5%, rgba(232, 216, 184, 0.18) 37.5% 62.5%, rgba(159, 224, 122, 0.3) 62.5% 80%, rgba(255, 215, 106, 0.35) 80%); border-radius: 2px; }
.rep-bar i { position: absolute; top: -3px; width: 4px; height: 10px; margin-left: -2px; border-radius: 2px; background: #fff3d8; box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); }
.mat-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.mat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 4px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(214, 240, 168, 0.22);
  border-radius: 999px;
  font-size: 12px;
  color: rgba(240, 225, 195, 0.8);
}
.mat-chip canvas { width: 22px; height: 22px; }
.mat-chip b { color: #fff3d8; font-variant-numeric: tabular-nums; }
.mat-chip.trophy { border-color: rgba(255, 180, 70, 0.6); }
.mat-chip.empty { opacity: 0.45; }

/* ---------- Crafting ---------- */
#craft { width: min(900px, calc(100vw - 32px)); }
.craft-body { display: flex; gap: 18px; flex-wrap: wrap; }
.craft-list { flex: 1 1 300px; min-width: 0; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.craft-list h3 { margin: 4px 0 6px; font: 600 13px system-ui, sans-serif; color: #e8c88a; letter-spacing: 0.5px; text-transform: uppercase; }
.craft-list h3:not(:first-child) { margin-top: 12px; }
.recipe-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 4px;
  padding: 4px 8px 4px 4px;
  text-align: left;
  font: 600 13px system-ui, sans-serif;
  color: #f2e6cc;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(230, 190, 130, 0.16);
  border-radius: 6px;
}
.recipe-row:hover { background: rgba(255, 220, 150, 0.1); filter: none; }
.recipe-row.sel { border-color: #f2c66d; background: rgba(255, 220, 150, 0.12); }
.recipe-row .ri { width: 32px; height: 32px; flex: 0 0 auto; }
.recipe-row .rn { flex: 1; min-width: 0; }
.recipe-row .tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); color: rgba(240, 225, 195, 0.65); }
.recipe-row.st-ready .tag { background: rgba(114, 213, 114, 0.18); color: #9fe07a; }
.recipe-row.st-forge .tag { color: #ffb48a; }
.recipe-row .new { font-size: 10px; font-weight: 800; text-transform: uppercase; color: #1a1006; background: #9fe0ff; padding: 1px 5px; border-radius: 4px; }
.craft-empty { color: rgba(240, 225, 195, 0.7); line-height: 1.5; }
.craft-detail { flex: 1 1 340px; min-width: 0; font-size: 13px; line-height: 1.45; }
.cd-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.cd-head canvas { width: 64px; height: 64px; background: rgba(0, 0, 0, 0.3); border-radius: 8px; flex: 0 0 auto; }
.cd-odds { margin-top: 8px; font-size: 12px; color: rgba(240, 225, 195, 0.75); }
.cd-odds em { color: rgba(240, 225, 195, 0.55); }
.craft-detail h3 { margin: 12px 0 6px; font: 600 13px system-ui, sans-serif; color: #e8c88a; letter-spacing: 0.5px; text-transform: uppercase; }
.cd-mats { display: grid; gap: 4px; }
.cd-mat { display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px; background: rgba(0, 0, 0, 0.25); border-radius: 6px; }
.cd-mat canvas { width: 28px; height: 28px; flex: 0 0 auto; }
.cd-mat span { flex: 1; min-width: 0; }
.cd-mat em { display: block; font-size: 11px; color: rgba(240, 225, 195, 0.55); }
.cd-mat b { font-variant-numeric: tabular-nums; }
.cd-mat b.ok { color: #9fe07a; }
.cd-mat b.short { color: #ff8a6a; }
.cd-mat .q { width: 28px; text-align: center; font: 800 18px Georgia, serif; color: rgba(240, 225, 195, 0.5); }
.craft-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.craft-tabs button {
  width: auto;
  margin: 0;
  padding: 6px 14px;
  font-size: 13px;
  color: #f2e6cc;
  background: rgba(255, 230, 180, 0.06);
  border: 1px solid rgba(230, 190, 130, 0.25);
}
.tier-filter { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.tier-filter button { padding: 4px 9px; font-size: 12px; }
.tier-filter button:disabled { opacity: 0.35; cursor: default; }
.craft-tabs button.on { color: #2a1606; background: linear-gradient(180deg, #f6d48a, #d9a24a); border-color: #f9e2a8; }
.recipe-row .rn em { font-style: normal; font-size: 11px; font-weight: 400; color: rgba(240, 225, 195, 0.5); margin-left: 4px; }
.recipe-row.st-max .tag { color: #ffd76a; }
.pips { display: flex; gap: 4px; margin-top: 4px; }
.pips span { width: 14px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); }
.pips span.on { background: #ffd76a; }
.up-stat { color: #9fe07a; }
.cd-mat .q.gold { color: #ffd76a; font-size: 16px; }
.tt-attacks .locked { opacity: 0.45; }
.tt-attacks em { font-style: normal; font-size: 11px; color: #ffb48a; }
#craftBtn { margin-top: 12px; }
.craft-actions { display: flex; gap: 8px; align-items: flex-end; }
.craft-actions #craftBtn { flex: 1; }
.craft-actions #planBtn { width: auto; padding-inline: 18px; }
.recipe-row .planned { font-size: 10px; font-weight: 800; text-transform: uppercase; color: #1a1006; background: #ffd76a; padding: 1px 5px; border-radius: 4px; }
.plan-row { padding: 6px 8px; margin-bottom: 6px; background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(230, 190, 130, 0.16); border-radius: 6px; }
.plan-row.ready { border-color: rgba(114, 213, 114, 0.5); }
.plan-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.plan-head canvas { width: 28px; height: 28px; }
.plan-head b { flex: 1; min-width: 0; color: #f6e2b8; }
.plan-st { font-size: 11px; color: rgba(240, 225, 195, 0.6); }
.plan-row.ready .plan-st { color: #9fe07a; font-weight: 700; }
.plan-x { width: 24px; height: 24px; margin: 0; padding: 0; font-size: 16px; line-height: 1; color: #f2e6cc; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(230, 190, 130, 0.25); border-radius: 4px; }
.plan-mats { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 4px 0 0 36px; font-size: 12px; font-variant-numeric: tabular-nums; }
.plan-mats .ok { color: #9fe07a; }
.plan-mats .short { color: #ff8a6a; }
.plan-total { margin: 4px 0 0; font-size: 12px; color: #e8d8b8; line-height: 1.5; }
#craftBtn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: not-allowed; }
.craft-note { min-height: 1.2em; margin: 8px 0 0; font-weight: 600; color: #9fe07a; }
.craft-note.bad { color: #ff8a6a; }

/* ---------- Dialogue ---------- */
.dialogue {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 32px));
  display: flex;
  gap: 16px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(44, 29, 17, 0.97), rgba(26, 17, 10, 0.97));
  border: 1px solid rgba(230, 190, 130, 0.4);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  z-index: 12;
}
#dlgPortrait {
  flex: 0 0 auto;
  width: 112px;
  height: 112px;
  border-radius: 8px;
  border: 1px solid rgba(230, 190, 130, 0.35);
}
.dlg-body { flex: 1; min-width: 0; }
.dlg-head { display: flex; align-items: baseline; gap: 10px; }
.dlg-head b { font: 700 19px Georgia, serif; color: #f6d48a; }
.dlg-head span { font-size: 12px; color: rgba(240, 225, 195, 0.6); text-transform: uppercase; letter-spacing: 0.6px; }
#dlgText { margin: 6px 0 10px; min-height: 3.6em; line-height: 1.5; color: #f2e6cc; font-size: 15px; }
.dlg-options { display: grid; gap: 6px; }
.dlg-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 7px 10px;
  text-align: left;
  font: 600 14px system-ui, sans-serif;
  color: #f2e6cc;
  background: rgba(255, 230, 180, 0.06);
  border: 1px solid rgba(230, 190, 130, 0.22);
  border-radius: 6px;
}
.dlg-opt:hover { background: rgba(255, 220, 150, 0.16); filter: none; }
.dlg-opt kbd { min-width: 22px; text-align: center; }

@media (max-width: 520px) {
  .dialogue { flex-direction: column; align-items: center; }
}

/* ---------- Runes ---------- */
.rune-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.rune-chip { display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--rune, rgba(230, 190, 130, 0.2)); border-radius: 999px; font-size: 12px; color: rgba(240, 225, 195, 0.85); }
.rune-chip canvas { width: 22px; height: 22px; }
.rune-chip b { color: var(--rune, #fff3d8); font-weight: 700; }
.rune-chip em { font-style: normal; color: rgba(240, 225, 195, 0.55); }
.rune-chip.unknown { opacity: 0.5; border-color: rgba(230, 190, 130, 0.15); }
.rune-card { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0; padding: 8px; background: rgba(0, 0, 0, 0.28); border: 1px solid var(--rune, rgba(230, 190, 130, 0.2)); border-radius: 8px; }
.rune-card canvas { width: 36px; height: 36px; flex: none; }
.rune-card > div { flex: 1; min-width: 0; }
.rune-card b { color: var(--rune); }
.rune-card p { margin: 3px 0 0; font-size: 12px; color: rgba(240, 225, 195, 0.8); }
.rune-card p i { font-style: normal; color: var(--rune); font-weight: 700; }
.rune-card button { width: auto; flex: none; padding: 6px 14px; align-self: center; }
.tt-rune { margin-top: 4px; font-size: 12px; }

/* ---------- Armor sets ---------- */
.tt-set { margin-top: 6px; padding-top: 5px; border-top: 1px solid rgba(230, 200, 150, 0.18); font-size: 12px; color: rgba(240, 225, 195, 0.42); line-height: 1.4; }
.tt-set-name { color: var(--set); font-weight: 700; margin-bottom: 2px; }
.tt-set .on { color: var(--set); }
.tt-set b { font-weight: 700; }

/* Quest journal */
.quest { padding: 7px 10px; margin-bottom: 6px; border-radius: 6px; background: rgba(255, 230, 180, 0.06); border: 1px solid rgba(255, 215, 106, 0.18); }
.quest b { color: #ffd76a; font-size: 13px; }
.quest small { margin-left: 8px; color: rgba(240, 225, 195, 0.55); font-size: 11px; }
.quest p { margin: 4px 0 0; font-size: 12px; color: rgba(240, 225, 195, 0.85); }
.quest.lead { border-style: dashed; }
.quest-done { display: flex; flex-wrap: wrap; gap: 6px; }
.quest-done span { font-size: 12px; padding: 3px 8px; border-radius: 10px; background: rgba(159, 224, 122, 0.12); color: #b8e0a0; }
