:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #2a2622;
  --muted: #6f675e;
  --line: #e2dbd0;
  --accent: #7a1f2b;
  --accent-ink: #ffffff;
  --accent-soft: #f3e4e6;
  --ok: #2f6b3f;
  --warn: #9a6a00;
  --danger: #a4262c;
  --radius: 8px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1a18; --panel: #262320; --ink: #ece6dd; --muted: #a39a8e; --line: #3a352f;
    --accent: #d98a94; --accent-ink: #1c1a18; --accent-soft: #3a2a2d;
    --ok: #7fc08f; --warn: #e0b04a; --danger: #ee8b90;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
h1 { font-size: 1.7rem; margin: 0 0 .75rem; }
a { color: var(--accent); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 4rem; }
.narrow { max-width: 420px; }

nav.top { background: var(--panel); border-bottom: 1px solid var(--line); }
nav.top .inner { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
nav.top .brand { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; color: var(--accent); text-decoration: none; padding: .7rem 0; margin-right: .5rem; }
nav.top a.link, nav.top button.link { color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; padding: .7rem .1rem; border-bottom: 2px solid transparent; }
nav.top a.link[aria-current="page"] { border-bottom-color: var(--accent); font-weight: 600; }
nav.top .spacer { flex: 1; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.row-flex { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { margin-left: auto; }

label { display: block; font-size: .85rem; font-weight: 600; margin: .75rem 0 .2rem; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--ink); font: inherit;
}
textarea { min-height: 220px; font-family: var(--serif); font-size: 1.05rem; line-height: 1.5; resize: vertical; }
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; min-height: 120px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .btn {
  display: inline-block; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.icon { padding: .15rem .45rem; min-width: 1.9rem; line-height: 1.3; }
button:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:hover td { background: var(--accent-soft); }

.pill { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .75rem; border: 1px solid var(--line); margin: 0 .2rem .2rem 0; }
.pill.draft { color: var(--warn); border-color: var(--warn); }
.pill.proofed { color: var(--accent); border-color: var(--accent); }
.pill.final { color: var(--ok); border-color: var(--ok); }
.pill.season { background: var(--accent-soft); }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: .6rem 1rem; border-radius: 8px; max-width: 90vw; z-index: 50; display: none; }
#toast.error { background: var(--danger); color: #fff; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); max-width: 520px; width: calc(100% - 32px); padding: 1.2rem; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog menu { display: flex; gap: .5rem; justify-content: flex-end; padding: 0; margin: 1rem 0 0; }

/* outline tree */
ul.tree { list-style: none; margin: 0; padding-left: 1.4rem; }
ul.tree.root { padding-left: 0; }
.node > .row { display: flex; align-items: center; gap: .3rem; padding: .25rem .4rem; border: 1px solid transparent; border-radius: 6px; }
.node > .row:hover { background: var(--accent-soft); }
.node .title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; }
.node .count { font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0 .45rem; }
.node .actions { margin-left: auto; display: flex; gap: .15rem; flex-wrap: wrap; justify-content: flex-end; }
.node .row.drop-before { border-top: 2px solid var(--accent); }
.node .row.drop-after { border-bottom: 2px solid var(--accent); }
.node .row.drop-inside { background: var(--accent-soft); border-color: var(--accent); }
.node.dragging { opacity: .4; }
ul.entries { list-style: none; margin: 0 0 .3rem; padding-left: 2.4rem; }
ul.entries li { display: flex; align-items: center; gap: .3rem; padding: .1rem .4rem; font-size: .95rem; }
ul.entries li .actions { margin-left: auto; }

/* OCR / editor */
.preview-box { border: 1px dashed var(--line); border-radius: var(--radius); min-height: 220px; display: grid; place-items: center; overflow: auto; max-height: 70vh; background: var(--panel); }
.preview-box img, .preview-box canvas { max-width: 100%; height: auto; display: block; }
.strip { display: flex; gap: .5rem; overflow-x: auto; padding: .5rem 0 .2rem; margin-top: .4rem; }
.strip button { position: relative; padding: 2px; line-height: 0; border: 2px solid var(--line); border-radius: 6px; flex: none; }
.strip button[aria-current="true"] { border-color: var(--accent); }
.strip img { height: 72px; display: block; border-radius: 3px; }
.strip .n { position: absolute; left: 3px; top: 3px; background: var(--ink); color: var(--bg); font: 600 12px/1 var(--sans); padding: 2px 5px; border-radius: 4px; }
.stage { position: relative; max-width: 100%; line-height: 0; overflow: hidden; }
.stage.cropping canvas { cursor: crosshair; touch-action: none; }
#sel { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45); pointer-events: none; }
progress { width: 100%; height: .7rem; }
.checks { display: flex; flex-wrap: wrap; gap: .25rem .9rem; }
.checks label { font-weight: 400; font-size: .95rem; margin: 0; display: inline-flex; gap: .3rem; align-items: center; }
.scroll { max-height: 190px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: .4rem .6rem; background: var(--panel); }
pre.out { white-space: pre-wrap; word-break: break-word; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; max-height: 60vh; overflow: auto; font-size: .85rem; }
.err { color: var(--danger); }
