/* Bricolage Grotesque, SIL Open Font License 1.1 (see /fonts/OFL.txt) */
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/bricolage-grotesque-latin.woff2") format("woff2");
}

:root {
  --bg: #f5f3ee;
  --ink: #111110;
  --muted: #77756f;
  --line: #e2dfd7;
  --card: #ffffff;
  /* Underrated things are the good finds, so they get the hot colour. */
  --over: #2b5cff;
  --over-ink: #ffffff;
  --over-soft: #dfe7ff;
  --under: #ff4a1c;
  --under-ink: #ffffff;
  --under-soft: #ffe3da;
  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --gutter: clamp(16px, 4vw, 48px);
  --radius: 28px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101010;
    --ink: #f3f1ec;
    --muted: #8d8a83;
    --line: #26251f;
    --card: #1a1a18;
    --over-soft: #121c3d;
    --under-soft: #3a1a10;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
kbd {
  font: 600 0.8rem/1 var(--font);
  padding: 0.3em 0.5em;
  border: 1.5px solid currentColor;
  border-radius: 6px;
  opacity: 0.55;
}
@media (hover: none) { kbd { display: none; } }

/* ---------- Header ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px var(--gutter);
}
.logo {
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--ink);
}
.logo .o { color: var(--over); }
.logo .u { color: var(--under); }
nav { display: flex; gap: 4px; }
nav a {
  font-weight: 600;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  transition: color .15s, background .15s;
}
nav a:hover { color: var(--ink); }
nav a.active { color: var(--bg); background: var(--ink); }
nav a.add-link { color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); margin-left: 6px; }
nav a.add-link.active { box-shadow: none; color: var(--bg); }
@media (max-width: 520px) {
  .logo { font-size: 1.2rem; }
  nav a { font-size: 0.95rem; padding: 7px 10px; }
  nav a.add-link { margin-left: 2px; }
}

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view { flex: 1; display: flex; flex-direction: column; padding: 0 var(--gutter) var(--gutter); min-height: 0; }
.view[hidden] { display: none; }

.kicker {
  margin: 0;
  font-size: clamp(1.1rem, 2.2vw, 1.6rem);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: -0.01em;
}
.thing {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 0.92;
  overflow-wrap: anywhere;
}

/* ---------- Rate ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 2vh, 24px);
  min-height: 34vh;
  padding: 2vh 0 3vh;
  position: relative;
  overflow: hidden;
}
.stage .thing {
  font-size: 12vw; /* refined by fit() */
  max-height: 44vh;
}
/* On a vote the old name drops out and the new one drops in, simultaneously. */
:root { --swap: 260ms; }
.stage .thing.leave { animation: drop-out var(--swap) ease-in forwards; pointer-events: none; }
.stage .thing.enter { animation: drop-in var(--swap) ease-out both; }
/* The old one clears out quickly so the two barely overlap. */
@keyframes drop-out { 45%, to { opacity: 0; } to { transform: translateY(0.35em); } }
@keyframes drop-in { from { opacity: 0; transform: translateY(-0.35em); } 40% { opacity: 0; } }

.result { min-height: 48px; }
.split {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--line);
  max-width: 720px;
}
.split i { display: block; height: 100%; }
.split .o { background: var(--over); }
.split .u { background: var(--under); }
.last {
  margin: 0 0 8px;
  font-weight: 600;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.6vw, 1.2rem);
}
.last b { color: var(--ink); }
.last .o { color: var(--over); font-weight: 700; }
.last .u { color: var(--under); font-weight: 700; }

.choices {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(10px, 1.6vw, 20px);
}
.choice {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: clamp(150px, 26vh, 280px);
  padding: clamp(18px, 2.6vw, 34px);
  border-radius: var(--radius);
  text-align: left;
  font-weight: 800;
  letter-spacing: -0.04em;
}
.choice .arrow { font-size: clamp(2rem, 5vw, 4rem); line-height: 1; }
.choice { container-type: inline-size; }
.choice .label { font-size: min(6.5rem, 19cqi); line-height: 0.9; }
.choice kbd { position: absolute; top: clamp(18px, 2.6vw, 34px); right: clamp(18px, 2.6vw, 34px); }
.choice.over { background: var(--over); color: var(--over-ink); }
.choice.under { background: var(--under); color: var(--under-ink); align-items: flex-end; text-align: right; }
.choice.under kbd { right: auto; left: clamp(18px, 2.6vw, 34px); }
.choice:hover { filter: brightness(1.06); }
.choice:active, .choice.picked { filter: brightness(0.9); }
.choice:focus-visible, .side:focus-visible, .tab:focus-visible, .go:focus-visible { outline: 4px solid var(--ink); outline-offset: 4px; }
@media (max-width: 520px) {
  .choice { min-height: 150px; padding: 18px 16px; }
  .choice kbd { display: none; }
}

