:root {
  --bg: #10131f;
  --bg-card: #171c2c;
  --bg-card-2: #1f2740;
  --bg-header: rgba(16, 19, 31, 0.9);
  --border: #2c3654;
  --text: #edf0f7;
  --text-dim: #a4aec7;
  --text-faint: #707c9c;
  --accent: #ffb054;      /* sofa amber */
  --accent-ink: #241503;
  --accent-2: #5ad4ff;    /* tv-glow blue */
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.15);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.15);
  --radius: 14px;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  --chart-text: #a4aec7;
  --chart-grid: rgba(44, 54, 84, 0.6);
  --chart-you: #ffb054;
}

html[data-theme="light"] {
  --bg: #f2f4f9;
  --bg-card: #ffffff;
  --bg-card-2: #edf0f7;
  --bg-header: rgba(242, 244, 249, 0.92);
  --border: #d6dbe8;
  --text: #1c2436;
  --text-dim: #4d5a75;
  --text-faint: #7c88a3;
  --accent: #e58f1f;
  --accent-ink: #2a1a04;
  --accent-2: #2288c9;
  --green: #158f60;
  --green-soft: rgba(21, 143, 96, 0.12);
  --red: #d04545;
  --red-soft: rgba(208, 69, 69, 0.1);
  --shadow: 0 4px 14px rgba(25, 35, 65, 0.08);
  --chart-text: #5a6780;
  --chart-grid: rgba(80, 95, 130, 0.15);
  --chart-you: #e58f1f;
}

html[data-theme="pink"] {
  --bg: #fdf3f7;
  --bg-card: #ffffff;
  --bg-card-2: #fbe8f1;
  --bg-header: rgba(253, 243, 247, 0.92);
  --border: #f0cede;
  --text: #38202e;
  --text-dim: #7d5a6c;
  --text-faint: #a8869a;
  --accent: #d6488f;      /* rose */
  --accent-ink: #ffffff;
  --accent-2: #8f6fd8;    /* lavender */
  --green: #1a9e6f;
  --green-soft: rgba(26, 158, 111, 0.12);
  --red: #dd5470;
  --red-soft: rgba(221, 84, 112, 0.1);
  --shadow: 0 4px 14px rgba(150, 60, 110, 0.1);
  --chart-text: #8a6a7c;
  --chart-grid: rgba(150, 90, 120, 0.15);
  --chart-you: #d6488f;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 780px; margin: 0 auto; padding: 14px 14px 60px; }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg-header); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px 0; max-width: 780px; margin: 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.theme-toggle { margin-left: auto; display: flex; gap: 3px; align-self: center; }
.theme-toggle button {
  border: 1px solid transparent; background: transparent; font-size: 14px; line-height: 1;
  padding: 4px 5px; border-radius: 8px; cursor: pointer; opacity: 0.55;
}
.theme-toggle button:hover { opacity: 0.9; }
.theme-toggle button.active { opacity: 1; border-color: var(--border); background: var(--bg-card-2); }
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; color: var(--accent); }
.subtitle { color: var(--text-faint); font-size: 12.5px; font-weight: 500; }
.tabs { display: flex; gap: 2px; margin-top: 10px; }
.tab {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 14.5px; font-weight: 600; padding: 9px 13px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-title { font-size: 17px; font-weight: 700; margin: 18px 2px 10px; }
.muted { color: var(--text-faint); font-size: 13px; }
.muted.small { font-size: 11.5px; }
.hidden { display: none !important; }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-top: 14px; box-shadow: var(--shadow);
}

/* Auth */
.auth-card { max-width: 380px; margin: 40px auto 0; display: flex; flex-direction: column; gap: 10px; }
.auth-toggle { display: flex; gap: 8px; }
.auth-card input { width: 100%; }
.auth-error { color: var(--red); font-size: 13px; min-height: 1em; margin: 0; }
.invite-banner {
  margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; line-height: 1.45;
  background: var(--green-soft); border: 1px solid var(--green); color: var(--text);
}

