/* IBM Plex Mono — self-hosted */
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/static/fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/static/fonts/IBMPlexMono-SemiBold.woff2") format("woff2");
  font-weight: 600; font-style: normal;
}

/* ── design tokens ───────────────────────────────────────────────────────── */
:root {
  --ink:       #1a1a1a;
  --muted:     #6b6b6b;
  --faint:     #a8a8a8;
  --rule:      #e3e3e3;
  --paper:     #ffffff;
  --tint:      #f6f5f1;
  --mistake:   #cc4444;
  --ambiguous: #e0a000;
  --correct:   #4a8a3f;
}

/* ── reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ink); }
a:hover { color: var(--muted); }
button {
  font-family: inherit; font-size: 14px;
  background: var(--ink); color: var(--paper);
  border: none; padding: 12px 18px; cursor: pointer;
  text-align: left; width: 100%;
}
button.secondary {
  background: var(--paper); color: var(--ink); border: 1px solid var(--ink);
}
button:hover { opacity: 0.85; }

/* ── header ──────────────────────────────────────────────────────────────── */
header.site {
  border-bottom: 1px solid var(--rule);
  padding: 22px 40px;
  display: flex; align-items: baseline; justify-content: space-between;
}
.brand { display: flex; align-items: baseline; gap: 22px; }
.wordmark { font-size: 18px; font-weight: 600; text-decoration: none; color: var(--ink); }
.topnav { display: flex; gap: 18px; font-size: 13px; }
.topnav a { text-decoration: none; color: var(--muted); }
.topnav a.active { color: var(--ink); font-weight: 600; }
.endnav { font-size: 13px; color: var(--muted); }
.endnav a { text-decoration: none; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { text-decoration: none; }

/* ── footer ──────────────────────────────────────────────────────────────── */
footer.site {
  border-top: 1px solid var(--rule);
  padding: 24px 40px;
  font-size: 12px; color: var(--muted);
  display: flex; gap: 24px; flex-wrap: wrap;
}
footer.site a { text-decoration: none; }
footer.site .right { margin-left: auto; display: flex; gap: 18px; }

/* ── library page ────────────────────────────────────────────────────────── */
.lib-main {
  max-width: 880px; margin: 0 auto; padding: 56px 40px 96px;
}
.intro { margin: 0 0 36px; color: var(--muted); font-size: 14px; }

.filters {
  display: flex; gap: 8px; margin: 0 0 28px;
  padding-bottom: 24px; border-bottom: 1px solid var(--rule);
  align-items: center;
}
.filters .label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--faint); margin-right: 8px;
}
.pill {
  font-family: inherit; font-size: 12px;
  background: var(--paper); color: var(--muted);
  border: 1px solid var(--rule); padding: 6px 14px;
  cursor: pointer; border-radius: 999px;
}
.pill:hover { color: var(--ink); border-color: var(--muted); }
.pill.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.count { margin-left: auto; font-size: 12px; color: var(--faint); }

.view { display: none; }
.view.active { display: block; }

/* puzzle rows */
ol.puzzles { list-style: none; margin: 0; padding: 0; }
ol.puzzles li { border-bottom: 1px solid var(--rule); }
ol.puzzles li:first-child { border-top: 1px solid var(--rule); }
.row {
  display: grid;
  grid-template-columns: 1fr auto auto auto 16px;
  gap: 18px; padding: 16px 4px; align-items: baseline;
  text-decoration: none; color: var(--ink);
}
.row:hover { background: var(--tint); }
.row .title {
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .by   { font-size: 12px; color: var(--muted); }
.row .type {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
  padding: 3px 8px; border: 1px solid var(--rule); border-radius: 2px;
}
.row .date { font-size: 12px; color: var(--faint); white-space: nowrap; }
.row .arrow { font-size: 14px; color: var(--faint); text-align: right; }
.row:hover .arrow { color: var(--ink); }

.row.directory { color: var(--muted); }
.row.directory .title { font-weight: 400; }
.row.directory .arrow::before { content: "→"; }
.row.directory .external {
  font-size: 11px; color: var(--muted);
  border-bottom: 1px dotted var(--muted); text-decoration: none;
}

/* constructor sections */
.constructor-section { margin-bottom: 56px; }
.constructor-head {
  padding-bottom: 14px; margin-bottom: 0; border-bottom: 1px solid var(--ink);
}
.constructor-head h2 {
  font-size: 17px; font-weight: 600; margin: 0 0 6px;
  letter-spacing: -0.01em; scroll-margin-top: 32px;
}
.constructor-head .bio { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.constructor-head .links { font-size: 12px; color: var(--muted); display: flex; gap: 14px; }
.constructor-head .links a {
  color: var(--muted); text-decoration: none;
  border-bottom: 1px dotted var(--muted);
}
.constructor-head.directory h2::after {
  content: "external"; font-size: 10px; font-weight: 400;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--faint); margin-left: 10px; padding: 2px 6px;
  border: 1px solid var(--rule); border-radius: 2px; vertical-align: middle;
}

/* type sections */
.type-section { margin-bottom: 48px; }
.type-head {
  font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted);
  margin: 0 0 14px; font-weight: 600;
}

