:root {
  --bg: #0c0630;
  --surface: #1a0f4a;
  --surface-raised: #241663;
  --border: #6b5cff;
  --border-dark: #3d2780;
  --text: #f4f4f4;
  --text-muted: #a898e8;
  --accent: #ffe066;
  --accent-soft: rgba(255, 224, 102, 0.16);
  --player: #66ccff;
  --npc: #ffcc55;
  --rapport-positive: #44ff44;
  --rapport-negative: #ff4444;
  --scene-desc: #55ff88;
  --shadow: 0 0 0 2px var(--border-dark), 0 8px 0 rgba(0, 0, 0, 0.45);
  --font-body: "Handjet", system-ui, sans-serif;
  --font-display: "Jersey 25", "Handjet", sans-serif;
  --text-chat: 1.2rem;
  --text-ui: 1.2rem;
  --text-label: 0.8rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background:
    linear-gradient(180deg, #1a0a52 0%, var(--bg) 45%, #06021a 100%);
  color: var(--text);
  image-rendering: pixelated;
}

.app-layout {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  max-width: 1120px;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
}

.app-layout--solo {
  max-width: 860px;
}

.app-layout .app {
  flex: 1;
  min-width: 0;
  max-width: none;
  margin: 0;
  padding: 0;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
}

.stage {
  display: grid;
  gap: 0.75rem;
}

.stage.hidden {
  display: none;
}

.intro-screen {
  display: grid;
  gap: 0.85rem;
  width: 100%;
}

.intro-screen.hidden {
  display: none;
}

.intro-frame {
  overflow: hidden;
  border: 2px solid var(--border);
  border-radius: 0.85rem;
  background: #000;
  box-shadow: var(--shadow);
  width: 100%;
  aspect-ratio: 16 / 9.9;
  max-height: 46vh;
}

.intro-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.intro-instructions {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid #44ff88;
  border-radius: 0.85rem;
  background: rgba(68, 255, 136, 0.08);
  box-shadow: inset 0 0 0 1px rgba(68, 255, 136, 0.2);
}

.intro-instructions p {
  margin: 0;
  color: var(--scene-desc);
  font-size: var(--text-chat);
  font-weight: 400;
  line-height: 1.55;
  text-align: left;
  text-shadow: 0 0 8px rgba(85, 255, 136, 0.35);
}

.start-btn {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid #c9a000;
  border-radius: 0.7rem;
  background: var(--accent);
  color: #1a0f4a;
  font-family: var(--font-body);
  font-size: var(--text-chat);
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
  box-shadow: 0 4px 0 #b8860b;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.start-btn-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
}

.start-btn-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(26, 15, 74, 0.2);
  border-top-color: #1a0f4a;
  border-radius: 50%;
  animation: startBtnSpin 0.75s linear infinite;
}

.start-btn:not(.start-btn--loading) .start-btn-spinner {
  display: none;
}

@keyframes startBtnSpin {
  to {
    transform: rotate(360deg);
  }
}

.start-btn:hover:not(:disabled) {
  background: #fff099;
  transform: translateY(-1px);
  box-shadow: 0 5px 0 #b8860b;
}

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

.play-panel {
  display: grid;
  gap: 0.65rem;
  width: 100%;
}

.scene-frame {
  position: relative;
  overflow: hidden;
  border: 2px solid var(--border);
  border-radius: 0.85rem;
  background: #000;
  box-shadow: var(--shadow);
  width: 100%;
  aspect-ratio: 16 / 9.9;
  max-height: 46vh;
}

.scene-frame .scene-image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transform: scale(1) rotate(0deg);
  filter: blur(0);
  transition: opacity 2s ease;
}

.scene-frame[data-transition="fade"] .scene-image.is-visible {
  opacity: 1;
}

.scene-frame[data-transition="spiral"] .scene-image {
  transition: none;
}

.scene-frame .scene-image.is-spiral-in {
  opacity: 1;
  animation: sceneSpiralIn 2s ease forwards;
}

.scene-frame .scene-image.is-spiral-out {
  animation: sceneSpiralOut 2s ease forwards;
}

