:root {
  --paper: #f6f1e8;
  --paper-shade: #ebe4d6;
  --ink: #1b2740;
  --ink-muted: #4d596f;
  --accent: #0e5c57;
  --accent-ink: #073e3b;
  --accent-soft: rgba(14, 92, 87, 0.14);
  --rule: #c9bda8;
  --error: #7a2e2a;
  --error-soft: #f3e4dc;
  --focus: #0e5c57;
  --surface: #fffdf8;
  --canvas-bg: #fff;
  --on-accent: #f6f1e8;
  --panel-fill: rgba(246, 241, 232, 0.88);
  --dot: rgba(27, 39, 64, 0.07);
  --wash-start: rgba(14, 92, 87, 0.1);
  --wash-end: rgba(201, 189, 168, 0.28);
  --max: 52rem;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

[data-theme="dark"] {
  --paper: #1a1f2e;
  --paper-shade: #242b3d;
  --ink: #e8e4dc;
  --ink-muted: #a8b0c0;
  --accent: #3db8a8;
  --accent-ink: #7ee0d8;
  --accent-soft: rgba(61, 184, 168, 0.18);
  --rule: #3d4558;
  --error: #f0a8a4;
  --error-soft: #3d2a2a;
  --focus: #3db8a8;
  --surface: #252d3f;
  --canvas-bg: #1e2433;
  --on-accent: #1a1f2e;
  --panel-fill: rgba(26, 31, 46, 0.92);
  --dot: rgba(232, 228, 220, 0.12);
  --wash-start: rgba(61, 184, 168, 0.16);
  --wash-end: rgba(61, 80, 120, 0.28);
  color-scheme: dark;
}

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

html {
  color-scheme: light dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--paper);
  border-inline-start: 0.55rem solid var(--accent);
  background-image:
    radial-gradient(ellipse 90% 55% at 0% -10%, var(--wash-start), transparent 58%),
    radial-gradient(ellipse 70% 45% at 100% 110%, var(--wash-end), transparent 55%),
    radial-gradient(circle, var(--dot) 1.1px, transparent 1.35px);
  background-size: auto, auto, 1.35rem 1.35rem;
  font-family: var(--sans);
  font-size: 1.05rem;
  line-height: 1.55;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 10;
  padding: 0.4rem 0.8rem;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

.site-header,
main {
  width: min(var(--max), calc(100% - 2.5rem));
  margin-inline: auto;
}

.site-header {
  display: flex;
  flex-direction: column;
  padding: 2.4rem 0 0.5rem;
}

.site-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0 0 1rem;
  margin-inline-start: auto;
}

.site-toolbar label {
  font-weight: 600;
  font-size: 0.92rem;
}

.site-toolbar select {
  width: auto;
  min-width: 8rem;
}

.locale-hint {
  margin: -0.55rem 0 1rem;
  max-width: 36rem;
}

.eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

h1,
h2 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
}

h1 {
  margin: 0 0 0.8rem;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
}

.lede {
  margin: 0 0 1.6rem;
  max-width: 42rem;
  color: var(--ink-muted);
}

.panel {
  margin-bottom: 1.25rem;
  padding: 1.15rem 1.2rem 1.25rem;
  border: 1px solid var(--rule);
  background: var(--panel-fill);
}

fieldset.panel {
  min-inline-size: 0;
}

legend,
summary {
  font-family: var(--serif);
  font-size: 1.05rem;
  padding-inline: 0.25rem;
}

summary {
  cursor: pointer;
}

.advanced {
  padding-top: 0.85rem;
}

.setup-steps {
  margin: 0 0 1rem;
}

.setup-steps ol {
  margin: 0.65rem 0 0;
  padding-inline-start: 1.25rem;
}

.setup-steps li {
  margin-bottom: 0.45rem;
}

.setup-steps li:last-child {
  margin-bottom: 0;
}

