:root {
  color-scheme: light;
  --bg: #f5f2fa;
  --surface: #fdfcfe;
  --ink: #1f1b29;
  --ink-2: #514c5e;
  --ink-3: #6f6a7d;
  --line: #e4dfee;
  --accent: #5a2ca0;
  --accent-ink: #ffffff;
  --summary-bg: #ece5f7;
  --summary-line: #d6cbea;
  --grade-good: #14803f;
  --grade-middle: #a07a00;
  --grade-low: #c62828;
  --header-from: #1b1464;
  --header-mid: #4a1a8c;
  --header-to: #8c2a78;
  --danger: #b3261e;
  --good: #1a7f4e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --confetti-1: #ffc42e;
  --confetti-2: #ff5d73;
  --confetti-3: #31c8e8;
  --confetti-4: #5ddb7c;
  --confetti-5: #b57bff;
  --confetti-6: #ff9a3d;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14111c;
    --surface: #1c1926;
    --ink: #f1eef7;
    --ink-2: #c6c0d4;
    --ink-3: #a29cb1;
    --line: #342f42;
    --accent: #b99cf2;
    --accent-ink: #1a1030;
    --summary-bg: #2b2540;
    --summary-line: #3f3757;
    --grade-good: #5fd38d;
    --grade-middle: #f4cf4e;
    --grade-low: #ff8a80;
    --header-from: #15104a;
    --header-mid: #351468;
    --header-to: #64205a;
    --danger: #f2837b;
    --good: #5ccb94;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1rem; }

.page-decorations { position: fixed; inset: 0; width: 100%; height: 100%; opacity: 0.1; pointer-events: none; z-index: -1; }

.topbar {
  position: relative;
  background: linear-gradient(100deg, var(--header-from) 0%, var(--header-mid) 55%, var(--header-to) 100%);
  color: #ffffff;
  border-bottom: 3px solid var(--confetti-1);
}
.header-decorations { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.35; pointer-events: none; }
.topbar-inner, .topbar nav { position: relative; }
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; font-weight: 650; }
.brand .login-medal { width: 22px; height: 25px; flex: none; }
.who { display: flex; align-items: center; gap: 10px; color: #e9e2f5; font-size: 0.875rem; min-width: 0; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who button { background: transparent; border-color: rgb(255 255 255 / 0.55); color: #ffffff; flex: none; }
.who button:hover { background: rgb(255 255 255 / 0.15); }

nav { max-width: 1040px; margin: 0 auto; padding: 0 16px; display: flex; flex-wrap: wrap; gap: 2px; }
nav button {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 8px 10px;
  color: #e9e2f5;
  font-weight: 500;
  white-space: nowrap;
}
nav button:hover { color: #ffffff; background: rgb(255 255 255 / 0.1); }
nav button[aria-current="page"] { color: #ffffff; border-bottom-color: var(--confetti-1); }
.menu-wrap { position: relative; }
.menu-caret { font-size: 0.7em; margin-left: 4px; }
.admin-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  min-width: 170px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.25);
}
.admin-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 5px;
  color: var(--ink);
}
.admin-menu button:hover { background: var(--bg); color: var(--ink); }
.admin-menu button[aria-current="page"] { color: var(--accent); font-weight: 650; border: 0; }

main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; display: grid; gap: 16px; }
main > * { min-width: 0; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}
.stack { display: grid; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tiles .card { border-top: 3px solid var(--confetti-1); }
.tile-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.tile-total { font-size: 2rem; font-weight: 650; line-height: 1.2; margin-top: 8px; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--ink-2); font-size: 0.875rem; }
.charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.muted { color: var(--ink-2); font-size: 0.875rem; margin: 0; }
.error { color: var(--danger); font-size: 0.875rem; margin: 0; }
.success { color: var(--good); font-size: 0.875rem; margin: 0; }
.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.875rem;
  color: var(--ink-2);
  margin: 0;
}