/* ── puzzle detail ───────────────────────────────────────────────────────── */
.detail-main { max-width: 1080px; margin: 0 auto; padding: 56px 40px 96px; }
.detail {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
  gap: 64px; align-items: start;
}

.preview-wrap { position: relative; }
.preview {
  aspect-ratio: 8.5 / 11;
  background: #fafafa; border: 1px solid var(--rule);
  position: relative; overflow: hidden; transition: border-color 0.15s;
}
.preview img, .preview svg { width: 100%; height: 100%; display: block; object-fit: contain; }
.preview.drag { border-color: var(--ink); border-style: dashed; }
.drop-hint {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(255,255,255,0.92); font-size: 14px; pointer-events: none;
}
.preview.drag .drop-hint { display: flex; }
.preview-meta {
  font-size: 12px; color: var(--muted); margin-top: 10px;
  display: flex; justify-content: space-between;
}

aside.actions { position: sticky; top: 32px; }
.meta h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.meta .byline { margin: 0; color: var(--muted); font-size: 13px; }
.meta .tags {
  margin: 14px 0 0; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.08em;
}

.step { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--rule); }
.step h2 {
  font-size: 13px; font-weight: 600; margin: 0 0 14px;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
}
.step h2 .num { color: var(--ink); margin-right: 8px; }
.step p.lede { margin: 0 0 14px; font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.file-row { display: flex; gap: 8px; align-items: stretch; }
.file-row input[type=file] {
  flex: 1; font-family: inherit; font-size: 12px; padding: 10px;
  border: 1px solid var(--rule); background: var(--paper); min-width: 0;
}
.file-row button { width: auto; padding: 10px 16px; flex-shrink: 0; }

/* Grade button tooltip — pure CSS */
.tip-wrap { position: relative; display: inline-block; flex-shrink: 0; }
.tip {
  position: absolute; bottom: calc(100% + 10px); right: 0;
  width: 240px; background: var(--ink); color: var(--paper);
  padding: 10px 12px; font-size: 11px; line-height: 1.45;
  opacity: 0; pointer-events: none;
  transform: translateY(4px); transition: opacity 0.15s, transform 0.15s; z-index: 10;
}
.tip::after {
  content: ""; position: absolute; top: 100%; right: 18px;
  border: 5px solid transparent; border-top-color: var(--ink);
}
.tip-wrap:hover .tip, .tip-wrap:focus-within .tip { opacity: 1; transform: translateY(0); }

/* verdict block */
.verdict {
  margin-top: 36px; padding: 24px;
  background: var(--tint); border-left: 4px solid var(--ambiguous);
}
.verdict.ok  { border-color: var(--correct); }
.verdict.bad { border-color: var(--mistake); }
.verdict h2  { font-size: 16px; font-weight: 600; margin: 0 0 8px; letter-spacing: -0.01em; }
.verdict p   { margin: 0; font-size: 13px; color: var(--muted); }
.verdict .counts {
  margin-top: 14px; display: grid;
  grid-template-columns: 1fr 1fr; gap: 8px 16px; font-size: 12px;
}
.verdict .counts dt { color: var(--muted); }
.verdict .counts dd { margin: 0; font-weight: 600; }
.legend { margin-top: 14px; display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.swatch {
  display: inline-block; width: 10px; height: 10px;
  margin-right: 4px; vertical-align: middle;
}
.swatch.mistake   { background: var(--mistake);   opacity: 0.55; }
.swatch.ambiguous { background: var(--ambiguous);  opacity: 0.55; }

details.diag { margin-top: 14px; font-size: 12px; color: var(--muted); }
details.diag summary {
  cursor: pointer; list-style: none; color: var(--muted);
  text-decoration: underline; text-decoration-style: dotted;
  text-underline-offset: 3px;
}
details.diag summary::-webkit-details-marker { display: none; }
details.diag .cells {
  margin-top: 8px; padding: 10px 12px;
  background: var(--paper); border: 1px solid var(--rule); line-height: 1.7;
}
details.diag code { font-family: inherit; font-weight: 600; color: var(--ink); }

.outputs { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--rule); display: grid; gap: 10px; }
.outputs a {
  font-size: 12px; text-decoration: none;
  border: 1px solid var(--rule); padding: 10px 12px;
  display: flex; justify-content: space-between;
}
.outputs a:hover { border-color: var(--ink); }
.regrade { margin-top: 14px; font-size: 12px; color: var(--muted); }
.regrade a { color: var(--muted); }

/* ── my puzzles ──────────────────────────────────────────────────────────── */
:root { --warn: #cc4444; }

.my-main { max-width: 880px; margin: 0 auto; padding: 56px 40px 96px; }
.my-empty { max-width: 720px; margin: 0 auto; padding: 64px 40px 96px; }

.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 8px; gap: 24px;
}
.page-head h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.015em; margin: 0; }
.sub { margin: 0 0 36px; color: var(--muted); font-size: 13px; }

