:root {
  color-scheme: dark;
  --ink: #0d0b10;
  --panel: #19151d;
  --panel-2: #231d27;
  --line: #473a47;
  --bone: #e0d3ae;
  --muted: #948995;
  --ember: #d75a3a;
  --gold: #d2a64f;
  --danger: #e44f55;
}

.debug-scenario-link {
  display: block;
  width: fit-content;
  margin: 14px auto 0;
  color: var(--gold-soft);
  font: 700 12px/1.2 var(--mono);
  letter-spacing: .04em;
  text-decoration: none;
}

.debug-scenario-link:hover { text-decoration: underline; }

* { box-sizing: border-box; }

html, body { margin: 0; min-width: 320px; min-height: 100%; background: #08070a; color: var(--bone); }

body {
  font-family: "Courier New", monospace;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 25%, #2c2025 0, #100d12 36%, #08070a 72%),
    #08070a;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.keyboard-layout-button { margin-top: 12px; border: 1px solid var(--gold); padding: 8px 12px; color: var(--gold); background: #201922; cursor: pointer; }
.keyboard-layout-button--hud { width: 100%; margin-top: 7px; padding: 5px; font-size: 10px; }

#app {
  position: relative;
  width: min(1024px, 100vw);
  height: min(768px, 100vh);
  min-height: 620px;
  overflow: hidden;
  border: 1px solid #332936;
  background: var(--ink);
  box-shadow: 0 24px 80px #000b;
}

[hidden] { display: none !important; }
.screen { position: absolute; inset: 0; }
.screen--centered { display: grid; place-items: center; padding: 32px; }

.screen--centered::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.15;
  background-image: url("../../assets/sprites/generated/dungeon-wall-slate.png");
  background-size: 100px 100px;
  image-rendering: pixelated;
}

