:root {
  --bg: #fbf8f3;
  --surface: #ffffff;
  --ink: #2a2118;
  --muted: #74685a;
  --line: #e9e1d5;
  --accent: #b8400f;
  --accent-soft: #fbeadf;
  --gold: #c99a1a;
  --silver: #8d96a0;
  --bronze: #b0703a;
  --live: #1f9d55;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Noto Sans", "Noto Sans Malayalam", system-ui, sans-serif;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* Masthead */
.masthead {
  background: linear-gradient(135deg, #8f2d07, var(--accent) 55%, #d9661f);
  color: #fff;
  padding: 18px 0;
}
.masthead-inner { display: flex; align-items: center; gap: 16px; }
.logo { background: #fff; border-radius: 50%; padding: 4px; flex: none; }
.titles { flex: 1; min-width: 0; }
.titles h1 {
  margin: 0;
  font: 700 clamp(1.4rem, 3.5vw, 2.1rem)/1.15 "Noto Serif", serif;
  letter-spacing: .01em;
}
.titles p { margin: 2px 0 0; opacity: .92; font-size: .95rem; }
.titles .where { opacity: .8; font-size: .88rem; }
.live {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.18); border-radius: 999px;
  padding: 6px 12px; font-size: .82rem; white-space: nowrap; flex: none;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: #bbb; }
.live.ok .dot { background: #5be38f; animation: pulse 2s infinite; }
.live.err .dot { background: #ffb4a0; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(91,227,143,.7); }
  70% { box-shadow: 0 0 0 8px rgba(91,227,143,0); }
  100% { box-shadow: 0 0 0 0 rgba(91,227,143,0); }
}

.banner {
  margin: 16px 0 0; padding: 10px 14px; border-radius: 10px;
  background: #fff5d6; border: 1px solid #f0dc9a; font-size: .9rem;
}

/* Podium */
.podium {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  margin: 22px 0 8px;
}
.podium:empty { display: none; }
.place {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  border-top: 5px solid var(--c);
  display: flex; flex-direction: column; gap: 6px;
}
.place .medal {
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--c);
}
.place .name { font-weight: 600; line-height: 1.3; flex: 1; }
.place .pts { font: 700 2rem/1 "Noto Serif", serif; }
.place .pts small { font: 400 .85rem "Noto Sans", sans-serif; color: var(--muted); }
.place.p1 { --c: var(--gold); background: linear-gradient(#fffaf0, #fff); }
.place.p2 { --c: var(--silver); }
.place.p3 { --c: var(--bronze); }

/* Tabs */
.tabs {
  display: flex; gap: 6px; margin: 18px 0 10px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs button {
  font: inherit; font-size: .92rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  padding: 8px 16px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* Table */
.board {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 12px; text-align: center; border-bottom: 1px solid var(--line); }
th {
  font-size: .8rem; font-weight: 600; color: var(--muted);
  background: #faf6f0; vertical-align: bottom; line-height: 1.25;
}
th.item { font-family: "Noto Sans Malayalam", sans-serif; min-width: 84px; }
td.school, th.school { text-align: left; }
td.school { font-weight: 500; min-width: 220px; }
td.rank { width: 52px; font-weight: 700; color: var(--muted); }
td.total { font-weight: 700; font-size: 1.08rem; }
th.total, td.total { background: var(--accent-soft); }
td.empty { color: #c9bfb2; }
tbody tr:last-child td { border-bottom: 0; }
tr.r1 td.rank, tr.r2 td.rank, tr.r3 td.rank { color: #fff; }
.badge {
  display: inline-grid; place-items: center; width: 28px; height: 28px;
  border-radius: 50%; background: var(--c, transparent);
}
tr.r1 { --c: var(--gold); } tr.r2 { --c: var(--silver); } tr.r3 { --c: var(--bronze); }
tr.flash td { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: #fff1a8; } }

/* Sticky school column on narrow screens */
@media (max-width: 760px) {
  td.school, th.school {
    position: sticky; left: 0; background: var(--surface); z-index: 1;
    min-width: 128px; max-width: 140px; font-size: .86rem;
    box-shadow: 1px 0 0 var(--line);
  }
  th.school { background: #faf6f0; }
  th, td { padding: 9px 8px; }
  .podium { grid-template-columns: 1fr; gap: 8px; }
  .place { flex-direction: row; align-items: center; padding: 12px 14px; border-top: 0; border-left: 5px solid var(--c); }
  .place .medal { flex: none; }
  .place .pts { font-size: 1.5rem; white-space: nowrap; }
  .place .name { font-size: .92rem; min-width: 0; overflow-wrap: anywhere; }
  .place .medal { width: 56px; font-size: .7rem; }
  .titles { flex-basis: calc(100% - 64px); }
  .masthead-inner { flex-wrap: wrap; }
  .logo { width: 48px; height: 48px; }
  .live { order: 3; }
}

.notes { color: var(--muted); font-size: .85rem; margin: 18px 0 40px; }
.notes p { margin: 3px 0; }
.empty-state { padding: 40px 16px; text-align: center; color: var(--muted); }
