:root {
  --void: #0a0908;
  --wall: #1c1814;
  --rope: #5c1420;
  --cream: #c8b89a;
  --mute: #8a7a62;
  --panel: rgba(12, 10, 8, 0.88);
  --line: rgba(200, 184, 154, 0.35);
  --accent: #9a3a3a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--void);
  color: var(--cream);
  font-family: 'VT323', monospace;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
html.playing, body.playing {
  touch-action: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

canvas#c {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

.css3d-root {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  overflow: hidden;
}
.css3d-root > div {
  position: absolute !important;
  inset: 0;
}
/* Flat paint overlay — CSS3D iframes are not hit-tested. */
.theater-paint-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: none;
  background: #0d0208;
  pointer-events: none;
}
.theater-paint-overlay.is-on {
  display: block;
  pointer-events: auto;
}
body.theater-painting .css3d-root {
  pointer-events: none;
  visibility: hidden;
}
body.theater-painting .crosshair {
  opacity: 0;
}
body.theater-painting .touch-controls {
  display: none !important;
}
body.theater-painting .hub-link {
  opacity: 0.2;
  pointer-events: none;
}
body.in-theater .hub-link {
  opacity: 0.35;
}

.hub-link {
  position: fixed;
  z-index: 40;
  top: max(14px, env(safe-area-inset-top, 0px));
  right: max(14px, env(safe-area-inset-right, 0px));
  font-family: "DotGothic16", monospace;
  font-size: 8px;
  letter-spacing: 0.04em;
  color: var(--mute);
  text-decoration: none;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.hub-link:hover { color: var(--cream); border-color: var(--cream); }

.chat-bar {
  position: absolute;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(520px, calc(100vw - 24px));
  padding: 10px 12px;
  background: rgba(8, 6, 5, 0.94);
  border: 1px solid var(--line);
  font-family: "Fragment Mono", monospace;
  pointer-events: auto;
}
.chat-bar.hidden { display: none; }
.chat-slash {
  color: var(--cream);
  font: 700 18px "VT323", monospace;
  opacity: 0.85;
  flex: none;
}
.chat-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--cream);
  font: 16px "VT323", monospace;
  letter-spacing: 0.03em;
}
.chat-input::placeholder { color: var(--mute); opacity: 0.8; }
.chat-send,
.chat-cancel {
  flex: none;
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(42, 24, 20, 0.95);
  color: var(--cream);
  font-family: "DotGothic16", monospace;
  font-size: 8px;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  min-height: 40px;
  cursor: pointer;
}
.chat-cancel {
  padding: 8px 12px;
  font-size: 16px;
  line-height: 1;
}
.chat-send:active,
.chat-cancel:active { background: var(--accent); border-color: #fff; }
.chat-toast {
  position: absolute;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 5;
  max-width: min(440px, 88vw);
  padding: 8px 12px;
  background: rgba(8, 6, 5, 0.82);
  border: 1px solid var(--line);
  color: var(--cream);
  font: 15px "VT323", monospace;
  text-align: center;
  pointer-events: none;
}
.chat-toast.hidden { display: none; }
body.touch-hall.chatting .touch-controls { opacity: 0; pointer-events: none; }
body.touch-hall.chatting .crosshair { opacity: 0.25; }
body.touch-hall .chat-bar {
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  width: calc(100vw - 20px);
  padding: 12px;
}
body.touch-hall .chat-slash { display: none; }

.start {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 70% 55% at 50% 40%, rgba(40, 28, 20, 0.9), transparent 70%),
    linear-gradient(180deg, #120e0b 0%, #060504 100%);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
body.playing .start {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.start-inner {
  text-align: center;
  max-width: 22rem;
  padding: 1.5rem;
}
.status {
  margin: 0;
  font-size: 26px;
  color: var(--cream);
  min-height: 1.2em;
  letter-spacing: 0.02em;
}
#btn-enter {
  font-family: "DotGothic16", monospace;
  font-size: 11px;
  margin-top: 1.25rem;
  padding: 14px 22px;
  min-height: 48px;
  min-width: min(240px, 80vw);
  color: var(--cream);
  background: #2a1814;
  border: 2px solid var(--cream);
  cursor: pointer;
  image-rendering: pixelated;
  touch-action: manipulation;
}
#btn-enter.hidden { display: none; }
#btn-enter:hover { background: var(--accent); border-color: #fff; }
#btn-enter:disabled { opacity: 0.45; cursor: wait; }
.stats {
  margin: 1rem 0 0;
  font-size: 20px;
  color: var(--mute);
}
.start-hint {
  margin: 0.85rem 0 0;
  font-size: 18px;
  color: var(--mute);
  line-height: 1.3;
}
.start-hint[hidden] { display: none !important; }

.hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
.hud.hidden { display: none; }
.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border: 1px solid rgba(200, 184, 154, 0.7);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.crosshair::before,
.crosshair::after {
  content: '';
  position: absolute;
  background: rgba(200, 184, 154, 0.85);
}
.crosshair::before {
  left: 4px; top: -4px; width: 1px; height: 18px;
}
.crosshair::after {
  top: 4px; left: -4px; width: 18px; height: 1px;
}

.rate-hint {
  position: absolute;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%);
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 22px;
  color: var(--cream);
  text-align: center;
  white-space: nowrap;
}
.rate-hint.hidden { display: none; }

.touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.touch-controls.is-on { display: block; }
body.touch-hall .rate-hint { bottom: 30%; }
body.touch-hall .chat-toast { bottom: calc(34% + env(safe-area-inset-bottom, 0px)); }
.touch-stick {
  pointer-events: auto;
  position: absolute;
  left: max(14px, env(safe-area-inset-left, 0px));
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 2px solid var(--cream);
  background: rgba(12, 10, 8, 0.72);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  border: 2px solid var(--cream);
  background: #2a2218;
  transform: translate(0, 0);
  will-change: transform;
}
.touch-actions {
  pointer-events: auto;
  position: absolute;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.touch-action {
  font-family: "DotGothic16", monospace;
  font-size: 8px;
  color: var(--cream);
  background: rgba(12, 10, 8, 0.78);
  border: 2px solid var(--cream);
  padding: 14px 16px;
  min-width: 92px;
  min-height: 48px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.touch-action:active,
.touch-action.is-held {
  background: var(--accent);
  border-color: #fff;
}
@media (max-width: 420px) {
  .touch-stick { width: 104px; height: 104px; }
  .touch-action { min-width: 80px; padding: 12px 12px; }
}

.auth-dialog {
  border: 2px solid var(--cream);
  background: #16120e;
  color: var(--cream);
  padding: 1.25rem 1.4rem 1.4rem;
  max-width: 22rem;
  font-family: 'VT323', monospace;
}
.auth-dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
.auth-close {
  position: absolute;
  top: 8px;
  right: 10px;
  border: 0;
  background: transparent;
  color: var(--mute);
  font-size: 22px;
  cursor: pointer;
}
.auth-copy {
  font-size: 22px;
  margin: 0.4rem 1.5rem 1rem 0;
  line-height: 1.25;
}
.auth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.auth-link {
  font-family: "DotGothic16", monospace;
  font-size: 8px;
  color: var(--cream);
  text-decoration: none;
  border: 1px solid var(--cream);
  padding: 10px 12px;
}
.auth-link:hover { background: var(--accent); }
