:root {
  --blue: #173db6;
  --blue-dark: #0a216f;
  --cream: #f4efdf;
  --pink: #f5a3ad;
  --lime: #d7f447;
  --ink: #101a35;
  --white: #fffdf7;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}
body {
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding:
    max(40px, env(safe-area-inset-top))
    max(32px, env(safe-area-inset-right))
    max(40px, env(safe-area-inset-bottom))
    max(32px, env(safe-area-inset-left));
}
button { font: inherit; }

.game-frame {
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.game-shell {
  --game-scale: 1.3;
  --rail-gap: 24px;
  width: calc(100% / var(--game-scale));
  max-width: calc(100% / var(--game-scale));
  height: calc(100% / var(--game-scale));
  max-height: calc(100% / var(--game-scale));
  margin: 0;
  flex: 0 0 auto;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: minmax(0, 1fr);
  column-gap: var(--rail-gap);
  align-items: stretch;
  transform: scale(var(--game-scale));
  transform-origin: center center;
}

.side-panel {
  min-width: 0;
  max-width: 220px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding-top: 2px;
  align-self: start;
}
.side-left {
  justify-self: end;
  align-self: stretch;
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  height: 100%;
}
.side-right {
  justify-self: start;
  width: min(112px, 100%);
  align-items: stretch;
  justify-content: flex-start;
}

h1 {
  margin: 0;
  text-transform: uppercase;
  line-height: 1.08;
  font-size: clamp(20px, 2vw, 28px);
  letter-spacing: -.03em;
  font-weight: 700;
  color: var(--blue-dark);
}

.stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  align-items: stretch;
  width: 100%;
}
.stats > div {
  min-width: 0;
  background: var(--white);
  border: 2px solid var(--blue-dark);
  padding: 8px 10px;
}
.label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 600;
}
.stats strong {
  display: block;
  font-size: clamp(18px, 2.6vw, 26px);
  font-weight: 700;
  color: var(--blue);
}
.misses-box { display: flex; flex-direction: column; width: auto; }
.miss-cups {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 6px;
  margin-top: 6px;
  min-width: max-content;
}
.miss-cup {
  display: block;
  flex: 0 0 22px;
  width: 22px;
  height: 28px;
}
.miss-cup svg { display: block; width: 100%; height: 100%; overflow: visible; }
.miss-cup .cup-shape {
  fill: rgba(245,163,173,.35);
  stroke: var(--blue-dark);
  stroke-width: 2.4;
  stroke-linejoin: round;
}
.miss-cup .miss-x {
  fill: none;
  stroke: #c41e3a;
  stroke-width: 3.2;
  stroke-linecap: round;
  opacity: 0;
}
.miss-cup.missed .cup-shape { fill: rgba(196,30,58,.12); }
.miss-cup.missed .miss-x { opacity: 1; }

.game-wrap {
  position: relative;
  min-height: 0;
  min-width: 0;
  height: 100%;
  grid-row: 1;
  grid-column: 2;
  display: flex;
  align-items: stretch;
  justify-content: center;
  justify-self: center;
}
.stage {
  position: relative;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  border: 3px solid var(--blue-dark);
  background: #8fc3e8;
  overflow: hidden;
  flex: 0 0 auto;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: ew-resize;
}
.player-line {
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 400;
  color: var(--blue);
}
.how-line {
  margin: 14px 0 0;
  max-width: 18em;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--ink);
}
.player-line strong {
  font-weight: 600;
  color: var(--blue-dark);
}
.last-result {
  margin: 16px 0 0;
  padding: 12px 14px;
  background: var(--white);
  border: 3px solid var(--blue-dark);
  font-weight: 400;
  line-height: 1.5;
}
.last-result.hidden { display: none; }

.intro {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--cream);
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 100px 24px;
}
.intro.hidden { display: none; }
.intro-inner {
  width: min(920px, 100%);
}
.intro-inner > h1 {
  font-size: clamp(26px, 8vw, 62px);
  margin-bottom: 0;
}
.intro .how-line {
  margin-top: 14px;
  font-size: 15px;
  max-width: 30em;
  line-height: 1.55;
}
.intro .player-line {
  margin-top: 12px;
  font-size: 14px;
}
.intro-grid {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 16px;
  margin-top: 28px;
}
.intro-panel {
  background: var(--white);
  border: 3px solid var(--blue-dark);
  padding: 20px;
}
.intro-panel h2 {
  margin: 0 0 14px;
  text-transform: uppercase;
  color: var(--blue-dark);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.intro-panel ul {
  margin: 0 0 18px;
  padding-left: 18px;
  line-height: 1.6;
  font-weight: 400;
}
.intro-panel li { margin: 0 0 10px; }
.leaderboard {
  margin: 0;
  padding: 0 10px 0 0;
  list-style: none;
  max-height: calc(5 * (1.35em + 22px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.leaderboard li {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(16, 26, 53, .12);
  font-weight: 400;
}
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard .rank { color: var(--blue); font-weight: 600; }
.leaderboard .empty { color: rgba(16, 26, 53, .55); font-weight: 400; }
.leaderboard::-webkit-scrollbar {
  width: 6px;
}
.leaderboard::-webkit-scrollbar-thumb {
  background: rgba(23, 61, 182, .35);
  border-radius: 4px;
}
.leaderboard::-webkit-scrollbar-track {
  background: transparent;
  margin: 4px 0;
}

.site-credit {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid rgba(16, 26, 53, .14);
}
.credit-copy,
.credit-support,
.credit-links {
  margin: 0;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  color: rgba(16, 26, 53, .72);
}
.credit-support {
  margin-top: 6px;
  font-weight: 600;
  color: var(--blue-dark);
}
.credit-links {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.credit-links a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.credit-links a:hover {
  text-decoration: underline;
  color: var(--blue-dark);
}

.side-left .how-line { margin-top: 10px; }
.side-left .player-line { margin-top: 8px; }
.game-credit {
  margin-top: auto;
  padding-top: 16px;
  max-width: 12em;
}
.game-credit .credit-copy,
.game-credit .credit-support,
.game-credit .credit-links {
  font-size: 11px;
  line-height: 1.4;
}
.game-credit .credit-support {
  margin-top: 4px;
  font-weight: 500;
}
.game-credit .credit-links {
  margin-top: 5px;
  gap: 6px;
}
button {
  border: 0;
  background: var(--blue);
  color: white;
  padding: 12px 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  cursor: pointer;
}
button:hover { background: var(--blue-dark); }

@media (max-width: 900px) {
  body {
    padding:
      max(32px, env(safe-area-inset-top))
      20px
      max(32px, env(safe-area-inset-bottom))
      20px;
  }
  .game-shell {
    --game-scale: 1.15;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: calc(100% / var(--game-scale));
    max-width: calc(100% / var(--game-scale));
    row-gap: 14px;
    column-gap: 0;
  }
  .side-left,
  .side-right {
    justify-self: stretch;
    width: 100%;
    max-width: none;
  }
  .side-right {
    width: 100%;
  }
  .side-right .stats {
    flex-direction: row;
    width: auto;
  }
  .game-wrap {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    min-height: 0;
  }
  h1 { font-size: clamp(16px, 6.4vw, 22px); }
  .stats > div { flex: 0 0 auto; min-width: 64px; padding: 5px 8px; }
  .intro-grid { grid-template-columns: 1fr; }
}

@media (max-height: 720px) {
  h1 { font-size: clamp(16px, 3vw, 22px); }
  .stats > div { padding: 5px 8px; }
}

@media (max-height: 560px) {
  .intro { align-items: start; }
}