/* Landing (signed out) */
.landing-hero { text-align: center; margin: 30px auto 4px; max-width: 620px; }
.landing-kicker {
  margin: 0 0 10px; font-size: 11.5px; font-weight: 800;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-2);
}
.landing-title { margin: 0 0 10px; font-size: 30px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; }
.landing-sub { margin: 0; color: var(--text-dim); font-size: 15px; line-height: 1.55; }
.landing-countdown {
  display: inline-block; margin: 14px auto 0; padding: 7px 14px; border-radius: 999px;
  background: var(--green-soft); border: 1px solid var(--green); font-size: 13px; font-weight: 600;
}
.landing-cols { display: grid; gap: 14px; margin-top: 18px; align-items: start; }
.landing-cols .card { margin-top: 0; }
.landing-cols .auth-card { margin: 0; max-width: none; }
@media (min-width: 660px) { .landing-cols { grid-template-columns: 1fr 1fr; } }
.demo-title { margin: 0; font-size: 15px; color: var(--accent); }
.demo-fixture { margin-top: 10px; background: var(--bg); }
.demo-fixture .pick { -webkit-tap-highlight-color: transparent; }
.demo-note { margin: 10px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-dim); min-height: 3.9em; }
.feature-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 14px; }
.feature-grid .card { margin-top: 0; }
.feature-icon { font-size: 22px; display: block; margin-bottom: 8px; }
.feature h4 { margin: 0 0 6px; font-size: 14.5px; }
.feature p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--text-dim); }
.landing-foot { text-align: center; color: var(--text-faint); font-size: 12.5px; margin: 18px 0 0; }
.landing-foot .linklike { font-size: 12.5px; }
@media (max-width: 560px) {
  .feature-grid { grid-template-columns: 1fr; }
  .landing-title { font-size: 25px; }
  .landing-hero { margin-top: 18px; }
}

/* Chips / filters */
.chip {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-dim);
  padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.howto { color: var(--text-dim); font-size: 13px; line-height: 1.5; margin: 12px 2px 4px; }

/* Competition bar + matchweek nav */
.comp-bar { display: flex; gap: 8px; margin: 14px 0 0; flex-wrap: wrap; align-items: center; }
.comp-bar.tight { margin: 4px 0 0; }
.comp-bar .mw-title.small { font-size: 13.5px; min-width: 110px; }
.comps-label { margin: 6px 0 0; }
.mw-nav { display: flex; align-items: center; gap: 12px; margin: 14px 0 0; justify-content: center; }
.mw-title { font-weight: 800; font-size: 15px; min-width: 170px; text-align: center; }
.mw-nav .btn { min-width: 42px; }

/* Fixture list */
.fixture-list { margin-top: 8px; }
.day-head {
  margin: 18px 2px 8px; font-size: 13px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.fixture {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 10px;
}
.fx-top {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; color: var(--text-faint); margin-bottom: 10px;
}
.fx-badge {
  background: var(--bg-card-2); border-radius: 6px; padding: 2px 7px; font-weight: 600; color: var(--text-dim);
}
.fx-locked { color: var(--accent); font-weight: 600; }
.fx-auto { color: var(--accent); font-weight: 700; }
.fx-live { color: var(--green); font-weight: 800; letter-spacing: .04em; }
.fx-livedot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); margin-right: 5px; vertical-align: 1px;
  animation: livepulse 1.6s ease-in-out infinite;
}
@keyframes livepulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.pick.live-lead { outline: 2px dashed var(--green); }
.live-note {
  margin: 0 0 10px; padding: 9px 12px; border-radius: 10px; font-size: 13px;
  background: var(--green-soft); border: 1px solid var(--green); color: var(--text);
}

.picks { display: grid; grid-template-columns: 1fr 0.7fr 1fr; gap: 8px; }
.pick {
  border: 1px solid var(--border); background: var(--bg-card-2); color: var(--text);
  border-radius: 10px; padding: 10px 8px; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; gap: 4px; align-items: center; transition: all .12s;
}
/* hover-capable devices only — on touch screens the browser keeps :hover on
   the last-tapped element, leaving a stray orange border after deselecting */