.panel {
  position: relative;
  border: 2px solid var(--line);
  background: linear-gradient(145deg, #241c26f4, #151219f4);
  box-shadow: inset 0 0 0 4px #100d12, 0 18px 50px #000c;
}

.title-panel { width: min(620px, 100%); padding: 54px; text-align: center; }
.eyebrow { margin: 0 0 12px; color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: 0.18em; }
h1, h2 { margin: 0; font-family: Georgia, serif; text-transform: uppercase; }
h1 { color: #f2dfb8; font-size: clamp(42px, 7vw, 74px); line-height: 0.88; text-shadow: 4px 5px 0 #4e2630; }
.title-panel > p:not(.eyebrow, .controls) { max-width: 480px; margin: 28px auto; color: #bbb0b6; line-height: 1.6; }
.controls { margin: 22px 0 0; color: var(--muted); font-size: 12px; }
.audio-settings { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; align-items: center; width: 260px; margin: 20px auto 4px; color: var(--muted); font-size: 11px; text-align: left; }
.audio-settings label { display: flex; justify-content: space-between; grid-column: 1 / -1; }
.audio-settings input { accent-color: var(--gold); }
.audio-settings button { border: 1px solid #554653; padding: 6px 9px; color: var(--bone); background: #28212b; cursor: pointer; }
.audio-settings--hud { grid-template-columns: 1fr auto; width: auto; margin: 6px 0 0; gap: 3px 8px; }
.audio-settings--hud label { grid-column: 1 / -1; }
.audio-settings--hud input { width: 130px; }

.primary-button {
  border: 2px solid #f0b95a;
  padding: 14px 24px;
  color: #1a1110;
  background: linear-gradient(#ecb94f, #bd6f2f);
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 0 5px 0 #663425;
  cursor: pointer;
}

#game-shell { display: grid; grid-template-columns: 800px 224px; height: 600px; }
#game-canvas { width: 800px; height: 600px; background: #110f14; }
#game-canvas canvas { display: block; width: 800px !important; height: 600px !important; image-rendering: pixelated; }

#hud {
  padding: 16px 14px;
  overflow: hidden;
  border-left: 2px solid #3e303e;
  background: linear-gradient(180deg, #221b25, #121016);
}

.hud-brand { margin-bottom: 10px; color: var(--gold); font-size: 11px; font-weight: bold; letter-spacing: 0.14em; }
.hud-card { display: flex; align-items: center; gap: 8px; }
.hud-card img { width: 42px; height: 42px; object-fit: contain; image-rendering: pixelated; }
.hud-label { display: block; color: var(--muted); font-size: 9px; }
.health-card strong { font-size: 20px; }
.health-track { height: 8px; margin: 5px 0 10px; border: 1px solid #4b3940; background: #0d0a0e; }
.health-track span { display: block; height: 100%; background: linear-gradient(90deg, #872e3b, var(--danger)); transition: width 120ms linear; }
.stats { margin: 0 0 10px; }
.stats div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid #2e2731; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; color: #e7dabd; }
.equipment { display: grid; gap: 7px; margin-bottom: 9px; }
.equipment span { display: flex; align-items: center; min-height: 30px; padding: 4px 8px; border: 1px solid #3c303c; background: #19151d; font-size: 11px; }
.equipment img { width: 26px; height: 26px; object-fit: contain; image-rendering: pixelated; }
.equipment .artifact-button { display: flex; align-items: center; gap: 7px; min-height: 58px; padding: 5px 7px; border: 1px solid #806437; color: var(--bone); background: #2a211d; cursor: pointer; text-align: left; }
.equipment .artifact-button:disabled { filter: grayscale(0.8); opacity: 0.55; cursor: not-allowed; }
.equipment .artifact-button img { width: 38px; height: 38px; }
.equipment .artifact-button span { display: grid; padding: 0; border: 0; background: transparent; }
.equipment .artifact-button strong { font-size: 10px; font-weight: normal; }
.equipment .artifact-button small { color: var(--muted); font-size: 8px; line-height: 1.25; }
.equipment .artifact-button #artifact-status { margin-top: 2px; color: var(--gold); font-size: 9px; }
.event-log { height: 88px; overflow: hidden; padding: 7px; border: 1px solid #332a35; background: #0e0c10; }
.event-log p { margin: 0 0 7px; color: #978c97; font-size: 10px; line-height: 1.3; }
.event-log .danger-text { color: #f07070; }
.hud-actions { display: grid; gap: 4px; margin-top: 7px; }
.hud-actions button { border: 1px solid #4b3d4a; padding: 5px; color: var(--bone); background: #27202a; cursor: pointer; }
.hud-actions img { width: 24px; height: 24px; vertical-align: middle; image-rendering: pixelated; }
kbd { color: var(--gold); }

#debug-panel {
  height: 168px;
  padding: 16px;
  border-top: 2px solid #5b493d;
  color: #ccb978;
  background: #17120f;
  font-size: 12px;
  line-height: 1.6;
}

.modal { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; background: #09070bc9; }
.modal-card { width: min(480px, 100%); padding: 34px; text-align: center; }
.modal-card h2 { font-size: 34px; color: #f0ddb6; }
.modal-card > p:not(.eyebrow) { color: #aaa0aa; line-height: 1.55; }
#modal-message { white-space: pre-line; }
.modal-actions { display: flex; justify-content: center; gap: 12px; margin-top: 25px; }
.modal-actions button:not(.primary-button) { border: 1px solid #554653; padding: 14px 20px; color: var(--bone); background: #28212b; cursor: pointer; }
#toast { position: absolute; right: 20px; bottom: 20px; z-index: 70; padding: 10px 15px; background: var(--gold); color: #1b130b; transform: translateY(70px); transition: transform 180ms; }
#toast.show { transform: translateY(0); }

.inventory-overlay { position: absolute; inset: 0; z-index: 45; display: grid; place-items: center; padding: 38px; background: #08060acc; }
.inventory-panel { width: 900px; max-width: 100%; padding: 28px; }
.inventory-panel header { display: flex; justify-content: space-between; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.inventory-panel header h2 { font-size: 34px; }
#inventory-close { border: 1px solid var(--line); width: 40px; height: 40px; color: var(--bone); background: #2c232e; font-size: 25px; cursor: pointer; }
.equipped-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.equipped-grid article { padding: 14px; border: 1px solid #4b3d49; background: #17131a; }
.equipped-grid span { display: block; color: var(--gold); font-size: 10px; margin-bottom: 6px; }
.equipped-grid small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.inventory-body { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.inventory-body h3, .item-detail h3 { margin: 0 0 12px; color: #e7d7b5; }
.bag-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.bag-slot { min-height: 100px; border: 1px solid #4a3c49; color: var(--bone); background: #110e14; cursor: pointer; }
.bag-slot:disabled { opacity: 0.45; cursor: default; }
.bag-slot img { display: block; width: 58px; height: 58px; margin: 0 auto; object-fit: contain; image-rendering: pixelated; }
.bag-slot span { font-size: 10px; }
.item-detail { min-height: 210px; padding: 18px; border: 1px solid #4a3c49; background: #110e14; }
.item-detail p { min-height: 65px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.item-detail button { display: block; width: 100%; margin-top: 10px; border: 1px solid #5a4855; padding: 10px; color: var(--bone); background: #2b222c; cursor: pointer; }
.item-detail .primary-button { color: #1a1110; }
.special-items { margin-top: 16px; padding: 10px; border-top: 1px solid var(--line); color: var(--gold); font-size: 11px; }

.settings-overlay { position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; padding: 12px; background: #08060ae8; }
.settings-panel { width: min(520px, 100%); padding: 20px 24px; }
.settings-panel header { display: flex; justify-content: space-between; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.settings-panel header h2 { color: #f0ddb6; font-size: 31px; }
#settings-close { border: 1px solid var(--line); width: 40px; height: 40px; color: var(--bone); background: #2c232e; font-size: 25px; cursor: pointer; }
.settings-section { margin-top: 10px; padding: 10px 12px; border: 1px solid #4b3d49; background: #110e14; }
.settings-section h3 { margin: 0 0 10px; color: var(--gold); font-size: 13px; text-transform: uppercase; }
.settings-section .keyboard-layout-button { width: 100%; margin: 0; }
.settings-hint { margin: 8px 0 0; color: var(--muted); font-size: 10px; text-align: center; }
.binding-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.binding-grid button { display: grid; gap: 3px; min-height: 38px; border: 1px solid #554653; padding: 4px 6px; color: var(--bone); background: #28212b; cursor: pointer; }
.binding-grid button:hover { border-color: var(--gold); }
.binding-grid button.is-listening { border-color: #f0b95a; background: #3b2d24; box-shadow: inset 0 0 0 2px #8a5f2e; }
.binding-grid span { color: var(--muted); font-size: 9px; }
.binding-grid kbd { font-size: 13px; font-weight: bold; }
.binding-grid .binding-wide { grid-column: 1 / -1; min-height: 32px; grid-template-columns: 1fr auto; align-items: center; }
.preset-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.preset-buttons button { border: 1px solid #554653; padding: 6px; color: var(--bone); background: #28212b; font-size: 9px; cursor: pointer; }
.audio-settings--menu { width: 100%; margin: 0; }
.settings-panel > .primary-button { display: block; width: 100%; margin-top: 12px; padding-block: 10px; }
.settings-shortcut { margin: 8px 0 0; color: var(--muted); font-size: 10px; text-align: center; }

@media (max-width: 1023px), (max-height: 767px) {
  #app { transform: scale(min(calc(100vw / 1024), calc(100vh / 768))); transform-origin: center; width: 1024px; height: 768px; }
}
