:root {
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.18);
  --bg-dark: #050505;
  --surface: rgba(11, 16, 28, 0.9);
  --surface-strong: rgba(6, 10, 18, 0.95);
  --surface-line: rgba(148, 163, 184, 0.18);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-purple: #8b5cf6;
  --accent-cyan: #22d3ee;
  --danger: #ef4444;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Press Start 2P', cursive;
  background:
    radial-gradient(circle at 15% 18%, rgba(37, 99, 235, 0.16), transparent 26%),
    radial-gradient(circle at 82% 14%, rgba(139, 92, 246, 0.14), transparent 22%),
    linear-gradient(180deg, #040507 0%, #070b12 45%, #050505 100%);
  color: var(--text-main);
  min-height: 100vh;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.game-container {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 96px 24px 28px;
  display: grid;
  gap: 16px;
}

.header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
}

.title-block {
  display: grid;
  gap: 12px;
  max-width: 760px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(96, 165, 250, 0.18);
  background: rgba(37, 99, 235, 0.12);
  color: #dbeafe;
  font-size: 0.56rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(1.9rem, 4vw, 3rem);
  color: #dbeafe;
  text-shadow:
    0 0 22px rgba(37, 99, 235, 0.35),
    0 0 40px rgba(139, 92, 246, 0.14);
  line-height: 1.1;
}

.subtitle {
  max-width: 760px;
  color: var(--text-muted);
  font-size: 0.66rem;
  line-height: 1.8;
}

.score-container {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
}

.hud-cluster {
  display: grid;
  gap: 10px;
}

.score-pill,
.canvas-panel,
.overlay-card,
.result-card {
  border: 1px solid var(--surface-line);
  background: linear-gradient(180deg, var(--surface), var(--surface-strong));
  box-shadow:
    0 22px 46px -28px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.score-pill {
  min-height: 76px;
  border-radius: 16px;
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  align-content: center;
}

.score-pill.muted {
  background: linear-gradient(180deg, rgba(11, 15, 24, 0.88), rgba(6, 8, 14, 0.95));
}

.score-label {
  color: var(--text-muted);
  font-size: 0.54rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.score-pill strong {
  color: var(--text-main);
  font-size: 1rem;
}

.canvas-panel {
  position: relative;
  padding: 14px;
  border-radius: 24px;
  min-height: 500px;
  overflow: hidden;
}

canvas {
  width: 100%;
  max-width: 100%;
  display: block;
  border-radius: 16px;
  background: #070b14;
  image-rendering: pixelated;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.overlay-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 40px));
  border-radius: 18px;
  padding: 24px;
  display: grid;
  gap: 16px;
  text-align: left;
  z-index: 4;
  touch-action: manipulation;
}

.overlay-card.hidden {
  display: none !important;
}

.overlay-kicker {
  color: #93c5fd;
  font-size: 0.56rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.overlay-card h2 {
  color: var(--text-main);
  font-size: 1.25rem;
  line-height: 1.2;
}

.overlay-copy,
.overlay-instructions {
  color: var(--text-muted);
  font-size: 0.62rem;
  line-height: 1.8;
}

.story-points {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.story-points span {
  padding: 0.65rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.62);
  color: #dbeafe;
  font-size: 0.52rem;
  line-height: 1;
}

.status-panel {
  width: min(340px, calc(100vw - 120px));
  border: 1px solid rgba(96, 165, 250, 0.16);
  border-radius: 16px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(10, 15, 26, 0.9), rgba(7, 11, 19, 0.96));
  box-shadow:
    0 22px 46px -28px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-12px);
  pointer-events: auto;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    visibility 0.25s ease,
    border-color 0.25s ease,
    box-shadow 0.25s ease;
}

.status-panel.is-highlighted {
  border-color: rgba(139, 92, 246, 0.42);
  box-shadow:
    0 22px 52px -24px rgba(79, 70, 229, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.status-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0.38rem 0.78rem;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.18);
  background: rgba(34, 211, 238, 0.08);
  color: #cffafe;
  font-size: 0.5rem;
  line-height: 1;
}

.status-chip-muted {
  border-color: rgba(139, 92, 246, 0.2);
  background: rgba(139, 92, 246, 0.1);
  color: #ede9fe;
}

#story-ticker {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 0.52rem;
  line-height: 1.8;
}

.result-summary {
  color: var(--text-muted);
  font-size: 0.58rem;
  line-height: 1.9;
}