@keyframes sceneSpiralIn {
  from {
    opacity: 0;
    transform: scale(0.15) rotate(-540deg);
    filter: blur(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: blur(0);
  }
}

@keyframes sceneSpiralOut {
  from {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: blur(0);
  }
  to {
    opacity: 0;
    transform: scale(0.15) rotate(540deg);
    filter: blur(10px);
  }
}

.scene-frame .scene-image.is-visible {
  opacity: 1;
}

.scene-frame.game-over {
  background: #000;
}

.dialogue-panel {
  display: grid;
  gap: 0.65rem;
  width: 100%;
  padding: 0.85rem;
  border: 2px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface);
  box-shadow: inset 0 0 24px rgba(107, 92, 255, 0.12);
}

.dialogue {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 140px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 0.15rem;
}

.message {
  max-width: 92%;
  padding: 0.65rem 0.8rem;
  border-radius: 0.75rem;
  line-height: 1.5;
  font-size: var(--text-chat);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message .label {
  display: block;
  margin-bottom: 0.25rem;
  font-family: var(--font-display);
  font-size: var(--text-label);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.message-intro {
  align-self: stretch;
  width: 100%;
  max-width: 100%;
  padding: 0.85rem 1rem;
  background: rgba(85, 255, 136, 0.08);
  border: 2px solid rgba(85, 255, 136, 0.55);
  color: var(--scene-desc);
  font-size: var(--text-chat);
  font-weight: 400;
  line-height: 1.55;
  text-align: left;
  text-shadow: 0 0 8px rgba(85, 255, 136, 0.3);
}

.message-intro .text {
  white-space: pre-line;
}

.message-system {
  align-self: center;
  max-width: 100%;
  background: rgba(168, 152, 232, 0.08);
  border: 2px solid var(--border-dark);
  color: var(--text-muted);
  text-align: center;
  font-size: var(--text-chat);
}

.message-dice {
  align-self: stretch;
  width: 100%;
  max-width: 100%;
  background: rgba(255, 102, 255, 0.1);
  border: 2px solid #ff66ff;
  color: #ffb3ff;
  font-size: var(--text-chat);
  font-weight: 400;
  text-align: center;
  text-shadow: 0 0 6px rgba(255, 102, 255, 0.35);
}

.message-player {
  align-self: flex-end;
  background: rgba(102, 204, 255, 0.12);
  border: 2px solid rgba(102, 204, 255, 0.55);
}

.message-player .label {
  color: var(--player);
}

.message-npc {
  align-self: flex-start;
  background: rgba(255, 204, 85, 0.1);
  border: 2px solid rgba(255, 204, 85, 0.45);
}

.message-npc .label {
  color: var(--npc);
}

.message-rapport {
  display: none;
}

.camera-panel {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  padding: 0.6rem;
  border: 2px solid var(--border);
  border-radius: 0.7rem;
  background: var(--surface-raised);
}

.camera-panel.hidden {
  display: none;
}

.camera-video {
  width: 100%;
  max-width: 320px;
  border-radius: 0.6rem;
  background: #000;
  transform: scaleX(-1);
}

.camera-video.hidden,
.camera-canvas {
  display: none;
}

.camera-actions {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.camera-actions.hidden {
  display: none;
}

.camera-btn {
  flex: 1;
  padding: 0.7rem 1rem;
  border: 2px solid #2bb673;
  border-radius: 0.7rem;
  background: #2bb673;
  color: #06281a;
  font-family: var(--font-body);
  font-size: var(--text-chat);
  line-height: 1.4;
  cursor: pointer;
  box-shadow: 0 3px 0 #1e8f59;
}

.camera-btn--decline {
  border-color: #d6455d;
  background: #d6455d;
  color: #2a060e;
  box-shadow: 0 3px 0 #a82c42;
}

#camera-skip-btn {
  width: 100%;
}

.camera-btn.hidden {
  display: none;
}

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

.camera-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted, #b9b4e0);
  text-align: center;
}

.camera-status.error {
  color: #ff8a8a;
}

.choice-row {
  display: grid;
  gap: 0.5rem;
}

.choice-row.hidden {
  display: none;
}

.choice-btn {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 0.7rem;
  background: var(--surface-raised);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-chat);
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #fff8cc;
}

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

.continue-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #c9a000;
  border-radius: 0.7rem;
  background: var(--accent);
  color: #1a0f4a;
  font-family: var(--font-body);
  font-size: var(--text-chat);
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
  box-shadow: 0 3px 0 #b8860b;
}

.continue-btn.hidden {
  display: none;
}

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

