/* ---------------------------------------------------------------------------
   Final Bedtime — a Primer-flavoured stylesheet.
   Colour values follow Primer Primitives (github/primer) so the site reads like
   a GitHub surface, with a serif face reserved for the poems themselves.
   No web fonts, no CDN: everything here is one cached file.
   --------------------------------------------------------------------------- */

:root {
  --canvas-default: #ffffff;
  --canvas-subtle: #f6f8fa;
  --canvas-inset: #f6f8fa;
  --fg-default: #1f2328;
  --fg-muted: #59636e;
  --fg-subtle: #6e7781;
  --fg-on-emphasis: #ffffff;
  --border-default: #d1d9e0;
  --border-muted: #d8dee4;
  --accent-fg: #0969da;
  --accent-emphasis: #0969da;
  --accent-subtle: #ddf4ff;
  --success-fg: #1a7f37;
  --success-emphasis: #1f883d;
  --success-subtle: #dafbe1;
  --danger-fg: #d1242f;
  --danger-emphasis: #cf222e;
  --danger-subtle: #ffebe9;
  --attention-fg: #9a6700;
  --attention-emphasis: #bf8700;
  --attention-subtle: #fff8c5;
  --done-fg: #8250df;
  --neutral-muted: rgba(129, 139, 152, 0.2);
  --shadow-resting: 0 1px 0 rgba(31, 35, 40, 0.04);
  --radius: 6px;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial,
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Songti TC",
    "Noto Serif CJK TC", "Source Han Serif TC", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas-default: #0d1117;
    --canvas-subtle: #151b23;
    --canvas-inset: #010409;
    --fg-default: #f0f6fc;
    --fg-muted: #9198a1;
    --fg-subtle: #6e7681;
    --border-default: #3d444d;
    --border-muted: #2a3038;
    --accent-fg: #4493f8;
    --accent-emphasis: #1f6feb;
    --accent-subtle: #121d2f;
    --success-fg: #3fb950;
    --success-emphasis: #238636;
    --success-subtle: #0f2417;
    --danger-fg: #f85149;
    --danger-emphasis: #da3633;
    --danger-subtle: #25171c;
    --attention-fg: #d29922;
    --attention-emphasis: #9e6a03;
    --attention-subtle: #272115;
    --done-fg: #ab7df8;
    --neutral-muted: rgba(99, 110, 123, 0.4);
    --shadow-resting: 0 0 transparent;
  }
}

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

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg-default);
  background: var(--canvas-default);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-fg); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

.wrap { width: 100%; max-width: 768px; margin: 0 auto; padding: 0 16px; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--fg-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.dim { opacity: 0.45; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  padding: 8px 16px; background: var(--accent-emphasis); color: #fff; z-index: 10;
}
.skip-link:focus { left: 0; }

/* --- header --------------------------------------------------------------- */

.site-header {
  border-bottom: 1px solid var(--border-default);
  background: var(--canvas-subtle);
  margin-bottom: 24px;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg-default); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 32% 32%, var(--canvas-default) 0 38%, transparent 39%),
              var(--fg-default);
  flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 15px; letter-spacing: 0.01em; }
.brand-text small { color: var(--fg-muted); font-size: 12px; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-item {
  padding: 5px 10px; border-radius: var(--radius); color: var(--fg-muted); font-size: 13px;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--neutral-muted); color: var(--fg-default); text-decoration: none; }
.nav-item.is-active {
  color: var(--fg-default); font-weight: 600;
  background: var(--canvas-default); border-color: var(--border-default);
}

/* --- boxes ---------------------------------------------------------------- */

