:root {
  color-scheme: light;
  --bg: #efeae1;
  --sheet: #fbf8f3;
  --ink: #1c1612;
  --muted: #5e564c;
  --line: #e0d6c8;
  --margin: #b42318;
  --stamp: #9f1239;
  --good: #166534;
  --warn: #92400e;
  --bad: #9f1239;
  --focus: #1e3a8a;
  --chip: #f3eee6;
  --shadow: 0 1px 0 rgba(28, 22, 18, 0.04), 0 18px 40px rgba(28, 22, 18, 0.06);
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Liberation Serif", "Nimbus Roman", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", "Liberation Sans", "Nimbus Sans", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12100e;
  --sheet: #1c1916;
  --ink: #f6f0e6;
  --muted: #c3b8a8;
  --line: #3a332c;
  --margin: #fb7185;
  --stamp: #fda4af;
  --good: #86efac;
  --warn: #fcd34d;
  --bad: #fda4af;
  --focus: #93c5fd;
  --chip: #26221c;
  --shadow: 0 0 0 1px rgba(246, 240, 230, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12100e;
    --sheet: #1c1916;
    --ink: #f6f0e6;
    --muted: #c3b8a8;
    --line: #3a332c;
    --margin: #fb7185;
    --stamp: #fda4af;
    --good: #86efac;
    --warn: #fcd34d;
    --bad: #fda4af;
    --focus: #93c5fd;
    --chip: #26221c;
    --shadow: 0 0 0 1px rgba(246, 240, 230, 0.04);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  min-height: 100%;
  background-color: var(--bg);
  background-image: radial-gradient(900px 420px at 0% -10%, rgba(180, 35, 24, 0.08), transparent 55%);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 12px;
  z-index: 5;
}
.skip:focus { top: 12px; }

.wrap {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--ink);
  box-shadow: 0 3px 0 var(--bg), 0 4px 0 var(--margin);
}

.kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--margin);
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

h2 {
  margin: 28px 0 12px;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
h2:first-child { margin-top: 0; }
h2 .num {
  color: var(--margin);
  font-variant-numeric: tabular-nums;
  margin-right: 0.45rem;
  font-size: 0.85em;
}

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

button, .file-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
}
button.primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
button.ghost { background: transparent; }
button:hover { border-color: var(--ink); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.file-btn { display: inline-flex; align-items: center; }
.file-btn input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--margin);
  background: var(--sheet);
  border-radius: 12px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(260px, 0.9fr);
  gap: 22px;
  align-items: start;
}
.grid > * { min-width: 0; }

.sheet, .stamp-card {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.sheet {
  padding: 22px 22px 18px;
  border-left: 4px solid var(--margin);
}

.fields { display: grid; gap: 12px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1.3fr 0.5fr 0.9fr; gap: 12px; }

.field { display: grid; gap: 4px; }
.field > span, .axis-label {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--muted);
}
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.summary { min-height: 72px; }

.axis {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 16px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.axis-hint { display: block; color: var(--muted); font-size: 0.85rem; font-weight: 400; }

.segs { display: flex; gap: 4px; }
.segs button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.segs button[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.claim {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.claim-meta {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}
.claim textarea { min-height: 64px; }

.empty {
  margin: 8px 0 0;
  color: var(--muted);
}

.flags { display: flex; flex-wrap: wrap; gap: 8px; }
.flag {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
}
.flag input { width: 1.05rem; height: 1.05rem; min-height: 0; accent-color: var(--margin); }

.actions { margin-top: 18px; }
.fine {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.stamp-card {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 18px;
}
.stamp-head {
  display: flex;
  gap: 14px;
  align-items: center;
}
.mark {
  width: 7.75rem;
  height: 7.75rem;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  row-gap: 1px;
  border: 2px solid var(--stamp);
  color: var(--stamp);
  box-shadow: inset 0 0 0 1px var(--stamp);
  outline: 1px dashed var(--stamp);
  outline-offset: -7px;
  transform: rotate(-6deg);
}
.mark[data-tone="good"] { border-color: var(--good); color: var(--good); box-shadow: inset 0 0 0 1px var(--good); outline-color: var(--good); }
.mark[data-tone="warn"] { border-color: var(--warn); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); outline-color: var(--warn); }
.mark[data-tone="bad"] { border-color: var(--bad); color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); outline-color: var(--bad); }
.mark[data-tone="muted"] { border-color: var(--muted); color: var(--muted); box-shadow: inset 0 0 0 1px var(--muted); outline-color: var(--muted); }
.mark-score {
  font-family: var(--serif);
  font-size: 2.4rem;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}
.mark-of { font-size: 0.75rem; letter-spacing: 0.08em; }

#verdict-word {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.7rem;
  line-height: 1.05;
  letter-spacing: -0.03em;
}
#verdict-word[data-tone="good"] { color: var(--good); }
#verdict-word[data-tone="warn"] { color: var(--warn); }
#verdict-word[data-tone="bad"] { color: var(--bad); }
#verdict-word[data-tone="muted"] { color: var(--muted); }
#stamp-title {
  margin: 4px 0 0;
  font-weight: 650;
  overflow-wrap: anywhere;
}
#confidence-line, #paper-link { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }
#paper-link { color: var(--focus); }

.reasons { margin: 14px 0 0; padding-left: 1.1rem; }
.reasons li { margin: 6px 0; }
.reasons li::marker { color: var(--margin); }

.rubric { margin-top: 14px; }
.rubric summary { cursor: pointer; font-weight: 650; }
.rubric p { margin: 8px 0 0; color: var(--muted); font-size: 0.92rem; }

#toast {
  width: fit-content;
  max-width: 100%;
  margin: 12px 0 0;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
}

dialog {
  width: min(560px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--sheet);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(18, 16, 14, 0.5); }
.shelf-head, .shelf-body { padding: 16px 18px; }
.shelf-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.shelf-head h2 { margin: 0; }
.shelf-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.shelf-title { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.shelf-meta { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.shelf-copy { min-width: 0; }

.noscript { width: min(680px, calc(100% - 32px)); margin: 24px auto; }

@media (max-width: 800px) {
  .grid { grid-template-columns: 1fr; }
  .stamp-card { position: static; max-height: none; order: -1; }
  .wrap { width: min(1120px, calc(100% - 24px)); padding-top: 18px; }
  .sheet { padding: 16px 14px; }
}

@media (max-width: 640px) {
  .row-2, .row-3, .claim-meta { grid-template-columns: 1fr; }
  .axis { grid-template-columns: 1fr; }
  .segs button { flex: 1; width: auto; }
  .shelf-item { grid-template-columns: 1fr 1fr; }
  .shelf-copy { grid-column: 1 / -1; }
  #verdict-word { font-size: 1.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  button:active { transform: none; }
}
