/* Metropolitan Line: an open-source (OFL) revival of Edward Johnston's 1916 Underground type, via Railway Sans.
   It has a single Regular weight, like Johnston's original, so emphasis comes from size, case and colour. */
@font-face {
  font-family: "Metropolitan Line";
  src: url("fonts/MetropolitanLine-Regular.woff2") format("woff2");
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #F4F0E8;
  --paper-2: #EAE4D8;
  --card: #FFFFFF;
  --ink: #142A5C;
  --ink-soft: #4A5670;
  --line: #D9D1C1;
  --red: #C8102E;
  --red-ink: #FFFFFF;
  --shadow: 0 1px 2px rgba(20, 42, 92, .08), 0 8px 24px rgba(20, 42, 92, .08);
  --cat-transport: #C8102E;
  --cat-graphics: #0019A8;
  --cat-objects: #00782A;
  --cat-buildings: #B36305;
  --radius: 14px;
  --font: "Metropolitan Line", "Gill Sans", "Gill Sans MT", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101317;
    --paper-2: #181C22;
    --card: #1C2129;
    --ink: #EFEAE0;
    --ink-soft: #A7ADB8;
    --line: #2E3540;
    --red: #E23B4E;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    --cat-transport: #F0616F;
    --cat-graphics: #7B91FF;
    --cat-objects: #4CC47A;
    --cat-buildings: #E99A4A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #101317; --paper-2: #181C22; --card: #1C2129; --ink: #EFEAE0; --ink-soft: #A7ADB8;
  --line: #2E3540; --red: #E23B4E; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
  --cat-transport: #F0616F; --cat-graphics: #7B91FF; --cat-objects: #4CC47A; --cat-buildings: #E99A4A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  padding: .8em 1.3em;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease;
  white-space: nowrap;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--red); border-color: var(--red); color: var(--red-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--red) 88%, black); }
.btn.ghost { border-color: transparent; }
.btn.small { padding: .45em .9em; font-size: .9rem; }
.btn:disabled { opacity: .35; pointer-events: none; }
:focus-visible { outline: 3px solid var(--cat-graphics); outline-offset: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: .4em;
  font-size: .72rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-soft);
}
.chip::before {
  content: ""; width: .8em; height: .8em; border-radius: 50%;
  border: .22em solid var(--c, var(--ink-soft));
}
[data-cat="Transport"] { --c: var(--cat-transport); }
[data-cat="Graphics & type"] { --c: var(--cat-graphics); }
[data-cat="Objects, furniture & fashion"] { --c: var(--cat-objects); }
[data-cat="Buildings & structures"] { --c: var(--cat-buildings); }

/* ---------- Home ---------- */
.screen { min-height: 100vh; min-height: 100dvh; }
.home-head {
  max-width: 1100px; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top)) 16px 8px;
  display: grid; gap: 18px;
}
.home-title { display: flex; align-items: center; gap: 28px; }
.roundel {
  width: 110px; height: 110px; flex: none; position: relative; margin: 0 20px;
  border-radius: 50%; border: 19px solid var(--red);
}
.roundel span {
  position: absolute; left: -38px; right: -38px; top: 50%; transform: translateY(-50%);
  background: var(--ink); color: var(--paper); text-align: center; text-transform: uppercase; letter-spacing: .04em;
  font-size: 12px; padding: 5px 0;
}
h1 {
  font-size: clamp(2.3rem, 7vw, 4.2rem); line-height: .95; margin: 0 0 10px; letter-spacing: -.01em; text-transform: uppercase;
}
.lede { font-size: 1.05rem; color: var(--ink-soft); margin: 0; max-width: 36em; }
.cats { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.home-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; }
.btn.big { font-size: 1.1rem; padding: .9em 1.8em; }
.home-bracket-wrap { max-width: 1400px; margin: 0 auto; padding: 8px 0 calc(28px + env(safe-area-inset-bottom)); }
.home-status { padding: 0 16px; margin: 10px 0 4px; }
.home-status .hint { color: var(--ink-soft); font-size: .88rem; }
@media (max-width: 759px) {
  .home-title { flex-direction: column; align-items: flex-start; gap: 18px; }
  .roundel { width: 76px; height: 76px; border-width: 13px; margin: 0 26px; }
  .roundel span { left: -30px; right: -30px; font-size: 9px; padding: 4px 0; }
  .home-actions .btn.big { flex: 1; }
}

