:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #efefea;
  --text: #1b1b19;
  --muted: #65655f;
  --border: #e2e2dc;
  --accent: #2d55e0;
  --accent-ink: #ffffff;
  --danger: #c23a3a;
  --success: #1f8a4c;
  --focus: #2d55e0;

  --cat-inception: #7c4ddb;
  --cat-in-progress: #b86a00;
  --cat-pre-launch: #2160d8;
  --cat-production: #18834a;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 4%), 0 6px 20px rgb(0 0 0 / 5%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1b1b1a;
    --surface-2: #252523;
    --text: #ededea;
    --muted: #a3a39c;
    --border: #31312e;
    --accent: #7b9cff;
    --accent-ink: #0d1530;
    --danger: #ff7b7b;
    --success: #5fd291;
    --focus: #7b9cff;

    --cat-inception: #b596ff;
    --cat-in-progress: #f0a640;
    --cat-pre-launch: #6fa2ff;
    --cat-production: #5ccf8d;

    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -0.01em; }
p { margin: 0 0 1rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 820px; }
.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;
}
.muted { color: var(--muted); }

/* Header / footer */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: conic-gradient(var(--cat-inception) 0 25%, var(--cat-in-progress) 0 50%, var(--cat-pre-launch) 0 75%, var(--cat-production) 0);
}
.site-header nav { display: flex; gap: 18px; font-size: .95rem; }
.site-header nav a { color: var(--muted); }
.site-header nav a:hover { color: var(--text); }
.site-footer { border-top: 1px solid var(--border); margin-top: 64px; padding: 24px 0; color: var(--muted); font-size: .875rem; }

/* Hero */
.hero { padding: 48px 0 24px; max-width: 680px; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
.hero p { color: var(--muted); font-size: 1.1rem; margin: 0; }

/* Stage pipeline filter */
.stages {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 24px 0 16px;
}
.stage {
  appearance: none;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color .15s, background .15s;
}
.stage::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--cat, var(--muted));
}
.stage:hover { border-color: var(--cat, var(--muted)); }
.stage[aria-pressed="true"] {
  border-color: var(--cat, var(--text));
  background: color-mix(in srgb, var(--cat, var(--text)) 10%, var(--surface));
}
.stage-name { display: block; font-weight: 600; font-size: .95rem; }
.stage-meta { display: block; font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-count { float: right; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; font-size: .85rem; }

.cat-all { --cat: var(--text); }
.cat-inception { --cat: var(--cat-inception); }
.cat-in-progress { --cat: var(--cat-in-progress); }
.cat-pre-launch { --cat: var(--cat-pre-launch); }
.cat-production { --cat: var(--cat-production); }

/* Toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.search { flex: 1 1 260px; }
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 100%;
}
select { width: auto; }
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }

/* Buttons */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: progress; }

/* Badges & tags */
.badge {
  display: inline-block;
  font-size: .75rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 9px; border-radius: 999px;
  color: var(--cat);
  background: color-mix(in srgb, var(--cat) 14%, transparent);
}
.kind { font-size: .8rem; color: var(--muted); text-transform: capitalize; }
.tags { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { font-size: .78rem; color: var(--muted); background: var(--surface-2); padding: 2px 8px; border-radius: 6px; }

/* Card grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  border-top: 3px solid var(--cat);
}
.card-media { aspect-ratio: 16 / 9; background: var(--surface-2); }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 16px 16px 12px; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.card-meta { display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: 1.15rem; margin: 0; }
.card h3 a { color: var(--text); }
.card p { color: var(--muted); margin: 0; font-size: .95rem; }
.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-top: 1px solid var(--border);
  font-size: .875rem; color: var(--muted);
}
.card-foot a { color: var(--muted); }

/* Vote control */
.vote { display: inline-flex; align-items: center; gap: 2px; background: var(--surface-2); border-radius: 999px; padding: 2px; }
.vote-btn {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  width: 30px; height: 30px; border-radius: 999px; cursor: pointer;
  display: grid; place-items: center;
}
.vote-btn svg { width: 18px; height: 18px; fill: currentColor; }
.vote-btn.down svg { transform: rotate(180deg); }
.vote-btn:hover { background: var(--surface); color: var(--text); }
.vote-btn.up[aria-pressed="true"] { color: var(--success); }
.vote-btn.down[aria-pressed="true"] { color: var(--danger); }
.vote-score { min-width: 2ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
.vote-lg .vote-btn { width: 40px; height: 40px; }
.vote-lg .vote-btn svg { width: 22px; height: 22px; }
.vote-lg .vote-score { font-size: 1.15rem; min-width: 3ch; }

.status { color: var(--muted); min-height: 1.5em; margin: 0 0 8px; }
.empty {
  grid-column: 1 / -1; text-align: center; padding: 48px 16px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}

/* Item detail */
.back { display: inline-block; margin: 24px 0 16px; color: var(--muted); font-size: .9rem; }
.detail-head { display: flex; gap: 20px; align-items: flex-start; justify-content: space-between; }
.detail-head h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); margin-top: 8px; }
.detail-head .summary { color: var(--muted); font-size: 1.1rem; }
.detail-hero { border-radius: var(--radius); overflow: hidden; margin: 16px 0 24px; border: 1px solid var(--border); }
.description { white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 24px; }
.detail-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 16px 0 8px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-top: 24px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 1.25rem; }
.panel .lede { color: var(--muted); font-size: .92rem; }

.form { display: grid; gap: 12px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: .88rem; font-weight: 600; }
.form label .hint { font-weight: 400; color: var(--muted); }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.form-error { color: var(--danger); font-size: .9rem; margin: 0; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.rating { display: flex; gap: 4px; border: 0; padding: 0; margin: 0; }
.rating legend { font-size: .88rem; font-weight: 600; margin-bottom: 4px; padding: 0; }
.rating label { cursor: pointer; display: inline-flex; }
.rating input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.rating span {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-weight: 700; color: var(--muted);
}
.rating input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.rating input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.qa-list { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 14px; }
.qa { border-top: 1px solid var(--border); padding-top: 14px; }
.qa-q { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.qa-meta { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.qa-a {
  margin-top: 10px; padding: 10px 14px; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.qa-pending { margin-top: 8px; font-size: .85rem; color: var(--muted); font-style: italic; }
.thanks { padding: 16px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--text); }

/* Admin */
.admin-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 24px 0 20px; overflow-x: auto; }
.admin-tabs button {
  appearance: none; background: none; border: 0; font: inherit; color: var(--muted); font-weight: 600;
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.admin-tabs button[aria-selected="true"] { color: var(--text); border-color: var(--accent); }
.pill { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .75rem; text-align: center; }
.admin-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.admin-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; display: grid; gap: 8px;
}
.admin-row.unread { border-left: 3px solid var(--accent); }
.admin-row-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.admin-row-head h3 { font-size: 1.05rem; margin: 0; }
.admin-row .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-row .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-filter { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.login { max-width: 420px; margin: 64px auto; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 860px) {
  .stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stages .cat-all { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .hero { padding-top: 32px; }
  .form .row { grid-template-columns: 1fr; }
  .detail-head { flex-direction: column; }
  .stage-meta { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
