:root {
  --lime: #39ff14;
  --amber: #ffb000;
  --red: #ff3355;
  --cyan: #00e5ff;
  --panel: rgba(0, 8, 0, 0.92);
  --border: #1a5c1a;
  --font: "Courier New", Courier, monospace;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: var(--font);
  color: var(--lime);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

#game-canvas-host, #game-canvas-host canvas {
  position: fixed; inset: 0; width: 100%; height: 100%;
  image-rendering: pixelated;
}

/* —— Loading / Title —— */
#loading-screen, #title-screen, #ending {
  position: fixed; inset: 0; z-index: 1000;
  background: radial-gradient(ellipse at center, #0a1a0a 0%, #000 70%);
  display: flex; align-items: center; justify-content: center;
}

.load-inner, .title-panel, .end-panel { text-align: center; max-width: 520px; padding: 2rem; }

.pv-logo {
  font-size: 3.5rem; letter-spacing: 0.4em; font-weight: bold;
  color: var(--lime); text-shadow: 0 0 20px var(--lime);
  animation: pulse 2s ease-in-out infinite;
}
.pv-sub { font-size: 1.4rem; letter-spacing: 0.6em; color: var(--amber); margin-top: 0.25rem; }
.load-tag { color: #6a6; margin: 1rem 0 1.5rem; font-size: 0.9rem; }
.load-bar {
  width: 280px; height: 8px; margin: 0 auto 0.75rem;
  border: 1px solid var(--border); background: #111;
}
#load-fill { height: 100%; width: 0%; background: var(--lime); transition: width 0.2s; box-shadow: 0 0 8px var(--lime); }
#load-status { font-size: 0.75rem; color: #5a5; min-height: 1.2em; }
.disclaimer { margin-top: 2rem; font-size: 0.65rem; color: #555; line-height: 1.4; }

.title-panel h1 {
  font-size: 2.2rem; letter-spacing: 0.15em;
  text-shadow: 0 0 24px var(--lime); margin-bottom: 0.25rem;
}
.title-panel h2 { color: var(--amber); font-size: 1.1rem; margin-bottom: 0.75rem; }
.tagline { color: #7a7; margin-bottom: 1.5rem; font-size: 0.85rem; }
.title-hints {
  display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center;
  margin-top: 1.5rem; font-size: 0.7rem; color: #4a4;
}
.title-hints span {
  border: 1px solid #234; padding: 0.2rem 0.45rem; border-radius: 2px;
}

.menu-btn {
  display: block; width: 100%; max-width: 280px; margin: 0.5rem auto;
  padding: 0.75rem 1rem;
  background: #0a1a0a; border: 1px solid var(--border);
  color: var(--lime); font-family: inherit; font-size: 0.95rem;
  cursor: pointer; letter-spacing: 0.1em;
  transition: background 0.15s, box-shadow 0.15s;
}
.menu-btn:hover, .menu-btn:focus {
  background: #123012; box-shadow: 0 0 12px rgba(57,255,20,0.3); outline: none;
}
.menu-btn.primary { border-color: var(--lime); background: #0d280d; }
.menu-btn:disabled { opacity: 0.4; cursor: not-allowed; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* —— HUD —— */
#hud {
  position: fixed; inset: 0; z-index: 50; pointer-events: none;
}

#hud-top {
  position: absolute; top: 10px; left: 10px; right: 160px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
}

.stat {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 4px 8px; font-size: 0.7rem;
}
.stat .label { color: #6a6; min-width: 70px; }
.stat .bar {
  width: 80px; height: 8px; background: #111; border: 1px solid #333;
}
.stat .bar > div { height: 100%; background: var(--lime); width: 100%; }
.stat .bar.battery > div { background: var(--cyan); }
.stat .bar.stealth > div { background: var(--amber); }

#time-display {
  margin-left: auto;
  background: var(--panel); border: 1px solid var(--border);
  padding: 4px 10px; font-size: 0.75rem; color: var(--amber);
}

#quest-tracker {
  position: absolute; top: 50px; right: 10px;
  width: 220px; background: var(--panel); border: 1px solid var(--border);
  padding: 8px; font-size: 0.7rem;
}
.qt-title { color: var(--amber); margin-bottom: 6px; letter-spacing: 0.1em; }
#quest-list .q-item { margin-bottom: 6px; line-height: 1.3; }
#quest-list .q-item.done { color: #456; text-decoration: line-through; }
#quest-list .q-obj { color: #8a8; padding-left: 8px; font-size: 0.65rem; }

#crosshair {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px; color: rgba(57,255,20,0.55); font-weight: bold;
}

#interact-prompt {
  position: absolute; bottom: 18%; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--lime);
  padding: 8px 16px; font-size: 0.85rem; color: #fff;
  box-shadow: 0 0 16px rgba(57,255,20,0.25);
}

