/* Haunted House: Halloween look (SPEC 5j). Plain CSS, no external fonts. */

:root {
  --bg: #0d0716;
  --bg-deep: #06020c;
  --ink: #f3e9dc;
  --ink-soft: rgba(243, 233, 220, 0.72);
  --orange: #ff7a18;
  --orange-hot: #ffa052;
  --green: #7dff6a;
  --panel: rgba(14, 6, 24, 0.9);
  --panel-edge: rgba(255, 122, 24, 0.45);
  --error: #ff8a6b;
  --focus: #7dff6a;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The hidden attribute must win over component display rules. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ---------- 3D stage ---------- */

#game {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
  touch-action: none;
  overflow: hidden;
}

#game canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Full-screen overlays ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  background: radial-gradient(ellipse at center, rgba(40, 12, 60, 0.55), rgba(6, 2, 12, 0.82));
  touch-action: pan-y;
}

/* Loading sits above every other overlay (it comes first in the DOM). */
#screen-loading {
  z-index: 20;
}

/* Question sits low so the room stays visible above it. */
.screen-bottom {
  align-items: flex-end;
  background: rgba(6, 2, 12, 0.5);
}

.screen-bottom > .panel {
  margin: 0 auto 6vh;
}

.panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 24px 20px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.6), 0 0 32px rgba(255, 122, 24, 0.12);
}

.panel-small {
  max-width: 280px;
  text-align: center;
}

.panel-wide {
  max-width: 560px;
}

.panel-question {
  max-width: 480px;
  text-align: center;
  border-color: rgba(125, 255, 106, 0.4);
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 12px;
  color: var(--orange);
  text-shadow: 0 0 14px rgba(255, 122, 24, 0.35);
}

h2 {
  font-size: 1.6rem;
}

.title {
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  text-align: center;
  color: var(--orange);
  text-shadow: 0 0 18px rgba(255, 122, 24, 0.55), 0 0 4px rgba(125, 255, 106, 0.4);
  margin-bottom: 8px;
}

.board-heading {
  font-size: 1.15rem;
  margin: 16px 0 6px;
  color: var(--green);
  text-shadow: 0 0 10px rgba(125, 255, 106, 0.3);
}

.lede {
  margin: 0 0 18px;
  text-align: center;
  color: var(--ink);
}

.field-label {
  display: block;
  margin: 0 0 6px;
  font-weight: 600;
}

.hint {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.loading-text {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--orange);
}

.error {
  margin: 10px 0 0;
  color: var(--error);
  font-weight: 600;
}

/* An empty alert stays in the DOM (so it can announce) but takes no space. */
.error:empty {
  display: none;
}

.question {
  font-size: clamp(1.7rem, 7vw, 2.2rem);
  margin: 4px 0 18px;
  color: var(--green);
  text-shadow: 0 0 16px rgba(125, 255, 106, 0.4);
}

.score {
  margin: 4px 0 10px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--green);
  text-shadow: 0 0 14px rgba(125, 255, 106, 0.4);
}

.save-status {
  margin: 0 0 14px;
  text-align: center;
  color: var(--ink-soft);
}

.save-status[data-state="saved"] {
  color: var(--green);
}

.save-status[data-state="failed"] {
  color: var(--error);
  font-weight: 600;
}

/* ---------- Inputs and buttons (44px minimum tap target) ---------- */

input[type="text"] {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  font-size: 18px; /* 16px or more stops iOS zooming in on focus */
  color: var(--ink);
  background: #120821;
  border: 2px solid rgba(125, 255, 106, 0.5);
  border-radius: 10px;
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(125, 255, 106, 0.22);
}

input[type="text"]:disabled {
  opacity: 0.6;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  min-width: 44px;
  margin: 6px 0;
  padding: 10px 18px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 122, 24, 0.08);
  border: 2px solid var(--orange);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 120ms ease, transform 60ms ease;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 122, 24, 0.22);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--orange);
  color: #1a0a05;
  text-shadow: none;
}

