:root {
  --paper: #efe0c8;
  --earth: #6b3d2b;
  --earth-deep: #2d1a12;
  --green: #6a7b44;
  --ink: #100d0a;
  --panel: rgba(17, 13, 10, 0.84);
  --panel-soft: rgba(17, 13, 10, 0.58);
  --line: rgba(239, 224, 200, 0.18);
  --accent: #f1c98f;
  --beacon: #89f0d0;
  --hud-green: #7cff71;
  --hud-green-dim: rgba(124, 255, 113, 0.25);
  --scanline-opacity: 0;
  --scanline-pitch: 4px;
  --scanline-column-opacity: 0.04;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #060504;
  color: var(--paper);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

html.player-page,
body.player-view {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.player-view {
  position: fixed;
  inset: 0;
}

body.player-view * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.player-view::before,
body.map-view::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: var(--scanline-opacity);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.06) 50%, transparent 50%),
    linear-gradient(90deg, rgba(255, 180, 120, var(--scanline-column-opacity)), transparent 45%);
  background-size: 100% var(--scanline-pitch), var(--scanline-pitch) 100%;
  mix-blend-mode: lighten;
}

.control-view {
  min-height: 100%;
  background: #101419;
  color: #f2eadb;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.control-shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.control-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.control-header h1 {
  max-width: 820px;
  margin: 6px 0 0;
  color: #fff7e8;
  font-size: clamp(1.6rem, 2.6vw, 3.2rem);
  line-height: 1;
}

.connection-status {
  min-width: 94px;
  border: 1px solid rgba(242, 234, 219, 0.22);
  padding: 8px 10px;
  color: rgba(242, 234, 219, 0.8);
  text-align: center;
  text-transform: uppercase;
  font-size: 0.74rem;
  font-weight: 700;
}

.connection-status[data-status="online"] {
  border-color: rgba(105, 220, 156, 0.55);
  color: #9ff0be;
}

.connection-status[data-status="connecting"] {
  border-color: rgba(245, 199, 111, 0.6);
  color: #f5c76f;
}

.control-main {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr);
  gap: 16px;
  align-items: start;
  min-height: calc(100vh - 130px);
}

.state-column,
.notes-pane {
  min-height: 0;
}

.state-column {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
}

.control-status {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid rgba(242, 234, 219, 0.14);
  background: rgba(242, 234, 219, 0.14);
}

.control-status > div {
  min-width: 0;
  padding: 16px;
  background: #171d23;
}

.control-status strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: #ffffff;
  font-size: 1.25rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-actions {
  display: block;
}

.primary-control,
.state-list button {
  appearance: none;
  border: 1px solid rgba(242, 234, 219, 0.18);
  background: #202831;
  color: #f2eadb;
  font: inherit;
  cursor: pointer;
}

.primary-control {
  width: 100%;
  min-height: 54px;
  padding: 0 22px;
  background: #e3b85e;
  color: #121212;
  font-weight: 800;
}

.primary-control:hover,
.primary-control:focus-visible,
.state-list button:hover,
.state-list button:focus-visible {
  border-color: rgba(255, 255, 255, 0.58);
  outline: none;
}

.state-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  padding-right: 6px;
  scrollbar-color: rgba(227, 184, 94, 0.75) rgba(242, 234, 219, 0.08);
}

.state-list button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  min-height: 58px;
  padding: 12px 14px;
  text-align: left;
}

.state-list button span {
  align-self: start;
  color: #e3b85e;
  font-size: 0.78rem;
  font-weight: 800;
}

.state-list button strong {
  min-width: 0;
  color: #ffffff;
  font-size: 0.94rem;
  line-height: 1.2;
}

.state-list button.is-active {
  border-color: #e3b85e;
  background: #2d2b22;
}

.notes-pane {
  display: grid;
  gap: 16px;
}

.speaker-notes {
  min-height: calc(100vh - 240px);
  border: 1px solid rgba(242, 234, 219, 0.14);
  background: #171d23;
}