/* ---------- Top bar ---------- */
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; gap: 8px;
}
.topbar > :last-child { justify-self: end; }
.brand {
  display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px; text-transform: uppercase; letter-spacing: .03em; font-size: .85rem;
  cursor: pointer; justify-self: start;
}
.mini-roundel {
  width: 22px; height: 22px; border-radius: 50%; border: 4.5px solid var(--red); position: relative; flex: none;
}
.mini-roundel::after { content: ""; position: absolute; left: -7px; right: -7px; top: 50%; height: 5px; transform: translateY(-50%); background: var(--ink); }
.round-info { text-align: center; line-height: 1.15; }
.round-name { text-transform: uppercase; letter-spacing: .03em; }
.round-count { font-size: .8rem; color: var(--ink-soft); }
.progress { height: 3px; background: var(--line); }
.progress-bar { height: 100%; width: 0; background: var(--red); transition: width .3s ease; }

/* ---------- Match ---------- */
#match { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; }
.arena {
  flex: 1; min-height: 0; position: relative;
  display: grid; grid-template-rows: 1fr 1fr; gap: 12px; padding: 12px 16px;
}
.vs {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--paper);
  text-transform: uppercase; font-size: .85rem; box-shadow: 0 0 0 5px var(--paper);
  pointer-events: none;
}
.card {
  min-height: 0; display: flex; flex-direction: column;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; transition: transform .2s ease, opacity .2s ease, box-shadow .2s ease;
}
.card.enter { animation: cardIn .32s ease both; }
.card[data-side="1"].enter { animation-delay: .05s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.card.won { transform: scale(1.02); box-shadow: 0 0 0 3px var(--red), var(--shadow); }
.card.lost { opacity: .35; transform: scale(.97); }

.media {
  flex: 1; min-height: 0; position: relative; display: block; width: 100%;
  border: 0; padding: 0; margin: 0; background: var(--paper-2); cursor: zoom-in; overflow: hidden;
}
.media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.media img.bg { object-fit: cover; filter: blur(24px) saturate(1.1); transform: scale(1.2); opacity: .55; }
.media .info-badge {
  position: absolute; right: 10px; bottom: 10px; z-index: 1;
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(20, 25, 35, .72); color: #fff; font-style: italic; font-family: Georgia, serif;
  font-size: 16px; backdrop-filter: blur(6px);
}
.pick {
  appearance: none; border: 0; background: none; text-align: left; cursor: pointer; width: 100%;
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px;
  padding: 12px 14px 14px; border-top: 1px solid var(--line);
}
.pick:hover .pick-cta { background: var(--red); color: var(--red-ink); border-color: var(--red); }
.pick .chip { grid-column: 1; }
.pick-name { grid-column: 1; font-size: clamp(1.2rem, 2.7vw, 1.6rem); line-height: 1.15; }
.pick-credit { grid-column: 1; color: var(--ink-soft); font-size: .88rem; }
.pick-cta {
  grid-column: 2; grid-row: 1 / span 3;
  border: 1.5px solid var(--ink); border-radius: 999px; padding: .55em 1em; font-size: .92rem;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.matchbar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 4px 12px calc(8px + env(safe-area-inset-bottom));
}
.keys { font-size: .8rem; color: var(--ink-soft); display: none; }

@media (max-width: 759px) {
  .brand span:last-child { display: none; }
  .pick { padding: 9px 12px 11px; }
  .pick-credit { font-size: .8rem; }
  .pick-cta { padding: .45em .85em; font-size: .85rem; }
}
@media (min-width: 760px) {
  .arena { grid-template-rows: 1fr; grid-template-columns: 1fr 1fr; gap: 28px; padding: 20px 28px; }
  .keys { display: inline; }
  .vs { width: 54px; height: 54px; font-size: 1rem; }
  .pick { padding: 16px 20px 18px; }
}

/* Splash between rounds */
.splash {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: color-mix(in srgb, var(--paper) 86%, transparent); backdrop-filter: blur(6px);
  animation: fade .25s ease both; cursor: pointer;
}
.splash-inner { text-align: center; padding: 16px; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1) both; }
.splash-kicker { color: var(--red); text-transform: uppercase; letter-spacing: .12em; font-size: .85rem; }
.splash-title { font-size: clamp(2.6rem, 11vw, 5rem); text-transform: uppercase; line-height: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }

/* ---------- Results ---------- */
.results-inner { max-width: 980px; margin: 0 auto; padding: 8px 16px calc(40px + env(safe-area-inset-bottom)); }
.kicker { text-align: center; text-transform: uppercase; letter-spacing: .12em; color: var(--red); font-size: .85rem; margin: 12px 0 10px; }
.champion { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.champion .media { height: min(56vh, 480px); }
.champion .champ-body { padding: 16px 20px 20px; text-align: center; }
.champion h2 { margin: 6px 0 2px; font-size: clamp(1.8rem, 6vw, 3rem); line-height: 1; text-transform: uppercase; }
.champion .credit { color: var(--ink-soft); margin: 6px 0 0; }
.share-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 20px 0 8px; }
.tier { margin-top: 32px; }
.tier h3 {
  display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .03em; font-size: 1rem;
  border-bottom: 2px solid var(--ink); padding-bottom: 6px;
}
.tier h3 small { color: var(--ink-soft); text-transform: none; letter-spacing: 0; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tiles.big { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tile {
  appearance: none; border: 0; padding: 0; text-align: left; cursor: pointer;
  background: var(--card); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.tile .media { aspect-ratio: 4 / 3; flex: none; cursor: inherit; }
.tile .tile-body { padding: 8px 10px 10px; }
.tile .tile-name { font-size: .92rem; line-height: 1.2; display: block; }
.tile .chip { font-size: .62rem; margin-bottom: 2px; }
.results-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 40px; }

/* ---------- Bracket sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 30; background: var(--paper);
  display: flex; flex-direction: column; animation: fade .2s ease both;
}
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; text-transform: uppercase; font-size: 1.3rem; }
/* The overlay sheet scrolls itself; the inline brackets (home, stats) scroll with the page. */
.bracket { padding: 0 8px; }
.sheet .bracket { flex: 1; min-height: 0; overflow: auto; padding: 0 8px calc(20px + env(safe-area-inset-bottom)); }
/* Wide screens: every round side by side, sized to fit. */
.b-cols {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); align-items: stretch;
  padding-top: 12px;
}
.b-round { display: flex; flex-direction: column; min-width: 0; padding: 0 5px; }
.b-round h4 {
  margin: 0 0 6px; padding: 6px 0; background: var(--paper);
  font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft);
}
.sheet .b-round h4 { position: sticky; top: 0; z-index: 1; }
/* Narrow screens: one round at a time, picked with tabs. */
.b-tabs { display: none; }
@media (max-width: 1079px) {
  .b-tabs {
    display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
    position: sticky; top: 0; z-index: 3; background: var(--paper);
    padding: 10px 8px; margin: 0 -8px; border-bottom: 1px solid var(--line);
  }
  .b-tabs::-webkit-scrollbar { display: none; }
  .b-tab {
    flex: none; appearance: none; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
    border-radius: 999px; padding: .4em .9em; font-size: .88rem; cursor: pointer; white-space: nowrap;
  }
  .b-tab.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
  .b-cols { display: block; max-width: 560px; margin: 0 auto; }
  .b-round { display: none; padding: 0; }
  .b-round.active { display: flex; }
  .b-round h4 { display: none; }
  .b-round .b-matches { justify-content: flex-start; gap: 10px; }
  .b-match { font-size: .95rem; }
}
.b-matches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 8px; }
.b-match {
  background: var(--card); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; font-size: .82rem;
}
.b-match.current { box-shadow: 0 0 0 2px var(--red), var(--shadow); }
.b-row {
  display: flex; align-items: center; gap: 7px; padding: 5px 8px; line-height: 1.2;
  border: 0; background: none; width: 100%; text-align: left; cursor: pointer;
}
.b-row + .b-row { border-top: 1px solid var(--line); }
.b-row img {
  flex: none; width: 26px; height: 26px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--c, var(--line)); margin: 3px 4px 3px 3px;
}
.b-row.lose img { filter: grayscale(1); opacity: .5; }
.b-row.tbd::before { content: ""; flex: none; width: 26px; height: 26px; margin: 3px 4px 3px 3px; border-radius: 50%; border: 2px dashed var(--line); }
.b-row.win { color: var(--ink); }
.b-row.lose { color: var(--ink-soft); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ink-soft) 50%, transparent); }
.b-row.tbd { color: var(--ink-soft); cursor: default; }
.b-round:last-child .tile { width: 100%; }
/* Stats bracket: vote share bar behind each row */
.crowd .b-row { position: relative; isolation: isolate; }
.crowd .b-row::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: var(--share, 0%); z-index: -1;
  background: color-mix(in srgb, var(--c, var(--ink)) 13%, transparent);
}
.crowd .b-row.lose { text-decoration: none; }
.crowd .b-row span:nth-of-type(1) { flex: 1; }
.pct { font-variant-numeric: tabular-nums; font-size: .95rem; color: var(--ink); padding-left: 6px; }
.b-row.lose .pct { color: var(--ink-soft); }
.b-votes { font-size: .72rem; color: var(--ink-soft); padding: 3px 10px 5px; border-top: 1px solid var(--line); }
.stats-head { max-width: 1100px; margin: 0 auto; padding: 16px 16px 0; }
.stats-head h2 { font-size: clamp(1.8rem, 5vw, 2.8rem); line-height: 1; margin: 0 0 10px; text-transform: uppercase; }
.stats-head .home-status { padding: 0; margin: 14px 0 0; }
.stats-champion { max-width: 280px; margin-top: 14px; }
.stats-champion .kicker { text-align: left; margin: 0 0 8px; }
.stats-champion .tile { width: 100%; }
.b-champ { text-align: center; padding: 10px; text-transform: uppercase; }