button {
  justify-self: end;
  min-height: 46px;
  padding: 0.85rem 1.2rem;
  border: 1px solid #404040;
  border-radius: 9999px;
  background: transparent;
  color: #d4d4d4;
  font-size: 0.64rem;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease,
    transform 0.15s ease;
  touch-action: manipulation;
}

button:hover {
  background-color: #262626;
  color: #f5f5f5;
  border-color: #525252;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.result-card {
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.result-card span {
  color: var(--text-muted);
  font-size: 0.52rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result-card strong {
  color: var(--text-main);
  font-size: 0.84rem;
  line-height: 1.5;
}

@media (max-width: 960px) {
  .game-container {
    padding-inline: 16px;
  }

  .header {
    grid-template-columns: 1fr;
  }

  .score-container {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-panel {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .game-container {
    padding-top: 88px;
    gap: 14px;
  }

  h1 {
    font-size: 1.45rem;
  }

  .subtitle,
  .overlay-copy,
  .overlay-instructions {
    font-size: 0.55rem;
  }

  .score-pill {
    min-height: 68px;
    padding: 12px;
  }

  .score-pill strong {
    font-size: 0.86rem;
  }

  .overlay-card {
    padding: 18px;
    width: min(520px, calc(100% - 28px));
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .story-points span {
    font-size: 0.48rem;
  }
}

@media (max-width: 540px) {
  .game-container {
    padding-inline: 12px;
    padding-bottom: 20px;
  }

  .score-container {
    grid-template-columns: 1fr;
  }

  .canvas-panel {
    padding: 10px;
    border-radius: 18px;
  }

  .overlay-card h2 {
    font-size: 0.95rem;
  }
}

/* Immersive fullscreen layout for Creator Dash */
.game-container {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  display: block;
}

.header {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 7;
  display: block;
  pointer-events: none;
}

.header .back-btn {
  pointer-events: auto;
}

.title-block {
  display: none;
}

.score-container {
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
  width: min(340px, calc(100vw - 120px));
  opacity: 0;
  visibility: hidden;
  transform: translateY(-12px);
  pointer-events: auto;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    visibility 0.25s ease;
}

.game-container[data-mode='playing'] .score-container {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.game-container[data-mode='playing'] .status-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.canvas-panel {
  position: fixed;
  inset: 0;
  min-height: 100vh;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  display: grid;
  place-items: center;
  overflow: hidden;
}

canvas {
  --creator-dash-max-w: calc(100vw - 56px);
  --creator-dash-max-h: calc(100vh - 96px);
  width: min(var(--creator-dash-max-w), calc(var(--creator-dash-max-h) * 1200 / 460));
  height: auto;
  max-width: var(--creator-dash-max-w);
  max-height: var(--creator-dash-max-h);
  aspect-ratio: 1200 / 460;
  border: none;
  border-radius: 0;
}

.overlay-card {
  width: min(700px, calc(100vw - 40px));
  padding: 28px;
  border-radius: 22px;
  backdrop-filter: blur(18px);
}

#start-screen {
  justify-items: center;
  text-align: center;
}

#start-screen .overlay-kicker {
  justify-self: center;
}

#start-screen h2 {
  font-size: clamp(2rem, 6vw, 4.2rem);
  line-height: 1.05;
}

#start-screen .overlay-copy,
#start-screen .overlay-instructions {
  max-width: 60ch;
  text-align: center;
}

#start-screen button {
  justify-self: center;
}

#game-over-screen {
  width: min(640px, calc(100vw - 40px));
}

@media (max-width: 960px) {
  .score-container {
    width: min(320px, calc(100vw - 108px));
  }

  .status-panel {
    width: min(320px, calc(100vw - 108px));
  }
}

@media (max-width: 720px) {
  .header {
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
  }

  .score-container {
    width: min(280px, calc(100vw - 104px));
  }

  .status-panel {
    width: min(280px, calc(100vw - 104px));
  }

  .score-pill {
    min-height: 64px;
    padding: 12px 14px;
  }

  .score-pill strong {
    font-size: 0.86rem;
  }

  .overlay-card {
    width: min(560px, calc(100vw - 24px));
    padding: 20px;
  }

  #start-screen h2 {
    font-size: clamp(1.6rem, 8vw, 3rem);
  }

  canvas {
    --creator-dash-max-w: calc(100vw - 24px);
    --creator-dash-max-h: calc(100vh - 72px);
  }
}

@media (max-width: 540px) {
  .score-container {
    width: min(250px, calc(100vw - 96px));
  }

  .status-panel {
    width: min(250px, calc(100vw - 96px));
    padding: 10px 12px;
  }

  .overlay-card {
    width: calc(100vw - 18px);
    padding: 18px;
  }

  .status-chip,
  .story-points span {
    font-size: 0.44rem;
  }

  #story-ticker,
  .result-summary {
    font-size: 0.5rem;
  }
}