.notes-header {
  padding: 22px 26px 16px;
  border-bottom: 1px solid rgba(242, 234, 219, 0.12);
}

.notes-type {
  display: block;
  margin-bottom: 8px;
  color: #e3b85e;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.notes-header h2 {
  margin: 0;
  color: #fff7e8;
  font-size: clamp(1.4rem, 2.4vw, 2.8rem);
  line-height: 1.08;
}

.notes-body {
  max-width: 76ch;
  padding: 24px 26px 34px;
  color: rgba(255, 247, 232, 0.92);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(1.15rem, 1.5vw, 1.45rem);
  line-height: 1.58;
  white-space: pre-wrap;
}

@media (max-width: 720px) {
  .control-shell {
    width: min(100vw - 24px, 1120px);
    padding-top: 18px;
  }

  .control-header,
  .control-main,
  .control-status {
    grid-template-columns: 1fr;
  }

  .control-header {
    display: grid;
  }

  .state-column {
    position: static;
    max-height: none;
  }

  .state-list {
    max-height: 36vh;
  }
}

body.player-view.scanlines-disabled::before,
body.map-view.scanlines-disabled::before {
  display: none;
}

.screen-shell,
.map-shell {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: 0;
}

.viewport-frame,
.map-layout {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #050403;
}

.scene-root {
  position: absolute;
  inset: 0;
}

.scene-root,
.scene-root canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.player-view .scene-root,
.player-view .scene-root canvas,
.player-view .drag-indicator {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.player-view .scene-root canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.player-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.join-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  border: 0;
  background: #050403;
  color: var(--paper);
  font: 700 1.2rem system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

.join-gate.is-hidden {
  display: none;
}

.media-prime-host {
  position: fixed;
  left: -1px;
  top: -1px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.media-prime-video {
  width: 1px;
  height: 1px;
}

.drag-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.drag-indicator line {
  stroke: rgba(241, 201, 143, 0.85);
  stroke-width: 0.55;
}

.drag-indicator circle {
  fill: rgba(241, 201, 143, 0.9);
}

.headlight-hud {
  position: absolute;
  left: 50%;
  bottom: 28px;
  display: flex;
  gap: 8px;
  transform: translateX(-50%);
}

.headlight-brick {
  width: 22px;
  height: 10px;
  border: 2px solid var(--hud-green);
  background: transparent;
  box-shadow: 0 0 10px rgba(124, 255, 113, 0.12);
}

.headlight-brick.is-on {
  background: var(--hud-green);
  box-shadow: 0 0 12px rgba(124, 255, 113, 0.35);
}

.map-panel,
.map-header {
  background: var(--panel-soft);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
}

.map-header h1 {
  margin: 6px 0 8px;
  font-size: clamp(1.8rem, 2.4vw, 3rem);
  line-height: 1;
  letter-spacing: 0.02em;
}

.map-panel p {
  margin: 0;
  color: rgba(239, 224, 200, 0.84);
  line-height: 1.4;
}

.eyebrow,
.hud-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: rgba(239, 224, 200, 0.72);
}

.map-stats strong {
  font-size: 1rem;
}

.map-view .map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
}

.map-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
  padding: 16px 18px;
  border-radius: 18px;
}

.map-stats {
  display: flex;
  gap: 18px;
}

#map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, rgba(102, 62, 43, 0.78), rgba(12, 10, 8, 1));
}

.map-panel {
  margin: 18px;
  border-radius: 20px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.scene-buttons {
  display: grid;
  gap: 10px;
}

.scene-buttons button {
  appearance: none;
  border: 1px solid rgba(241, 201, 143, 0.28);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(241, 201, 143, 0.08);
  color: var(--paper);
  font: inherit;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.scene-buttons button:hover,
.scene-buttons button:focus-visible {
  background: rgba(241, 201, 143, 0.16);
  transform: translateY(-1px);
}

@media (max-width: 960px) {
  .map-view .map-layout {
    grid-template-columns: 1fr;
  }

  .map-panel {
    margin-top: 0;
  }
}
