:root {
  --ink: #1f2340;
  --muted: #667085;
  --panel: rgba(255, 255, 255, 0.92);
  --gold: #ffd84d;
  --pink: #ff7db8;
  --cyan: #5ed9ff;
  --green: #88e06f;
  --shadow: 0 18px 52px rgba(31, 35, 64, 0.24);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #15172d;
  color: var(--ink);
  font-family: Arial, "Helvetica Neue", sans-serif;
  letter-spacing: 0;
  overscroll-behavior-x: none;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255, 240, 106, .36), transparent 42%),
    linear-gradient(160deg, #190d46 0%, #293b93 42%, #126f8a 74%, #12243d 100%);
  overflow-x: hidden;
}

body.is-playing {
  overflow: hidden;
  touch-action: none;
}

body.is-run-view {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 12px;
}

.hud {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(128px, 1fr) repeat(2, minmax(88px, .7fr)) repeat(2, 62px) 70px;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 10px;
}

.hud-cell,
.hud-audio,
.quit-button {
  min-height: 56px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.98), rgba(236,244,255,.90)),
    var(--panel);
  color: var(--ink);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18), inset 0 1px 0 rgba(255,255,255,.9);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 6px 8px;
  line-height: 1.05;
  white-space: nowrap;
}

.hud-title {
  font-weight: 900;
  font-size: 21px;
  color: #171b37;
  background: linear-gradient(135deg, #fff06a 0%, #ff9ec8 54%, #83eaff 100%);
  text-shadow: 0 1px 0 rgba(255,255,255,.65);
}

.hud-score {
  background:
    linear-gradient(135deg, rgba(255,240,106,.95), rgba(255,158,200,.82) 58%, rgba(131,234,255,.74)),
    #ffffff;
  color: #171b37;
  transform: translateY(-1px);
}

.hud-cell span,
.hud-audio small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.hud-cell strong {
  font-size: 24px;
  font-weight: 900;
}

.hud-score strong {
  font-size: 34px;
  line-height: .92;
  color: #171b37;
  text-shadow:
    0 1px 0 rgba(255,255,255,.72),
    0 0 16px rgba(255,255,255,.75),
    0 6px 18px rgba(255,126,184,.36);
}

.hud-score span {
  color: #3e3356;
}

.hud-audio {
  gap: 3px;
  background: #f4f5f7;
}

.hud-audio.is-on .audio-icon {
  background: #414654;
}

.audio-icon {
  display: block;
  width: 22px;
  height: 22px;
  background: #b9bec8;
  mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='black' d='M4 9v6h4l5 4V5L8 9H4Zm12.5 3a4.2 4.2 0 0 0-2-3.6v7.2a4.2 4.2 0 0 0 2-3.6Zm-2-8.2v2.1a7 7 0 0 1 0 12.2v2.1a9 9 0 0 0 0-16.4Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.mobile-audio { display: none; }

.quit-button {
  display: none;
  background: #1f2340;
  color: white;
  font-weight: 900;
}

body.is-playing .quit-button {
  display: flex;
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  box-shadow:
    0 22px 70px rgba(0, 0, 0, .34),
    0 0 0 1px rgba(255,255,255,.24),
    0 0 40px rgba(131,234,255,.16);
  background: #161836 url("assets/images/bg-stage.png?v=20260518-jptext1") center / cover no-repeat;
  -webkit-tap-highlight-color: transparent;
}

body.is-run-view .stage-wrap {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body.is-run-view .app-shell,
body.is-run-view .hud,
body.is-run-view .stage-wrap * {
  touch-action: none;
}

body.is-run-view .hud-audio,
body.is-run-view .hud-audio *,
body.is-run-view .audio-popover,
body.is-run-view .audio-popover * {
  touch-action: manipulation;
}

.stage-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background:
    linear-gradient(90deg, rgba(255,255,255,.16), transparent 16%, transparent 84%, rgba(255,255,255,.14)),
    radial-gradient(ellipse at 50% 20%, rgba(255,255,255,.18), transparent 58%);
  mix-blend-mode: screen;
}

canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden {
  display: none !important;
}

.menu-overlay {
  z-index: 6;
  flex-direction: column;
  justify-content: flex-start;
  gap: clamp(10px, 2vw, 18px);
  padding: clamp(16px, 4vw, 38px);
  background: linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(18, 20, 48, .34));
  color: white;
  text-align: center;
}

.menu-copy {
  text-shadow: 0 4px 24px rgba(0, 0, 0, .34);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 900;
  color: #fff1a6;
}

.hero-title {
  margin: 0;
  line-height: .92;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(86px, 16vw, 160px);
}

.hero-title-logo {
  display: block;
  width: min(760px, 92vw);
  height: clamp(86px, 16vw, 160px);
  object-fit: contain;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, .28));
}

.hero-title-logo[hidden] {
  display: none;
}

.hero-title-fallback {
  font-size: clamp(42px, 8vw, 84px);
  font-weight: 900;
  color: #fff;
}

.hero-title-fallback[hidden] {
  display: none;
}

.lead {
  margin: 8px 0 0;
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 700;
}

.character-grid {
  width: min(880px, 100%);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.character-card {
  min-width: 0;
  border: 2px solid rgba(255, 255, 255, .45);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(235,244,255,.90));
  color: var(--ink);
  padding: 9px 6px;
  font-weight: 900;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .22), inset 0 1px 0 rgba(255,255,255,.92);
}