.Box {
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  background: var(--canvas-default);
  box-shadow: var(--shadow-resting);
  margin-bottom: 16px;
  overflow: hidden;
}
.Box.subtle { background: var(--canvas-subtle); }
.Box-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--canvas-subtle);
  border-bottom: 1px solid var(--border-default);
}
.Box-body { padding: 16px; }
.Box-footer {
  padding: 12px 16px; background: var(--canvas-subtle);
  border-top: 1px solid var(--border-default);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
details.Box > summary {
  padding: 10px 16px; cursor: pointer; background: var(--canvas-subtle);
  font-weight: 600; list-style: none;
}
details.Box > summary::-webkit-details-marker { display: none; }
details.Box > summary::before { content: "▸ "; color: var(--fg-muted); }
details.Box[open] > summary { border-bottom: 1px solid var(--border-default); }
details.Box[open] > summary::before { content: "▾ "; }

/* --- hero ----------------------------------------------------------------- */

.hero { margin-bottom: 24px; }
.hero h1 { font-size: 28px; letter-spacing: -0.01em; margin-bottom: 10px; }
.hero-lede { color: var(--fg-muted); font-size: 15px; max-width: 60ch; }
.hero-meta { color: var(--fg-subtle); }

.page-head { margin-bottom: 16px; }
.page-head h1 { margin-bottom: 6px; }

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

.field { display: block; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field-label small { font-weight: 400; color: var(--fg-muted); margin-left: 6px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 180px; }

.input {
  width: 100%; padding: 6px 10px; font: inherit; color: var(--fg-default);
  background: var(--canvas-default); border: 1px solid var(--border-default);
  border-radius: var(--radius); outline: none;
}
.input:focus { border-color: var(--accent-emphasis); box-shadow: 0 0 0 3px var(--accent-subtle); }
.textarea { resize: vertical; font-family: var(--serif); font-size: 16px; line-height: 1.9; }
.textarea.mono { font-family: var(--mono); font-size: 12px; line-height: 1.6; }

.form-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--fg-muted); }
.counter { color: var(--fg-subtle); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 14px; font-size: 13px; font-weight: 500; font-family: inherit;
  color: var(--fg-default); background: var(--canvas-subtle);
  border: 1px solid var(--border-default); border-radius: var(--radius);
  cursor: pointer; transition: background 0.1s;
}
.btn:hover { background: var(--neutral-muted); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 2px 8px; font-size: 12px; }
.btn-primary { color: var(--fg-on-emphasis); background: var(--success-emphasis); border-color: rgba(31, 35, 40, 0.15); }
.btn-primary:hover { background: var(--success-fg); }
.btn-good { color: var(--success-fg); }
.btn-bad, .btn-danger { color: var(--danger-fg); }

/* --- labels & dots -------------------------------------------------------- */