.roll-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #cc44ff;
  border-radius: 0.7rem;
  background: #cc44ff;
  color: #1a0f4a;
  font-family: var(--font-body);
  font-size: var(--text-chat);
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
  box-shadow: 0 3px 0 #9922cc;
}

.roll-btn.hidden {
  display: none;
}

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

.rapport-meter.hidden {
  display: none;
}

.stats-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.65rem;
  width: 100%;
}

.stats-row.hidden {
  display: none;
}

.interaction-counter {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex: 0 0 auto;
  min-width: 6.5rem;
  padding: 0.65rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface);
}

.interaction-label {
  font-family: var(--font-display);
  font-size: var(--text-label);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.interaction-value {
  font-size: var(--text-ui);
  font-weight: 400;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 6px rgba(255, 224, 102, 0.35);
}

.interaction-value.low {
  color: #ffaa00;
}

.interaction-value.out {
  color: var(--rapport-negative);
}

.input-row.hidden {
  display: none;
}

.rapport-meter {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface);
}

.rapport-label {
  font-family: var(--font-display);
  font-size: var(--text-label);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.rapport-track {
  position: relative;
  flex: 1;
  height: 0.55rem;
  min-height: 0;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--rapport-negative) 0%,
    #ffcc00 50%,
    var(--rapport-positive) 100%
  );
  opacity: 0.95;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45);
}

.rapport-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  height: 50%;
  pointer-events: none;
}

.rapport-marker {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.35rem;
  height: 1rem;
  margin-top: -0.5rem;
  margin-left: -0.175rem;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.65);
  transition: left 0.25s ease;
}

.rapport-value {
  font-size: var(--text-ui);
  font-weight: 400;
  color: var(--rapport-positive);
  min-width: 2rem;
  text-align: right;
  text-shadow: 0 0 6px rgba(68, 255, 68, 0.35);
}

.rapport-value.negative {
  color: var(--rapport-negative);
  text-shadow: 0 0 6px rgba(255, 68, 68, 0.35);
}

.rapport-value.neutral {
  color: var(--text-muted);
  text-shadow: none;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.input-row input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--border-dark);
  border-radius: 0.7rem;
  background: #12082e;
  color: var(--text);
  font: inherit;
  font-size: var(--text-ui);
}

.input-row input::placeholder {
  color: var(--text-muted);
}

.input-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 224, 102, 0.25);
}

.input-row input:disabled {
  opacity: 0.55;
}

.input-row button {
  padding: 0.7rem 1rem;
  border: 2px solid #c9a000;
  border-radius: 0.7rem;
  background: var(--accent);
  color: #1a0f4a;
  font-family: var(--font-body);
  font-size: var(--text-chat);
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
  box-shadow: 0 3px 0 #b8860b;
}

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

.status-line {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-ui);
}

.status-line.error {
  color: var(--rapport-negative);
  text-shadow: 0 0 6px rgba(255, 68, 68, 0.35);
}

#dialogue-status-top {
  align-self: stretch;
  width: 100%;
  max-width: 100%;
}

#dialogue-status-top.is-error {
  background: rgba(255, 68, 68, 0.08);
  border-color: var(--rapport-negative);
  color: var(--rapport-negative);
  text-shadow: 0 0 6px rgba(255, 68, 68, 0.35);
}

.end-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.restart-btn {
  flex: 1;
  width: 100%;
  padding: 0.65rem 1rem;
  border: 2px solid var(--border);
  border-radius: 0.7rem;
  background: var(--surface-raised);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: var(--text-chat);
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.restart-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.restart-btn.hidden {
  display: none;
}

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

.prize-btn {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.prize-btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--surface);
}

.debug-panel {
  flex: 0 0 13.5rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.debug-panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-label);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.debug-panel-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-label);
  line-height: 1.35;
}

.debug-scene-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.debug-scene-btn {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border-dark);
  border-radius: 0.5rem;
  background: var(--surface-raised);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-label);
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.debug-scene-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #fff8cc;
}

.debug-scene-btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.debug-scene-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.debug-scene-kind {
  display: block;
  margin-top: 0.15rem;
  color: var(--text-muted);
  font-size: 0.65rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

@media (max-width: 640px) {
  .app-layout {
    flex-direction: column;
  }

  .debug-panel {
    flex: none;
    width: 100%;
    position: static;
    max-height: 12rem;
  }

  .scene-frame {
    max-height: none;
  }
}
