:root {
  color-scheme: dark;
  --ink: #f3eadf;
  --paper: #151319;
  --surface: #201c24;
  --line: rgba(243, 234, 223, .14);
  --muted: #aaa0ad;
  --gold: #f2d985;
  --coral: #f08b72;
  --shadow: 0 28px 90px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 16% 3%, rgba(142,131,198,.16), transparent 28rem),
    radial-gradient(circle at 88% 24%, rgba(240,139,114,.11), transparent 24rem),
    var(--paper);
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", Avenir, system-ui, sans-serif;
}
button, a { color: inherit; font: inherit; }
a { text-decoration: none; }
button { cursor: pointer; }

.game-shell {
  width: min(900px, calc(100% - 28px));
  margin: 0 auto;
  padding-bottom: 40px;
}
header {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
}
.brand, .eyebrow, header button {
  font-size: .69rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.brand, .eyebrow { color: var(--gold); }
.header-actions { display: flex; gap: 16px; }
header button {
  padding: 8px 0;
  border: 0;
  background: transparent;
}

.intro {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 36px;
  align-items: end;
  padding: 30px 0 24px;
}
.eyebrow { margin: 0 0 10px; }
h1, h2 { margin: 0; letter-spacing: -.055em; }
h1 {
  font-family: Georgia, serif;
  font-size: clamp(4rem, 10vw, 7.4rem);
  font-weight: 400;
  line-height: .75;
}
.intro-copy { padding-bottom: 3px; }
.intro-copy p {
  margin: 0 0 8px;
  color: var(--ink);
  font-family: Georgia, serif;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
}
.intro-copy span { color: var(--muted); font-size: .83rem; line-height: 1.55; }

.play-card {
  width: min(430px, 100%);
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(32,28,36,.9);
  box-shadow: var(--shadow);
}
.score-bar {
  display: grid;
  grid-template-columns: 1fr 86px 1fr;
  align-items: center;
  min-height: 64px;
  gap: 10px;
  padding: 0 10px;
}
.score-bar > div:first-child { text-align: left; }
.score-bar > div:last-child { text-align: right; }
.score-bar span {
  display: block;
  color: var(--muted);
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.score-bar strong {
  display: block;
  margin-top: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9rem;
  letter-spacing: .08em;
}
.next-wrap { display: grid; justify-items: center; gap: 4px; }
#next-pebble {
  display: block;
  width: var(--pebble-size, 20px);
  aspect-ratio: 1;
  border: 1.5px solid #211c23;
  border-radius: 50%;
  background: var(--pebble-color, var(--coral));
  box-shadow: inset 3px 3px 0 rgba(255,255,255,.28);
}

.vessel-wrap { position: relative; display: flex; flex-direction: column; gap: 8px; }
#vessel {
  display: block;
  width: 100%;
  aspect-ratio: 360 / 468;
  border: 1px solid rgba(243,234,223,.18);
  border-radius: 20px;
  background: #17141b;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#vessel.is-warning {
  box-shadow: inset 0 0 0 2px rgba(240,139,114,.55);
  animation: warning-pulse .7s ease infinite alternate;
}
.drop-guide {
  position: absolute;
  top: 20px;
  width: 1px;
  height: 34px;
  background: linear-gradient(var(--gold), transparent);
  opacity: .38;
  pointer-events: none;
  transform: translateX(-50%);
}
.status {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(243,234,223,.11);
  border-radius: 999px;
  background: rgba(21,19,25,.6);
  color: rgba(243,234,223,.72);
  font-size: .69rem;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.note-ladder {
  display: grid;
  grid-template-columns: .7fr 1.3fr;
  gap: 36px;
  align-items: start;
  padding: 70px 0;
}
.note-ladder h2 {
  max-width: 340px;
  font-family: Georgia, serif;
  font-size: clamp(2.1rem, 5vw, 4rem);
  font-weight: 400;
  line-height: .95;
}
.tier-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.tier-list span {
  display: grid;
  min-height: 84px;
  place-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  font-size: .65rem;
}
.tier-list i {
  display: block;
  width: 26px;
  aspect-ratio: 1;
  border: 1px solid #211c23;
  border-radius: 50%;
  background: var(--tier-color);
  box-shadow: inset 4px 4px 0 rgba(255,255,255,.24);
  opacity: .45;
}
.tier-list span.is-reached { color: var(--ink); }
.tier-list span.is-reached i { opacity: 1; }
.tier-list b { font-weight: 750; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 25px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}
footer p { margin: 0; }
footer a { color: var(--gold); font-weight: 800; }

.result-dialog {
  width: min(420px, calc(100% - 28px));
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #211c25;
  box-shadow: 0 34px 100px rgba(0,0,0,.62);
  color: var(--ink);
}
.result-dialog::backdrop {
  background: rgba(10,8,12,.7);
  backdrop-filter: blur(5px);
}
.result-dialog h2 {
  font-family: Georgia, serif;
  font-size: 2.35rem;
  font-weight: 400;
  line-height: 1;
}
.result-dialog > p:not(.eyebrow):not(.achievement):not(.share-status) {
  color: var(--muted);
}
.achievement {
  display: inline-flex;
  margin: 2px 0 15px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(242,217,133,.12);
  color: var(--gold);
  font-size: .68rem;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.dialog-actions { display: flex; gap: 8px; margin-top: 22px; }
.primary-button, .secondary-button {
  min-height: 46px;
  padding: 0 17px;
  border-radius: 12px;
  font-weight: 800;
}
.primary-button { border: 0; background: var(--gold); color: #211c23; }
.secondary-button { border: 1px solid var(--line); background: transparent; }
.share-status { min-height: 1.2em; color: var(--muted); font-size: .72rem; }

@keyframes warning-pulse {
  to { box-shadow: inset 0 0 0 3px rgba(240,139,114,.78), 0 0 24px rgba(240,139,114,.16); }
}

@media (max-width: 640px) {
  .game-shell { width: min(100% - 14px, 900px); }
  header { min-height: 50px; padding-inline: 5px; }
  .header-actions { gap: 11px; }
  .intro {
    display: flex;
    padding: 9px 7px 13px;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
  }
  .intro .eyebrow { font-size: .58rem; }
  h1 { font-size: clamp(3rem, 15vw, 4rem); }
  .intro-copy { max-width: 155px; }
  .intro-copy p { font-size: 1rem; line-height: 1.05; }
  .intro-copy span { font-size: .66rem; }
  .play-card { padding: 7px; border-radius: 22px; }
  .score-bar { min-height: 53px; }
  #vessel { border-radius: 16px; }
  .note-ladder {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 48px 5px;
  }
  .tier-list { grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .tier-list span { min-height: 72px; padding: 7px 3px; font-size: .58rem; }
  footer { display: block; padding-inline: 5px; }
  footer a { display: inline-block; margin-top: 11px; }
}

@media (max-width: 350px) {
  .brand { font-size: .61rem; }
  header button { font-size: .6rem; }
  .intro-copy span { display: none; }
}

/* === P1.1 Leaderboard — Choir Ranking === */
.leaderboard-link {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--gold);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.leaderboard-link:hover { background: var(--surface); border-color: rgba(242,217,133,.4); }

.rank-status {
  margin: 10px 0 6px;
  font-size: .68rem;
  color: var(--muted);
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}
.rank-status::before { content: "♪ "; color: var(--coral); }

.leaderboard-top {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  gap: 5px;
  max-height: 280px;
  overflow-y: auto;
}
.leaderboard-top::-webkit-scrollbar { width: 4px; }
.leaderboard-top::-webkit-scrollbar-track { background: transparent; }
.leaderboard-top::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

.leaderboard-top li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .7rem;
  position: relative;
  overflow: hidden;
}
.leaderboard-top .rank {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: .05em;
  font-size: .66rem;
}
.leaderboard-top li:nth-child(1) .rank { color: var(--gold); font-weight: 900; }
.leaderboard-top li:nth-child(1) { border-color: rgba(242,217,133,.42); box-shadow: inset 0 0 14px rgba(242,217,133,.06); }
.leaderboard-top li:nth-child(2) .rank { color: var(--gold); opacity: .82; }
.leaderboard-top li:nth-child(3) .rank { color: var(--coral); }

.leaderboard-top .name {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: .02em;
}
.leaderboard-top .score-wrap { display: flex; align-items: center; gap: 8px; }
.leaderboard-top .signal-bar { width: 44px; height: 4px; background: rgba(242,217,133,.1); border-radius: 2px; overflow: hidden; }
.leaderboard-top .signal-bar-fill { height: 100%; background: var(--gold); border-radius: 2px; box-shadow: 0 0 6px rgba(242,217,133,.4); }
.leaderboard-top .score { color: var(--coral); font-variant-numeric: tabular-nums; font-weight: 700; min-width: 48px; text-align: right; }

.leaderboard-top li.is-me {
  background: rgba(242,217,133,.08);
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(242,217,133,.15), inset 0 0 18px rgba(242,217,133,.05);
}
.leaderboard-top li.is-me .name::before { content: "♪ "; color: var(--gold); font-size: .6rem; }

.submit-leaderboard {
  min-height: 46px;
  padding: 0 17px;
  border: 0;
  border-radius: 12px;
  background: var(--gold);
  color: #211c23;
  font-weight: 800;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(242,217,133,.3);
  transition: box-shadow .15s;
}
.submit-leaderboard:hover:not(:disabled) { box-shadow: 0 0 20px rgba(242,217,133,.5); }
.submit-leaderboard:disabled { opacity: .4; cursor: default; box-shadow: none; }

.leaderboard-panel[hidden] { display: none; }
.leaderboard-panel {
  position: fixed; inset: 0; z-index: 50;
  padding: 40px 20px; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background:
    radial-gradient(circle at 16% 3%, rgba(142,131,198,.16), transparent 28rem),
    radial-gradient(circle at 88% 24%, rgba(240,139,114,.11), transparent 24rem),
    rgba(21,19,25,.96);
}
.leaderboard-panel .leaderboard-head {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; max-width: 480px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.leaderboard-panel h2 {
  margin: 0; font-size: .86rem; color: var(--gold);
  letter-spacing: .08em; text-transform: uppercase;
  font-weight: 800;
}
.leaderboard-panel h2::before { content: "♪ "; color: var(--coral); }
.leaderboard-panel #close-leaderboard {
  background: transparent; border: 1px solid var(--line);
  color: var(--gold); width: 32px; height: 32px; border-radius: 50%;
  font-size: 1.1rem; cursor: pointer; display: grid; place-items: center;
  transition: border-color .15s, background .15s;
}
.leaderboard-panel #close-leaderboard:hover { border-color: var(--gold); background: rgba(242,217,133,.08); }
.leaderboard-panel .rank-status,
.leaderboard-panel .leaderboard-top { width: 100%; max-width: 480px; }
.leaderboard-panel .leaderboard-top { max-height: none; }

@media (max-width: 380px) {
  .leaderboard-top .signal-bar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; }
}
