/* PIU Weekly: a dim arcade, a bright screen. Colours come from the dance pad: the yellow centre step confirms,
   blue (the down arrows) selects and moves, red (the up arrows) goes back or removes. Orange and green are the
   game's Single and Double level balls. */

:root {
  --ink: #16153d;
  --ink-raised: #201f52;
  --ink-sunk: #0f0e2c;
  --line: #36357a;
  --text: #f5f3ff;
  --muted: #b3afdc;
  --faint: #8783bd;
  --yellow: #ffd23f;
  --yellow-ink: #221a00;
  --red: #ff5a6e;
  --blue: #4f90ff;
  --blue-soft: #9dbcff;
  --single: #ff8a1f;
  --double: #2ac46c;
  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "Saira Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --gutter: 16px;
  --tabs-h: 64px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 400 16px/1.45 var(--font-body);
  overflow-x: hidden;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px var(--gutter) calc(var(--tabs-h) + 32px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; line-height: 1.15; }
h1 { font: 800 30px/1.1 var(--font-num); letter-spacing: 0.01em; }
h2 { font: 800 22px/1.15 var(--font-num); letter-spacing: 0.01em; margin: 28px 0 10px; }
p { margin: 0 0 10px; }
a { color: var(--blue-soft); }
img { max-width: 100%; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* page head */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 14px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.back { display: inline-flex; align-items: center; min-height: 44px; color: var(--blue-soft); text-decoration: none; font-weight: 700; }

/* brand + countdown hero */
.brand { display: flex; align-items: center; gap: 8px; font: 800 18px/1 var(--font-num); letter-spacing: 0.02em; color: var(--muted); }
.brand svg { width: 26px; height: 26px; }
.hero { margin: 6px 0 4px; padding: 14px 0 6px; }
.hero-label { margin: 14px 0 0; color: var(--muted); font-weight: 700; }
.countdown {
  margin: 0;
  font: 800 clamp(44px, 15vw, 64px)/1 var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--text);
}
.countdown .unit { font-size: 0.55em; color: var(--muted); margin: 0 0.12em 0 0.02em; }
.countdown.soon { color: var(--yellow); }
.countdown.last { color: var(--red); }
.hero-sub { margin: 6px 0 0; color: var(--muted); }

/* level ball, after the game's */
.ball {
  --c: var(--single);
  flex: none;
  display: inline-grid;
  place-items: center;
  align-content: center;
  width: 50px; height: 50px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255,255,255,0.55) 0 14%, transparent 34%),
    radial-gradient(circle at 50% 50%, var(--c) 0 58%, color-mix(in srgb, var(--c) 60%, #000) 100%);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.85), 0 0 14px color-mix(in srgb, var(--c) 55%, transparent);
  color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,0.55), 0 0 3px rgba(0,0,0,0.6);
  font-family: var(--font-num);
  line-height: 1;
}
.ball.double { --c: var(--double); }
.ball-mode { font-size: 10px; font-weight: 800; letter-spacing: 0.08em; margin-bottom: 1px; }
.ball-lv { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ball.sm { width: 40px; height: 40px; }
.ball.sm .ball-lv { font-size: 19px; }
.ball.sm .ball-mode { font-size: 9px; }
.ball.lg { width: 64px; height: 64px; }
.ball.lg .ball-lv { font-size: 31px; }
.ball.lg .ball-mode { font-size: 11px; }

.hj {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--red);
  color: #2b0007;
  font: 800 13px/1.35 var(--font-num);
  letter-spacing: 0.06em;
  vertical-align: 1px;
}

.grade { font: 800 17px/1 var(--font-num); letter-spacing: 0.02em; color: var(--blue-soft); }
.grade.s { color: var(--yellow); }
.plate { font-size: 13px; color: var(--muted); }

/* song card art */
.art {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(135deg, #2c2b6e, #1a1946);
  display: grid;
  place-items: center;
}
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.art-ph {
  padding: 4px 6px;
  font: 800 13px/1.05 var(--font-num);
  color: var(--muted);
  text-align: center;
  overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* chart card (this week, past weeks) */
.playlist { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.chart-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  grid-template-areas: "art main ball" "scores scores scores";
  gap: 4px 12px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
  background: var(--ink-raised);
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
}
a.chart-card:active { border-color: var(--blue); }
.chart-card .art { grid-area: art; }
.card-main { grid-area: main; min-width: 0; }
.chart-card .ball { grid-area: ball; }
.card-title { font: 700 17px/1.2 var(--font-body); overflow-wrap: anywhere; }
.card-meta { margin: 3px 0 0; font-size: 14px; color: var(--muted); }
.card-scores { grid-area: scores; margin: 6px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.card-scores .line { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-size: 15px; }
.card-scores .who { width: 54px; flex: none; color: var(--muted); font-size: 14px; }
.card-scores .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-scores .score { margin-left: auto; font: 800 19px/1 var(--font-num); font-variant-numeric: tabular-nums; }
.card-scores .grade { width: 36px; text-align: right; }
.card-scores .pts { width: 44px; text-align: right; color: var(--muted); font-size: 14px; }
.card-scores .none { color: var(--muted); font-size: 14px; }

/* rankings */
.ranking { list-style: none; margin: 0; padding: 0; border-radius: 14px; background: var(--ink-raised); overflow: hidden; }
.rank-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 10px;
  padding: 10px 12px;
  min-height: 56px;
}
.rank-row + .rank-row { border-top: 1px solid var(--line); }
.rank-row.me { background: color-mix(in srgb, var(--blue) 14%, transparent); }
.rank-n { font: 800 24px/1 var(--font-num); color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.rank-n.r1 { color: var(--yellow); }
.rank-name { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.rank-sub { grid-column: 2 / 4; font-size: 14px; color: var(--muted); margin-top: -2px; }
.rank-sub::first-letter { text-transform: uppercase; }
.rank-val { text-align: right; white-space: nowrap; }
.rank-val .big { font: 800 22px/1 var(--font-num); font-variant-numeric: tabular-nums; }
.rank-val .grade { margin-left: 6px; }
.rank-val .unit { color: var(--muted); font-size: 13px; margin-left: 3px; }
.trophy { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; color: var(--yellow); }
.empty { padding: 16px; border-radius: 14px; background: var(--ink-raised); color: var(--muted); }
.empty p:last-child { margin: 0; }

/* buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--text);
  font: 700 16px/1.2 var(--font-body);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: var(--yellow-ink); }
.btn.primary:active { background: #ffe27a; }
.btn.select { border-color: var(--blue); color: var(--blue-soft); }
.btn.danger { border-color: color-mix(in srgb, var(--red) 70%, transparent); color: var(--red); }
.btn.small { min-height: 44px; padding: 8px 12px; font-size: 15px; }
.btn.block { display: flex; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row > .btn { flex: 1 1 auto; }

.field { display: block; margin: 0 0 14px; }
.field > span:first-child, .field > label:first-child { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 700; color: var(--muted); }
.field .hint { display: block; margin-top: 5px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--ink-sunk);
  color: var(--text);
  font: 400 17px/1.3 var(--font-body);
}
input[type="number"] { font-family: var(--font-num); font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
input:focus, select:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 35%, transparent); }
input[readonly] { color: var(--muted); }

.check { display: flex; align-items: center; gap: 12px; min-height: 48px; margin: 0 0 10px; cursor: pointer; font-weight: 700; }
.check input { width: 24px; height: 24px; min-height: 0; margin: 0; accent-color: var(--yellow); flex: none; }

/* a checkbox drawn as a switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; cursor: pointer; font-weight: 700; }
.switch input {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 52px; height: 30px; min-height: 0; padding: 0; margin: 0;
  border-radius: 15px; border: 0; background: var(--line); position: relative; cursor: pointer;
  transition: background 0.15s;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: transform 0.15s;
}
.switch input:checked { background: var(--red); }
.switch input:checked::after { transform: translateX(22px); }

.seg { display: flex; padding: 3px; gap: 3px; border-radius: 12px; background: var(--ink-sunk); border: 1.5px solid var(--line); }
.seg button {
  flex: 1; min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  font: 700 16px/1 var(--font-body); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 44px; height: 44px; flex: none; border-radius: 10px; border: 1.5px solid var(--line); background: var(--ink-sunk);
  color: var(--text); font: 800 22px/1 var(--font-num); cursor: pointer;
}
.stepper output { display: inline-block; min-width: 30px; text-align: center; font: 800 22px/1 var(--font-num); font-variant-numeric: tabular-nums; }

.form-error { color: var(--red); font-weight: 700; margin: 4px 0 10px; }
.form-error:empty { display: none; }
.note { padding: 10px 12px; border-radius: 10px; background: var(--ink-sunk); color: var(--muted); font-size: 15px; }

.card { padding: 14px; border-radius: 14px; background: var(--ink-raised); }
.card > :last-child { margin-bottom: 0; }
.card + .card { margin-top: 10px; }

/* next week */
.slots { display: grid; gap: 10px; }
.slot { padding: 12px; border-radius: 14px; background: var(--ink-raised); }
.slot-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 700; color: var(--muted); }
.mini { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mini .art { width: 72px; flex: none; }
.mini-main { flex: 1; min-width: 0; }
.mini-title { font-weight: 700; overflow-wrap: anywhere; }
.mini-sub { font-size: 14px; color: var(--muted); }

.picker-controls { display: grid; gap: 12px; padding: 12px; border-radius: 14px; background: var(--ink-raised); }
.levels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.levels > div > span { display: block; margin-bottom: 4px; font-weight: 700; color: var(--muted); font-size: 14px; }
.results { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.pick-result {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 10px;
  border-radius: 12px; border: 1.5px solid transparent; background: var(--ink-raised); color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.pick-result:disabled { opacity: 0.45; cursor: default; }
.pick-result .taken { display: block; font-size: 13px; color: var(--muted); }
.pick-result .taken.warn { color: var(--yellow); }
.list-plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list-plain > li { padding: 8px 10px; border-radius: 12px; background: var(--ink-raised); }

/* chart page */
.chart-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 14px; align-items: center; margin-bottom: 14px; }
.chart-head .art { grid-column: 1 / -1; border-radius: 14px; aspect-ratio: 2.4 / 1; }
.chart-head h1 { overflow-wrap: anywhere; }
.chart-head p { margin: 4px 0 0; color: var(--muted); }
.submissions { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.submission { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 4px 12px; padding: 10px; border-radius: 14px; background: var(--ink-raised); }
.submission .thumb {
  grid-row: span 3; width: 64px; height: 64px; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--ink-sunk);
  cursor: zoom-in; display: grid; place-items: center; color: var(--faint); font-size: 12px;
}
.submission .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sub-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.sub-top .score { font: 800 21px/1 var(--font-num); font-variant-numeric: tabular-nums; }
.sub-counts { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sub-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }

/* tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--ink-sunk) 94%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.tabs-inner { display: flex; width: 100%; max-width: 640px; }
.tabs a {
  flex: 1 1 0; min-width: 0; min-height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 700;
  position: relative; -webkit-tap-highlight-color: transparent;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a[aria-current="page"] { color: var(--yellow); }
.tabs a[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--yellow);
}

/* sheets */
dialog.sheet {
  position: fixed; inset: auto 0 0 0;
  width: 100%; max-width: 640px; max-height: 92dvh;
  margin: 0 auto; padding: 0;
  border: 0; border-radius: 20px 20px 0 0;
  background: var(--ink-raised); color: var(--text);
  overflow: hidden;
  display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet::backdrop { background: rgba(6, 5, 24, 0.72); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 8px 8px var(--gutter); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 22px; }
.sheet-close { width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 26px; cursor: pointer; }
.sheet-body { padding: 16px var(--gutter) calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: sheet-in 0.22s ease-out; }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
}

dialog.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; }
dialog.lightbox::backdrop { background: #000; }
dialog.lightbox img { width: 100%; height: 100%; object-fit: contain; }
dialog.lightbox .sheet-close { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,0.6); color: #fff; }

/* submit sheet */
.photo-pick { position: relative; overflow: hidden; }
.pick-area { margin-bottom: 16px; }
.pick-area > .btn-row { margin-top: 0; }
.photo-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.preview { position: relative; margin: 0 0 14px; border-radius: 12px; overflow: hidden; background: var(--ink-sunk); }
.preview img { display: block; width: 100%; max-height: 260px; object-fit: contain; }
.preview figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px;
  background: linear-gradient(transparent, rgba(6, 5, 24, 0.92) 45%);
  font-weight: 700;
}
.reading::before {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border-radius: 50%; border: 2.5px solid var(--yellow); border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .reading::before { animation: none; } }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 14px; padding: 0; border: 0; }
.sides legend { padding: 0; margin-bottom: 6px; font-size: 14px; font-weight: 700; color: var(--muted); }
.side {
  display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 8px 10px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--ink-sunk); cursor: pointer; min-width: 0; overflow-wrap: anywhere; font-size: 15px;
}
.side:has(input:checked) { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 18%, var(--ink-sunk)); }
.side input { width: 20px; height: 20px; min-height: 0; margin: 0; flex: none; accent-color: var(--blue); }
.counts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 10px; }
.score-row { display: grid; grid-template-columns: minmax(0, 1fr) 64px; gap: 10px; align-items: end; }
.score-row .grade { display: grid; place-items: center; min-height: 48px; margin-bottom: 14px; font-size: 22px; }
.warnings { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.warnings li { padding: 9px 12px; border-radius: 10px; background: color-mix(in srgb, var(--yellow) 14%, var(--ink-sunk)); border-left: 4px solid var(--yellow); font-size: 15px; }
.logged-in { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; color: var(--muted); }
.logged-in strong { color: var(--text); }

/* toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + 14px + env(safe-area-inset-bottom)); z-index: 20; display: grid; justify-items: center; gap: 6px; pointer-events: none; padding: 0 var(--gutter); }
.toast { max-width: 560px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--ink); font-weight: 700; box-shadow: 0 6px 24px rgba(0,0,0,0.45); }
.toast.error { background: var(--red); color: #2b0007; }

/* admin */
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.admin-row .who { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.tag { display: inline-block; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line); font-size: 12px; color: var(--muted); margin-left: 6px; vertical-align: 2px; font-weight: 700; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; font-size: 15px; }
dl.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0 0 12px; font-size: 15px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; }

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

@media (min-width: 720px) {
  main { padding-top: 24px; }
  .chart-card { grid-template-columns: 128px minmax(0, 1fr) auto; }
}