/* ---------- Info dialog ---------- */
dialog#info {
  border: 0; padding: 0; border-radius: 16px; background: var(--card); color: var(--ink);
  width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  overflow: auto;
}
dialog#info::backdrop { background: rgba(10, 14, 22, .6); backdrop-filter: blur(3px); }
dialog#info[open] { animation: pop .25s ease both; }
.info-media { position: relative; height: min(46vh, 380px); background: var(--paper-2); overflow: hidden; }
.info-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.info-media img.bg { object-fit: cover; filter: blur(24px); transform: scale(1.2); opacity: .55; }
.info-body { padding: 16px 20px 20px; }
.info-body h2 { margin: 6px 0 2px; font-size: 1.7rem; line-height: 1.1; }
.info-body .credit { margin: 0; color: var(--ink-soft); }
.info-body .note { font-style: italic; margin: 10px 0 0; }
.info-body .note:empty { display: none; }
.imgsrc { margin: 12px 0 0; font-size: .78rem; }
.imgsrc a { color: var(--ink-soft); }
.close-x {
  position: absolute; top: 10px; right: 10px; z-index: 1; width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: rgba(20, 25, 35, .72); color: #fff; font-size: 24px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; backdrop-filter: blur(6px);
}
.info-actions {
  position: sticky; bottom: 0; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line);
}
.info-actions .btn { text-decoration: none; text-align: center; }
@media (max-width: 759px) {
  .info-media { height: 34vh; }
  .info-actions .btn { flex: 1; padding-left: .8em; padding-right: .8em; }
  .champion .media { height: 44vh; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
