:root {
  --bg: #17181c;
  --panel: #222329;
  --panel-2: #2b2d34;
  --line: #34363e;
  --line-2: #43464f;
  --text: #f2f3f5;
  --muted: #9ea3ad;
  --accent: #5865f2;
  --accent-2: #4752c4;
  --good: #22c55e;
  --bad: #ef4444;
  --season: #3b82f6;
  --radius: 16px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 "gg sans", "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(900px 420px at 50% -120px, color-mix(in srgb, var(--season) 22%, transparent), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
h2, h3 { letter-spacing: -.01em; }

#app { max-width: 780px; margin: 0 auto; padding: 14px 16px 48px; }
.center { min-height: 70vh; display: grid; place-content: center; text-align: center; gap: 10px; color: var(--muted); }
.small-center { min-height: 120px; }
.spinner { width: 30px; height: 30px; margin: 0 auto; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; max-width: 420px; color: var(--text); box-shadow: var(--shadow); }
.error-box h2 { margin: 0 0 6px; font-size: 18px; }
.error-box p { margin: 0 0 14px; color: var(--muted); }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.who .name { font-weight: 700; }
.who small { display: block; color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 13px; transition: background .15s, color .15s; }
.tabs button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.35); }

/* ---------- banner ---------- */
.banner {
  position: relative; border-radius: var(--radius); overflow: hidden; aspect-ratio: 5 / 2; max-height: 210px; width: 100%;
  background:
    radial-gradient(circle at 20% 120%, rgba(255,255,255,.18), transparent 45%),
    linear-gradient(135deg, var(--season), color-mix(in srgb, var(--season) 40%, #000));
  display: grid; place-items: center; margin-bottom: 14px; box-shadow: var(--shadow);
}
.banner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.banner .label { position: relative; font-size: clamp(22px, 6vw, 38px); font-weight: 800; letter-spacing: -.01em; text-shadow: 0 2px 14px rgba(0,0,0,.35); }
.banner.has-img .label { display: none; }

/* ---------- cards & buttons ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h2 small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.btn {
  border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 12px; padding: 10px 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; min-height: 42px;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--c, var(--accent)) 70%, var(--line-2));
  background: color-mix(in srgb, var(--c, var(--accent)) 14%, var(--panel-2));
}
.btn:focus-visible, .pill:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.big {
  flex-direction: column; gap: 2px; min-height: 96px; padding: 14px 10px; border-radius: 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c, var(--accent)) 10%, var(--panel-2)), var(--panel-2));
}
.btn.big .e { font-size: 28px; line-height: 1.1; margin-bottom: 2px; }
.btn.big .l { font-size: 16px; }
.btn.big .s { font-size: 12px; font-weight: 400; color: var(--muted); }
.btn.big:hover:not(:disabled) { box-shadow: 0 6px 18px color-mix(in srgb, var(--c, var(--accent)) 25%, transparent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: none; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 12.5px; border-radius: 9px; }
.btn.wide { min-width: 200px; min-height: 46px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.center-row { justify-content: center; }
.muted { color: var(--muted); }
.back { border: 0; background: none; color: var(--muted); padding: 0; margin-bottom: 10px; font-size: 13px; }
.back:hover { color: var(--text); }

/* ---------- result stage ---------- */
.stage { text-align: center; overflow: hidden; border-color: color-mix(in srgb, var(--c) 40%, var(--line)); }
.scene { position: relative; height: 250px; display: grid; place-items: center; margin: -4px -4px 8px; }
.scene.small { height: 150px; }
.scene .glow {
  position: absolute; inset: 0; border-radius: 12px;
  background: radial-gradient(closest-side at 50% 58%, color-mix(in srgb, var(--c) 45%, transparent), transparent);
}
.art-wrap { position: relative; width: min(290px, 80%); }
.art-wrap .art { width: 100%; height: auto; display: block; filter: drop-shadow(0 10px 18px rgba(0,0,0,.35)); }
.art-wrap img.art { max-height: 220px; object-fit: contain; border-radius: 12px; }
.emoji-art { font-size: 90px; text-align: center; }
.big-emoji { position: relative; font-size: 84px; line-height: 1; filter: drop-shadow(0 8px 14px rgba(0,0,0,.35)); }
.leaf { position: relative; font-size: 64px; }
.sparks { position: absolute; left: 50%; top: 55%; }
.sparks b { position: absolute; width: 9px; height: 9px; margin: -4.5px; border-radius: 50%; background: color-mix(in srgb, var(--c) 50%, #fff); opacity: 0; }
.sparks b:nth-child(3n) { background: #fde68a; width: 7px; height: 7px; }
.caption .kicker { color: var(--muted); font-size: 13px; margin-bottom: 2px; }
.caption .headline { font-size: clamp(22px, 5vw, 30px); font-weight: 800; margin: 0 0 6px; }
.story { margin: 4px auto 0; max-width: 520px; }
.foot { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.stage .row { margin-top: 14px; }

/* searching */
.scene.searching { overflow: hidden; }
.grass { position: absolute; left: 0; right: 0; bottom: 0; height: 80px; }
.grass i {
  position: absolute; bottom: -6px; width: 22px; border-radius: 60% 60% 0 0 / 100% 100% 0 0;
  background: linear-gradient(180deg, #4ade80, #166534); transform-origin: 50% 100%; opacity: .9;
}
.grass i:nth-child(even) { background: linear-gradient(180deg, #22c55e, #14532d); width: 18px; }
.prints { position: relative; display: flex; gap: 22px; font-size: 26px; transform: rotate(-8deg) translateY(-24px); }
.prints span { opacity: .25; }
.searching-text { color: var(--muted); }

/* tally */
.tally .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px 3px 4px; font-size: 13px; }
.mini { display: inline-grid; place-items: center; width: 34px; height: 26px; flex: none; }
.mini svg { width: 100%; height: 100%; }
.mini.e { font-size: 18px; }

/* ---------- admin ---------- */
.admin-nav { margin-bottom: 14px; }
.seasons { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.seasons .btn.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 28%, var(--panel-2)); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.pill { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s, border-color .15s; }
.pill:hover { color: var(--text); }
.pill.on { color: var(--text); border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 22%, var(--panel-2)); }
.pill .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #f59e0b; margin-left: 6px; vertical-align: middle; }
.pill .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: #f59e0b; color: #1b1b1b; font-size: 11px; line-height: 18px; }
.odds { display: grid; gap: 8px; }
.odd { display: grid; grid-template-columns: minmax(130px, 1.2fr) 2fr 72px; gap: 10px; align-items: center; }
.odd .name { display: flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.odd input[type=range] { width: 100%; accent-color: var(--c, var(--accent)); }
.odd input[type=number], .field, .select {
  background: var(--bg); border: 1px solid var(--line-2); color: var(--text); border-radius: 8px; padding: 7px 9px; font: inherit;
}
.odd input[type=number] { width: 100%; text-align: right; }
.total { margin: 12px 0; font-weight: 700; }
.total.bad { color: var(--bad); }
.total.ok { color: var(--good); }
.note { font-size: 13px; color: var(--muted); margin: 0 0 12px; }

/* pictures */
.pic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; }
.pic-grid.wide { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: 13px; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.thumb {
  position: relative; aspect-ratio: 4 / 3; border-radius: 9px; overflow: hidden; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 65%, color-mix(in srgb, var(--c, var(--accent)) 35%, transparent), var(--bg) 72%);
}
.tile.wide .thumb { aspect-ratio: 5 / 2; background: var(--bg); }
.thumb .art { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb .art.cover { object-fit: cover; }
.thumb-busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); }
.mini-banner {
  width: 100%; height: 100%; display: grid; place-items: center; font-weight: 800; font-size: 15px;
  background: linear-gradient(135deg, var(--season), color-mix(in srgb, var(--season) 40%, #000));
}
.tile-head { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tile-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { flex: none; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.badge.upload { background: color-mix(in srgb, var(--good) 22%, transparent); color: #86efac; }
.badge.link { background: color-mix(in srgb, var(--accent) 28%, transparent); color: #c7cbff; }
.tile-link { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.tile-actions .btn { padding: 5px 4px; gap: 4px; font-size: 12px; white-space: nowrap; }
.tile-actions .btn:last-child { grid-column: 1 / -1; }
.tile.wide .tile-actions { grid-template-columns: 1fr 1fr 1fr; }
.tile.wide .tile-actions .btn:last-child { grid-column: auto; }

/* dialog + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; z-index: 20; }
.sheet { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.sheet h3 { margin: 0 0 6px; font-size: 17px; }
.sheet p { margin: 0 0 12px; color: var(--muted); }
.sheet .field { width: 100%; margin-bottom: 14px; }
#toast {
  position: fixed; left: 50%; bottom: 18px; translate: -50% 0; max-width: calc(100% - 32px);
  background: #0f1013; border: 1px solid var(--line-2); color: var(--text); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); z-index: 30;
}
#toast.bad { border-color: var(--bad); }

@media (max-width: 520px) {
  .odd { grid-template-columns: 1fr 64px; }
  .odd input[type=range] { grid-column: 1 / -1; order: 3; }
  .btn.big { min-height: 84px; }
  .scene { height: 215px; }
  .pic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