label { display: grid; gap: 4px; font-size: 0.875rem; color: var(--ink-2); }
input, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--ink-3);
  border-radius: 6px;
  padding: 7px 9px;
  min-height: 38px;
  width: 100%;
}
input[aria-invalid="true"] { border-color: var(--danger); outline-color: var(--danger); }
select { width: auto; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  min-height: 38px;
}
button:hover { background: var(--bg); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--danger); }
button.small { min-height: 32px; padding: 4px 9px; font-size: 0.875rem; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th { color: var(--ink-2); font-weight: 600; font-size: 0.8125rem; white-space: nowrap; }
tbody th { font-weight: 500; white-space: nowrap; }
td.num, th.num { text-align: right; }
td.center, th.center { text-align: center; }
tr.summary th, tr.summary td { font-weight: 650; background: var(--summary-bg); border-bottom-color: var(--summary-line); }
tr:not(.summary) + tr.summary th, tr:not(.summary) + tr.summary td { border-top: 2px solid var(--accent); }
.sticky-first tr.summary th:first-child, .sticky-first tr.summary td:first-child { background: var(--summary-bg); }
.grade-A, .grade-B, .behavior-1 { color: var(--grade-good); }
.grade-C, .behavior-2 { color: var(--grade-middle); }
.grade-D, .grade-E, .behavior-3 { color: var(--grade-low); }
tr.final th, tr.final td { font-weight: 700; border-top: 2px solid var(--ink-3); border-bottom: 0; }
.sticky-first th:first-child, .sticky-first td:first-child { position: sticky; left: 0; background: var(--surface); }

.grade { display: inline-block; min-width: 1.4em; text-align: center; font-weight: 650; }
.blank { color: var(--ink-3); }
.pill { font-size: 0.75rem; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }

.picker {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  gap: 12px 16px;
  align-items: end;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
}
.picker select { width: 100%; }
.picker-label { font-size: 0.875rem; color: var(--ink-2); margin-bottom: 4px; }
.letter-buttons { display: flex; gap: 6px; }
.letter-buttons button { width: 46px; min-height: 42px; font-weight: 700; padding: 0; border-color: var(--ink-3); }
.letter-buttons button:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  min-height: 30px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 650;
  font-size: 0.875rem;
  border-color: var(--ink-3);
}
.chip span { margin-left: 5px; color: var(--ink-3); font-weight: 400; }
.chip:hover { border-color: var(--danger); }
.chip-locked { display: inline-flex; align-items: center; border: 1px solid var(--line); }
.chip-locked:hover { border-color: var(--line); }
.notice-action { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.retired th, .retired td { color: var(--ink-3); }
.subject-name { min-width: 150px; }
.icon-button { min-width: 32px; padding: 4px 6px; }
.result-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 12px; }
.result-card {
  display: grid;
  gap: 2px;
  align-content: start;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--summary-bg);
  border: 1px solid var(--summary-line);
}
.result-card-label { font-size: 0.875rem; font-weight: 600; color: var(--ink-2); }
.result-card-value { font-size: 2.25rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.result-card-note { font-size: 0.8125rem; color: var(--ink-2); }
.result-card-strong { font-size: 0.9375rem; font-weight: 600; color: var(--ink); }
.result-card-final {
  background: linear-gradient(100deg, var(--header-from) 0%, var(--header-mid) 55%, var(--header-to) 100%);
  border: 0;
  border-bottom: 3px solid var(--confetti-1);
  color: #ffffff;
}
.result-card-final .result-card-label, .result-card-final .result-card-note { color: #e9e2f5; }
.result-card-final .result-card-strong { color: #ffffff; }
/* Rewards wait behind question marks, then roll like a calculator before locking in. */
.hidden-totals .result-card-value { opacity: 0.7; }
td.num.rolling, .rolling .result-card-value, .rolling .result-card-strong { font-variant-numeric: tabular-nums; opacity: 0.8; }
@media (prefers-reduced-motion: no-preference) {
  .rolling .result-card-value { animation: calculating 0.35s ease-in-out infinite alternate; }
}
@keyframes calculating { from { opacity: 0.6; } to { opacity: 1; } }
.picker-section { padding-left: 16px; border-left: 1px solid var(--line); }
.rates-line { color: var(--ink-2); font-size: 0.875rem; margin: 0; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .picker { grid-template-columns: 1fr; }
  .picker-section { padding-left: 0; border-left: 0; }
  .letter-buttons button { flex: 1; width: auto; }
}
.money-input { min-width: 90px; max-width: 120px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.inline-form input { width: 190px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.form-grid select { width: 100%; }

.sub-title { color: var(--ink-2); font-size: 0.9375rem; margin: 2px 0 0; }
th .level { display: block; color: var(--ink-3); font-weight: 500; font-size: 0.75rem; }
.result-banner {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 0;
}
.result-banner.honor { border-left-color: var(--confetti-1); }
.result-message { font-size: 1.75rem; font-weight: 700; line-height: 1.25; }
tr.selectable { cursor: pointer; }
tr.selectable:hover th, tr.selectable:hover td { background: var(--bg); }
tr.selected-row th, tr.selected-row td, tr.selected-row:hover th, tr.selected-row:hover td { background: var(--summary-bg); }
tr.selected-row th { box-shadow: inset 3px 0 0 var(--accent); }
.row-subject {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: inherit;
  text-align: left;
}
.row-subject:hover { background: none; }

/* Sign-in page */
.login {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(160deg, #1b1464 0%, #4a1a8c 48%, #b02a78 100%);
}
.login-decorations { position: absolute; inset: 0; width: 100%; height: 100%; }
.login form {
  position: relative;
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 14px;
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.4);
}
.login button { width: 100%; }
.login-head { display: grid; justify-items: center; gap: 6px; text-align: center; }
.login-medal { width: 58px; height: 65px; }
.login-title { font-size: 1.4rem; font-weight: 700; }
.login-tagline { color: var(--ink-2); font-size: 0.9375rem; margin: 0; }

/* Fireworks */
.fireworks-overlay { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }
.fireworks-sky { fill: rgb(18 10 48 / 0.62); }
.fireworks-name-sky { fill: rgb(10 5 30 / 0.62); }
.fireworks-flash { fill: #ffffff; }
.fireworks-trail { stroke: rgb(255 255 255 / 0.55); stroke-width: 2; stroke-linecap: round; }
.fireworks-trail-main { stroke: rgb(255 220 130 / 0.85); stroke-width: 4; }
.fireworks-shock { fill: none; stroke: #fff3c4; stroke-width: 5; }

/* Confetti colors, shared with the fireworks */
.confetti-fill-0 { fill: var(--confetti-1); }
.confetti-fill-1 { fill: var(--confetti-2); }
.confetti-fill-2 { fill: var(--confetti-3); }
.confetti-fill-3 { fill: var(--confetti-4); }
.confetti-fill-4 { fill: var(--confetti-5); }
.confetti-fill-5 { fill: var(--confetti-6); }
.confetti-stroke-0, .confetti-stroke-1, .confetti-stroke-2, .confetti-stroke-3, .confetti-stroke-4, .confetti-stroke-5 {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}
.confetti-stroke-0 { stroke: var(--confetti-1); }
.confetti-stroke-1 { stroke: var(--confetti-2); }
.confetti-stroke-2 { stroke: var(--confetti-3); }
.confetti-stroke-3 { stroke: var(--confetti-4); }
.confetti-stroke-4 { stroke: var(--confetti-5); }
.confetti-stroke-5 { stroke: var(--confetti-6); }
.balloon-string { fill: none; stroke: rgb(255 255 255 / 0.6); stroke-width: 1.5; }
.balloon-shine { fill: rgb(255 255 255 / 0.4); }
.medal-gold { fill: #e8a800; }
.medal-ring { fill: none; stroke: #fff3c4; stroke-width: 2; }
.medal-star { fill: #fff3c4; }

/* Charts */
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.series-1-bg { background: var(--series-1); }
.series-2-bg { background: var(--series-2); }
.series-3-bg { background: var(--series-3); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8125rem; color: var(--ink-2); margin: 6px 0 2px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font: 12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; fill: var(--ink-2); }
.chart text.end-label { fill: var(--ink); font-weight: 600; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.zero-line { stroke: var(--ink-3); stroke-width: 1; }
.crosshair { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.reference-line { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart text.reference-label { fill: var(--ink-2); font-weight: 600; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-1-line { stroke: var(--series-1); }
.series-2-line { stroke: var(--series-2); }
.series-3-line { stroke: var(--series-3); }
.series-dot { stroke: var(--surface); stroke-width: 2; }
.series-1-dot { fill: var(--series-1); }
.series-2-dot { fill: var(--series-2); }
.series-3-dot { fill: var(--series-3); }
.tooltip {
  position: absolute;
  top: 8px;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--ink-3);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 0.8125rem;
  white-space: nowrap;
  z-index: 2;
}
.tooltip div { display: flex; align-items: center; gap: 6px; }
.tooltip strong { display: block; margin-bottom: 2px; }
.tooltip .value { margin-left: auto; padding-left: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