#toast {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  background: rgba(0,20,0,0.9); border: 1px solid var(--amber);
  color: var(--amber); padding: 10px 18px; font-size: 0.85rem;
  max-width: 90%; text-align: center;
  animation: toastIn 0.25s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#record-overlay {
  position: absolute; top: 14%; left: 50%; transform: translateX(-50%);
  color: var(--red); font-size: 0.9rem; letter-spacing: 0.15em;
  display: flex; align-items: center; gap: 8px;
  text-shadow: 0 0 8px var(--red);
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--red);
  animation: blink 0.8s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

#minimap-wrap {
  position: absolute; bottom: 56px; right: 10px;
  border: 1px solid var(--border); background: rgba(0,0,0,0.7);
}
#minimap { display: block; image-rendering: pixelated; }
.mm-label {
  text-align: center; font-size: 0.55rem; color: #4a4; padding: 2px;
}

#hotbar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px;
}
.hot-slot {
  width: 44px; height: 44px;
  border: 1px solid var(--border); background: var(--panel);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem; color: #8a8; position: relative;
}
.hot-slot .key {
  position: absolute; top: 1px; left: 3px; font-size: 0.55rem; color: #555;
}
.hot-slot.filled { border-color: var(--lime); color: var(--lime); }

/* —— Dialogue —— */
#dialogue {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 1rem 2rem; pointer-events: auto;
  background: linear-gradient(transparent 40%, rgba(0,0,0,0.75));
}
.dlg-panel {
  width: min(640px, 100%);
  background: var(--panel); border: 2px solid var(--border);
  padding: 1rem 1.25rem;
}
#dlg-name { color: var(--amber); font-size: 0.9rem; margin-bottom: 0.5rem; letter-spacing: 0.08em; }
#dlg-text { color: #cfc; font-size: 0.95rem; line-height: 1.45; min-height: 3em; margin-bottom: 0.75rem; }
#dlg-choices { display: flex; flex-direction: column; gap: 0.4rem; }
.dlg-choice {
  text-align: left; padding: 0.55rem 0.75rem;
  background: #0a150a; border: 1px solid #2a4a2a;
  color: var(--lime); font-family: inherit; font-size: 0.85rem; cursor: pointer;
}
.dlg-choice:hover { border-color: var(--lime); background: #102010; }
.dlg-choice.risk { border-color: #663; color: var(--amber); }

#dlg-timing { margin-top: 0.75rem; }
.timing-label { font-size: 0.7rem; color: var(--cyan); margin-bottom: 0.4rem; }
.timing-track {
  position: relative; height: 16px; background: #111; border: 1px solid #333;
}
.timing-zone {
  position: absolute; left: 42%; width: 16%; height: 100%;
  background: rgba(57,255,20,0.35); border: 1px solid var(--lime);
}
#timing-marker {
  position: absolute; top: 0; left: 0; width: 4px; height: 100%;
  background: var(--amber); box-shadow: 0 0 6px var(--amber);
}

/* —— Inventory —— */
#inventory, #pause-menu {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
}
.inv-panel, .pause-panel {
  background: var(--panel); border: 2px solid var(--border);
  width: min(720px, 96vw); max-height: 92vh; overflow-y: auto;
  padding: 1rem 1.25rem;
}
.inv-header {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border); padding-bottom: 0.5rem;
}
.inv-header h2 { flex: 1; font-size: 1.1rem; letter-spacing: 0.12em; }
.close-x {
  background: none; border: 1px solid #444; color: #888;
  width: 28px; height: 28px; cursor: pointer; font-family: inherit;
}
.close-x:hover { color: var(--red); border-color: var(--red); }