.Label {
  display: inline-block; padding: 0 8px; font-size: 12px; font-weight: 600;
  line-height: 20px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.Label--good { color: var(--success-fg); background: var(--success-subtle); border-color: var(--success-fg); }
.Label--bad { color: var(--danger-fg); background: var(--danger-subtle); border-color: var(--danger-fg); }
.Label--undecided { color: var(--fg-muted); background: var(--canvas-subtle); border-color: var(--border-default); }
.Label--neutral { color: var(--fg-muted); background: var(--canvas-subtle); border-color: var(--border-muted); }
.Label--warn { color: var(--attention-fg); background: var(--attention-subtle); border-color: var(--attention-fg); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-good { background: var(--success-fg); }
.dot-warn { background: var(--attention-fg); }
.dot-bad { background: var(--danger-fg); }

.flash {
  padding: 12px 16px; border: 1px solid; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px;
}
.flash-warn { background: var(--attention-subtle); border-color: var(--attention-emphasis); color: var(--fg-default); }
.flash-note { background: var(--accent-subtle); border-color: var(--accent-emphasis); color: var(--fg-default); }

/* --- the poem itself ------------------------------------------------------ */

.poem {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 2;
  white-space: pre-wrap;
  color: var(--fg-default);
  padding: 4px 0;
}
.poem-line { display: block; }
.byline { margin-top: 12px; color: var(--fg-muted); font-family: var(--serif); }

.critique { font-size: 14px; line-height: 1.8; margin-top: 14px; }
.quote {
  margin: 14px 0 0; padding: 6px 0 6px 14px;
  border-left: 3px solid var(--border-default);
  font-family: var(--serif); font-size: 16px; color: var(--fg-muted);
}

/* --- score meter ---------------------------------------------------------- */

.meter { margin: 4px 0 14px; }
.meter-track {
  position: relative; height: 8px; border-radius: 999px;
  background: var(--neutral-muted); overflow: hidden;
}
.meter-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.meter-good { background: var(--success-emphasis); }
.meter-bad { background: var(--danger-emphasis); }
.meter-undecided { background: var(--fg-subtle); }
.meter-warn { background: var(--attention-emphasis); }
.meter-mid {
  position: absolute; top: -2px; bottom: -2px; left: 50%; width: 1px;
  background: var(--canvas-default); opacity: 0.9;
}
.meter-scale { display: flex; justify-content: space-between; color: var(--fg-subtle); margin-top: 6px; }

.dims { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.dims li {
  display: flex; align-items: baseline; gap: 6px;
  padding: 3px 10px; font-size: 12px;
  border: 1px solid var(--border-muted); border-radius: 999px; background: var(--canvas-subtle);
}
.dims b { font-family: var(--mono); color: var(--accent-fg); }

.verdict-box { border-left: 3px solid var(--border-default); }
.verdict-good { border-left-color: var(--success-emphasis); }
.verdict-bad { border-left-color: var(--danger-emphasis); }
.verdict-undecided { border-left-color: var(--fg-subtle); }

.meta-footer { color: var(--fg-subtle); gap: 14px; }

/* --- wall ----------------------------------------------------------------- */

.tabs { display: flex; gap: 4px; margin-top: 12px; border-bottom: 1px solid var(--border-default); }
.tab {
  padding: 6px 12px; font-size: 13px; color: var(--fg-muted);
  border: 1px solid transparent; border-bottom: none; border-radius: var(--radius) var(--radius) 0 0;
  margin-bottom: -1px;
}
.tab:hover { color: var(--fg-default); text-decoration: none; }
.tab.is-active {
  color: var(--fg-default); font-weight: 600;
  background: var(--canvas-default); border-color: var(--border-default);
  border-bottom: 1px solid var(--canvas-default);
}

.wall-item { border-left: 3px solid var(--border-default); }
.wall-good { border-left-color: var(--success-emphasis); }
.wall-bad { border-left-color: var(--danger-emphasis); }
.wall-undecided { border-left-color: var(--fg-subtle); }
.wall-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.wall-title { font-weight: 600; font-size: 15px; color: var(--fg-default); }
.wall-item .poem { font-size: 15px; line-height: 1.9; }
.wall-foot { margin-top: 10px; }

/* --- stats ---------------------------------------------------------------- */

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat { margin-bottom: 0; }
.stat .Box-body { display: flex; flex-direction: column; gap: 2px; }
.stat-num { font-size: 26px; font-weight: 600; line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--fg-muted); }
.stat-sub { color: var(--fg-subtle); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td {
  padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--border-muted);
  vertical-align: top;
}
.table th { font-size: 12px; color: var(--fg-muted); font-weight: 600; background: var(--canvas-subtle); }
.table tr:last-child td { border-bottom: none; }
.poem-cell { font-family: var(--serif); }

.kv { list-style: none; margin: 8px 0 0; padding: 0; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--border-muted); }
.kv li:last-child { border-bottom: none; }
.kv span { color: var(--fg-muted); }

/* --- prose ---------------------------------------------------------------- */

.prose .Box-body { font-size: 14px; line-height: 1.75; }
.prose h2 { margin: 26px 0 10px; font-size: 17px; }
.prose h2:first-child { margin-top: 0; }
.steps { padding-left: 20px; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }

code {
  padding: 2px 5px; font-family: var(--mono); font-size: 85%;
  background: var(--neutral-muted); border-radius: var(--radius);
}
pre.code {
  margin: 0 0 12px; padding: 12px; overflow-x: auto;
  background: var(--canvas-inset); border: 1px solid var(--border-muted); border-radius: var(--radius);
}
pre.code code { padding: 0; background: none; font-size: 12px; line-height: 1.6; }

.empty-state { text-align: center; }
.empty-state .Box-body { padding: 48px 16px; }

.note-box summary { font-weight: 500; font-size: 13px; }

/* --- footer --------------------------------------------------------------- */

.site-footer {
  margin-top: 40px; padding: 20px 0 32px;
  border-top: 1px solid var(--border-default); background: var(--canvas-subtle);
}
.footer-inner { font-size: 12px; color: var(--fg-muted); }
.footer-machine { color: var(--fg-subtle); }
.footer-machine .mono { margin-left: 8px; }

@media (max-width: 600px) {
  .hero h1 { font-size: 22px; }
  .header-inner { gap: 8px; }
  .nav { width: 100%; }
}

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