:root {
  --bg: #0b0d12;
  --panel: #151923;
  --panel-2: #1c2130;
  --line: #2a3142;
  --text: #eef1f7;
  --muted: #8b93a7;
  --accent: #ffd166;
  --live: #ff3b4d;
  --upset: #d1001f;
  --upset-dim: #3a0810;
  --close-a: #0b5fd6;
  --close-b: #0f9d58;
  --chip: #232a3a;
  --chip-on: #ffd166;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 0 14px calc(24px + env(safe-area-inset-bottom));
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 88%, transparent);
  padding: calc(8px + env(safe-area-inset-top)) 0 8px;
}
.bar { display: flex; align-items: center; gap: 8px; }
.bar h1 { margin: 0; font-size: 19px; letter-spacing: .2px; white-space: nowrap; flex: none; }
.demo-badge { font-size: 10px; font-weight: 800; background: var(--accent); color: #1a1400; border-radius: 4px; padding: 1px 5px; margin-left: 6px; vertical-align: middle; }
.demo-badge[hidden] { display: none; }
#week-select {
  appearance: none; -webkit-appearance: none; min-width: 0;
  background: var(--chip) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b93a7' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 8px center;
  color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 22px 5px 9px; font: inherit; font-weight: 700; font-size: 12.5px; cursor: pointer;
}
.menu-btn {
  flex: none; margin-left: auto;
  border: 1px solid var(--line); background: var(--chip); color: var(--text);
  border-radius: 8px; padding: 5px 9px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  white-space: nowrap;
}
.menu-btn .caret { color: var(--muted); margin-left: 2px; }
.menu-btn.has-teams { border-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--chip); color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background .15s, color .15s;
}
.chip.on { background: var(--chip-on); color: #1a1400; border-color: var(--chip-on); }
.chip.all { border-style: dashed; }
.chip.fav.on { background: var(--accent); }
.refresh { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.refresh button {
  border: 1px solid var(--line); background: var(--chip); color: var(--text);
  border-radius: 8px; width: 26px; height: 26px; font-size: 14px; cursor: pointer;
}
.refresh button.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Favorite star, top-right of every card */
.star {
  position: absolute; top: 4px; right: 6px; z-index: 1;
  background: none; border: 0; padding: 4px; cursor: pointer; line-height: 0;
  color: var(--muted); opacity: .7; -webkit-tap-highlight-color: transparent;
}
.star svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.star.on { color: var(--accent); opacity: 1; }
.star.on svg { fill: currentColor; }
.card.upset .star, .card.close:not(.upset) .star { color: #fff; }
.card.upset .star.on, .card.close:not(.upset) .star.on { color: var(--accent); }

/* Groups */
.group { margin-top: 18px; }
.group h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted);
  margin: 0 0 8px 2px; display: flex; align-items: center; gap: 6px;
}
.dot.live { width: 8px; height: 8px; border-radius: 50%; background: var(--live); display: inline-block;
  animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 10px; }

/* Cards */
.card {
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 12px 9px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto;
  column-gap: 10px;
  transition: border-color .2s;
}
.card.live { border-color: #3a4560; }
.card .teams { grid-column: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.team { display: flex; align-items: center; gap: 8px; min-height: 28px; min-width: 0; }
.team img { width: 26px; height: 26px; object-fit: contain; flex: none; }
.team .rank { color: var(--accent); font-size: 12px; font-weight: 700; width: 24px; flex: none; text-align: right; }
.team .rank:empty { visibility: hidden; }
.team .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team .rec { color: var(--muted); font-size: 12px; flex: none; }
.team .poss { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; margin-left: 2px; }
.team .score { margin-left: auto; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }
.team.loser .name, .team.loser .score { opacity: .55; }
.card.pre .team .score { display: none; }

.status {
  grid-column: 2; grid-row: 1; align-self: center; margin-top: 14px;
  text-align: right; font-weight: 700; font-size: 14px; min-width: 64px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.status .q { font-size: 15px; }
.status .clock { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.card.live .status .q { color: var(--live); }
.card.post .status { color: var(--muted); }
.card.pre .status { color: var(--text); }
.status .day { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }

.meta {
  grid-column: 1 / -1; margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--line);
  display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 12.5px; flex-wrap: wrap;
}
.meta .spread { font-weight: 700; color: var(--text); }
.meta .tv { margin-left: auto; font-weight: 600; }
.meta .tier { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

.badges { position: absolute; top: -9px; left: 10px; display: flex; gap: 6px; }
.badge {
  font-size: 10.5px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; color: #fff;
}
.badge.upset { background: var(--upset); }
.badge.close { background: var(--close-a); }

/* Alerts */
.card.upset {
  animation: upset-blink .9s steps(1, end) infinite;
  border-color: var(--live);
}
@keyframes upset-blink {
  0%, 49% { background: var(--upset); }
  50%, 100% { background: var(--upset-dim); }
}
.card.upset .team .rec, .card.upset .meta, .card.upset .status .clock { color: rgba(255,255,255,.8); }
.card.upset .meta { border-top-color: rgba(255,255,255,.25); }
.card.upset .team .rank { color: #fff; }

.card.close:not(.upset) {
  animation: close-flash 1.6s ease-in-out infinite;
  border-color: #7fb6ff;
}
@keyframes close-flash {
  0%, 100% { background: var(--close-a); }
  50% { background: var(--close-b); }
}
.card.close:not(.upset) .team .rec, .card.close:not(.upset) .meta, .card.close:not(.upset) .status .clock,
.card.close:not(.upset) .status .clock { color: rgba(255,255,255,.85); }
.card.close:not(.upset) .meta { border-top-color: rgba(255,255,255,.25); }
.card.close:not(.upset) .status .q, .card.close:not(.upset) .team .rank { color: #fff; }

@media (max-width: 480px) {
  .menu-btn .long { display: none; }
}
@media (max-width: 400px) {
  .team .name { font-size: 15px; }
  .team .rec { font-size: 11px; }
  .team .score { font-size: 20px; min-width: 28px; }
  .status { min-width: 56px; }
}

/* Footer, states */
.legend { margin-top: 26px; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.swatch.upset { background: var(--upset); }
.swatch.close { background: linear-gradient(90deg, var(--close-a), var(--close-b)); }
.empty, .error { color: var(--muted); text-align: center; margin-top: 40px; }
.error { color: #ff8a94; }

/* Favorite Teams panel */
body.panel-open { overflow: hidden; }
.panel {
  position: fixed; inset: 0; z-index: 50; background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
}
.panel[hidden] { display: none; }
.panel-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.panel-head h2 { margin: 0; font-size: 16px; text-align: center; white-space: nowrap; }
.panel-nav {
  background: none; border: 0; color: var(--accent); font: inherit; font-size: 15px; font-weight: 700;
  cursor: pointer; padding: 6px 4px; justify-self: start;
}
#panel-close { justify-self: end; }
#panel-back[hidden] { display: block; visibility: hidden; } /* keep the title centered */
.panel-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px 20px; max-width: 720px; width: 100%; margin: 0 auto; }
.panel-foot { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.panel-foot:empty { display: none; }
.btn-primary {
  display: block; width: 100%; max-width: 720px; margin: 0 auto;
  background: var(--accent); color: #1a1400; border: 0; border-radius: 10px;
  padding: 12px; font: inherit; font-size: 15px; font-weight: 800; cursor: pointer;
}
.panel-empty { color: var(--muted); text-align: center; padding: 40px 10px; line-height: 1.5; }
.panel-note { color: var(--muted); font-size: 12.5px; margin: 0 0 10px; }

.team-list { list-style: none; margin: 0; padding: 0; }
.team-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line);
}
.team-list img { width: 30px; height: 30px; object-fit: contain; flex: none; }
.team-list .t-name { font-weight: 700; font-size: 15px; }
.team-list .t-conf { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.team-list .grow { flex: 1; min-width: 0; }
.star.inline { position: static; padding: 6px; opacity: .8; }
.star.inline svg { width: 22px; height: 22px; }
.remove-btn {
  background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 8px;
  padding: 5px 10px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}

.cat-list { display: flex; flex-direction: column; gap: 8px; }
.cat-btn {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 12px;
  padding: 14px 14px; font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; text-align: left;
}
.cat-btn .count { color: var(--accent); font-size: 12px; font-weight: 800; }
.cat-btn .chev { color: var(--muted); margin-left: 8px; }

.search {
  width: 100%; box-sizing: border-box; margin-bottom: 10px;
  background: var(--chip); border: 1px solid var(--line); color: var(--text); border-radius: 10px;
  padding: 9px 12px; font: inherit; font-size: 15px;
}
.team-list h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted);
  margin: 16px 0 4px; position: sticky; top: -12px; background: var(--bg); padding: 6px 0;
}
