:root {
  color-scheme: dark light;
  --bg: #0d0e12;
  --surface: #171923;
  --surface-2: #202333;
  --line: #2b2f40;
  --text: #f3f4f8;
  --muted: #9aa0b4;
  --accent: #ff4d6d;
  --accent-ink: #fff;
  --ok: #3ddc97;
  --danger: #ff6b6b;
  --radius: 18px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f5f9;
    --surface: #ffffff;
    --surface-2: #eeeff5;
    --line: #dfe1ea;
    --text: #14151b;
    --muted: #64697c;
    --accent: #e8264a;
    --ok: #12a06a;
    --danger: #d63c3c;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- chrome ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand img {
  width: 28px;
  height: 28px;
}

.site-nav {
  display: flex;
  gap: 4px;
}

.site-nav a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--text);
}

.site-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-2);
}

.site-footer {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

main.narrow {
  max-width: 560px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 4vw + 0.5rem, 2.6rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.lead {
  margin: 0 0 24px;
  color: var(--muted);
}

/* ---------- vote ---------- */

.prompt {
  text-align: center;
  margin-bottom: 20px;
}

.arena {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  /* Two 4:5 cards side by side are 1.6x wider than tall, so cap the width to
     keep both fully on screen without scrolling. */
  width: min(100%, 900px, calc((100dvh - 250px) * 1.6));
  min-width: min(100%, 300px);
  margin: 0 auto;
}

/* Cards only ever animate transform and opacity, which the browser can run on
   the GPU without repainting the photo. vote.js drives the states below:
   picked/dimmed -> leaving -> entering -> (rest). Keep its timings in step. */
.card {
  position: relative;
  display: block;
  padding: 0;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  touch-action: manipulation; /* no double-tap delay when voting quickly */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.32s var(--ease-out), opacity 0.32s var(--ease-out);
  will-change: transform, opacity;
}

.card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* The accent ring fades in on an overlay, so the card's border is never repainted. */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 3px var(--accent);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.card .name {
  position: absolute;
  inset: auto 0 0 0;
  padding: 40px 14px 14px;
  color: #fff;
  font-weight: 700;
  font-size: clamp(1rem, 2.4vw, 1.4rem);
  text-align: left;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
  overflow-wrap: anywhere;
}

/* Hover effects only on devices that really hover, so a tap on a phone doesn't leave a card stuck lifted. */
@media (hover: hover) {
  .card:hover:not(:disabled) {
    transform: translateY(-3px);
  }
  .card:hover:not(:disabled)::after {
    opacity: 1;
  }
}

.card:disabled {
  cursor: default;
}

.card.picked {
  transform: scale(1.03);
}

.card.picked::after {
  opacity: 1;
}

.card.dimmed {
  opacity: 0.35;
  transform: scale(0.97);
}

/* Both cards drift up and fade out together... */
.card.leaving {
  opacity: 0;
  transform: translateY(-12px) scale(0.97);
  transition-duration: 0.18s;
  transition-timing-function: var(--ease-in);
}

/* ...the next pair is swapped in while invisible, parked low with no transition... */
.card.entering {
  opacity: 0;
  transform: translateY(18px) scale(0.97);
  transition: none;
}

.card.entering::after {
  transition: none;
}

/* ...then this class is removed, and the cards rise into place, right one a beat after the left. */
.arena.settling .card:not(.picked):not(.dimmed) {
  transition-duration: 0.46s;
}

.arena.settling #card-b:not(.picked):not(.dimmed) {
  transition-delay: 0.07s;
}

.vs {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  z-index: 2; /* above both cards, including a hovered/picked one */
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--line);
  color: var(--muted);
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.arena.swapping .vs {
  opacity: 0;
}

.vote-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 16px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  text-decoration: underline;
  cursor: pointer;
}

.empty {
  max-width: 420px;
  margin: 60px auto;
  text-align: center;
  color: var(--muted);
}

.empty h2 {
  color: var(--text);
  font-size: 1.4rem;
}

/* ---------- leaderboard ---------- */