.skip {
  align-self: center;
  margin-top: 14px;
  padding: 8px 14px;
  color: var(--muted);
  font-weight: 600;
  font-size: 1rem;
  display: inline-flex;
  gap: 10px;
  align-items: center;
  border-radius: 999px;
}
.skip:hover { color: var(--ink); }

/* Waiting for something to show: muted text, buttons greyed out and inert. */
.thing.loading, .duel-grid.loading .thing { color: var(--line); }
.choices.loading .choice { filter: grayscale(1) opacity(.3); pointer-events: none; }
.duel-grid.loading .side { pointer-events: none; }
.duel-grid.loading .meta { visibility: hidden; }
.skip:disabled { opacity: .35; pointer-events: none; }

/* ---------- Duel ---------- */
.duel-q {
  margin: 1vh 0 2.4vh;
  font-weight: 800;
  letter-spacing: -0.035em;
  font-size: clamp(1.8rem, 4.6vw, 4rem);
  line-height: 1;
}
.mode-switch { display: inline-flex; gap: .12em; vertical-align: baseline; }
.duel-q .mode {
  font: inherit;
  letter-spacing: inherit;
  padding: 0 .14em .04em;
  border-radius: .18em;
  color: var(--muted);
  box-shadow: inset 0 0 0 2px var(--line);
}
.duel-q .mode:hover { color: var(--ink); }
.duel-q .mode.over[aria-checked="true"] { background: var(--over); color: #fff; box-shadow: none; }
.duel-q .mode.under[aria-checked="true"] { background: var(--under); color: #fff; box-shadow: none; }
.duel-q .mode:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }
.duel-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: clamp(10px, 1.6vw, 20px);
  min-height: 0;
}
.vs {
  align-self: center;
  font-weight: 800;
  font-size: clamp(1.2rem, 2.4vw, 2rem);
  color: var(--muted);
}
.side {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  min-height: clamp(220px, 50vh, 620px);
  padding: clamp(20px, 3vw, 40px);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: inset 0 0 0 2px var(--line);
  text-align: left;
  overflow: hidden;
}
.side .thing { display: block; font-size: 7vw; margin: auto 0; }
.side .meta { font-weight: 600; color: var(--muted); font-size: 1rem; }
.side kbd { position: absolute; top: clamp(20px, 3vw, 40px); right: clamp(20px, 3vw, 40px); }
#duel.over .side:hover { box-shadow: inset 0 0 0 4px var(--over); }
#duel.under .side:hover { box-shadow: inset 0 0 0 4px var(--under); }
#duel.over .side.picked { background: var(--over); color: var(--over-ink); box-shadow: none; }
#duel.under .side.picked { background: var(--under); color: var(--under-ink); box-shadow: none; }
.side.picked .meta { color: inherit; opacity: .8; }
@media (max-width: 720px) {
  .duel-grid { grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; }
  .side { min-height: 26vh; }
  .side .thing { font-size: 11vw; }
  .vs { justify-self: center; }
}
.empty { font-size: 1.4rem; color: var(--muted); }