.inv-body { display: grid; grid-template-columns: 110px 1fr 170px; gap: 12px; }
@media (max-width: 700px) {
  .inv-body { grid-template-columns: 1fr; }
}
.inv-help { font-size: 0.65rem; color: #6a6; flex: 1; }

.inv-equip .slot {
  border: 1px solid var(--border); height: 52px; margin-bottom: 6px;
  display: flex; align-items: center; gap: 4px; padding: 4px; font-size: 0.6rem;
  cursor: pointer; transition: border-color 0.12s, box-shadow 0.12s;
}
.inv-equip .slot:hover, .inv-equip .slot.drop-hover {
  border-color: var(--amber); box-shadow: 0 0 8px rgba(255,176,0,0.25);
}
.inv-equip .item { flex: 1; color: var(--cyan); font-size: 0.7rem; font-weight: bold; }
.inv-equip .item.filled { color: var(--lime); }

.inv-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.inv-use-zone {
  border: 1px dashed var(--amber); color: var(--amber); font-size: 0.65rem;
  text-align: center; padding: 8px; background: rgba(255,176,0,0.08);
  letter-spacing: 0.04em; cursor: copy;
}
.inv-use-zone:hover { background: rgba(255,176,0,0.18); }

.inv-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  background: #050a05; padding: 4px; border: 1px solid #222;
}
.grid-cell {
  aspect-ratio: 1; border: 1px solid #1a2a1a; background: #0a100a;
  font-size: 0.55rem; display: flex; align-items: center; justify-content: center;
  color: #8c8; cursor: grab; position: relative; text-align: center; padding: 2px;
  word-break: break-word; user-select: none;
  transition: border-color 0.1s, background 0.1s;
}
.grid-cell.has-item { border-color: #2a5a2a; background: #0d1a0d; color: var(--lime); }
.grid-cell:hover { border-color: var(--amber); }
.grid-cell .item-name { pointer-events: none; line-height: 1.1; }
.grid-cell .qty {
  position: absolute; bottom: 1px; right: 2px; font-size: 0.5rem; color: var(--amber);
}
.inv-tip { margin-top: 6px; color: #6a6; font-size: 0.65rem; }
.inv-detail kbd {
  border: 1px solid #345; padding: 0 4px; border-radius: 2px; color: var(--lime);
}

.drag-ghost {
  position: fixed; z-index: 9999; pointer-events: none;
  background: rgba(0,20,0,0.92); border: 1px solid var(--lime);
  color: var(--lime); font-family: var(--font); font-size: 0.75rem;
  padding: 6px 10px; box-shadow: 0 0 12px rgba(57,255,20,0.35);
}

.inv-detail {
  font-size: 0.7rem; color: #9a9; line-height: 1.4;
  border: 1px solid #222; padding: 8px; min-height: 100px;
}
.inv-detail h4 { color: var(--amber); margin-bottom: 0.35rem; }
.inv-detail .stat-line { color: var(--cyan); }

.skills-mini {
  margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.75rem;
  font-size: 0.75rem;
}
.skills-mini h3 { color: var(--amber); margin-bottom: 0.5rem; font-size: 0.8rem; }
.skill-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.skill-row button {
  margin-left: auto; padding: 2px 8px; font-family: inherit;
  background: #0a1a0a; border: 1px solid var(--border); color: var(--lime); cursor: pointer;
}
.skill-row button:disabled { opacity: 0.3; cursor: default; }

/* —— Pause —— */
.pause-panel h1 {
  text-align: center; letter-spacing: 0.2em; margin-bottom: 0.75rem;
  text-shadow: 0 0 12px var(--lime);
}
.pause-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 0.75rem; }
.pause-tabs .tab {
  flex: 1; min-width: 70px; padding: 0.4rem;
  background: #0a120a; border: 1px solid #234; color: #6a6;
  font-family: inherit; font-size: 0.7rem; cursor: pointer;
}
.pause-tabs .tab.active { border-color: var(--lime); color: var(--lime); }
.tab-pane { min-height: 200px; font-size: 0.8rem; line-height: 1.4; color: #aca; }
.tab-pane h3 { color: var(--amber); margin: 0.5rem 0 0.25rem; }
.pause-actions {
  display: flex; gap: 8px; margin-top: 1rem; flex-wrap: wrap;
}
.pause-actions .menu-btn { max-width: none; flex: 1; margin: 0; }
#big-map {
  display: block; margin: 0 auto; background: #0a100a;
  border: 1px solid var(--border); image-rendering: pixelated; max-width: 100%;
}
.hint { text-align: center; font-size: 0.65rem; color: #555; margin-top: 0.5rem; }
#tab-options label {
  display: block; margin: 0.6rem 0; color: #9a9;
}
#tab-options input[type="range"] { width: 160px; vertical-align: middle; margin-left: 8px; }

/* —— QTE —— */
#qte {
  position: fixed; inset: 0; z-index: 95;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20,0,0,0.55); pointer-events: auto;
}
.qte-panel {
  text-align: center; background: var(--panel); border: 2px solid var(--red);
  padding: 1.5rem 2rem; min-width: 240px;
}
#qte-title { color: var(--red); letter-spacing: 0.15em; margin-bottom: 0.5rem; }
#qte-prompt { color: #ccc; font-size: 0.85rem; margin-bottom: 0.75rem; }
#qte-key {
  font-size: 2.5rem; color: var(--amber);
  border: 2px solid var(--amber); display: inline-block;
  width: 64px; height: 64px; line-height: 60px; margin-bottom: 0.75rem;
  box-shadow: 0 0 16px rgba(255,176,0,0.4);
}
.qte-bar { width: 200px; height: 10px; background: #222; margin: 0 auto; border: 1px solid #444; }
#qte-fill { height: 100%; width: 100%; background: var(--red); transition: width 0.05s linear; }

/* —— Ending —— */
.end-panel h1 { color: var(--amber); margin-bottom: 1rem; text-shadow: 0 0 16px var(--amber); }
#end-body { color: #aca; line-height: 1.5; margin-bottom: 1.5rem; white-space: pre-wrap; }

.mobile-tip {
  margin-top: 0.75rem;
  font-size: 0.7rem;
  color: #5a8;
  line-height: 1.35;
}

/* —— Touch / mobile controls —— */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}
#touch-controls.touch-dim #touch-stick-base,
#touch-controls.touch-dim #touch-actions,
#touch-controls.touch-dim #touch-look-zone {
  opacity: 0.15;
  pointer-events: none !important;
}
#touch-look-zone {
  position: absolute;
  top: 0;
  right: 0;
  width: 58%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}
