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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  color: #b9b0a2;
  font-family: Georgia, "Times New Roman", serif;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}

canvas#game {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: crosshair;
  transform: none;
  transition: transform .45s ease;
}
body.camera-3d #world3d {
  position: fixed; inset: 0; z-index: 0; display: block;
  width: 100%; height: 100%; touch-action: none; cursor: crosshair;
}
body.camera-3d canvas#game { display: none; }
body.camera-3d #crt, body.low-effects #crt { animation: none; background: none; }

/* scanlines + subtle flicker */
#crt {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 20;
  background: repeating-linear-gradient(0deg,
    rgba(0,0,0,.22) 0, rgba(0,0,0,.22) 1px,
    transparent 1px, transparent 3px);
  animation: crt .15s infinite;
}
@keyframes crt {
  0%   { opacity: .85; }
  50%  { opacity: 1; }
  100% { opacity: .9; }
}

.hidden { display: none !important; }

/* HUD */
#hud {
  position: fixed; left: 18px; top: 16px;
  z-index: 5; pointer-events: none;
  font-size: 14px; letter-spacing: .25em;
  color: #9a8f80; text-shadow: 0 0 6px #000;
}
#hud .label { font-size: 10px; margin-top: 10px; opacity: .6; }
#threat { margin-top: 9px; color: #a9c5a5; font-size: 11px; letter-spacing: .18em; }
#threat[data-state="near"] { color: #d3b779; }
#threat[data-state="close"] { color: #e27f70; animation: threat-pulse .7s infinite alternate; }
@keyframes threat-pulse { to { opacity: .55; } }
.bar {
  width: 140px; height: 5px; margin-top: 4px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
}
.bar span { display: block; height: 100%; width: 100%; background: #b8a46a; }
#stam span { background: #6a8fb8; }

/* messages */
#message {
  position: fixed; left: 0; right: 0; bottom: 14%;
  text-align: center; z-index: 6; pointer-events: none;
  font-style: italic; font-size: clamp(16px, 2.4vw, 24px);
  color: #cfc4b0; letter-spacing: .08em;
  text-shadow: 0 0 10px #000, 0 0 20px #300;
  opacity: 0; transition: opacity 1s;
  padding: 0 20px;
}
#message.show { opacity: 1; transition: opacity .2s; }

#note {
  position: fixed; left: 50%; top: 12%;
  transform: translateX(-50%) rotate(-1.5deg);
  z-index: 6; pointer-events: none;
  max-width: min(440px, 88vw);
  padding: 18px 22px;
  background: #d6ccb0;
  color: #2a1a12;
  font-family: "Courier New", monospace;
  font-size: 15px; line-height: 1.5;
  box-shadow: 0 0 40px rgba(0,0,0,.9), inset 0 0 30px rgba(90,50,10,.35);
  opacity: 0; transition: opacity 1.2s;
}
#note b { color: #7a1010; letter-spacing: .15em; }
#note.show { opacity: .96; transition: opacity .3s; }

#pause {
  position: fixed; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.7);
  font-size: 48px; letter-spacing: .4em; color: #822;
}