@media (hover: hover) {
  .pick:hover:not(.disabled) { border-color: var(--accent); }
}
.pick .team { font-weight: 650; font-size: 14px; line-height: 1.15; }
.pick .crest { width: 26px; height: 26px; object-fit: contain; display: block; }
.pick .meta { font-size: 11px; color: var(--text-faint); }
.pick .pts { font-size: 12px; font-weight: 700; color: var(--accent); }
.pick.selected { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pick.selected .pts, .pick.selected .meta { color: var(--accent-ink); opacity: 0.8; }
.pick.disabled { cursor: default; opacity: 0.95; }
.pick.win { outline: 2px solid var(--accent-2); }
.pick.correct { background: var(--green-soft); border-color: var(--green); }
.pick.wrong { background: var(--red-soft); border-color: var(--red); }

.fx-result { margin-top: 10px; font-size: 13px; color: var(--text-dim); display: flex; justify-content: space-between; align-items: center; }
.fx-score { font-weight: 800; font-size: 16px; color: var(--text); }
.earned.pos { color: var(--green); font-weight: 700; }
.earned.zero { color: var(--text-faint); }

/* Standings */
.standings { margin-top: 6px; }
.srow {
  display: grid; grid-template-columns: 30px 1fr repeat(var(--scols, 6), auto); gap: 8px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--border); background: var(--bg-card);
  border-radius: 10px; margin-bottom: 8px;
}
.srow.shead { padding: 8px 14px; background: transparent; border-color: transparent; margin-bottom: 4px; }
.srow.me { border-color: var(--accent); background: var(--bg-card-2); }
.srank { font-weight: 800; color: var(--text-faint); text-align: center; }
.srow.top .srank { color: var(--accent); }
.sname { font-weight: 650; }
.spts { font-weight: 800; font-size: 16px; color: var(--accent); min-width: 34px; text-align: right; }
.smeta { font-size: 12px; color: var(--text-faint); min-width: 30px; text-align: right; }
.pnl { font-variant-numeric: tabular-nums; }
.pnl-toggle { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; }
.switch {
  width: 36px; height: 20px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-card-2); position: relative; cursor: pointer; padding: 0; flex: 0 0 auto;
  transition: background .15s, border-color .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--text-dim); transition: transform .15s, background .15s;
}
.switch.on { background: var(--accent); border-color: var(--accent); }
.switch.on::after { transform: translateX(16px); background: var(--accent-ink); }
.pnl.pos { color: var(--green); font-weight: 700; }
.pnl.neg { color: var(--red); }
.col-head { color: var(--text-faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; }
.col-head.sortable { cursor: pointer; user-select: none; }
.col-head.sortable:hover { color: var(--text); }
.col-head.spts { font-size: 10.5px; font-weight: 800; }

.chart-canvas-box { position: relative; height: 280px; }
.chart-canvas-box.tall { height: 420px; }

/* How it works */
.how-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--accent); }
.how-card p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.55; color: var(--text-dim); }
.how-card p:last-child { margin-bottom: 0; }
.how-card strong { color: var(--text); }
.how-card em { color: var(--text); }
.how-example {
  display: flex; flex-direction: column; gap: 6px; margin: 0 0 10px;
  background: var(--bg-card-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 13.5px;
}

/* Admin */
.admin-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-results-row {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.ar-teams { font-size: 13.5px; }
.ar-inputs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ar-inputs input { width: 52px; }
input, select {
  background: var(--bg-card-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.btn {
  border: none; border-radius: 9px; padding: 9px 14px; font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.ghost { background: var(--bg-card-2); color: var(--text); border: 1px solid var(--border); }

/* Modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 360px; box-shadow: var(--shadow); position: relative; }
.modal-card h2 { margin: 0 0 6px; font-size: 19px; }
.modal-card input { width: 100%; margin: 7px 0; }
.modal-card .btn { width: 100%; margin-top: 7px; }
.modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--text-faint); font-size: 24px; line-height: 1; cursor: pointer; padding: 2px 6px;
}
.modal-close:hover { color: var(--text); }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 10px 18px;
  border-radius: 999px; z-index: 60; box-shadow: var(--shadow); transition: opacity .2s;
}

.app-foot { text-align: center; color: var(--text-faint); font-size: 12px; padding: 16px; }
.linklike { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; padding: 0; text-decoration: underline; }
.linklike:hover { color: var(--text); }

/* League switcher bar */
.league-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }
.league-toggle { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; }
.league-toggle .chip { padding: 6px 13px; font-size: 13px; }
.league-bar .btn { white-space: nowrap; margin-left: auto; }
.league-bar .btn + .btn { margin-left: 0; }

/* League modal */
.league-card { max-width: 440px; }
.league-card h3 { margin: 0 0 4px; font-size: 15px; }
.league-list { margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.league-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--bg-card-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
.league-row .lr-name { font-weight: 650; flex: 1 1 auto; }
.league-row .lr-owner { font-size: 10px; font-weight: 700; color: var(--accent-2); text-transform: uppercase; margin-left: 4px; }
.league-row .lr-members { color: var(--text-faint); font-size: 12px; }
.league-row .lr-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  color: var(--accent); background: var(--bg); padding: 2px 8px; border-radius: 6px; letter-spacing: .06em;
}
.league-row .btn { width: auto; margin: 0; }
.league-forms { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
.league-form p.muted { font-size: 12.5px; margin: 0 0 8px; }
.lf-row { display: flex; gap: 8px; }
.lf-row input { flex: 1 1 auto; width: auto; margin: 0; }
.lf-row .btn { width: auto; flex: 0 0 auto; margin: 0; }

/* Admin: all-leagues overview */
.admin-league-row { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.admin-league-row:last-child { border-bottom: none; }
.alr-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alr-name { font-weight: 700; }
.alr-head .lr-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  color: var(--accent); background: var(--bg); padding: 1px 7px; border-radius: 6px; font-size: 12px;
}
.alr-head .muted { font-size: 12px; }
.alr-members { font-size: 12.5px; }
.admin-league-row .btn { align-self: flex-start; margin-top: 4px; }
.alr-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 6px; }
.alr-add input { flex: 1 1 160px; }
.alr-add .btn { flex: 0 0 auto; }

@media (max-width: 430px) {
  .pick .team { font-size: 13px; }
  .srow { grid-template-columns: 26px 1fr repeat(var(--scols-m, 3), auto); }
  .srow .hidecol { display: none; }
  .mw-title { min-width: 130px; font-size: 14px; }
}