#touch-stick-base {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(57, 255, 20, 0.45);
  background: rgba(0, 20, 0, 0.35);
  pointer-events: auto;
  touch-action: none;
}
#touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(57, 255, 20, 0.55);
  border: 2px solid #39ff14;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 12px rgba(57, 255, 20, 0.35);
  pointer-events: none;
}
#touch-actions {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 56px);
  gap: 8px;
  pointer-events: auto;
  touch-action: none;
}
.tbtn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(57, 255, 20, 0.55);
  background: rgba(0, 16, 0, 0.72);
  color: #39ff14;
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.tbtn-sm {
  width: 48px;
  height: 48px;
  font-size: 0.6rem;
  justify-self: center;
}
.tbtn-primary {
  border-color: #ffb000;
  color: #ffb000;
  background: rgba(40, 24, 0, 0.8);
  box-shadow: 0 0 10px rgba(255, 176, 0, 0.3);
}
.tbtn-wide {
  width: min(280px, 70vw);
  height: 52px;
  border-radius: 10px;
  font-size: 0.95rem;
}
.tbtn.held, .tbtn.flash {
  background: rgba(57, 255, 20, 0.35);
  transform: scale(0.96);
}
.tbtn-primary.held, .tbtn-primary.flash {
  background: rgba(255, 176, 0, 0.35);
}
#touch-timing {
  position: absolute;
  left: 50%;
  bottom: max(150px, env(safe-area-inset-bottom) + 120px);
  transform: translateX(-50%);
  pointer-events: auto;
  z-index: 70;
}

body.touch-mode #hotbar { display: none; }
body.touch-mode #crosshair { opacity: 0.35; }
body.touch-mode #minimap-wrap {
  transform: scale(0.78);
  transform-origin: bottom right;
  bottom: auto;
  top: 52px;
  right: 6px;
}
body.touch-mode #quest-tracker {
  top: auto;
  bottom: 150px;
  right: 8px;
  width: min(160px, 42vw);
  font-size: 0.58rem;
  max-height: 28vh;
  overflow-y: auto;
}
body.touch-mode #hud-top {
  right: 8px;
  left: 8px;
  gap: 6px;
  flex-wrap: wrap;
}
body.touch-mode #hud-top .stat .bar { width: 44px; }
body.touch-mode #hud-top .stat .label { min-width: 0; font-size: 0.55rem; }
body.touch-mode #interact-prompt {
  bottom: 38%;
  font-size: 0.8rem;
  padding: 10px 14px;
}
body.touch-mode .inv-panel,
body.touch-mode .pause-panel {
  width: 96vw;
  max-height: 88vh;
  padding: 0.75rem;
}
body.touch-mode .inv-body {
  grid-template-columns: 1fr;
}
body.touch-mode .grid-cell {
  min-height: 44px;
}
body.touch-mode .dlg-choice {
  min-height: 48px;
  font-size: 0.9rem;
  padding: 0.75rem;
}
body.touch-mode .menu-btn {
  min-height: 48px;
  font-size: 1rem;
}
body.touch-mode #qte-prompt::after {
  content: " — TAP ANYWHERE";
  color: #ffb000;
}

/* Mobile layout polish */
@media (max-width: 600px) {
  #quest-tracker { width: 160px; font-size: 0.6rem; top: 90px; }
  #hud-top { right: 10px; }
  .stat .bar { width: 50px; }
  #minimap-wrap { transform: scale(0.85); transform-origin: bottom right; }
}
