:root {
  --bg: #0f0a10;
  --bg-card: #1b1420;
  --bg-card-2: #251a2c;
  --line: #3b2a45;
  --text: #faeef5;
  --text-dim: #b39ab0;
  --accent: #ff4fa3;
  --accent-2: #ff8ec4;
  --gold: #ffd166;
  --win: #4ade80;
  --draw: #facc15;
  --loss: #f87171;
  --us: rgba(255, 79, 163, 0.13);
  --radius: 14px;
  font-size: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: #fff;
  object-fit: contain;
  flex: none;
  border: 1px solid var(--line);
}
.brand-diamond { width: 30px; height: 30px; color: var(--accent); flex: none; }
.brand h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.02em; }
.league-label { font-size: 0.72rem; color: var(--text-dim); }
.refresh-btn {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--accent);
  border-radius: 50%;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  cursor: pointer;
}
.refresh-btn:active { transform: rotate(180deg); transition: transform 0.3s; }

/* ---------- team switch ---------- */
.team-switch {
  display: flex;
  gap: 8px;
  padding: 6px 16px 2px;
}
.team-pill {
  flex: 1;
  padding: 9px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.team-pill.active {
  background: linear-gradient(135deg, rgba(255,79,163,0.2), rgba(255,142,196,0.14));
  border-color: var(--accent);
  color: var(--text);
}
.team-pill small { display: block; font-weight: 400; font-size: 0.68rem; opacity: 0.8; }

.updated-label {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-align: right;
  padding: 4px 18px 0;
  min-height: 1em;
}

/* ---------- layout ---------- */
.view { padding: 10px 14px 24px; display: grid; gap: 12px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card h2 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.card h2 .accent { color: var(--accent); }

.loading {
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 60px 0;
  color: var(--text-dim);
}
.spin { animation: spin 1.4s linear infinite; width: 36px; height: 36px; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 0.85rem;
}

/* ---------- home ---------- */
.hero {
  display: flex;
  align-items: center;
  gap: 14px;
}
.pos-badge {
  width: 62px; height: 62px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(255,79,163,0.28), rgba(255,142,196,0.18));
  border: 1px solid var(--accent);
  display: grid;
  place-items: center;
  flex: none;
}
.pos-badge b { font-size: 1.5rem; }
.pos-badge span { font-size: 0.6rem; color: var(--text-dim); }
.hero-facts { flex: 1; }
.hero-facts .big { font-size: 1.02rem; font-weight: 700; }
.hero-facts .sub { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }

.form-row { display: flex; gap: 5px; margin-top: 8px; }
.form-chip {
  width: 24px; height: 24px;
  border-radius: 7px;
  display: grid; place-items: center;
  font-size: 0.68rem;
  font-weight: 800;
  color: #0d1220;
}
.form-chip.W { background: var(--win); }
.form-chip.D { background: var(--draw); }
.form-chip.L { background: var(--loss); }
.form-chip.blank { background: var(--line); color: var(--text-dim); }

.match-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.86rem;
}
.match-line:last-child { border-bottom: none; }
.match-teams { flex: 1; min-width: 0; }
.match-teams .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.match-teams .t.us { color: var(--accent); font-weight: 700; }
.match-meta { text-align: right; flex: none; }
.match-score { font-weight: 800; font-size: 0.98rem; }
.match-date { font-size: 0.68rem; color: var(--text-dim); }
.badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 6px;
  color: #0d1220;
}
.badge.W { background: var(--win); }
.badge.D { background: var(--draw); }
.badge.L { background: var(--loss); }

.next-card .big-opp { font-size: 1.05rem; font-weight: 800; margin: 2px 0; }
.next-card .when { color: var(--accent); font-weight: 600; font-size: 0.85rem; }
.next-card .where { color: var(--text-dim); font-size: 0.78rem; margin-top: 2px; }
.danger-note {
  margin-top: 10px;
  padding: 9px 11px;
  background: rgba(255, 209, 102, 0.08);
  border: 1px solid rgba(255, 209, 102, 0.3);
  border-radius: 10px;
  font-size: 0.8rem;
}
.danger-note b { color: var(--gold); }

/* ---------- table ---------- */
table.standings { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.standings th {
  font-size: 0.64rem;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: right;
  padding: 5px 4px;
  border-bottom: 1px solid var(--line);
}
.standings th.team-col, .standings td.team-col { text-align: left; }
.standings td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
.standings tr:last-child td { border-bottom: none; }
.standings tr.us td { background: var(--us); }
.standings tr.us td:first-child { border-radius: 8px 0 0 8px; }
.standings tr.us td:last-child { border-radius: 0 8px 8px 0; }
.standings td.team-col {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.standings tr { cursor: pointer; }
.standings .pts { font-weight: 800; color: var(--accent); }

/* ---------- matches ---------- */
.seg {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px;
  border-radius: 999px;
  cursor: pointer;
}
.seg button.active { background: var(--accent); color: #0d1220; }
.month-head {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 6px 2px 0;
}

/* ---------- scout ---------- */
.opp-grid { display: grid; gap: 8px; }
.opp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}
.opp-row .nm { font-weight: 700; font-size: 0.88rem; }
.opp-row .st { font-size: 0.7rem; color: var(--text-dim); margin-top: 2px; }
.opp-row .chev { color: var(--text-dim); flex: none; }

.scout-detail .back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat-tile {
  background: var(--bg-card-2);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}
.stat-tile b { display: block; font-size: 1.05rem; }
.stat-tile span { font-size: 0.62rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }

.scorer-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}
.scorer-line:last-child { border-bottom: none; }
.scorer-line .rank { color: var(--text-dim); width: 20px; flex: none; }
.scorer-line .nm { flex: 1; font-weight: 600; }
.scorer-line .gl { font-weight: 800; color: var(--gold); }
.scorer-line .per { font-size: 0.7rem; color: var(--text-dim); margin-left: 6px; }

/* ---------- ask ---------- */
.chat-log { display: grid; gap: 10px; }
.bubble {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.45;
}
.bubble.q {
  justify-self: end;
  background: linear-gradient(135deg, #b81d74, #ff4fa3);
  border-bottom-right-radius: 4px;
}
.bubble.a {
  justify-self: start;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.bubble.a b { color: var(--gold); }
.bubble.a .mini {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.q-chip {
  border: 1px solid var(--accent);
  background: rgba(255, 79, 163, 0.08);
  color: var(--accent-2);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.q-chip:active { background: rgba(255, 79, 163, 0.25); }
.picker-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.picker-row .q-chip { border-color: var(--gold); color: var(--gold); background: rgba(255,209,102,0.08); }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(15, 10, 16, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: grid;
  justify-items: center;
  gap: 2px;
  font-size: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }
