:root {
  --bg: #140f2e;
  --panel: rgba(24, 17, 56, 0.9);
  --panel-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --muted: #bdb6e0;
  --gold: #ffc93c;
  --blue: #4aa8ff;
  --red: #ff6b6b;
  --hot-a: #ffa53d;
  --hot-b: #ff5f6d;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: 500;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ HUD */

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

.hud.is-hidden {
  visibility: hidden;
}

.scoreboard {
  position: absolute;
  top: calc(var(--safe-t) + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: min(780px, calc(100% - 12px - var(--safe-l) - var(--safe-r)));
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.card {
  --c: #ffffff;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  border-radius: 14px;
  background: rgba(14, 10, 36, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 4px 0 0 var(--c);
}

.card.is-you {
  border-color: var(--c);
  background: rgba(30, 20, 70, 0.9);
}

.card.is-bump {
  animation: bump 0.4s ease-out;
}

.card__face {
  width: 38px;
  height: 38px;
  flex: none;
}

.card__meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1;
  flex: 1;
}

.card__name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card.is-you .card__name {
  color: var(--c);
}

.card__score {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.clock {
  pointer-events: auto;
  flex: none;
  min-width: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 14px;
  border: 2px solid rgba(255, 201, 60, 0.6);
  background: rgba(14, 10, 36, 0.86);
  cursor: pointer;
}

.clock__time {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  line-height: 1;
}

.clock__pause {
  width: 10px;
  height: 12px;
  border-left: 3px solid rgba(255, 255, 255, 0.7);
  border-right: 3px solid rgba(255, 255, 255, 0.7);
}

.clock.is-urgent {
  border-color: var(--red);
  animation: pulse 1s ease-in-out infinite;
}

.clock.is-urgent .clock__time {
  color: var(--red);
}

.banner {
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  text-align: center;
  font-size: clamp(44px, 13vmin, 128px);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  -webkit-text-stroke: 0.06em #1a1033;
  paint-order: stroke fill;
  text-shadow: 0 0.08em 0 #1a1033, 0 0.2em 0.4em rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(-50%) scale(0.6);
}

.banner.is-show {
  animation: banner 0.95s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}

.banner.is-gold {
  color: var(--gold);
}

.banner.is-red {
  color: var(--red);
}

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 14px);
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(14, 10, 36, 0.78);
  border: 1px solid var(--line);
  font-size: 15px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.hint.is-show {
  opacity: 1;
}

/* ------------------------------------------------------------------ overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
  background: radial-gradient(ellipse at center, rgba(12, 8, 32, 0.35), rgba(12, 8, 32, 0.78));
  touch-action: pan-y;
}

.panel {
  margin: auto;
  width: min(560px, 100%);
  padding: 22px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 26px;
  font-weight: 700;
}

.logo {
  margin: 0;
  font-size: clamp(40px, 9vw, 64px);
  line-height: 0.95;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  gap: 0.22em;
  justify-content: center;
  -webkit-text-stroke: 0.07em #1a1033;
  paint-order: stroke fill;
  text-shadow: 0 0.07em 0 #1a1033;
}

.logo__a {
  color: var(--gold);
}

.logo__b {
  color: #ff8a4c;
}

.tagline {
  margin: 10px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.rotate-tip {
  display: none;
  margin: 8px auto 0;
  width: fit-content;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: #1a1033;
  background: var(--gold);
}

@media (orientation: portrait) and (pointer: coarse) {
  .rotate-tip {
    display: block;
  }
}

.menu__body {
  margin-top: 18px;
  display: grid;
  gap: 16px;
}

.label {
  margin: 0 0 8px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.beans {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.bean {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 6px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: var(--panel-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.bean canvas {
  width: 48px;
  height: 48px;
}

.bean[aria-checked='true'] {
  border-color: var(--c, var(--gold));
  background: rgba(255, 255, 255, 0.12);
}

.bean[aria-checked='true'] canvas {
  animation: hop 0.9s ease-in-out infinite;
}

.blurb {
  margin: 8px 0 0;
  min-height: 1.3em;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.blurb b {
  color: var(--text);
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
  gap: 4px;
  border-radius: 999px;
  background: var(--panel-2);
}

.seg button {
  padding: 9px 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
}

.seg button[aria-checked='true'] {
  background: var(--gold);
  color: #1a1033;
}

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

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  cursor: pointer;
  font-size: 15px;
}

.toggle input {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 36px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.toggle input:checked {
  background: #5fd38d;
}

.toggle input:checked::after {
  transform: translateX(14px);
}

.best {
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.best b {
  color: var(--gold);
}

.menu__actions {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  gap: 10px;
}

.row .btn {
  flex: 1;
}

.btn {
  display: block;
  width: 100%;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.1);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn--primary {
  border: 0;
  padding: 15px 18px;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--hot-a), var(--hot-b));
  box-shadow: 0 6px 0 #a3324a, 0 10px 24px rgba(255, 95, 109, 0.35);
  text-shadow: 0 2px 0 rgba(120, 20, 40, 0.5);
}

.btn--primary:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #a3324a, 0 6px 16px rgba(255, 95, 109, 0.3);
}

.btn--ghost {
  background: transparent;
}

.pause {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  text-align: center;
}

.how {
  width: min(600px, 100%);
}

.rules {
  margin: 0 0 14px;
  padding-left: 22px;
  display: grid;
  gap: 10px;
  font-size: 16px;
  line-height: 1.45;
}

.rules b {
  color: var(--gold);
}

kbd {
  font-family: inherit;
  font-size: 0.85em;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.chip {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.9em;
  font-weight: 600;
  color: #1a1033;
}

.chip--top {
  background: var(--blue);
}

.chip--mid {
  background: var(--gold);
}

.chip--bot {
  background: var(--red);
}

.how__note {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ results */

.results {
  width: min(520px, 100%);
}

.results__title {
  text-align: center;
  font-size: clamp(34px, 7vw, 46px) !important;
  margin-bottom: 4px !important;
  color: var(--gold);
}

.results__sub {
  margin: 0 0 14px;
  text-align: center;
  color: var(--muted);
}

.results__sub b {
  color: var(--text);
}

.ranking {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.rank {
  display: grid;
  grid-template-columns: 34px 48px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  border-radius: 16px;
  background: var(--panel-2);
  border: 2px solid transparent;
  animation: slide-in 0.4s ease-out backwards;
}

.rank.is-you {
  border-color: var(--c);
}

.rank__place {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--muted);
}

.rank:first-child .rank__place {
  color: var(--gold);
}

.rank canvas {
  width: 48px;
  height: 48px;
}

.rank__name {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.1;
}

.rank__name small {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.rank__score {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.noscript {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-size: 20px;
}

/* ------------------------------------------------------------------ responsive */

@media (max-width: 560px) {
  .card {
    gap: 3px;
    padding: 2px 6px 2px 2px;
    border-radius: 12px;
  }

  .card__face {
    width: 30px;
    height: 30px;
  }

  .card__name {
    font-size: 9px;
  }

  .card__score {
    font-size: 19px;
  }

  .clock {
    min-width: 58px;
    padding: 0 8px;
    gap: 4px;
  }

  .clock__time {
    font-size: 23px;
  }

  .clock__pause {
    display: none;
  }

  .beans {
    grid-template-columns: repeat(3, 1fr);
  }

  .panel {
    padding: 18px 16px;
  }
}

@media (max-width: 380px) {
  .card__name {
    display: none;
  }
}

/* Short landscape screens (phones on their side): two columns, tighter spacing */
@media (orientation: landscape) and (max-height: 540px) {
  .menu {
    width: min(860px, 100%);
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    grid-template-rows: auto 1fr;
    column-gap: 22px;
    padding: 16px 20px;
  }

  .menu__head {
    grid-column: 1;
    grid-row: 1;
    align-self: end;
  }

  .menu__actions {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
  }

  .menu__body {
    grid-column: 2;
    grid-row: 1 / span 2;
    margin-top: 0;
    gap: 12px;
  }

  .logo {
    font-size: 44px;
  }

  .tagline {
    font-size: 13px;
  }

  .beans {
    grid-template-columns: repeat(6, 1fr);
  }

  .bean canvas {
    width: 40px;
    height: 40px;
  }

  .results {
    width: min(760px, 100%);
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    column-gap: 20px;
    align-items: center;
    padding: 16px 20px;
  }

  .results__title {
    grid-column: 1;
    grid-row: 1;
  }

  .results__sub {
    grid-column: 1;
    grid-row: 2;
  }

  .results .menu__actions {
    grid-column: 1;
    grid-row: 3;
  }

  .ranking {
    grid-column: 2;
    grid-row: 1 / span 3;
  }

  .how {
    width: min(760px, 100%);
  }

  .rules {
    font-size: 14px;
    gap: 6px;
  }

  .card__face {
    width: 32px;
    height: 32px;
  }

  .card__score {
    font-size: 21px;
  }

  .clock__time {
    font-size: 24px;
  }
}

/* ------------------------------------------------------------------ motion */

@keyframes banner {
  0% {
    opacity: 0;
    transform: translateY(-50%) scale(0.5);
  }
  18% {
    opacity: 1;
    transform: translateY(-50%) scale(1.08);
  }
  30% {
    transform: translateY(-50%) scale(1);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-60%) scale(1.02);
  }
}

@keyframes bump {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes pulse {
  50% {
    transform: scale(1.06);
  }
}

@keyframes hop {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .banner.is-show {
    animation: none;
    opacity: 1;
    transform: translateY(-50%);
  }
}
