:root {
  --bg: #1b1022;
  --bg-2: #24162d;
  --card: #2e1d39;
  --card-2: #3a2647;
  --line: #4a3358;
  --text: #fbf3ff;
  --muted: #bca8c9;
  --gold: #ffc94a;
  --pink: #ff5d8f;
  --ok: #4fd18b;
  --near: #ffc94a;
  --bad: #ff6b6b;
  --radius: 14px;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, #3b1a45 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
}

body.sheet-open { overflow: hidden; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}

.loading { text-align: center; color: var(--muted); padding-top: 40vh; }

h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 17px;
  text-decoration: none;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--gold); color: #2a1500; }
.btn-ghost { background: var(--card-2); color: var(--text); }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn-block { width: 100%; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--card-2);
  font-size: 16px;
}

/* ---------- Intro ---------- */

.intro { padding-top: 12vh; text-align: center; }
.intro .big {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(88px, 30vw, 150px);
  line-height: .9;
  color: var(--gold);
  text-shadow: 0 4px 0 var(--pink);
}
.intro h1 { font-size: 30px; font-weight: 800; margin-top: 4px; }
.intro .lead { color: var(--muted); margin: 12px auto 28px; max-width: 34ch; }

.rules {
  text-align: left;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 0 24px;
  list-style: none;
}
.rules li { display: flex; gap: 10px; padding: 5px 0; }
.rules li span:first-child { width: 22px; flex: none; text-align: center; }

.name-form { display: grid; gap: 12px; }
.name-form input {
  width: 100%;
  min-height: 54px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font: 500 18px var(--body);
  padding: 0 16px;
  text-align: center;
}
.name-form input:focus { outline: none; border-color: var(--gold); }
.form-error { color: var(--bad); min-height: 1.4em; margin: 0; font-size: 14px; }
.intro .link { display: inline-block; margin-top: 22px; color: var(--muted); }

/* ---------- Board ---------- */

.board-head {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(var(--bg) 75%, transparent);
}
.board-head .row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.board-head h1 { font-size: 22px; }
.board-head .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.board-head .count b { color: var(--text); }
.bar { height: 6px; border-radius: 3px; background: var(--card-2); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--pink)); transition: width .25s ease; }
.practice-tag {
  font: 600 12px var(--body);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #2a1500;
  background: var(--gold);
  border-radius: 6px;
  padding: 2px 6px;
  vertical-align: middle;
  margin-left: 6px;
}

.years { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }

.slot {
  width: 100%;
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  min-height: 60px;
  text-align: left;
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}
.slot .yr {
  align-self: stretch;
  display: grid;
  place-items: center;
  font: 800 19px var(--display);
  font-variant-numeric: tabular-nums;
  background: var(--card-2);
  color: var(--gold);
}
.slot .what { padding: 8px 14px; min-width: 0; }
.slot .empty { color: var(--muted); font-style: italic; }
.slot.filled { background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); }
.slot.flash { animation: flash .5s ease; }
@keyframes flash { 0% { box-shadow: inset 0 0 0 2px var(--gold); } 100% { box-shadow: inset 0 0 0 1.5px var(--line); } }

/* Drag to move: ⠿ grip on the right of a placed row. */
.years li { position: relative; }
.years li .slot.filled { padding-right: 44px; }
.handle {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 48px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.handle:active { color: var(--gold); }
.years li.drag-src { opacity: .35; }
.years li.drop-target .slot { box-shadow: inset 0 0 0 2px var(--gold); background: var(--card-2); }
.drag-ghost {
  position: fixed;
  z-index: 40;
  margin: 0;
  list-style: none;
  pointer-events: none;
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5), inset 0 0 0 2px var(--gold);
  transform: scale(1.02);
}
.drag-ghost .handle { color: var(--gold); }
body.dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }

.item { display: flex; align-items: center; gap: 10px; min-width: 0; }
.item .em { font-size: 22px; flex: none; width: 28px; text-align: center; }
.item .tx { min-width: 0; }
.item .t { display: block; font-weight: 600; line-height: 1.25; }
.item .s { display: block; color: var(--muted); font-size: 14px; line-height: 1.3; margin-top: 2px; }