.add-btn {
  font-family: inherit; font-size: 13px;
  background: var(--ink); color: var(--paper);
  border: none; padding: 10px 16px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  position: relative; text-decoration: none; white-space: nowrap;
}
.add-btn:hover { opacity: 0.85; color: var(--paper); }
.add-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* delete affordance on rows */
ol.puzzles li { position: relative; }
.del {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  background: none; border: none; color: var(--faint); cursor: pointer;
  font-family: inherit; font-size: 16px; line-height: 1; padding: 6px 4px;
  opacity: 0; transition: opacity 0.1s, color 0.1s; z-index: 1; width: auto;
}
ol.puzzles li:hover .del { opacity: 1; }
.del:hover { color: var(--warn); }
ol.puzzles li:hover .row .arrow { opacity: 0; }
@media (max-width: 700px) { .del { right: 0; opacity: 0.4; } }

/* dropzone */
.dropzone {
  border: 1.5px dashed var(--muted); padding: 56px 24px; text-align: center;
  background: var(--paper); transition: background 0.12s, border-color 0.12s;
  cursor: pointer; position: relative; display: block;
}
.dropzone:hover, .dropzone.drag { background: var(--tint); }
.dropzone.drag { border-color: var(--ink); border-style: solid; }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone .big { font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.dropzone .small { font-size: 12px; color: var(--muted); margin: 0; }
.dropzone .formats { margin-top: 18px; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.1em; }

.explainer { margin: 0 0 40px; color: var(--muted); font-size: 14px; max-width: 60ch; }
.explainer p { margin: 0 0 12px; }
.explainer p:last-child { margin: 0; }
.explainer strong { color: var(--ink); font-weight: 600; }

.sources { margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--rule); }
.sources h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 14px; }
.sources p { margin: 0 0 10px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.sources a { color: var(--muted); text-decoration: none; border-bottom: 1px dotted var(--muted); }
.sources a:hover { color: var(--ink); border-color: var(--ink); }

/* manage section */
.manage { margin-top: 56px; padding-top: 32px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--muted); }
.manage summary { cursor: pointer; list-style: none; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.manage summary::-webkit-details-marker { display: none; }
.manage summary::after { content: ' +'; color: var(--faint); }
.manage[open] summary::after { content: ' \2212'; }
.manage .body { margin-top: 18px; display: grid; gap: 14px; }
.manage .stat { font-size: 12px; color: var(--muted); padding: 12px 14px; background: var(--tint); }
.manage .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.manage .actions button { font-family: inherit; font-size: 12px; background: var(--paper); color: var(--ink); border: 1px solid var(--ink); padding: 8px 14px; cursor: pointer; width: auto; }
.manage .actions button.warn { border-color: var(--warn); color: var(--warn); }
.manage .actions button:hover { opacity: 0.8; }
.manage .note { font-size: 12px; color: var(--faint); line-height: 1.55; }

/* ── about / privacy ─────────────────────────────────────────────────────── */
.prose-main { max-width: 640px; margin: 0 auto; padding: 56px 40px 96px; }
.prose-main h1 { font-size: 20px; font-weight: 600; margin: 0 0 32px; }
.prose-main h2 { font-size: 14px; font-weight: 600; margin: 28px 0 8px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.prose-main p  { margin: 0 0 16px; font-size: 14px; color: var(--muted); }
.prose-main ul { margin: 0 0 16px; padding: 0 0 0 1.2em; font-size: 14px; color: var(--muted); }

/* ── responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .detail { grid-template-columns: 1fr; gap: 36px; }
  aside.actions { position: static; }
  .detail-main { padding: 32px 24px 64px; }
}
@media (max-width: 700px) {
  .lib-main { padding: 32px 24px 64px; }
  header.site, footer.site { padding: 18px 24px; }
  .row { grid-template-columns: 1fr auto; gap: 6px; padding: 14px 4px; }
  .row .by, .row .type, .row .arrow { display: none; }
  .row .title { white-space: normal; }
  .row::after {
    content: attr(data-by) " · " attr(data-type);
    font-size: 11px; color: var(--muted); grid-column: 1 / -1;
  }
}