/* screens */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 20px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.55) 0%, rgba(0,0,0,.95) 75%, #000 100%);
}
#screen-dead { background: radial-gradient(ellipse at center, rgba(40,0,0,.85), #000 80%); }
#screen-win  { background: radial-gradient(ellipse at center, rgba(0,0,0,.75), #000 85%); }
.dead-screen { background: radial-gradient(ellipse at center, rgba(50,5,8,.95), rgba(8,3,4,.98) 66%, #000 100%); }
.death-kicker { color: #d67569; font: 12px "Courier New", monospace; letter-spacing: .3em; }
.death-detail { margin: -18px 0 24px; color: #795b57; font: 11px "Courier New", monospace; letter-spacing: .16em; }
.dead-screen .sub { max-width: 560px; color: #aa8980; }

h1 {
  font-weight: normal;
  font-size: clamp(44px, 11vw, 130px);
  letter-spacing: .18em;
  margin-right: -.18em;
  color: #a31414;
  text-shadow: 0 0 20px #500, 0 0 60px #300;
}
h1.dead { color: #c00; animation: shake .4s infinite; }
h1.win  { color: #b9b0a2; text-shadow: 0 0 30px #333; }

.glitch { position: relative; animation: flick 5s infinite; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute; left: 0; top: 0; width: 100%;
  overflow: hidden; opacity: .7;
}
.glitch::before {
  color: #0cc; transform: translate(-3px, 0);
  animation: gl1 3s infinite steps(1);
}
.glitch::after {
  color: #f0a; transform: translate(3px, 0);
  animation: gl2 2.3s infinite steps(1);
}
@keyframes gl1 {
  0%, 90%, 100% { clip-path: inset(0 0 100% 0); }
  92% { clip-path: inset(20% 0 55% 0); }
  95% { clip-path: inset(60% 0 10% 0); }
  97% { clip-path: inset(5% 0 80% 0); }
}
@keyframes gl2 {
  0%, 85%, 100% { clip-path: inset(0 0 100% 0); }
  87% { clip-path: inset(50% 0 20% 0); }
  90% { clip-path: inset(10% 0 70% 0); }
  93% { clip-path: inset(75% 0 5% 0); }
}
@keyframes flick {
  0%, 18%, 22%, 62%, 66%, 100% { opacity: 1; }
  20% { opacity: .2; }
  64% { opacity: .4; }
  65% { opacity: .9; }
}
@keyframes shake {
  0% { transform: translate(0,0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -3px); }
  100% { transform: translate(0,0); }
}

.sub {
  margin: 22px 0 34px;
  font-style: italic; font-size: clamp(15px, 2.2vw, 22px);
  letter-spacing: .1em; color: #8a8072;
  max-width: 640px; line-height: 1.5;
}

.btn {
  background: transparent; color: #c33;
  border: 1px solid #711; padding: 14px 44px;
  font-family: inherit; font-size: 20px; letter-spacing: .4em;
  cursor: pointer; transition: all .3s;
}
.btn:hover {
  background: #300; color: #f55; border-color: #c22;
  box-shadow: 0 0 25px #600, inset 0 0 15px #400;
}
.menu-actions {
  display: grid; grid-template-columns: repeat(2, minmax(130px, 190px));
  gap: 9px; margin: 0 0 8px;
}
.menu-actions .primary { grid-column: 1 / -1; }
.menu-actions .btn { padding: 12px 10px; font-size: 15px; letter-spacing: .22em; }
.menu-screen { justify-content: flex-start; gap: 14px; overflow-y: auto; padding-top: clamp(18px, 4vh, 36px); }
.menu-title { color: #a31414; font-size: clamp(30px, 7vw, 58px); font-weight: normal; letter-spacing: .18em; }
.menu-screen .sub { margin: 0 0 8px; }
.setting-row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px;
  width: min(390px, 88vw); color: #b9b0a2; font-size: 13px; letter-spacing: .15em;
}
.setting-row input { grid-column: 1 / -1; width: 100%; accent-color: #b64b3c; }
.setting-row output { color: #e0b895; }
.voice-option { display: flex; align-items: center; gap: 10px; color: #c9b9a7; font: 12px "Courier New", monospace; letter-spacing: .1em; }
.voice-option input { accent-color: #b64b3c; }
.camera-options { display: grid; grid-template-columns: repeat(2, minmax(150px, 240px)); gap: 10px; }
.camera-option {
  display: grid; gap: 10px; min-height: 120px; padding: 18px;
  border: 1px solid #55413b; background: rgba(15, 15, 14, .82); color: #c9c0b4;
  text-align: left; font: inherit; cursor: pointer;
}
.camera-option[aria-pressed="true"] { border-color: #bd7966; box-shadow: inset 0 0 20px rgba(130, 45, 28, .2); }
.camera-option b { color: #e4a18c; letter-spacing: .2em; }
.camera-option span { color: #91877d; font-size: 13px; line-height: 1.5; }
.multiplayer-columns { display: grid; grid-template-columns: repeat(2, minmax(230px, 340px)); gap: 20px; width: min(720px, 92vw); text-align: left; }
.signal-panel { display: grid; align-content: start; gap: 8px; }
.signal-panel h3 { color: #d3a68e; font-weight: normal; letter-spacing: .18em; margin-bottom: 4px; }
.signal-panel label { color: #9a8f80; font: 11px "Courier New", monospace; letter-spacing: .12em; }
.signal-panel textarea {
  width: 100%; height: 66px; padding: 8px; resize: vertical;
  border: 1px solid #493c37; background: rgba(0,0,0,.7); color: #d2c8bb;
  font: 11px/1.4 "Courier New", monospace; user-select: text;
}
.signal-panel .btn { padding: 9px; font-size: 12px; letter-spacing: .13em; }
#multiplayer-status { min-height: 1.4em; color: #c8b79e; font: 12px "Courier New", monospace; }
#btn-camera-toggle {
  position: fixed; top: 14px; right: 18px; z-index: 6; pointer-events: auto;
  padding: 8px 11px; border: 1px solid rgba(190, 133, 111, .55);
  background: rgba(5, 7, 7, .82); color: #d3b6a1;
  font: 11px "Courier New", monospace; letter-spacing: .12em; cursor: pointer;
}
#btn-camera-toggle:hover { background: rgba(58, 24, 21, .9); color: #f0c2aa; }
#voice-state { margin-top: 8px; color: #7fd0ca; font: 10px "Courier New", monospace; letter-spacing: .12em; }
.low-effects #crt { display: none; }
.pause-panel { display: grid; justify-items: center; gap: 12px; }
.pause-panel h2 { margin-bottom: 12px; }

.controls { margin-top: 40px; font-size: 13px; letter-spacing: .08em; color: #6d655a; line-height: 2; }
.controls b { color: #9a8f80; font-weight: normal; border-bottom: 1px solid #433; }
.touchhint { display: none; }
body.touch .touchhint { display: block; }
.warn { margin-top: 28px; font-size: 11px; letter-spacing: .1em; color: #4a1a1a; max-width: 520px; }

/* touch buttons */
#touch { display: none; }
body.touch #touch {
  display: flex; flex-direction: column; gap: 14px;
  position: fixed; right: 16px; bottom: 22px; z-index: 8;
}
#touch button {
  width: 76px; height: 76px; border-radius: 50%;
  background: rgba(30,0,0,.55); color: #a55;
  border: 1px solid #522; font-family: inherit;
  font-size: 12px; letter-spacing: .15em;
}
#touch button:active { background: rgba(120,0,0,.6); }
#btn-voice { display: none; }
body.touch.multiplayer #btn-voice { display: block; border-color: #3b8c89; color: #80d5cc; }
/* ---------- v2 additions ---------- */
#items {
  margin-top: 12px; font-size: 11px; letter-spacing: .2em;
  color: #9a8f80; line-height: 1.8;
}
#items b { color: #c9b98a; font-weight: normal; }

#mini {
  display: block; margin-top: 14px;
  width: 135px; height: 135px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.5);
  opacity: .85; image-rendering: pixelated;
}

#prompt {
  position: fixed; left: 0; right: 0; bottom: 24%;
  text-align: center; z-index: 6; pointer-events: none;
  letter-spacing: .3em; font-size: 15px;
  color: #c9b98a; text-shadow: 0 0 8px #000;
  opacity: 0; transition: opacity .2s;
}
#prompt.show { opacity: 1; }

/* touch buttons: 2-column grid */
body.touch #touch {
  display: grid; grid-template-columns: repeat(3, 52px); gap: 7px;
}
#touch button { width: 52px; height: 52px; padding: 3px; font-size: 9px; letter-spacing: .04em; }

#dev-menu {
  position: fixed; top: 14px; right: 14px; z-index: 30;
  width: min(280px, calc(100vw - 28px)); padding: 12px;
  display: grid; gap: 7px;
  border: 1px solid rgba(145, 190, 160, .42);
  background: rgba(5, 12, 11, .96); color: #b7c8b9;
  box-shadow: 0 8px 36px rgba(0,0,0,.7);
  font: 11px/1.4 "Courier New", monospace; letter-spacing: .12em;
}
#dev-menu.hidden { display: none; }
.dev-heading { display: flex; justify-content: space-between; padding: 2px 3px 6px; color: #d3e2d4; }
.dev-heading span { color: #718477; }
#dev-menu button {
  min-height: 34px; padding: 7px 9px;
  border: 1px solid #35443b; background: #101a16; color: #a8b7aa;
  text-align: left; font: inherit; letter-spacing: .08em; cursor: pointer;
}
#dev-menu button:hover, #dev-menu button[aria-pressed="true"] {
  border-color: #9ac294; color: #d7f0d0; background: #1b2b21;
}
@media (max-width: 520px) {
  #dev-menu { top: 8px; right: 8px; width: min(250px, calc(100vw - 16px)); }
}
@media (max-width: 620px) {
  .multiplayer-columns { grid-template-columns: 1fr; max-height: 42vh; overflow-y: auto; }
  .camera-options { grid-template-columns: 1fr; width: min(360px, 90vw); }
  #hud { left: 10px; top: 10px; font-size: 11px; }
  #mini { width: 108px; height: 108px; }
  #btn-camera-toggle { top: 10px; right: 10px; }
}
@media (max-height: 700px) {
  #screen-title { justify-content: flex-start; overflow-y: auto; padding-top: 18px; }
  #screen-title h1 { font-size: clamp(38px, 9vh, 70px); }
  #screen-title .sub { margin: 8px 0 14px; }
  #screen-title .controls { margin-top: 14px; line-height: 1.65; }
  #screen-title .warn { margin-top: 14px; }
}
