:root {
  --bg: #0d1520;
  --panel: #16222f;
  --panel2: #1c2a3a;
  --line: #263a4e;
  --text: #e8eef4;
  --muted: #8fa3b5;
  --accent: #4fc3f7;
  --gold: #ffcf5c;
  --win: #3ddc84;
  --loss: #ff6b6b;
  --otl: #ffb74d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  flex: none;
  background: linear-gradient(180deg, #101c2a, #0d1520);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-badge { flex: none; display: flex; }
.brand-badge img { width: 52px; height: auto; border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 24px;
}
.view > * { max-width: 640px; margin-left: auto; margin-right: auto; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  overflow-x: auto; /* wide tables scroll inside the card, never the page */
}
.card h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin-bottom: 10px; font-weight: 600;
}

.next-when { font-size: 14px; color: var(--accent); font-weight: 600; }
.next-matchup { font-size: 20px; font-weight: 700; margin: 6px 0; line-height: 1.3; }
.next-venue { color: var(--muted); font-size: 14px; }
.badge-ha {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; margin-left: 6px;
  background: var(--panel2); color: var(--gold); border: 1px solid var(--line);
  vertical-align: 2px;
}

.btn {
  display: inline-block; width: 100%;
  background: linear-gradient(135deg, var(--accent), #2196f3);
  color: #06121e; font-weight: 700; font-size: 15px;
  border: none; border-radius: 10px; padding: 12px;
  margin-top: 12px; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; text-align: center; flex: 1;
  min-width: 62px;
}
.chip .n { font-size: 18px; font-weight: 700; display: block; }
.chip .l { font-size: 11px; color: var(--muted); text-transform: uppercase; }

.result-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit;
}
.result-row:last-child { border-bottom: none; }
.res-code {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; background: var(--panel2);
}
.res-code.W { color: var(--win); }
.res-code.L, .res-code.SOL { color: var(--loss); }
.res-code.OTL, .res-code.T { color: var(--otl); }
.res-main { flex: 1; min-width: 0; }
.res-opp { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-meta { font-size: 12px; color: var(--muted); }
.res-score { font-weight: 700; font-size: 16px; }

table.stats { width: 100%; border-collapse: collapse; font-size: 13px; }
table.stats th {
  text-align: right; color: var(--muted); font-size: 10px;
  text-transform: uppercase; letter-spacing: .4px;
  padding: 5px 4px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.stats tr:last-child td { border-bottom: none; }
table.stats td.name {
  font-weight: 600; overflow: hidden; max-width: 128px;
  text-overflow: ellipsis; white-space: nowrap;
}
table.stats td.name .sub { white-space: normal; }
.sub { color: var(--muted); font-size: 12px; }

select, input[type="search"] {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; margin-bottom: 12px;
  appearance: none;
}

.tabbar {
  flex: none;
  display: flex; background: #101c2a;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 8px 0 6px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabbar a.active { color: var(--accent); }
.tab-ico { display: block; margin-bottom: 2px; }
.tab-ico svg { width: 22px; height: 22px; display: block; margin: 0 auto; }

.seg { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.seg button {
  background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600;
  white-space: nowrap; cursor: pointer;
}
.seg button.active { background: var(--accent); color: #06121e; border-color: var(--accent); }

.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.error { color: var(--loss); padding: 20px; text-align: center; }
.back { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 14px; display: inline-block; margin-bottom: 10px; }

.goal-line { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.goal-line:last-child { border-bottom: none; }
.goal-line .who { font-weight: 600; }
.goal-line .meta { color: var(--muted); font-size: 12px; }
.pill {
  display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 7px;
  border-radius: 999px; background: var(--panel2); border: 1px solid var(--line);
  color: var(--gold); margin-left: 4px; vertical-align: 1px; white-space: nowrap;
}
.pill.right { float: right; margin-top: 2px; }
.pct-good, .pill.pct-good { color: var(--win); }
.pct-bad, .pill.pct-bad { color: var(--loss); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.card-head h2 { margin-bottom: 0; }
.mini-toggle { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.mini-toggle button {
  background: var(--panel2); color: var(--muted); border: none;
  font-size: 11px; font-weight: 700; padding: 5px 10px; cursor: pointer;
}
.mini-toggle button.active { background: var(--accent); color: #06121e; }
td.divider-row {
  text-align: left !important; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px; font-weight: 600;
  padding-top: 12px !important;
}
td.excomm {
  color: var(--loss); font-weight: 700; font-style: italic;
  text-align: center !important; letter-spacing: .5px;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .two-col { grid-template-columns: 1fr; } }

.mile-row { margin-bottom: 12px; }
.mile-row:last-of-type { margin-bottom: 0; }
.mile-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.mile-bar {
  position: relative; display: flex; align-items: center;
  height: 26px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 999px;
  overflow: visible;
}
.mile-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #1976d2, var(--accent));
  display: flex; align-items: center; justify-content: flex-end;
  min-width: 0;
}
.mile-mi {
  font-size: 12px; font-weight: 700; color: #06121e;
  padding-right: 10px; white-space: nowrap;
}
.mile-car {
  font-size: 20px; line-height: 1; margin-left: 2px;
  transform: scaleX(-1); /* face the direction of travel */
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.4));
}
.odo-total { font-size: 26px; font-weight: 800; margin-bottom: 2px; }
.odo-trip { display: flex; align-items: center; gap: 8px; }
.odo-end { font-size: 20px; flex: none; }
.odo-bar { flex: 1; height: 18px; }
.odo-bar .mile-car { position: absolute; top: -6px; margin: 0; }

.egg-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; padding: 24px; text-align: center;
  opacity: 0; transition: opacity .7s ease;
}
.egg-overlay.show { opacity: 1; }
.egg-banner {
  font-size: 26px; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.egg-plant {
  font-size: 130px; line-height: 1;
  animation: egg-pulse 1s ease-in-out infinite;
  filter: drop-shadow(0 8px 24px rgba(79,195,247,.35));
}
@keyframes egg-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.22); }
}
.egg-return {
  width: auto; padding: 12px 28px; margin-top: 8px;
  opacity: 0; pointer-events: none; transition: opacity .5s;
}
.egg-return.show { opacity: 1; pointer-events: auto; }

.install-banner {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2);
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}
.install-banner img { width: 40px; height: 40px; border-radius: 9px; flex: none; }
.ib-text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.35; }
.ib-text b { display: block; }
.ib-text span { color: var(--muted); font-size: 12px; }
.ib-install {
  flex: none; background: var(--accent); color: #06121e;
  border: none; border-radius: 8px; font-weight: 700;
  padding: 8px 14px; font-size: 13px; cursor: pointer;
}
.ib-close {
  flex: none; background: none; border: none; color: var(--muted);
  font-size: 15px; padding: 6px; cursor: pointer;
}
