:root {
  color-scheme: dark;
  --bg: #10130f;
  --panel: #1a1c18;
  --panel-2: #22251f;
  --ink: #f4ecd8;
  --muted: #b8aa91;
  --line: #3c3e35;
  --floor: #2a3027;
  --wall: #6d6049;
  --blood: #bc4740;
  --gold: #e2b04f;
  --green: #79a56f;
  --violet: #8a6fb0;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(226, 176, 79, 0.12), transparent 26rem),
    linear-gradient(135deg, #10130f 0%, #171812 46%, #0b0c0a 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  gap: 1rem;
  width: min(1180px, calc(100vw - 2rem));
  min-height: 100vh;
  margin: 0 auto;
  padding: 1rem 0;
}

.game-column,
.panel {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.75rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.version {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.label {
  margin: 0 0 0.2rem;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.6rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 0.9;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.name-field {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.name-field input {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: 800 1.25rem Inter, ui-sans-serif, system-ui, sans-serif;
  outline: 0;
  padding: 0.15rem 0.35rem;
}

.name-field input:focus {
  border-color: #735f36;
  background: #222017;
}

h3 {
  margin-bottom: 0.65rem;
  font-size: 0.85rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.command,
.icon-command,
.mobile-controls button {
  border: 1px solid #735f36;
  border-radius: 6px;
  background: #332710;
  color: #ffe6a6;
  cursor: pointer;
  transition: transform 130ms ease, border-color 130ms ease, background 130ms ease;
}

.command {
  min-width: 7.5rem;
  padding: 0.7rem 0.9rem;
  font-weight: 800;
}

.command.secondary {
  min-width: 6.4rem;
  background: #22251f;
  border-color: var(--line);
  color: var(--ink);
}

.command:hover,
.icon-command:hover,
.mobile-controls button:hover {
  border-color: #d8a943;
  background: #4a3612;
  transform: translateY(-1px);
}

.command:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.command:disabled:hover {
  border-color: var(--line);
  background: #22251f;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0c0a;
  box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.32);
  image-rendering: pixelated;
}

.minimap-section {
  margin-top: 0.5rem;
}

.minimap-section.hidden {
  display: none;
}

#minimap {
  aspect-ratio: auto;
  width: min(100%, 320px);
  height: auto;
  box-shadow: none;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 4.75rem;
}

.hero-card,
.stats,
.attributes,
.inventory,
.equipment,
.scores,
.graveyard,
.examine,
.log {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 28, 24, 0.92);
}

.hero-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem;
}

.portrait {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border: 1px solid #735f36;
  border-radius: 8px;
  background: #262015;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.9rem;
  font-weight: 700;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}

.stats div,
.attributes div,
.equipment div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3.1rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.stats div:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.stats div:nth-last-child(-n + 2),
.attributes div:last-child,
.equipment div:last-child {
  border-bottom: 0;
}

.stats div:nth-child(3),
.stats div:nth-child(4) {
  border-bottom: 1px solid var(--line);
}

.stats .wide {
  grid-column: 1 / -1;
  border-right: 0;
}

.stats span,
.attributes span,
.equipment span,
.inventory p,
.examine p,
.scores li,
.scores .empty,
.graveyard,
.log li {
  color: var(--muted);
  font-size: 0.92rem;
}

.stats strong,
.attributes b,
.equipment b {
  color: var(--ink);
}

.attributes,
.inventory,
.equipment,
.scores,
.graveyard,
.examine,
.log {
  padding: 0.85rem;
}

.stats div.statuses-row {
  border-bottom: 1px solid var(--line);
}

.status-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  background: #22251f;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.status-badge small {
  display: grid;
  place-items: center;
  min-width: 1.15rem;
  height: 1.15rem;
  border-radius: 999px;
  background: rgba(244, 236, 216, 0.12);
  color: inherit;
  font: 800 0.72rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.status-badge.clear {
  color: var(--muted);
}

.status-badge.poison {
  border-color: #5f824f;
  background: #1f2d1d;
  color: #b9e889;
}

.status-badge.dread {
  border-color: #765f9a;
  background: #211b2f;
  color: #d7c6ff;
}

.status-badge.curse {
  border-color: #884b4b;
  background: #321d1d;
  color: #ffb0a6;
}

.status-badge.burning {
  border-color: #a05c20;
  background: #311808;
  color: #ffcc66;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.section-title h3 {
  margin-bottom: 0;
}

.section-actions {
  display: flex;
  gap: 0.35rem;
}

.icon-command {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.2rem;
  font-weight: 900;
}

.inventory p {
  margin-bottom: 0;
}

.tile {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 2px;
}

.tile.hero {
  background: var(--gold);
}

.tile.enemy {
  background: var(--blood);
}

.tile.stairs {
  background: var(--violet);
}

.tile.tonic {
  background: var(--green);
}

.tile.gear {
  background: #d9d0ba;
}

.scores ol,
.graveyard-preview {
  display: grid;
  gap: 0.45rem;
  margin: 0;
}

.scores ol {
  padding-left: 1.35rem;
}

.scores .section-title,
.graveyard .section-title {
  margin-bottom: 0.65rem;
}

.scores.collapsed .section-title,
.graveyard.collapsed .section-title {
  margin-bottom: 0;
}

.scores.collapsed ol,
.graveyard.collapsed .graveyard-preview {
  display: none;
}

.scores li::marker {
  color: var(--gold);
  font-weight: 800;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.score-row strong {
  color: var(--ink);
}

.score-row span {
  color: var(--muted);
  font-size: 0.8rem;
}

.history-row {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.history-row strong,
.history-row span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row strong {
  color: var(--ink);
}

.history-row span {
  color: var(--muted);
  font-size: 0.8rem;
}

.empty {
  margin-bottom: 0;
}

.examine p {
  min-height: 3.25rem;
  margin-bottom: 0;
  line-height: 1.35;
}

.log {
  flex: 1;
  min-height: 12rem;
  overflow: hidden;
}

.log ol {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 18rem;
  margin: 0;
  padding-left: 1.25rem;
  overflow: auto;
}

.mobile-controls {
  display: none;
}

.danger {
  color: #ff8c7f;
}

.good {
  color: #b9e889;
}

.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 9, 8, 0.78);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(48rem, 100%);
  max-height: min(42rem, calc(100vh - 2rem));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1a1c18;
  box-shadow: 0 2rem 5rem rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}

.roadmap-content,
.help-content {
  max-height: calc(min(42rem, 100vh - 2rem) - 5.5rem);
  overflow: auto;
  padding: 1rem 1.25rem 1.25rem;
  color: var(--muted);
}

.death-panel {
  width: min(42rem, 100%);
}

.death-panel.victory {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green), 0 1.5rem 3rem rgba(0, 0, 0, 0.55);
}

.death-panel.victory .death-score strong {
  color: var(--green);
}

.victory-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--green);
  border-radius: 999px;
  background: rgba(121, 165, 111, 0.15);
  color: var(--green);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

