:root {
  --bg: #0a0806;
  --panel: rgba(20, 16, 10, 0.82);
  --yellow: #d6bf6a;
  --yellow-dim: #8a7a45;
  --text: #e8e0c8;
  --muted: #9a8f74;
  --accent: #ffdf6b;
  --danger: #c33;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "DejaVu Sans", system-ui, sans-serif;
}

#stage { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: #000; }

#viewport {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 100vw;
  max-height: 100vh;
  background: #000;
  cursor: crosshair;
}

/* ---------- overlays ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(90,78,40,0.35), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(0,0,0,0.85), transparent 70%),
    #060504;
  text-align: center;
  padding: 24px;
  overflow-y: auto;
  z-index: 20;
}
.screen.hidden { display: none; }

.title {
  font-size: 64px;
  line-height: 0.9;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(255, 220, 90, 0.55), 2px 2px 0 #000;
}
.title.small { font-size: 40px; }
.subtitle { color: var(--muted); font-style: italic; margin-top: -8px; }

.controls-card, .options-card, .enemy-legend {
  background: var(--panel);
  border: 1px solid #3a3222;
  border-radius: 8px;
  padding: 18px 22px;
  max-width: 560px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.controls-card h2, .options-card h3 { color: var(--yellow); margin-bottom: 10px; font-weight: 600; }
.options-card h3 { margin-top: 16px; }
.controls-card table { margin: 0 auto; border-collapse: collapse; }
.controls-card td { padding: 4px 10px; text-align: left; color: var(--text); }
.controls-card td:first-child { color: var(--muted); text-align: right; }
.hint { margin-top: 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }

kbd {
  display: inline-block; padding: 1px 7px; margin: 0 2px;
  background: #1c1710; border: 1px solid #4a3f28; border-bottom-width: 3px;
  border-radius: 4px; font-size: 12px; color: var(--accent); font-family: inherit;
}

.menu-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.btn {
  padding: 12px 22px; font-size: 15px; letter-spacing: 0.04em;
  background: #1a150d; color: var(--text); border: 1px solid #5a4d2e;
  border-radius: 6px; cursor: pointer; transition: all .12s ease;
  text-transform: uppercase;
}
.btn:hover { background: #2a2212; border-color: var(--accent); color: var(--accent); }
.btn.primary { background: #3a2f14; border-color: var(--accent); color: var(--accent); }
.btn.primary:hover { background: #54420f; }

.enemy-legend { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; font-size: 13px; color: var(--muted); }
.enemy-legend .lbl { color: var(--text); }

/* options rows */
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 0; }
.opt-row label { color: var(--muted); min-width: 150px; text-align: right; }
.opt-row select, .opt-row input[type=range] { accent-color: var(--accent); }
.opt-row select { background: #1c1710; color: var(--text); border: 1px solid #4a3f28; border-radius: 4px; padding: 4px 8px; }
input[type=checkbox] { width: 18px; height: 18px; }

#bindings { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 16px; }
.bind {
  display: flex; align-items: center; gap: 8px;
  background: #17120b; border: 1px solid #3a3222; border-radius: 6px; padding: 6px 10px;
}
.bind .action { color: var(--muted); font-size: 12px; }
.bind .key {
  min-width: 70px; text-align: center; padding: 3px 8px; cursor: pointer;
  background: #241d11; border: 1px solid #5a4d2e; border-radius: 4px; color: var(--accent); font-size: 13px;
}
.bind .key.listening { border-color: #fff; color: #fff; animation: blink .5s step-end infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud.hidden { display: none; }

#crosshair {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: #fff; box-shadow: 0 0 6px rgba(255,255,255,0.9);
}

#wand-ui {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.5); border: 1px solid #5a4d2e; border-radius: 20px; padding: 5px 12px;
}
#wand-ui.hidden { display: none; }
#wand-icon { font-size: 20px; }
#wand-bar { width: 120px; height: 10px; background: #241d11; border-radius: 6px; overflow: hidden; }
#wand-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ffe066, #ff9a3c); }
#wand-time { font-size: 12px; color: var(--accent); min-width: 34px; }

#enemy-ui { position: absolute; right: 16px; top: 16px; display: flex; flex-direction: column; gap: 6px; }
.enemy-chip {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.5); border: 1px solid #3a3222; border-radius: 16px; padding: 3px 10px; font-size: 12px;
}
.enemy-dot { width: 10px; height: 10px; border-radius: 50%; background: #555; }
.enemy-dot.hunt { background: #e33; box-shadow: 0 0 8px #e33; }
.enemy-dot.dead { background: #2a2a2a; }
.enemy-state { color: var(--muted); }

#fps { position: absolute; left: 16px; top: 16px; font-size: 11px; color: var(--muted); }

#minimap {
  position: absolute; right: 16px; bottom: 16px;
  border: 1px solid #3a3222; background: rgba(10,8,6,0.72); opacity: 0.9;
}
#minimap.hidden { display: none; }

#grace {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%);
  padding: 6px 16px; background: rgba(0,0,0,0.6); border: 1px solid #6b2a1f; border-radius: 6px;
  color: #ffb3a0; font-size: 16px; letter-spacing: 0.03em; white-space: nowrap;
}
#grace.hidden { display: none; }

#toast {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 90px;
  max-width: 70%; text-align: center; padding: 8px 16px;
  background: rgba(0,0,0,0.65); border: 1px solid var(--yellow-dim); border-radius: 6px;
  color: var(--accent); font-size: 14px; transition: opacity .3s;
}
#toast.hidden { opacity: 0; }

#center-message {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
  font-size: 40px; letter-spacing: 0.04em; text-align: center;
  color: #fff; text-shadow: 0 0 20px rgba(255,0,0,0.7), 3px 3px 0 #000;
  animation: shake .35s ease;
}
#center-message.green { text-shadow: 0 0 20px rgba(120,255,120,0.7), 3px 3px 0 #000; }
#center-message.hidden { display: none; }
@keyframes shake {
  0%,100% { transform: translate(-50%,-50%) translateX(0); }
  25% { transform: translate(-50%,-50%) translateX(-8px); }
  75% { transform: translate(-50%,-50%) translateX(8px); }
}