.setup-steps code {
  font-size: 0.88em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

[hidden] {
  display: none !important;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.field-row .field {
  flex: 1 1 14rem;
  margin-bottom: 0;
}

.field-narrow {
  flex: 0 1 10rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#ollama-fields {
  margin: 1rem 0;
}

#ollama-refresh {
  align-self: end;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
}

label {
  font-weight: 600;
}

.hint,
.file-meta,
.progress-label {
  margin: 0;
  font-size: 0.92rem;
  color: var(--ink-muted);
}

.progress-label {
  display: block;
  margin-bottom: 0.35rem;
}

input[type="password"],
input[type="text"],
input[type="number"],
input[type="url"],
input[type="file"],
select,
textarea,
button {
  font: inherit;
}

input[type="password"],
input[type="text"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  border-radius: 2px;
}

textarea {
  min-height: 4.5rem;
  resize: vertical;
}

.drop-zone {
  padding: 1.2rem 1rem;
  border: 2px dashed var(--rule);
  background: var(--paper-shade);
  text-align: center;
}

.drop-zone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-lead {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
}

.drop-or {
  margin: 0.35rem 0 0.7rem;
  color: var(--ink-muted);
}

.file-picker {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  text-align: start;
}

.file-picker-label {
  font-weight: 600;
}

.file-meta {
  margin-top: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0.2rem 0 1.4rem;
}

.downloads .actions {
  margin-bottom: 0;
}

button {
  padding: 0.5rem 0.95rem;
  border-radius: 2px;
  border: 1px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button[type="submit"],
#download-docx-btn,
#download-md-btn {
  background: var(--accent);
  border-color: var(--accent-ink);
  color: var(--on-accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

#cancel-btn {
  border-color: var(--error);
  color: var(--error);
}

.alert {
  margin: 0 0 1.25rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--error);
  background: var(--error-soft);
  color: var(--error);
}

progress {
  display: block;
  width: 100%;
  height: 0.7rem;
  margin-bottom: 1rem;
  accent-color: var(--accent);
}

.batch-list,
.error-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.batch-row,
.error-item {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) auto auto;
  gap: 0.6rem 1rem;
  align-items: center;
  padding: 0.45rem 0.15rem;
  border-bottom: 1px solid var(--rule);
  font-size: 0.95rem;
}

.batch-issues a {
  color: var(--accent-ink);
}

.batch-row:target {
  background: var(--accent-soft);
}

.issue-detail-list {
  grid-column: 1 / -1;
  margin: 0.15rem 0 0.2rem;
  padding-inline-start: 1.2rem;
}

.issue-message,
.issue-excerpt {
  margin: 0;
}

.issue-excerpt {
  margin: 0.15rem 0 0.55rem;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.latex-hint {
  margin: -0.35rem 0 0;
}

.clarify-draft-wrap h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.clarify-draft {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--rule);
  background: var(--surface);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  font-size: 0.95rem;
}

.clarify-question {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border-inline-start: 3px solid var(--accent);
  background: var(--accent-soft);
}

.clarify-actions {
  margin-bottom: 0;
}

.blank-actions {
  margin-bottom: 0;
}

.blank-pages {
  display: grid;
  gap: 1rem;
  margin: 0 0 1rem;
}

.blank-page {
  margin: 0;
  padding: 0.7rem;
  border: 1px solid var(--rule);
  background: var(--surface);
}

.blank-page figcaption {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.blank-page canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--rule);
  background: var(--canvas-bg);
}

.blank-page-fallback {
  margin: 0.6rem 0 0;
}

.batch-row[data-status="running"],
.batch-row[data-status="retrying"],
.batch-row[data-status="clarify"],
.batch-row[data-status="blank"] {
  background: var(--accent-soft);
}

.batch-row[data-status="done"] .batch-status {
  color: var(--accent-ink);
}

.batch-row[data-status="error"] .batch-status,
.error-item {
  color: var(--error);
}

.error-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.error-item p {
  margin: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-contrast: more) {
  body {
    background-image: none;
  }
}

@media (max-width: 40rem) {
  body {
    border-inline-start-width: 0.35rem;
  }

  .site-header,
  main {
    width: min(var(--max), calc(100% - 1.4rem));
  }

  .site-toolbar {
    margin-inline-start: 0;
    justify-content: flex-start;
  }

  .field-row,
  .actions,
  .batch-row,
  .error-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .file-picker {
    width: 100%;
  }

  input[type="file"] {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