.history-card.victory {
  border-color: var(--green);
}

.history-panel {
  width: min(44rem, 100%);
}

.item-panel {
  width: min(42rem, 100%);
}

.item-content {
  display: grid;
  gap: 1rem;
  max-height: calc(min(42rem, 100vh - 2rem) - 5.5rem);
  overflow: auto;
  padding: 1rem 1.25rem 1.25rem;
}

.item-compare,
.bag-list {
  display: grid;
  gap: 0.75rem;
}

.item-compare {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.item-card {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22251f;
}

.item-card span,
.item-card small,
.item-card em,
.item-note,
.item-empty {
  color: var(--muted);
}

.item-card span {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.item-card b {
  min-width: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.item-card em {
  font-size: 0.86rem;
  font-style: normal;
  line-height: 1.35;
}

.item-card.relic {
  border-color: #8a6fb0;
  background: linear-gradient(135deg, #22251f 0%, #29243a 100%);
}

.item-card.relic b {
  color: #f4d98a;
}

.item-actions,
.bag-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.bag-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.75rem;
}

.item-note,
.item-empty {
  margin: 0;
}

.death-content {
  display: grid;
  gap: 1rem;
  max-height: calc(min(42rem, 100vh - 2rem) - 9.5rem);
  overflow: auto;
  padding: 1rem 1.25rem 1.25rem;
}

.history-content {
  display: grid;
  gap: 0.75rem;
  max-height: calc(min(42rem, 100vh - 2rem) - 5.5rem);
  overflow: auto;
  padding: 1rem 1.25rem 1.25rem;
}

.history-card {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22251f;
}

.history-card-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.history-card-head div {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.history-card-head span,
.history-card dt,
.history-empty {
  color: var(--muted);
}

.history-card-head span,
.history-card dt {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.history-card-head strong,
.history-card-head b {
  color: var(--gold);
}

.history-card-head strong,
.history-card dd {
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-card-head b {
  white-space: nowrap;
}

.history-card p,
.history-empty {
  margin: 0;
}

.history-card p {
  color: var(--muted);
  line-height: 1.35;
}

.history-card dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0;
}

.history-card dl div {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.history-card dd {
  margin: 0;
  color: var(--ink);
  font-weight: 800;
}

.death-score {
  display: grid;
  gap: 0.35rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.death-score span,
.death-stats span,
.death-final span,
.death-loadout span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.death-score strong {
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.4rem, 11vw, 4.5rem);
  line-height: 0.9;
}

.death-score p,
.death-empty {
  margin-bottom: 0;
  color: var(--muted);
}

.death-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151712;
}

.death-stats div {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
  padding: 0.75rem;
  border-right: 1px solid var(--line);
}

.death-stats div:last-child {
  border-right: 0;
}

.death-stats b {
  color: var(--ink);
  font-size: 1.15rem;
}

.death-final,
.death-loadout,
.death-breakdown {
  display: grid;
  gap: 0.65rem;
}

.death-final h3,
.death-loadout h3,
.death-breakdown h3 {
  margin-bottom: 0;
}

.death-final div,
.death-loadout div {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr;
  gap: 0.2rem 0.75rem;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22251f;
}

.death-final b,
.death-final small,
.death-loadout b,
.death-loadout small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.death-final b,
.death-loadout b {
  color: var(--ink);
}

.death-final small,
.death-loadout small {
  grid-column: 2;
  color: var(--muted);
}

.death-kills {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.death-kills li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22251f;
}

.death-kills span {
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.death-kills b {
  color: var(--ink);
}

.death-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.roadmap-content h2 {
  margin: 1.1rem 0 0.5rem;
  color: var(--gold);
  font-size: 1rem;
  text-transform: uppercase;
}

.roadmap-content h2:first-child {
  margin-top: 0;
}

.roadmap-content ul {
  display: grid;
  gap: 0.45rem;
  margin: 0 0 0.85rem;
  padding-left: 1.1rem;
}

.roadmap-content li::marker {
  color: var(--gold);
}

.help-content {
  display: grid;
  gap: 1rem;
}

.help-content section {
  display: grid;
  gap: 0.55rem;
}

.help-content h3,
.help-content p {
  margin-bottom: 0;
}

.help-content ul {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding-left: 1.1rem;
}

.help-content li::marker {
  color: var(--gold);
}

.help-footer {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border, #444);
  display: flex;
  justify-content: flex-end;
}

.key-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem 0.75rem;
  margin: 0;
}

.key-list div {
  display: grid;
  grid-template-columns: minmax(5.5rem, auto) 1fr;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.key-list dt {
  display: inline-flex;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.25rem 0.45rem;
  background: #22251f;
  color: var(--ink);
  font: 800 0.8rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}

.key-list dd {
  min-width: 0;
  margin: 0;
  font-size: 0.92rem;
}

.legend-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  list-style: none;
  padding-left: 0;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.roadmap-content code {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .panel {
    padding-top: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .key-list,
  .legend-list {
    grid-template-columns: 1fr;
  }

  .death-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-card dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-card-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.35rem;
  }

  .death-stats div:nth-child(2) {
    border-right: 0;
  }

  .death-stats div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .death-actions {
    flex-direction: column-reverse;
  }

  .death-actions .command {
    width: 100%;
  }

  .item-compare,
  .bag-row {
    grid-template-columns: 1fr;
  }

  .item-actions,
  .bag-actions {
    flex-direction: column;
  }

  .item-actions .command,
  .bag-actions .command {
    width: 100%;
  }

  .mobile-controls {
    display: grid;
    grid-template-columns: repeat(3, 3.25rem);
    grid-template-areas:
      ". n ."
      "w wait e"
      ". s .";
    justify-content: center;
    gap: 0.45rem;
    margin-top: 0.75rem;
  }

  .mobile-controls button {
    width: 3.25rem;
    height: 3.25rem;
    padding: 0;
    font-weight: 900;
  }

  [data-move="0,-1"] {
    grid-area: n;
  }

  [data-move="-1,0"] {
    grid-area: w;
  }

  [data-wait] {
    grid-area: wait;
  }

  [data-move="1,0"] {
    grid-area: e;
  }

  [data-move="0,1"] {
    grid-area: s;
  }
}

.equipment b {
  max-width: 11rem;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.levelup-panel {
  width: min(44rem, 100%);
}

.levelup-content {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 1.25rem;
}

@media (max-width: 600px) {
  .levelup-content {
    grid-template-columns: 1fr;
  }
}

.debug-panel {
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.debug-panel h3 {
  margin: 0 0 0.6rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--blood);
}

.debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.debug-depth-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.4rem;
}

.debug-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
}

.debug-input:focus {
  outline: 1px solid var(--gold);
  border-color: var(--gold);
}

.debug-grid .command.secondary {
  min-width: 0;
  padding: 0.45rem 0.5rem;
  font-size: 0.8rem;
}

.debug-grid .command.secondary.active {
  background: #3a1010;
  border-color: var(--blood);
  color: #ff8c7f;
}

.perk-card {
  display: grid;
  gap: 0.4rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22251f;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, background 0.12s;
}

.perk-card:hover,
.perk-card:focus-visible {
  border-color: var(--gold);
  background: #2a2d22;
  outline: none;
}

.perk-card strong {
  color: var(--gold);
  font-size: 1rem;
}

.perk-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}
