@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@400;500;700;900&display=swap');

:root {
  --paper: #F6F8FB;
  --card: #FFFFFF;
  --ink: #16213A;
  --muted: #5B6884;
  --line: #DCE3EE;
  --cobalt: #2B59C3;
  --cobalt-soft: #E6EDFB;
  --gold: #F2B705;
  --green: #1E9E6A;
  --red: #D1495B;
  --radius: 10px;
  font-family: 'Lexend', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 16px; line-height: 1.5; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 500; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 1.25rem; background: var(--ink); color: #fff;
}
.topbar .brand { font-weight: 900; font-size: 1.1rem; margin-right: auto; }
.topbar button { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tabs button {
  background: transparent; color: rgba(255,255,255,.75); border: 0; border-radius: 6px;
}
.tabs button[aria-selected="true"] { background: rgba(255,255,255,.14); color: #fff; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
section[hidden] { display: none; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.25rem;
}
.grid-2 { display: grid; grid-template-columns: 280px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* Forms */
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .25rem; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
textarea { min-height: 120px; resize: vertical; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 140px; }
.row > button { flex: 0 0 auto; }
.field { margin-bottom: .85rem; }

button {
  font: inherit; font-weight: 500; cursor: pointer;
  padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
button.primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
button.danger { color: var(--red); }
button.link { border: 0; background: none; padding: .2rem .4rem; color: var(--cobalt); }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Period list */
.period-list { list-style: none; margin: 0; padding: 0; }
.period-list li button {
  width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center;
  border: 0; border-radius: 8px; padding: .6rem .75rem; margin-bottom: .25rem;
}
.period-list li button[aria-current="true"] { background: var(--cobalt-soft); }
.code {
  font-weight: 700; letter-spacing: .08em; background: var(--ink); color: #fff;
  padding: .1rem .5rem; border-radius: 6px; font-size: .9rem;
}

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { padding: .5rem .75rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: .85rem; font-weight: 500; color: var(--muted); background: var(--paper); position: sticky; top: 0; }
.gradebook th:first-child, .gradebook td:first-child {
  position: sticky; left: 0; background: #fff; z-index: 1; border-right: 1px solid var(--line);
}
.gradebook th:first-child { background: var(--paper); z-index: 2; }
.gradebook td.score { text-align: center; cursor: pointer; }
.gradebook td.score:hover { background: var(--cobalt-soft); }
.gradebook td.empty { color: #B8C1D3; text-align: center; }
.gradebook th.game { text-align: center; max-width: 160px; white-space: normal; }

.checks { display: flex; flex-wrap: wrap; gap: .35rem .9rem; }
.checks label { display: inline-flex; gap: .35rem; align-items: center; font-weight: 400; margin: 0; }
.checks input { width: auto; }

/* Toast */
#toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 8px;
  display: none; z-index: 100; max-width: 90vw;
}
#toast.show { display: block; }
#toast.error { background: var(--red); }

/* Dialog */
dialog { border: 0; border-radius: var(--radius); padding: 1.25rem; max-width: 560px; width: 92vw; }
dialog::backdrop { background: rgba(22,33,58,.55); }
dialog.wide { max-width: 1000px; height: 85vh; display: flex; flex-direction: column; }
dialog.wide:not([open]) { display: none; }
dialog.wide iframe { flex: 1; border: 1px solid var(--line); border-radius: 8px; width: 100%; }

/* ===== The leaderboard — the one loud element ===== */
.board { list-style: none; margin: 0; padding: 0; }
.board li {
  display: grid; grid-template-columns: 3.2rem 1fr auto; align-items: center; gap: .75rem;
  padding: .55rem .9rem; margin-bottom: .4rem; border-radius: 10px;
  background: #fff; border: 1px solid var(--line); position: relative; overflow: hidden;
}
.board li .bar {
  position: absolute; inset: 0 auto 0 0; background: var(--cobalt-soft); z-index: 0;
  transition: width .6s ease;
}
.board li > *:not(.bar) { position: relative; z-index: 1; }
.board .place { font-weight: 900; font-size: 1.6rem; text-align: center; }
.board .who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 900; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.board li.p1 { border-color: var(--gold); }
.board li.p1 .bar { background: #FDF0C2; }
.board li.p1 .place { color: #B58700; }
.board li.me { outline: 3px solid var(--cobalt); }
.board.big li { padding: .9rem 1.2rem; font-size: 1.35rem; }
.board.big .place { font-size: 2.4rem; }
.board.big .pts { font-size: 1.9rem; }
@media (prefers-reduced-motion: reduce) { .board li .bar { transition: none; } }

.live-wrap:fullscreen { background: var(--ink); padding: 3rem; overflow: auto; }
.live-wrap:fullscreen h2, .live-wrap:fullscreen .muted { color: #fff; }