.board {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.row {
  display: grid;
  grid-template-columns: 40px 64px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 10px 16px 10px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.row .rank {
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.row.top .rank {
  color: var(--accent);
  font-size: 1.4rem;
}

.row img {
  width: 64px;
  height: 80px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-2);
}

.row .who {
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.row .who small {
  display: block;
  color: var(--muted);
  font-weight: 400;
}

.row .score {
  text-align: right;
  font-weight: 800;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.row .score small {
  display: block;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.75rem;
}

/* ---------- forms ---------- */

form,
.panel {
  display: grid;
  gap: 20px;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span,
legend {
  font-weight: 700;
  font-size: 0.95rem;
}

small {
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.photo-field {
  display: grid;
  grid-template-columns: minmax(120px, 200px) 1fr;
  gap: 16px;
  align-items: start;
}

.photo-field canvas {
  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
}

.photo-field .controls {
  display: grid;
  gap: 12px;
  align-content: start;
}

.photo-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

fieldset {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

legend {
  padding: 0 8px;
}

.check {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 12px;
  align-items: start;
  cursor: pointer;
  font-size: 0.95rem;
}

.check input {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.danger {
  border-color: transparent;
  background: var(--danger);
  color: #fff;
}

.btn.small {
  padding: 8px 14px;
  font-size: 0.9rem;
}

.error {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
  font-weight: 600;
}

.notice {
  margin: 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
}

.linkbox {
  display: flex;
  gap: 8px;
}

.linkbox input {
  flex: 1;
  min-width: 0;
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.pill.ok {
  background: color-mix(in srgb, var(--ok) 18%, transparent);
  color: var(--ok);
}

.pill.wait {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}

/* ---------- admin ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.tabs button {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  background: var(--surface-2);
  color: var(--text);
}

.narrow-form {
  max-width: 380px;
  margin: 40px auto;
}

.bulk {
  display: grid;
  gap: 10px;
}

.bulk-row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.bulk-row canvas {
  width: 64px;
  aspect-ratio: 4 / 5;
  border-radius: 8px;
  background: var(--surface-2);
}

.bulk-row .fields {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.bulk-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.state {
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.85rem;
}

.state.good {
  color: var(--ok);
}

.state.bad {
  color: var(--danger);
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tabs .link-btn {
  margin-left: auto;
  padding: 8px;
  border: 0;
  color: var(--muted);
  font-weight: 600;
}

.people {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.person {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.person img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 12px;
  background: var(--surface-2);
}

.person h3 {
  margin: 0;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.person .meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.person .actions {
  display: flex;
  gap: 8px;
}

.person .actions .btn {
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

td.code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.codes {
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface-2);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: pre-line;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.inline-form .field {
  flex: 1 1 160px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  translate: -50% 0;
  max-width: min(92vw, 420px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  z-index: 10;
}

@media (max-width: 560px) {
  .site-header {
    padding: 10px 12px;
  }
  .site-nav a {
    padding: 8px 10px;
  }
  .brand span {
    display: none;
  }
  .arena {
    gap: 8px;
  }
  .row {
    grid-template-columns: 28px 52px 1fr auto;
    gap: 10px;
  }
  .row img {
    width: 52px;
    height: 65px;
  }
  .photo-field {
    grid-template-columns: 1fr;
  }
  .photo-field canvas {
    max-width: 220px;
  }
}

/* ---------- blog ---------- */

.posts {
  display: grid;
  gap: 14px;
}

.post-card {
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.post-card h2 {
  margin: 4px 0 8px;
  font-size: 1.4rem;
}

.post-card h2 a {
  text-decoration: none;
}

.post-card h2 a:hover {
  text-decoration: underline;
}

.post-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.post-excerpt {
  margin: 0;
  color: var(--muted);
}

.back-link {
  display: inline-block;
  margin-bottom: 20px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

.post-body p {
  margin: 0 0 1.1em;
  font-size: 1.05rem;
  line-height: 1.7;
  white-space: pre-line;
}

textarea {
  width: 100%;
  min-height: 12em;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font: inherit;
  line-height: 1.5;
  resize: vertical;
}

textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.post-head {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.post-head .lead {
  margin: 0;
}

.post-rows {
  display: grid;
  gap: 10px;
}

.post-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.post-row-main {
  display: grid;
  flex: 1 1 200px;
  gap: 2px;
  min-width: 0;
}

.post-row-main strong {
  overflow-wrap: anywhere;
}

.post-row .actions {
  display: flex;
  gap: 8px;
}

/* Blog pictures: shown whole on a post, and as a thumbnail in lists and the review queue. */
.post-picture {
  display: block;
  width: 100%;
  max-height: 70vh;
  margin: 0 0 20px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.post-thumb {
  display: block;
  max-width: 100%;
  max-height: 220px;
  margin: 8px 0;
  object-fit: contain;
  border-radius: 12px;
  background: var(--surface-2);
}

/* Honeypot field: off-screen for people, still present in the form for bots. */
.hp {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.post-text {
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.pending {
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.pending h2 {
  margin: 0;
}

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