/* ---------- Top ---------- */
.tabs { display: flex; gap: 10px; margin: 1vh 0 3vh; flex-wrap: wrap; }
.tab {
  font-weight: 800;
  letter-spacing: -0.035em;
  font-size: clamp(1.05rem, 4.2vw, 3.4rem);
  padding: .18em .5em .24em;
  border-radius: 999px;
  color: var(--muted);
  box-shadow: inset 0 0 0 2px var(--line);
}
.tab.over[aria-selected="true"] { background: var(--over); color: #fff; box-shadow: none; }
.tab.under[aria-selected="true"] { background: var(--under); color: #fff; box-shadow: none; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"]:hover { color: #fff; }

.lists { display: grid; grid-template-columns: 1fr; }
.col { min-width: 0; }
.col[hidden] { display: none; }
.col-title { display: none; }
.toplist { list-style: none; margin: 0; padding: 0; }
.toplist li {
  display: grid;
  grid-template-columns: 3.2ch 1fr auto;
  align-items: baseline;
  gap: clamp(10px, 2vw, 28px);
  padding: clamp(10px, 1.6vh, 18px) 0;
  border-bottom: 1.5px solid var(--line);
}
.toplist .n { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--muted); font-size: clamp(1.1rem, 2.4vw, 2rem); }
.toplist .name { font-weight: 800; letter-spacing: -0.035em; line-height: 1; font-size: clamp(1.6rem, 4.4vw, 3.8rem); overflow-wrap: anywhere; }
.toplist li:nth-child(1) .name { font-size: clamp(2.4rem, 8vw, 7rem); }
.toplist li:nth-child(2) .name { font-size: clamp(2rem, 6vw, 5.2rem); }
.toplist li:nth-child(3) .name { font-size: clamp(1.8rem, 5vw, 4.4rem); }
.toplist .pct { text-align: right; font-weight: 700; font-size: clamp(1rem, 2vw, 1.6rem); font-variant-numeric: tabular-nums; white-space: nowrap; }
.toplist .pct small { display: block; font-weight: 500; font-size: .7em; color: var(--muted); }
.toplist.over .pct b { color: var(--over); }
.toplist.under .pct b { color: var(--under); }
.toplist .none { display: block; color: var(--muted); font-size: 1.3rem; border: 0; }
.foot { color: var(--muted); font-size: 1rem; margin-top: 3vh; }

/* Wide screens: overrated and underrated side by side. */
@media (min-width: 900px) {
  #top .tabs { display: none; }
  .lists { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(32px, 4vw, 80px); margin-top: 1vh; }
  .col[hidden] { display: block; }
  .col-title {
    display: inline-block;
    margin: 0 0 2vh;
    font-weight: 800;
    letter-spacing: -0.035em;
    font-size: clamp(1.6rem, 2.8vw, 2.8rem);
    line-height: 1;
    padding: .18em .5em .24em;
    border-radius: 999px;
    color: #fff;
  }
  .col-title.over { background: var(--over); }
  .col-title.under { background: var(--under); }
  .toplist .n { font-size: clamp(1rem, 1.4vw, 1.4rem); }
  .toplist .name { font-size: clamp(1.3rem, 2.2vw, 2.2rem); }
  .toplist li:nth-child(1) .name { font-size: clamp(2rem, 4vw, 4.2rem); }
  .toplist li:nth-child(2) .name { font-size: clamp(1.7rem, 3.2vw, 3.2rem); }
  .toplist li:nth-child(3) .name { font-size: clamp(1.5rem, 2.7vw, 2.7rem); }
  .toplist .pct { font-size: clamp(0.95rem, 1.3vw, 1.3rem); }
}

/* ---------- Add ---------- */
#add form {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2vh;
  max-width: 1400px;
}
#add-input {
  width: 100%;
  border: 0;
  border-bottom: 4px solid var(--ink);
  background: transparent;
  font-weight: 800;
  letter-spacing: -0.045em;
  font-size: clamp(2.6rem, 9vw, 9rem);
  line-height: 1.05;
  padding: 0 0 .08em;
  outline: none;
  border-radius: 0;
}
#add-input::placeholder { color: var(--line); }
#add-input:focus { border-bottom-color: var(--under); }
.hint { margin: 0; color: var(--muted); font-size: clamp(1rem, 1.8vw, 1.3rem); min-height: 1.5em; }
.hint.error { color: var(--under); font-weight: 600; }
.go {
  align-self: flex-start;
  margin-top: 2vh;
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
  padding: .35em .9em .4em;
  border-radius: 999px;
}
.go:hover { filter: brightness(1.2); }
.go:disabled { opacity: .4; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translate(-50%, -12px);
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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