@media (max-width: 768px), (pointer: coarse) {
  /* Move HUD scores below the back button so they never overlap on mobile */
  .header {
    top: calc(max(12px, env(safe-area-inset-top)) + 56px);
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: center;
  }
  .hud-cluster {
    width: 100%;
    justify-items: center;
  }
  .score-container {
    width: min(360px, calc(100vw - 28px));
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .score-pill {
    min-height: 48px;
    padding: 8px 12px;
    border-radius: 12px;
    gap: 4px;
  }
  .score-label {
    font-size: 0.48rem;
    letter-spacing: 0.08em;
  }
  .score-pill strong {
    font-size: 0.78rem;
  }

  canvas {
    --creator-dash-max-w: calc(100vw - 12px);
    --creator-dash-max-h: calc(100svh - 88px);
  }

  .game-container[data-mode='playing'] canvas {
    --creator-dash-max-h: calc(100svh - 206px);
  }

  .overlay-card {
    width: min(calc(100vw - 26px), 356px);
    max-height: calc(100svh - 28px);
    padding: 18px 16px;
    gap: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    text-align: center;
    justify-items: center;
    touch-action: pan-y manipulation;
    -webkit-overflow-scrolling: touch;
  }

  .overlay-card .overlay-copy,
  .overlay-card .overlay-instructions,
  .result-summary {
    font-size: 0.54rem;
    line-height: 1.72;
    text-align: center;
  }

  #start-screen {
    width: min(calc(100vw - 26px), 340px);
  }

  #start-screen .story-points {
    display: none;
  }

  #start-screen h2,
  .overlay-card h2 {
    font-size: clamp(1.35rem, 6vw, 1.9rem);
    line-height: 1.08;
  }

  #start-screen button,
  #restart-button {
    justify-self: center;
    width: min(100%, 280px);
  }

  #game-over-screen .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .result-card {
    padding: 12px 10px;
    gap: 8px;
  }

  .result-card span {
    font-size: 0.44rem;
  }

  .result-card strong {
    font-size: 0.68rem;
    line-height: 1.45;
  }
}

/* Portrait mobile: let the runner span more of the viewport height */
@media (orientation: portrait) and (max-width: 768px) {
  canvas {
    --creator-dash-max-w: calc(100vw - 8px);
    --creator-dash-max-h: calc(100svh - 116px);
  }

  .game-container[data-mode='playing'] canvas {
    --creator-dash-max-h: calc(100svh - 292px);
  }

  .overlay-card {
    width: min(calc(100vw - 20px), 340px);
    max-height: calc(100svh - 22px);
    padding: 16px 14px;
    gap: 10px;
  }

  #start-screen h2,
  .overlay-card h2 {
    font-size: clamp(1.25rem, 5vw, 1.75rem);
  }
}

/* Mobile on-screen jump / slide pad (show only while playing) */
#mobile-controls {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 14px max(14px, env(safe-area-inset-bottom)) 14px;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  z-index: 30;
  pointer-events: none;
}
#mobile-controls .mc-btn {
  pointer-events: auto;
  width: 86px;
  height: 86px;
  min-width: 86px;
  min-height: 86px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(96, 165, 250, 0.55);
  background: rgba(15, 5, 25, 0.6);
  color: #fff;
  font-family: 'Press Start 2P', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(4px);
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.08s ease,
    background-color 0.12s ease,
    border-color 0.12s ease;
}
#mobile-controls .mc-btn span {
  font-size: 0.42rem;
  opacity: 0.78;
}
#mobile-controls .mc-btn:active,
#mobile-controls .mc-btn.is-active {
  background: rgba(37, 99, 235, 0.35);
  border-color: var(--primary);
  transform: scale(0.96);
}
#mc-slide {
  border-color: rgba(139, 92, 246, 0.6);
  background: rgba(20, 8, 32, 0.62);
}

#mc-slide:active,
#mc-slide.is-active {
  background: rgba(139, 92, 246, 0.35);
}

@media (max-width: 420px), (pointer: coarse) {
  #mobile-controls .mc-btn {
    width: 78px;
    height: 78px;
    min-width: 78px;
    min-height: 78px;
    font-size: 1rem;
  }

  #mobile-controls .mc-btn span {
    font-size: 0.38rem;
  }
}

@media (max-width: 768px), (pointer: coarse) {
  body[data-creator-dash-mode='playing'] #mobile-controls {
    display: flex;
  }
}
