/* The Cutler World Cup
 *
 * Design note: the structural motif is pitch markings — white 2px lines on
 * green, a centre circle, a halfway line. It is used in exactly one place (the
 * "you're on" card) so it stays a signature rather than wallpaper. Everything
 * else is quiet: flat surfaces, one amber accent reserved for what is happening
 * next, and tabular monospace figures so score columns line up like a
 * scoreboard.
 */

:root {
  --pitch: #0b7a3b;
  --pitch-deep: #075c2c;
  --trophy: #e8a317;
  --line: #ffffff;

  --bg: #f4f7f3;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --ink: #10231a;
  --ink-soft: #587065;
  --edge: #d8e2da;
  --danger: #b3261e;

  --display: 800 1rem/1.05 ui-sans-serif, -apple-system, 'Segoe UI', system-ui, sans-serif;
  --body: ui-sans-serif, -apple-system, 'Segoe UI', system-ui, sans-serif;
  --figures: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --r: 10px;
  --pad: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c120f;
    --surface: #141c17;
    --surface-2: #1b241e;
    --ink: #e8f0ea;
    --ink-soft: #93a89b;
    --edge: #26332b;
    --pitch: #1e9b52;
    --danger: #f2b8b5;
  }
}

:root[data-theme='light'] {
  --bg: #f4f7f3; --surface: #fff; --surface-2: #eef2ec;
  --ink: #10231a; --ink-soft: #587065; --edge: #d8e2da;
  --pitch: #0b7a3b; --danger: #b3261e;
}
:root[data-theme='dark'] {
  --bg: #0c120f; --surface: #141c17; --surface-2: #1b241e;
  --ink: #e8f0ea; --ink-soft: #93a89b; --edge: #26332b;
  --pitch: #1e9b52; --danger: #f2b8b5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, .eyebrow, .btn, th {
  font-family: var(--body);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.85rem; margin: 0; }

.eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  font-weight: 700;
}

.num { font-family: var(--figures); font-variant-numeric: tabular-nums; }

a { color: var(--pitch); }

/* ---- shell ------------------------------------------------------------- */

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--pitch-deep);
  color: #fff;
  border-bottom: 3px solid var(--trophy);
}

.top-in {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px var(--pad);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.top h1 { color: #fff; font-size: 1.15rem; }
.top .spacer { flex: 1; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill.warn { background: var(--trophy); color: #21170a; }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--pad);
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  main.split { grid-template-columns: 360px 1fr; align-items: start; }
  main.split > .panel { position: sticky; top: 76px; }
}

/* On a phone the columns stack, and DOM order would bury the player's own team
 * under the whole registration form and roster. Once this device knows who it
 * belongs to, lead with their team instead. */
@media (max-width: 899px) {
  main.me-first > .panel { order: 2; }
  main.me-first > .results { order: 1; }
}

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: var(--pad);
}

.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--ink-soft); font-size: 0.85rem; }

/* ---- controls ---------------------------------------------------------- */

label { display: block; font-size: 0.78rem; font-weight: 700; margin-bottom: 4px; color: var(--ink-soft); }

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
}

input:focus-visible, select:focus-visible, .btn:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--trophy);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--pitch);
  color: #fff;
  font-size: 0.82rem;
  cursor: pointer;
}
.btn:hover { background: var(--pitch-deep); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--edge); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.amber { background: var(--trophy); color: #21170a; }
.btn.small { padding: 5px 10px; font-size: 0.72rem; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.seg { display: flex; gap: 0; border: 1px solid var(--edge); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; padding: 9px 4px; border: 0; background: var(--surface-2);
  color: var(--ink); font: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.seg button[aria-pressed='true'] { background: var(--pitch); color: #fff; }

.err {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 12px; border-radius: 8px; font-size: 0.85rem;
}

/* ---- the signature: a marked-out pitch --------------------------------- */

.mine {
  position: relative;
  overflow: hidden;
  border-radius: var(--r);
  padding: 26px var(--pad);
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 28px, transparent 28px 56px),
    linear-gradient(180deg, var(--pitch) 0%, var(--pitch-deep) 100%);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.55);
}
/* halfway line + centre circle, drawn not decorated */
.mine::before {
  content: '';
  position: absolute; inset: 0 auto 0 50%;
  width: 2px; background: rgba(255, 255, 255, 0.4);
}
.mine::after {
  content: '';
  position: absolute; top: 50%; left: 50%;
  width: 132px; height: 132px; margin: -66px 0 0 -66px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
}
.mine > * { position: relative; z-index: 1; }
.mine .eyebrow { color: rgba(255, 255, 255, 0.75); }
.mine .team-name { font-size: 1.9rem; font-weight: 800; text-transform: uppercase; line-height: 1; }
.mine .next {
  margin-top: 18px; padding-top: 14px;
  border-top: 2px solid rgba(255, 255, 255, 0.35);
}

/* ---- flags, badges ----------------------------------------------------- */

.flag {
  width: 26px; height: 18px; border-radius: 2px; flex: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
  vertical-align: -3px;
}
.mine .flag { width: 44px; height: 30px; }

.badge {
  display: inline-block; padding: 2px 7px; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--edge);
}
.badge.expert { background: color-mix(in srgb, var(--pitch) 18%, transparent); color: var(--pitch); border-color: transparent; }
.badge.intermediate { background: color-mix(in srgb, var(--trophy) 22%, transparent); color: #7a5605; border-color: transparent; }
.badge.beginner { background: var(--surface-2); }

@media (prefers-color-scheme: dark) {
  .badge.intermediate { color: var(--trophy); }
}

/* ---- roster ------------------------------------------------------------ */

.roster { list-style: none; margin: 0; padding: 0; max-height: 44vh; overflow-y: auto; }
.roster li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--edge);
}
.roster li:last-child { border-bottom: 0; }
.roster .who { flex: 1; min-width: 0; }
.roster .who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 0; background: transparent; color: var(--ink-soft);
  cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 4px 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }

