:root {
  color-scheme: dark;
  --ink: #f7f1e4;
  --gold: #e6c27a;
  --walnut: #2a1a12;
  --panel: rgba(28, 18, 12, 0.88);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a120c;
  color: var(--ink);
  font-family: Georgia, "Palatino Linotype", Palatino, serif;
  user-select: none;
  touch-action: none;
}

canvas#world {
  display: block;
  width: 100%;
  height: 100%;
}

#fade {
  position: fixed;
  inset: 0;
  background: #140e0a;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 8;
}

#fade.on { opacity: 1; }

.fatal {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translateX(-50%);
  z-index: 9;
  background: var(--panel);
  border: 1px solid var(--gold);
  padding: 16px 18px;
  border-radius: 12px;
}

#banner {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 3;
  pointer-events: none;
}

#banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#banner span {
  display: inline-block;
  padding: 8px 18px 9px;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 999px;
  letter-spacing: 0.08em;
  font-size: 15px;
}

#radar-wrap {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: 148px;
  z-index: 3;
  pointer-events: none;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-start;
  gap: 6px;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.35));
}

#radar { width: 148px; height: 148px; display: block; }

#hint {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 12px;
  background: rgba(28, 18, 12, 0.62);
  border-radius: 999px;
  color: rgba(247, 241, 228, 0.82);
  font-family: "Segoe UI", sans-serif;
  font-size: 12px;
  letter-spacing: 0.01em;
  z-index: 3;
  pointer-events: none;
  max-width: calc(100% - 360px);
  text-align: center;
}

#prompt[hidden],
#panel[hidden],
#directory[hidden],
#fatal[hidden] {
  display: none !important;
}

#prompt {
  position: fixed;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 14px;
  padding: 8px 14px 8px 8px;
  z-index: 4;
  font-size: 16px;
}

#prompt kbd {
  min-width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--gold);
  color: #2a1a12;
  font-family: "Segoe UI", sans-serif;
  font-weight: 700;
}

#map-btn, #mute, #panel button, #directory button, #touch button, #panel a {
  font-family: "Segoe UI", sans-serif;
  border-radius: 12px;
  border: 1px solid var(--gold);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

#map-btn, #mute {
  position: fixed;
  top: 18px;
  z-index: 4;
  padding: 8px 12px;
}

#map-btn { right: 18px; }
#mute { right: 124px; }

#panel, #directory {
  position: fixed;
  z-index: 6;
  background: rgba(250, 244, 232, 0.96);
  color: #2a1a12;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  user-select: text;
}

#panel {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100% - 28px));
  padding: 22px 22px 18px;
}

#panel h2, #directory h2 { margin: 0 0 8px; font-size: 28px; }

.kicker {
  margin: 0 0 4px;
  color: #8a6234;
  letter-spacing: 0.08em;
  font-size: 12px;
  text-transform: uppercase;
}

#panel-copy { margin: 0 0 16px; line-height: 1.45; }

.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; }

#pass {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 4;
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(20, 40, 32, 0.88);
  border: 1px solid #7dffa8;
  color: #d9ffe6;
  font-family: "Segoe UI", sans-serif;
  font-size: 13px;
}

#panel a, #panel button, #dir-close {
  text-decoration: none;
  padding: 10px 14px;
  background: #2a1a12;
  color: #f7f1e4;
}

#directory {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 18px;
}

.dir-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }

#directory h3 {
  margin: 12px 0 8px;
  font-size: 15px;
  letter-spacing: 0.04em;
}

#dir-world,
#dir-house {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#dir-world button,
#dir-house button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  padding: 10px 12px;
  background: #fffaf3;
  color: #2a1a12;
}

#dir-world button span,
#dir-house button span {
  font-family: "Segoe UI", sans-serif;
  font-size: 12px;
  color: #6b5344;
}

#dir-world button:disabled {
  opacity: 0.48;
  cursor: default;
  background: #efe8dc;
}

#legend {
  list-style: none;
  margin: 8px 0 0;
  padding: 8px;
  width: 148px;
  background: rgba(20, 14, 10, 0.78);
  border: 1px solid rgba(230, 194, 122, 0.7);
  border-radius: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 6px;
}

#legend li {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: "Segoe UI", sans-serif;
  font-size: 10px;
  color: #f7f1e4;
}

#legend i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: block;
  flex: none;
}

.fine { margin: 0; font-size: 12px; line-height: 1.4; color: #5c4634; }

#touch { display: none; }

#stick {
  position: fixed;
  left: 22px;
  bottom: 22px;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(20, 14, 10, 0.45);
  border: 2px solid rgba(230, 194, 122, 0.85);
  z-index: 5;
  touch-action: none;
}

#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(247, 241, 228, 0.92);
  transform: translate(-50%, -50%);
}

#touch-actions {
  position: fixed;
  right: 16px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}

#touch-enter {
  min-width: 112px;
  min-height: 64px;
  font-size: 18px;
  background: var(--gold);
  color: #2a1a12;
  border-color: #f3e2bc;
  font-weight: 700;
}

#touch-jog, #touch-map, #touch-mute {
  min-height: 42px;
  padding: 8px 10px;
}

#touch-jog.on { background: var(--gold); color: #2a1a12; }

@media (max-width: 820px), (pointer: coarse) {
  #touch { display: block; }
  #hint, #map-btn, #mute { display: none; }
  #radar-wrap { top: 14px; bottom: auto; left: 14px; width: 112px; height: 112px; }
  #radar { width: 112px; height: 112px; }
  #banner {
    top: 16px;
    left: 136px;
    right: 12px;
    transform: none;
    text-align: left;
  }
  #banner.show { transform: none; }
  #banner span { font-size: 13px; padding: 6px 10px; }
  #prompt { bottom: 150px; }
  #prompt kbd { display: none; }
}

@media (max-width: 520px) {
  #dir-world, #dir-house { grid-template-columns: 1fr; }
  #legend { display: none; }
}