.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 35%);
}
.dock-inner { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; }
.dock-inner .btn-primary { flex: 1; }

/* ---------- Sheet ---------- */

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 2, 12, .6); animation: fade .2s ease; }
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .4);
  animation: up .22s cubic-bezier(.2, .8, .3, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.sheet-head h2 { font-size: 28px; color: var(--gold); font-variant-numeric: tabular-nums; }
.sheet-body { overflow-y: auto; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
.sheet-label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; margin: 14px 6px 6px; }
.choice {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: 12px;
}
.choice:active { background: var(--card-2); }
.choice + .choice { border-top: 1px solid var(--card); }
.choice .tag { flex: none; font: 600 13px var(--body); color: var(--muted); background: var(--card); border-radius: 6px; padding: 2px 7px; font-variant-numeric: tabular-nums; }
.current { background: var(--card); border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.current .btn { min-height: 40px; padding: 0 14px; font-size: 15px; }
.none-left { color: var(--muted); text-align: center; padding: 16px; }

@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Result ---------- */

.result-hero { text-align: center; padding: 8vh 0 18px; }
.result-hero .label { color: var(--muted); }
.result-hero .score {
  font: 800 clamp(80px, 26vw, 128px)/1 var(--display);
  color: var(--gold);
  text-shadow: 0 4px 0 var(--pink);
}
.result-hero .of { color: var(--muted); font-size: 18px; }
.result-hero .rank { font: 800 24px var(--display); margin-top: 10px; }
.result-hero .note { color: var(--muted); font-size: 14px; margin-top: 6px; }
.stats { display: flex; justify-content: center; gap: 18px; margin: 14px 0 0; color: var(--muted); font-size: 15px; }
.stats b { color: var(--text); }

.result-actions { display: grid; gap: 10px; margin: 20px 0 26px; }

.reveal { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.reveal li {
  display: grid;
  grid-template-columns: 64px 1fr;
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
  opacity: 0;
  animation: pop .35s ease forwards;
}
.reveal .yr { display: grid; place-items: center; align-content: center; gap: 2px; font: 800 19px var(--display); background: var(--card-2); }
.reveal .mark { font-size: 16px; }
.reveal .body { padding: 10px 14px; display: grid; gap: 6px; min-width: 0; }
.reveal li.ok { box-shadow: inset 4px 0 0 var(--ok); }
.reveal li.near { box-shadow: inset 4px 0 0 var(--near); }
.reveal li.bad { box-shadow: inset 4px 0 0 var(--bad); }
.reveal .yours { opacity: .7; }
.reveal .yours .t { text-decoration: line-through; text-decoration-color: var(--bad); }
.reveal li.near .yours .t { text-decoration: none; }
.reveal .hint { color: var(--muted); font-size: 13px; }
.reveal .right-lbl { color: var(--ok); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  z-index: 60;
  animation: fade .2s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}

/* ---------- Leaderboard ---------- */

.lb { padding-top: calc(24px + env(safe-area-inset-top)); }
.lb-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.lb-head h1 { font-size: clamp(30px, 6vw, 56px); font-weight: 800; }
.lb-head .meta { color: var(--muted); font-size: 14px; text-align: right; }
.lb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lb-list li {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: clamp(16px, 2.4vw, 26px);
}
.lb-list .pos { font: 800 1.2em var(--display); color: var(--muted); text-align: center; }
.lb-list li:nth-child(1) .pos { color: var(--gold); }
.lb-list li:nth-child(1) { box-shadow: inset 0 0 0 2px var(--gold); }
.lb-list .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .sub { color: var(--muted); font-size: .7em; }
.lb-list .pts { font: 800 1.3em var(--display); font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--muted); text-align: center; padding: 18vh 0; }
.lb-foot { text-align: center; margin-top: 22px; color: var(--muted); }
.lb-foot a { color: var(--gold); }
@media (min-width: 900px) {
  .lb { max-width: 900px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal li { opacity: 1; }
}