.character-card.is-selected {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 16px 38px rgba(255, 216, 77, .34), 0 0 0 3px rgba(255,255,255,.42);
}

.character-card img {
  display: block;
  width: 100%;
  height: 72px;
  object-fit: contain;
  margin-bottom: 4px;
  pointer-events: none;
}

.primary-cta,
.secondary-cta,
.entry-panel button {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 22px;
  font-weight: 900;
}

.primary-cta {
  color: #22253e;
  background: linear-gradient(135deg, #fff06a, #ff9ec8 58%, #83eaff);
  box-shadow: 0 12px 34px rgba(255, 126, 184, .30);
}

.secondary-cta {
  color: var(--ink);
  background: #edf1f7;
}

.primary-cta:disabled,
.secondary-cta:disabled {
  filter: grayscale(.85);
  opacity: .55;
  cursor: not-allowed;
}

.scroll-cue {
  position: absolute;
  bottom: 12px;
  left: 50%;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, .9);
  font-weight: 900;
  animation: cue 1.3s ease-in-out infinite;
}

@keyframes cue {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

.howto-overlay,
.result-overlay {
  background: rgba(15, 18, 44, .72);
  padding: 16px;
}

.howto-card,
.result-card {
  width: min(92%, 540px);
  max-height: min(88%, 620px);
  overflow: auto;
  background: rgba(255, 255, 255, .96);
  border-radius: 8px;
  padding: clamp(18px, 4vw, 28px);
  box-shadow: var(--shadow);
  text-align: center;
}

.howto-card h2,
.result-card h2 {
  margin: 0 0 12px;
}

.howto-copy {
  text-align: left;
  line-height: 1.45;
  color: #3f465c;
}

.result-card h2 {
  font-size: clamp(44px, 9vw, 84px);
  line-height: 1;
}

.best-line {
  font-weight: 900;
  color: #4b5570;
}

.result-message,
.entry-summary {
  overflow-wrap: anywhere;
}

.result-character-name {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 900;
  color: #263153;
}

.result-character {
  display: block;
  width: min(148px, 42vw);
  height: 132px;
  object-fit: contain;
  margin: 8px auto 6px;
  filter: drop-shadow(0 12px 22px rgba(31, 35, 64, .22));
  pointer-events: none;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.audio-popover {
  position: absolute;
  top: 64px;
  right: 78px;
  z-index: 20;
  width: 180px;
  padding: 8px;
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

.audio-popover button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0;
  border-radius: 8px;
  background: #f2f4f7;
  color: var(--ink);
  font-weight: 900;
}

.entry-panel {
  margin-top: 14px;
  padding: clamp(16px, 3vw, 26px);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .16);
}

body.is-run-view .entry-panel {
  display: none;
}

.entry-panel h2 {
  margin: 0 0 14px;
  font-size: clamp(22px, 4vw, 34px);
}

.entry-note {
  color: #4b5570;
}

.entry-panel label {
  display: block;
  margin: 10px 0;
  font-weight: 900;
}

.entry-panel input {
  width: 100%;
  min-height: 44px;
  margin-top: 5px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 8px 10px;
}

.entry-panel .full {
  width: 100%;
}

.entry-status {
  font-weight: 900;
  color: #2c7a4b;
}


@media (max-width: 760px) {
  .app-shell {
    padding: 8px;
  }

  .hud {
    grid-template-columns: 1.3fr repeat(3, .72fr) 62px 62px;
    gap: 6px;
  }

  .hud-title {
    grid-column: 1 / -1;
    min-height: 34px;
    font-size: 16px;
  }

  .hud-cell,
  .hud-audio,
  .quit-button {
    min-height: 48px;
    padding: 4px 5px;
  }

  .hud-cell strong {
    font-size: 18px;
  }

  .hud-score strong {
    font-size: 28px;
  }

  .desktop-audio { display: none; }
  .mobile-audio { display: flex; }

  .stage-wrap {
    aspect-ratio: auto;
    min-height: max(520px, calc(100svh - 116px));
  }

  .menu-overlay {
    padding: 12px 10px 44px;
    gap: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .hero-title {
    min-height: 68px;
  }

  .hero-title-logo {
    width: min(330px, 88vw);
    height: 68px;
  }

  .hero-title-fallback {
    font-size: 38px;
  }

  .eyebrow {
    margin-bottom: 4px;
  }

  .lead {
    font-size: 14px;
    margin-top: 4px;
    overflow-wrap: anywhere;
  }

  .character-grid {
    width: 100%;
    max-width: 340px;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .character-card {
    padding: 6px 4px;
    font-size: 12px;
  }

  .character-card img {
    height: 46px;
  }

  .howto-card,
  .result-card {
    max-height: 84%;
    padding: 14px;
  }

  .result-character {
    width: min(112px, 38vw);
    height: 92px;
    margin: 6px auto 4px;
  }

  .howto-card .primary-cta {
    position: sticky;
    bottom: 0;
    width: 100%;
  }

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

  .result-actions .primary-cta {
    min-height: 56px;
    order: -1;
  }

  .audio-popover {
    top: 92px;
    right: 8px;
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  body.is-run-view .stage-wrap {
    aspect-ratio: 16 / 9;
    height: auto;
    min-height: 0;
  }
}
