:root {
  color-scheme: dark;
  --ink: #211812;
  --paper: #f2d78b;
  --cream: #ffe8af;
  --amber: #f3a83b;
  --red: #d84b39;
  --cyan: #3ad2c6;
  --green: #61b85a;
  --violet: #6b5fb5;
  --shadow: rgba(10, 7, 5, 0.72);
  --line: rgba(255, 230, 171, 0.34);
  font-family: "Trebuchet MS", "Arial Narrow", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(circle at 18% 10%, rgba(216, 75, 57, 0.25), transparent 28%),
    linear-gradient(135deg, #16100d 0%, #2a171f 38%, #102a31 100%);
  color: var(--cream);
}

button {
  border: 2px solid #321d13;
  background: linear-gradient(#ffe3a0, #d78a32);
  color: #24140e;
  font: 700 0.92rem/1 "Trebuchet MS", Arial, sans-serif;
  min-height: 42px;
  cursor: pointer;
  box-shadow: 0 4px 0 #6f2e22;
  touch-action: manipulation;
  user-select: none;
}

button:hover,
button:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #6f2e22;
}

.game-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto auto;
  gap: 10px;
  padding: 14px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  border: 2px solid var(--line);
  background: rgba(22, 12, 8, 0.72);
  padding: 10px 12px;
}

.kicker {
  margin: 0 0 2px;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 2.45rem);
  text-transform: uppercase;
  text-shadow: 3px 3px 0 #64271e;
}

.scene-name {
  color: var(--paper);
  font-weight: 800;
  text-align: right;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 10px;
}

.scan-button {
  min-height: 38px;
  padding: 0 12px;
  background: linear-gradient(#8ff2e8, #2ca59b);
  box-shadow: 0 4px 0 #16534e;
}

.scan-button[aria-pressed="true"] {
  background: linear-gradient(#ffe3a0, #d84b39);
  box-shadow: 0 4px 0 #64271e;
}

.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 245px);
  min-height: 245px;
  overflow: hidden;
  border: 3px solid #140b08;
  background: #090705;
  box-shadow: 0 16px 36px var(--shadow);
}

.scene-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  image-rendering: auto;
}

.hotspots {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.hotspot {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 50%;
  background: rgba(58, 210, 198, 0.03);
  transform: translateZ(0);
  touch-action: manipulation;
}

.hotspot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 232, 175, 0.86);
  border-radius: 50%;
  background: rgba(58, 210, 198, 0.72);
  box-shadow: 0 0 0 4px rgba(10, 7, 5, 0.34);
  opacity: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.hotspot::after {
  content: attr(aria-label);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  width: max-content;
  max-width: 170px;
  transform: translateX(-50%);
  padding: 6px 8px;
  border: 2px solid #28160e;
  background: #ffe4a1;
  color: #24140e;
  font-size: 0.76rem;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.hotspot:hover,
.hotspot:focus-visible {
  border-color: var(--cyan);
  background: rgba(58, 210, 198, 0.17);
  outline: none;
}

.hotspot:hover::after,
.hotspot:focus-visible::after,
.hotspot.peek::after {
  opacity: 1;
}

.show-hotspots .hotspot {
  border-color: rgba(58, 210, 198, 0.72);
  background: rgba(58, 210, 198, 0.13);
}

.show-hotspots .hotspot::before {
  opacity: 1;
}

.toast {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  min-height: 0;
  padding: 0;
  color: #1d120d;
  background: transparent;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  transition: opacity 140ms ease;
}

.toast.visible {
  opacity: 1;
  padding: 10px 12px;
  border: 2px solid #321d13;
  background: #ffe4a1;
}

.command-line {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 74px;
  border: 2px solid var(--line);
  background: rgba(22, 12, 8, 0.82);
  padding: 10px;
}

.portrait {
  width: 46px;
  height: 46px;
  border: 2px solid #0b0705;
  background:
    linear-gradient(135deg, transparent 0 46%, #211812 47% 52%, transparent 53%),
    radial-gradient(circle at 52% 36%, #ffe0a1 0 24%, transparent 25%),
    linear-gradient(160deg, var(--red), var(--violet));
}

#narration {
  margin: 0;
  color: var(--cream);
  font-size: clamp(0.95rem, 2vw, 1.08rem);
  line-height: 1.35;
}

.bottom-panel {
  display: grid;
  grid-template-columns: minmax(230px, 0.45fr) 1fr;
  gap: 10px;
}

.nav-panel,
.inventory-wrap {
  border: 2px solid var(--line);
  background: rgba(22, 12, 8, 0.82);
  padding: 10px;
}

.nav-panel {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.inventory-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.inventory-title {
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.selected-status {
  color: rgba(255, 232, 175, 0.7);
  font-size: 0.82rem;
  font-weight: 700;
  margin-top: 3px;
}

.cancel-selection {
  min-height: 38px;
  padding: 0 12px;
}

.inventory {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.inventory button {
  min-width: 0;
  width: 100%;
  padding: 0 8px;
  overflow-wrap: anywhere;
}

.inventory button.selected {
  background: linear-gradient(#8ff2e8, #2ca59b);
  box-shadow: 0 4px 0 #16534e;
}

.empty-slot {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(255, 230, 171, 0.3);
  color: rgba(255, 232, 175, 0.68);
  font-size: 0.9rem;
}

.ending {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 7, 5, 0.82);
}

.ending-panel {
  width: min(640px, 100%);
  border: 3px solid #321d13;
  background: #ffe4a1;
  color: #24140e;
  padding: 22px;
  box-shadow: 0 18px 0 rgba(0, 0, 0, 0.28);
}

.ending-panel h2 {
  margin-bottom: 10px;
  font-size: clamp(1.4rem, 4vw, 2.3rem);
  line-height: 1.05;
}

.ending-panel p {
  line-height: 1.42;
}

@media (max-width: 760px) {
  .game-shell {
    padding: 8px;
    gap: 8px;
  }

  .topbar {
    align-items: start;
  }

  .scene-name {
    max-width: 42%;
    font-size: 0.9rem;
  }

  .top-actions {
    align-items: start;
  }

  .stage {
    height: min(48svh, 380px);
    aspect-ratio: auto;
    max-height: none;
  }

  .bottom-panel {
    grid-template-columns: 1fr;
  }

  .nav-panel {
    grid-template-columns: repeat(3, 1fr);
  }

  .command-line {
    grid-template-columns: 44px 1fr;
    min-height: 66px;
  }

  .portrait {
    width: 38px;
    height: 38px;
  }
}

@media (max-width: 420px) {
  .topbar {
    display: block;
  }

  .scene-name {
    max-width: none;
    margin-top: 6px;
    text-align: left;
  }

  .top-actions {
    justify-content: space-between;
    margin-top: 8px;
  }

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

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

@media (pointer: coarse) {
  button {
    min-height: 48px;
    font-size: 0.98rem;
  }

  .scan-button,
  .cancel-selection {
    min-height: 44px;
  }

  .hotspot {
    min-width: 46px;
    min-height: 46px;
  }

  .hotspot::before {
    width: 16px;
    height: 16px;
  }

  .hotspot.peek::after {
    opacity: 1;
  }

  .toast.visible {
    bottom: 10px;
    padding: 9px 10px;
  }
}
