:root {
  color-scheme: dark;
  --bg: #070b14;
  --panel: #111827;
  --panel-alt: #1e293b;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --brand: #38bdf8;
  --gold: #fbbf24;
  --emerald: #34d399;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px 10px;
  gap: 6px;
}

body.is-fullscreen #app {
  max-width: 100%;
  padding: 4px 8px;
  gap: 4px;
}

body.is-fullscreen #journalBar {
  display: none;
}

/* Header HUD */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  flex-shrink: 0;
}

.title-block h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.meters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.meter {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.meter strong {
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* 3D Stage & Canvas */
#stage {
  position: relative;
  container-type: size;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #030712;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  padding: 2px;
}

#game {
  display: block;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: min(100cqh, calc(100cqw * 9 / 16));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 960 / 540;
  border-radius: 6px;
  outline: none;
  cursor: grab;
}

#game:active {
  cursor: grabbing;
}

/* Clue Journal & Pockets */
#journalBar {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 6px;
  flex-shrink: 0;
}

.journal-col,
.pockets-col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  min-width: 0;
}

#journalBar h2 {
  margin: 0 0 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#clueList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

#clueList li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

#clueList li.solved {
  color: var(--emerald);
  font-weight: 600;
}

#inventoryList {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  min-height: 22px;
  align-items: center;
}

.item-chip {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 11px;
  color: var(--text);
}

.item-chip[aria-pressed="true"] {
  border-color: var(--gold);
  background: rgba(251, 191, 36, 0.16);
  color: #fef08a;
}

.empty-pocket {
  font-size: 11px;
  color: var(--muted);
}

/* Controls Section */
#controls {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11.5px;
}

#promptText {
  margin: 0;
  color: #fef08a;
  font-weight: 600;
}

#liveMessage {
  margin: 0;
  color: var(--brand);
  font-size: 11px;
}

.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.action-group,
#dpad {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

button {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}

button:hover:not(:disabled) {
  border-color: var(--brand);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: #0284c7;
  border-color: #38bdf8;
  color: #ffffff;
}

button.accent {
  background: #b45309;
  border-color: #fbbf24;
  color: #fef08a;
}

#fullscreenBtn[aria-pressed="true"] {
  background: #4f46e5;
  border-color: #818cf8;
  color: #ffffff;
}

.legend {
  margin: 0;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

kbd {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  font-size: 9.5px;
}

/* Modal Dialog (Clue Readouts, 3-Dial Portal Keypad & Victory) */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 40;
}

#modal[hidden] {
  display: none;
}

#modalPanel {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: #111827;
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 2px 8px;
  font-size: 15px;
}

#modalTitle {
  margin: 0 28px 8px 0;
  font-size: 16px;
  color: #fef08a;
}

#modalBody {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#modalBody p {
  margin: 0;
}

.keypad-dials {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 6px 0;
}

.dial-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
}

.dial-numeral {
  font-size: 10px;
  color: var(--muted);
}

.dial-value {
  font-size: 22px;
  font-weight: 700;
  font-family: monospace;
  color: #fef08a;
}

#modalActions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* Compact phone viewport adjustments (360x740) */
@media (max-width: 640px) {
  #app {
    padding: 4px 6px;
    gap: 4px;
  }
  #journalBar {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .pockets-col {
    display: none;
  }
  .subtitle,
  .legend {
    display: none;
  }
  button {
    padding: 2px 6px;
    font-size: 10.5px;
  }
}