.mix { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ---- teams ------------------------------------------------------------- */

.teams { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.team { background: var(--surface-2); border: 1px solid var(--edge); border-radius: var(--r); padding: 12px; }
.team header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.team header b { font-weight: 800; text-transform: uppercase; font-size: 0.95rem; }
.team ol { margin: 8px 0 0; padding-left: 18px; font-size: 0.85rem; }
.team ol li { padding: 1px 0; }
.team ol li.sub { color: var(--ink-soft); }
.team .meta { font-size: 0.72rem; color: var(--ink-soft); display: flex; gap: 6px; flex-wrap: wrap; }
.team .meta > span + span::before { content: '·'; margin-right: 6px; opacity: 0.6; }

/* ---- tables ------------------------------------------------------------ */

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--edge); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; width: 99%; }
th { font-size: 0.66rem; color: var(--ink-soft); letter-spacing: 0.06em; }
td.pts { font-weight: 800; }
tr.qualifies td { background: color-mix(in srgb, var(--pitch) 9%, transparent); }
td .num, th .num { font-family: var(--figures); }

/* ---- fixtures ---------------------------------------------------------- */

.fix { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--edge); }
.fix:last-child { border-bottom: 0; }
.fix .no { font-family: var(--figures); font-size: 0.72rem; color: var(--ink-soft); width: 2.2em; flex: none; }
.fix .sides { flex: 1; min-width: 0; display: grid; gap: 2px; }
.fix .side { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; }
.fix .side.win { font-weight: 700; }
.fix .side.tbd { color: var(--ink-soft); font-style: italic; }
.fix .score { font-family: var(--figures); font-size: 1.05rem; font-weight: 700; text-align: right; min-width: 1.6em; }
.fix .score.dim { color: var(--ink-soft); font-weight: 400; }
.fix.next { background: color-mix(in srgb, var(--trophy) 12%, transparent); border-radius: 8px; padding-inline: 8px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--trophy); flex: none; }
@media (prefers-reduced-motion: no-preference) {
  .fix.next .dot { animation: pulse 2s ease-in-out infinite; }
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.score-form { display: flex; gap: 6px; align-items: center; }
.score-form input { width: 56px; text-align: center; padding: 6px; }

/* ---- bracket ----------------------------------------------------------- */

.bracket { display: flex; gap: 28px; padding: 4px 2px 12px; min-width: min-content; }
.bracket .round { display: flex; flex-direction: column; justify-content: space-around; gap: 16px; min-width: 190px; }
.tie {
  border: 1px solid var(--edge); border-left: 3px solid var(--pitch);
  border-radius: 8px; background: var(--surface-2); padding: 8px 10px;
}
.tie .side { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; padding: 2px 0; }
.tie .side .score { margin-left: auto; font-family: var(--figures); font-weight: 700; }
.tie .side.tbd { color: var(--ink-soft); font-style: italic; }
.tie .side.win { font-weight: 800; }
.pens { font-family: var(--figures); font-size: 0.68rem; color: var(--ink-soft); white-space: nowrap; }
.tie.champion { border-left-color: var(--trophy); background: color-mix(in srgb, var(--trophy) 14%, transparent); }

/* ---- misc -------------------------------------------------------------- */

.divider { border: 0; border-top: 2px solid var(--edge); margin: 22px 0; }
.empty { text-align: center; color: var(--ink-soft); padding: 28px 12px; font-size: 0.9rem; }
.code {
  font-family: var(--figures); font-size: 1.3rem; font-weight: 700;
  letter-spacing: 0.12em; color: var(--pitch);
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media print {
  header.top, .panel, .btn, .icon-btn { display: none !important; }
  main { display: block; max-width: none; }
  .card { break-inside: avoid; border: 1px solid #999; }
}
