/* ============================================================================
 * Marginal - styles
 * Risograph duotone in the spirit of the sibling tools (Mergeless / School
 * Writing): flat hex tints, a hard "second-pass" offset shadow evoking
 * imperfect two-colour registration, bordered panels, no soft blur. Here the
 * palette is dialled professional: warm charcoal ink + a muted ochre second
 * pass on warm grey paper.
 * ========================================================================== */

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

/* === Palette ===
   Two-tone riso: warm charcoal ink + muted ochre second pass on greige paper.
     bg        warm grey paper, the "page"
     bg-alt    warm near-white for content panels
     ink       warm charcoal body copy
     ink-d     near-black warm, headings + emphasis
     ochre     the second-pass ink (offset shadow + accents)
     ochre-d   deeper ochre for hover/active
     muted     softened warm grey for secondary text
     line      ink-tinted border
     ok / warn / error: kept warm so they sit in the palette */
:root {
  --bg: #e6e1d8;
  --bg-alt: #f6f3ec;
  --ink: #36322c;
  --ink-d: #1f1c17;
  --ochre: #d9a441;
  --ochre-d: #b5822b;
  --ochre-soft: #f4e7c7;
  --muted: #6b655b;
  --line: #cbc4b6;
  --ok: #5c7a45;
  --warn: #a4691f;
  --error: #a8442f;

  /* Riso "second pass": a flat ochre rectangle offset down/right behind the
     element, as if the second colour mis-registered on the press. */
  --riso-offset: 5px 5px 0 var(--ochre);
  --riso-offset-sm: 3px 3px 0 var(--ochre);
  --radius: 7px;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 840px;
  margin: 0 auto;
  padding: 40px 22px 72px;
}

/* === Header === */
header { text-align: center; margin-bottom: 16px; }

h1 {
  font-size: 2.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ink-d);
  /* Second pass: ochre registered slightly off behind the charcoal. */
  text-shadow: 3px 3px 0 var(--ochre);
}

.subtitle {
  margin-top: 12px;
  color: var(--ink);
  font-style: italic;
  font-size: 1.05rem;
}

.header-note { margin-top: 8px; font-size: 0.8rem; }

.donate-link {
  color: var(--ochre-d);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.donate-link:hover { color: var(--ink-d); }

.lede {
  max-width: 620px;
  margin: 22px auto 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.98rem;
}

/* === Dropzone === */
.dropzone {
  position: relative;
  background: var(--bg-alt);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--riso-offset);
  transition: border-color 0.12s, background 0.12s, transform 0.06s;
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--ink);
  outline: none;
}
.dropzone.dragging {
  border-color: var(--ochre-d);
  background: var(--ochre-soft);
}
.dropzone.has-file {
  padding: 22px 24px;
  border-style: solid;
  border-color: var(--ink);
}

.dz-icon { color: var(--ochre-d); margin-bottom: 8px; }
.dz-title { font-size: 1.15rem; font-weight: 700; color: var(--ink-d); }
.dz-link { color: var(--ochre-d); text-decoration: underline; }
.dz-sub { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.dropzone.has-file .dz-prompt { display: none; }
.file-name {
  display: none;
  font-weight: 700;
  color: var(--ink-d);
  word-break: break-all;
}
.dropzone.has-file .file-name { display: block; }
.dropzone.has-file .file-name::before { content: "\1F4C4  "; }

/* === Controls === */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px 24px;
  margin-top: 24px;
  padding: 18px 22px;
  background: var(--bg-alt);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--riso-offset);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 320px;
}
.control-group label { font-weight: 700; white-space: nowrap; color: var(--ink-d); }

input[type="range"] {
  flex: 1;
  accent-color: var(--ochre-d);
  min-width: 120px;
}

.margin-value {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--ink-d);
  background: var(--ochre-soft);
  border: 1.5px solid var(--ochre);
  border-radius: 5px;
  padding: 2px 9px;
  min-width: 54px;
  text-align: center;
}
.control-hint { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }

.control-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 5px;
  border: 2px solid var(--ink-d);
  transition: transform 0.06s, box-shadow 0.06s, background 0.12s;
}

.btn-primary {
  background: var(--ochre);
  color: var(--ink-d);
  font-weight: 800;
  padding: 10px 20px;
  box-shadow: var(--riso-offset-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--ochre-d); color: var(--bg-alt); }
.btn-primary:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.btn-ghost {
  background: var(--bg-alt);
  color: var(--ink);
  font-weight: 700;
  padding: 9px 14px;
  box-shadow: var(--riso-offset-sm);
}
.btn-ghost:hover { background: #ece7dd; }
.btn-ghost:active { transform: translate(3px, 3px); box-shadow: none; }

/* === Status / warning === */
.status {
  margin-top: 18px;
  min-height: 1.4em;
  font-size: 0.95rem;
  text-align: center;
  color: var(--muted);
}
.status-busy { color: var(--ochre-d); font-weight: 600; }
.status-busy::before {
  content: "";
  display: inline-block;
  width: 13px; height: 13px;
  margin-right: 8px;
  vertical-align: -1px;
  border: 2px solid var(--ochre-soft);
  border-top-color: var(--ochre-d);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.status-ok { color: var(--ok); font-weight: 700; }
.status-error { color: var(--error); font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }

.warning {
  margin: 14px auto 0;
  max-width: 680px;
  background: var(--ochre-soft);
  border: 1.5px solid var(--ochre);
  border-left: 5px solid var(--ochre-d);
  color: #6e511c;
  padding: 12px 16px;
  border-radius: 5px;
  font-size: 0.9rem;
}

/* === Preview === */
.preview-wrap { margin-top: 30px; }
.preview-label {
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 10px;
  text-align: center;
}
.preview-frame {
  width: 100%;
  height: 78vh;
  min-height: 480px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: #4a463f;
  box-shadow: var(--riso-offset);
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(31, 28, 23, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal-inner {
  position: relative;
  background: var(--bg-alt);
  max-width: 620px;
  width: 100%;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 28px 30px 30px;
  box-shadow: var(--riso-offset);
}
.modal-close {
  position: absolute;
  top: 10px; right: 12px;
  background: transparent;
  border: none;
  font-size: 1.7rem;
  line-height: 1;
  color: var(--muted);
  padding: 4px 8px;
}
.modal-close:hover { color: var(--ink-d); }
.modal-inner h2 { margin-bottom: 12px; color: var(--ink-d); }
.modal-inner h3 { margin: 18px 0 6px; color: var(--ochre-d); font-size: 1.02rem; }
.modal-inner p { font-size: 0.92rem; margin-bottom: 8px; color: var(--ink); }
.modal-inner ul { margin: 0 0 8px 1.3em; }
.modal-inner li { font-size: 0.92rem; margin-bottom: 5px; }
.modal-inner a { color: var(--ochre-d); }

.hidden { display: none !important; }

/* === Responsive === */
@media (max-width: 620px) {
  h1 { font-size: 2.1rem; }
  .controls { flex-direction: column; align-items: stretch; }
  .control-actions { margin-left: 0; justify-content: center; }
  .control-group { flex-wrap: wrap; }
  .preview-frame { height: 70vh; }
}