.btn-primary:hover:not(:disabled) {
  background: var(--orange-hot);
}

.btn-answer {
  flex: 1 1 0;
  width: auto;
  min-height: 60px;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.answer-row {
  display: flex;
  gap: 12px;
}

.btn-small {
  width: auto;
  min-height: 44px;
  margin: 0;
  padding: 8px 14px;
  font-size: 14px;
  background: rgba(14, 6, 24, 0.85);
}

/* ---------- HUD (room label, mute, pause) ---------- */

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  pointer-events: none;
}

.hud-room {
  margin: 0;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(14, 6, 24, 0.82);
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  pointer-events: none;
}

.hud-buttons {
  display: flex;
  gap: 8px;
  margin-left: auto;
  pointer-events: none;
}

.hud-buttons .btn {
  pointer-events: auto;
}

/* ---------- Touch controls ---------- */

/* The key hint only makes sense with a keyboard; touch devices see the tap hint instead. */
body.is-touch .keyboard-hint,
body:not(.is-touch) .touch-hint {
  display: none;
}

/* Hidden unless body has is-touch (set by ui.js on touch devices). */
body:not(.is-touch) #touch-controls {
  display: none;
}

#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

#touch-stick,
#touch-look {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#touch-stick {
  left: 0;
  bottom: 0;
  width: 50%;
  height: 55%;
}

#touch-look {
  right: 0;
  top: 0;
  width: 50%;
  height: 100%;
}

#touch-stick::before,
#touch-look::before {
  position: absolute;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(243, 233, 220, 0.35);
  pointer-events: none;
}

#touch-stick::before {
  content: "Walk";
  left: 16px;
  bottom: 14px;
}

#touch-look::before {
  content: "Drag to look";
  right: 16px;
  bottom: 14px;
}

/* ---------- Flash overlay (scares) ---------- */

#flash {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #fff4e0;
  opacity: 0;
  pointer-events: none;
}

/* ---------- Leaderboard ---------- */

.status {
  margin: 0 0 8px;
  color: var(--ink-soft);
}

.status:empty {
  display: none;
}

.status[data-kind="error"] {
  color: var(--error);
  font-weight: 600;
}

.board {
  list-style: none;
  margin: 0;
  padding: 0;
}

.board li {
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1fr) auto;
  column-gap: 8px;
  row-gap: 2px;
  align-items: baseline;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(243, 233, 220, 0.08);
}

.board .lb-rank {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.board .lb-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.board .lb-score {
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.board .lb-date {
  grid-column: 2 / 4;
  font-size: 13px;
  color: var(--ink-soft);
}

.board li.me {
  background: rgba(255, 122, 24, 0.2);
  border-radius: 8px;
  border-bottom-color: transparent;
}

.board li.me .lb-name::after {
  content: " (you)";
  font-size: 13px;
  font-weight: 500;
  color: var(--orange-hot);
}

.board li:empty {
  display: none;
}

/* The note is a single line of text, so it skips the three-column board grid. */
.board li.lb-empty {
  display: block;
  border-bottom: 0;
  font-style: italic;
  opacity: 0.7;
  padding: 0.5rem 0;
}

#screen-leaderboard .btn {
  margin-top: 16px;
}

/* ---------- Narrow phones (320px) ---------- */

@media (max-width: 360px) {
  .screen {
    padding: 16px;
  }

  .panel {
    padding: 20px 16px;
  }

  .btn-answer {
    font-size: 20px;
  }

  .hud {
    padding: 8px 16px;
  }

  .hud-room {
    font-size: 13px;
    padding: 7px 12px;
  }

  .btn-small {
    padding: 8px 10px;
  }
}

/* ---------- Short landscape screens (phones turned sideways) ---------- */

@media (max-height: 480px) {
  .panel {
    padding: 16px 18px;
  }

  h2 {
    font-size: 1.35rem;
  }

  .title {
    font-size: 2rem;
  }

  .hint {
    margin-top: 8px;
  }
}
