:root {
  --bg: #0b0b16;
  --panel: #14142a;
  --panel-2: #1d1d3a;
  --gold: #ffcf4d;
  --gold-2: #ff9d2f;
  --text: #f4f4ff;
  --muted: #9a9ac4;
  --accent: #ff4da6;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 0%, #1a1030 0%, var(--bg) 60%);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

body {
  /* Track the viewport that is actually visible on phones (URL bar shown or
     hidden) — a plain 100% can be taller than the screen, clipping the HUD. */
  height: 100dvh;
}

#app {
  height: 100%;
}

/* ── Lock screen ─────────────────────────────────────────────────────────── */
.lock {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.lock__card {
  text-align: center;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid rgba(255, 207, 77, 0.25);
  border-radius: 24px;
  padding: 40px 32px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.lock__spark {
  font-size: 64px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  50% {
    transform: translateY(-8px);
  }
}
.lock__greeting {
  margin: 12px 0 4px;
  font-size: 30px;
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lock__teaser {
  color: var(--muted);
  margin: 0 0 28px;
}
.lock__cd-label {
  letter-spacing: 3px;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 12px;
}
.lock__cd {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.cd-unit {
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 10px;
  min-width: 72px;
}
.cd-unit__num {
  display: block;
  font-size: 34px;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.cd-unit__label {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
}
#app.is-unlocking {
  transition: opacity 0.6s ease;
  opacity: 0;
}

/* Narrow portrait phones: the four fixed-width countdown tiles are what push
   the card past the screen edge — let them share the row instead. */
@media (max-width: 480px) {
  .lock {
    padding: 16px;
  }
  .lock__card {
    padding: 28px 16px;
  }
  .lock__greeting {
    font-size: 26px;
  }
  .lock__cd {
    gap: 8px;
  }
  .cd-unit {
    flex: 1 1 0;
    min-width: 0;
    padding: 12px 6px;
  }
  .cd-unit__num {
    font-size: 26px;
  }
}

/* Rotated phone (landscape, short): compact the lock card so it fits without
   clipping, and let it scroll as a fallback on very short screens. */
@media (orientation: landscape) and (max-height: 560px) {
  .lock {
    padding: 12px;
    overflow-y: auto;
  }
  .lock__card {
    padding: 16px 24px;
  }
  .lock__spark {
    font-size: 38px;
  }
  .lock__greeting {
    font-size: 22px;
    margin: 8px 0 2px;
  }
  .lock__teaser {
    margin-bottom: 12px;
  }
  .lock__cd-label {
    margin-bottom: 8px;
  }
  .cd-unit {
    min-width: 58px;
    padding: 8px;
  }
  .cd-unit__num {
    font-size: 24px;
  }
}

/* ── Rotate gate ─────────────────────────────────────────────────────────────
   Shown only while the game is running (body.in-game) on a touch device held
   in portrait — the lock screen works in any orientation. Tapping anywhere
   goes fullscreen and, where supported, flips to landscape (see main.js). */
.rotate-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 32%, #1a1030 0%, var(--bg) 70%);
}
@media (orientation: portrait) and (pointer: coarse) {
  body.in-game .rotate-gate {
    display: flex;
  }
}
.rotate-gate__icon {
  font-size: 76px;
  animation: rotate-hint 2.4s ease-in-out infinite;
}
@keyframes rotate-hint {
  0%,
  35% {
    transform: rotate(0);
  }
  60%,
  100% {
    transform: rotate(-90deg);
  }
}
.rotate-gate__title {
  margin: 20px 0 6px;
  font-size: 26px;
  font-weight: 700;
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.rotate-gate__sub {
  margin: 0;
  color: var(--muted);
}

/* ── Game ────────────────────────────────────────────────────────────────── */
.game {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
}
.stage canvas {
  display: block;
}

.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: linear-gradient(180deg, var(--panel), #0d0d1e);
  border-top: 1px solid rgba(255, 207, 77, 0.2);
  flex-wrap: wrap;
  justify-content: center;
}
.readout {
  display: flex;
  flex-direction: column;
  min-width: 96px;
}
.readout__label {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--muted);
}
.readout__value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}
.readout--win .readout__value {
  color: var(--accent);
}

.bets {
  display: flex;
  gap: 8px;
}
.bet {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition:
    transform 0.08s,
    background 0.15s;
}
.bet:hover {
  transform: translateY(-1px);
}
.bet.is-active {
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  color: #2a1600;
  border-color: transparent;
}

.spin-btn {
  border: none;
  border-radius: 50%;
  width: 84px;
  height: 84px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #14240d;
  background: radial-gradient(circle at 35% 30%, #a6ff7a, #34b233);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(52, 178, 51, 0.5);
  transition: transform 0.08s;
}
.spin-btn:hover {
  transform: scale(1.04);
}
.spin-btn:active {
  transform: scale(0.96);
}
.spin-btn:disabled {
  filter: grayscale(0.6) brightness(0.8);
  cursor: default;
}

.mute-btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--panel-2);
  color: var(--text);
  font-size: 18px;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  cursor: pointer;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s,
    transform 0.25s;
  z-index: 5;
}
.toast.is-shown {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Big win flash ───────────────────────────────────────────────────────── */
.bigwin {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(48px, 12vw, 140px);
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--gold);
  text-shadow:
    0 0 30px var(--gold-2),
    0 6px 0 #7a4a00;
  background: radial-gradient(circle, rgba(255, 157, 47, 0.25), rgba(0, 0, 0, 0.55));
  opacity: 0;
  transform: scale(0.6);
  transition:
    opacity 0.4s,
    transform 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
  z-index: 10;
  pointer-events: none;
}
.bigwin.is-in {
  opacity: 1;
  transform: scale(1);
}
.bigwin.is-out {
  opacity: 0;
  transform: scale(1.2);
}

/* ── Reveal ──────────────────────────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 6, 16, 0.9);
  opacity: 0;
  transition: opacity 0.5s;
  z-index: 20;
  pointer-events: none; /* must not intercept clicks while hidden */
}
/* Author display:grid above overrides the UA [hidden] rule, so hide explicitly. */
.overlay[hidden] {
  display: none;
}
.overlay.is-shown {
  opacity: 1;
  pointer-events: auto;
}
.reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 560px;
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--gold);
  border-radius: 24px;
  padding: clamp(16px, 4vw, 32px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes pop {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
}
.reveal__body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
.reveal__photo {
  display: block;
  max-width: 100%;
  max-height: 40dvh;
  border-radius: 16px;
  border: 3px solid var(--gold);
}
.reveal__title {
  margin: 18px 0 8px;
  font-size: clamp(22px, 5vw, 30px);
  background: linear-gradient(90deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.reveal__message {
  color: var(--text);
  line-height: 1.6;
  font-size: clamp(15px, 3.6vw, 17px);
}
.reveal__trip {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  margin-top: 16px;
  padding: 14px 18px;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--gold);
  border-radius: 16px;
}
.reveal__trip-logo {
  width: 72px;
  height: 72px;
  flex: none;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid var(--gold);
}
.reveal__trip-text {
  min-width: 0;
}
.reveal__trip-name {
  margin: 0;
  font-weight: 800;
  font-size: clamp(15px, 3.6vw, 18px);
  background: linear-gradient(90deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.reveal__trip-subtitle {
  margin: 2px 0 8px;
  color: var(--text);
  opacity: 0.75;
  font-size: clamp(12px, 3vw, 14px);
}
.reveal__trip-row {
  margin: 2px 0 0;
  color: var(--text);
  font-size: clamp(13px, 3.2vw, 15px);
  line-height: 1.5;
}
.reveal__trip-label {
  color: var(--gold);
  font-weight: 700;
}
.reveal__again {
  margin-top: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--panel-2);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}
.reveal__again:hover {
  border-color: var(--gold);
}

/* ── Phones ──────────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .hud {
    gap: 8px 12px;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    /* Tidy two-tier layout: readouts + mute on top, bets + spin below. */
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      'mute balance win'
      'bets bets spin';
    align-items: center;
  }
  .mute-btn {
    grid-area: mute;
    width: 40px;
    height: 40px;
  }
  .readout:not(.readout--win) {
    grid-area: balance;
  }
  .readout--win {
    grid-area: win;
    text-align: right;
  }
  .readout--win .readout__label {
    display: block;
  }
  .bets {
    grid-area: bets;
    flex-wrap: wrap;
  }
  .spin-btn {
    grid-area: spin;
    width: 64px;
    height: 64px;
    justify-self: end;
  }
  .readout__value {
    font-size: 20px;
  }
  .bet {
    padding: 8px 12px;
  }
}

/* ── Rotated phone (landscape, short) ────────────────────────────────────────
   Move the controls into a slim right-hand rail so the photos get the whole
   height. Hide the mute + bet buttons (bet is fixed in config.landscape.bet)
   and shrink the spin button. */
@media (orientation: landscape) and (max-height: 560px) {
  .game {
    flex-direction: row;
  }
  .hud {
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    padding: 8px 14px;
    border-top: none;
    border-left: 1px solid rgba(255, 207, 77, 0.2);
    flex-wrap: nowrap;
  }
  .hud .mute-btn,
  .hud .bets {
    display: none;
  }
  .readout {
    min-width: 0;
    align-items: center;
    text-align: center;
  }
  .readout__value {
    font-size: 18px;
  }
  .readout__label {
    font-size: 9px;
  }
  .spin-btn {
    width: 58px;
    height: 58px;
    font-size: 13px;
  }

  /* Present reveal sits photo-beside-text so it fits the short height. */
  .overlay {
    padding: 14px;
  }
  .reveal {
    flex-direction: row;
    align-items: center;
    text-align: left;
    gap: 22px;
    max-width: 94vw;
  }
  .reveal__photo {
    max-height: 76dvh;
  }
  .reveal__body {
    align-items: flex-start;
  }
  .reveal__title {
    margin-top: 0;
  }
  .reveal__trip {
    margin-top: 10px;
    padding: 10px 14px;
    gap: 12px;
  }
  .reveal__trip-logo {
    width: 56px;
    height: 56px;
  }
}
