/* ============================================================
   SiftCV — Markdown → PDF
   A print-studio surface: warm paper, ink, and one accent.
   Screen chrome is light; the document sheet is white paper.
   ============================================================ */

:root {
  /* surface */
  --bg: #eceae3;          /* workspace (canvas) */
  --panel: #fbfaf7;       /* sidebar */
  --panel-2: #f3f1ea;     /* recessed fields */
  --card: #ffffff;
  --border: #e2ddd0;
  --border-strong: #cfc8b6;

  /* ink */
  --text: #26231d;
  --text-dim: #7d7669;
  --text-faint: #a89f8e;
  --ink: #1d1b17;

  /* accent — a single print red, used sparingly */
  --accent: #c0432b;
  --accent-ink: #9c3521;
  --accent-soft: rgba(192, 67, 43, 0.1);
  --doc-accent: #7d4698; /* document accent — overridden per user pick */

  --page-w: 8.5in;
  --page-h: 11in;
  --margin: 0.6in;
  --font-scale: 1;

  --radius: 10px;
  --shadow-1: 0 1px 2px rgba(29, 27, 23, 0.05), 0 4px 14px rgba(29, 27, 23, 0.06);
  --shadow-2: 0 8px 32px rgba(29, 27, 23, 0.16), 0 2px 8px rgba(29, 27, 23, 0.08);
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

html[data-page="a4"] { --page-w: 210mm; --page-h: 297mm; }
html[data-margin="narrow"] { --margin: 0.4in; }
html[data-margin="normal"] { --margin: 0.6in; }
html[data-margin="wide"]   { --margin: 0.9in; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
::selection { background: rgba(192, 67, 43, 0.18); }

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

/* ---------- Top bar ---------- */

.topbar {
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 2.5px;
  background: var(--accent);
  transform: translateY(-1px) rotate(45deg);
}
.filename {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pagecount {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border: 1px solid rgba(192, 67, 43, 0.25);
  padding: 3px 11px;
  border-radius: 99px;
  font-variant-numeric: tabular-nums;
}
.spacer { flex: 1; }

.iconlink {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-dim);
  transition: color 0.15s, background 0.15s;
}
.iconlink:hover { color: var(--ink); background: var(--panel-2); }

/* ---------- Buttons ---------- */

.btn {
  background: var(--card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font: 500 13px var(--font-ui);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--text-faint); background: var(--panel); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #f6f4ee;
}
.btn.primary:hover { background: #33302a; border-color: #33302a; }

/* ---------- Layout ---------- */

main { flex: 1; display: flex; min-height: 0; }

/* ---------- Sidebar ---------- */

.sidebar {
  flex: 0 0 282px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 22px 18px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.sidebar::-webkit-scrollbar { width: 10px; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
  border: 3px solid var(--panel);
}

.control { display: flex; flex-direction: column; gap: 9px; }
.control-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: flex;
  align-items: baseline;
}
.control-title .val {
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.control .row { display: flex; gap: 8px; }
.control .row .btn { flex: 1; padding: 8px 4px; font-size: 12.5px; }
.control.spacer { margin-top: auto; }

select {
  width: 100%;
  appearance: none;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237d7669' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 30px 8px 11px;
  font: 500 13px var(--font-ui);
  transition: border-color 0.15s;
  cursor: pointer;
}
select:hover { border-color: var(--border-strong); }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.hint {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-dim);
  margin-top: 2px;
}
.hint code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  font: 500 10.5px ui-monospace, "SF Mono", Menlo, monospace;
}

/* ---------- Canvas & sheet ---------- */

.canvas {
  flex: 1;
  position: relative;
  overflow: auto;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(29, 27, 23, 0.07) 1px, transparent 1px);
  background-size: 22px 22px;
  padding: 48px 28px 90px;
}
.sheet {
  position: relative;
  width: var(--page-w);
  min-height: var(--page-h);
  background: #fff;
  margin: 0 auto;
  box-shadow: 0 1px 0 rgba(29, 27, 23, 0.06),
              0 24px 60px -12px rgba(29, 27, 23, 0.28);
}
.doc { position: relative; padding: var(--margin); }

html[data-font="serif"] .doc {
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
}
html[data-font="sans"] .doc {
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Document typography ---------- */

.doc {
  font-size: calc(10pt * var(--font-scale));
  line-height: 1.55;
  color: #22262c;
}
.doc h1 {
  font-size: calc(25pt * var(--font-scale));
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 6pt;
}
.doc h1 + p { margin-top: 2pt; color: #4a4f57; }
.doc h2 {
  font-size: calc(10.5pt * var(--font-scale));
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--doc-accent);
  border-bottom: 1.5pt solid var(--doc-accent);
  padding-bottom: 4pt;
  margin: 16pt 0 9pt;
}
.doc p { margin: 0 0 7pt; }
.doc ul { margin: 0 0 8pt; padding-left: 14pt; }
.doc li { margin-bottom: 5pt; }
.doc hr { border: 0; border-top: 1px solid #cfd2d8; margin: 13pt 0; }
.doc a { color: var(--doc-accent); text-decoration: none; }
.doc strong { font-weight: 700; }

/* keep the printed layout clean */
.doc h1, .doc h2 { break-after: avoid; }
.doc li, .doc p { break-inside: avoid; }
.doc p { orphans: 3; widows: 3; }

/* ---------- Page guides (screen only) ---------- */

.guides { position: absolute; inset: 0; pointer-events: none; }
.guide {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 2px dashed rgba(192, 67, 43, 0.45);
}
.guide-label {
  position: absolute;
  right: 10px;
  top: -11px;
  background: var(--accent);
  color: #fff;
  font: 700 10px var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 9px;
  border-radius: 99px;
}

/* ---------- Empty state ---------- */

.doc.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: calc(var(--page-h) - 2 * var(--margin));
  color: #8b8577;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.65;
  gap: 4px;
}
.doc.empty .big {
  font-family: var(--font-display);
  font-size: 52px;
  color: var(--border-strong);
  margin-bottom: 8px;
  line-height: 1;
}
.doc.empty code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text);
}

/* ---------- Drag & drop ---------- */

.drop-hint {
  position: absolute;
  inset: 16px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: rgba(192, 67, 43, 0.05);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  pointer-events: none;
  z-index: 5;
}
.canvas.dragging .drop-hint { display: flex; }

/* ---------- Accent color picker ---------- */

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(29, 27, 23, 0.12);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected {
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink);
}
.hex-row input {
  flex: 1;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font: 500 12.5px ui-monospace, "SF Mono", Menlo, monospace;
  min-width: 0;
  transition: border-color 0.15s;
}
.hex-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hex-row input.invalid { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- First-visit onboarding toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 120px));
  background: var(--ink);
  color: #ece8dd;
  font-size: 13px;
  line-height: 1.6;
  padding: 14px 44px 14px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  z-index: 40;
  animation: toast-in 0.25s ease;
}
.toast b { color: #fff; font-weight: 600; }
.toast-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: 0;
  color: #9a9484;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.toast-close:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Help bubble (bottom-right) ---------- */

.help-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--ink);
  border: 1px solid rgba(0, 0, 0, 0.2);
  color: #f6f4ee;
  font: 600 19px var(--font-display);
  cursor: pointer;
  box-shadow: var(--shadow-2);
  z-index: 50;
  transition: transform 0.15s, background 0.15s;
}
.help-fab:hover { transform: scale(1.07); background: #33302a; }

.help-panel {
  position: fixed;
  right: 24px;
  bottom: 86px;
  width: min(440px, calc(100vw - 48px));
  max-height: min(74vh, 660px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
  z-index: 51;
  overflow: hidden;
  animation: panel-in 0.2s ease;
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.help-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.help-close {
  background: none;
  border: 0;
  color: var(--text-faint);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.help-close:hover { color: var(--ink); background: var(--panel-2); }
.help-body {
  overflow-y: auto;
  padding: 16px 20px 20px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-dim);
}
.help-body::-webkit-scrollbar { width: 10px; }
.help-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
  border: 3px solid var(--card);
}
.help-body b { color: var(--text); font-weight: 600; }
.help-body h3 {
  margin: 18px 0 8px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.help-body h3::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  transform: rotate(45deg);
  flex: 0 0 auto;
}
.help-lead { margin: 0 0 4px; font-size: 13.5px; color: var(--text); }
.help-steps { margin: 0; padding-left: 18px; }
.help-steps li { margin-bottom: 8px; }
.help-body code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 5px;
  font: 500 11.5px ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
}
.help-note { font-size: 12px; }
.help-links { margin-top: 16px; display: flex; flex-direction: column; gap: 5px; }
.help-links a { color: var(--accent-ink); font-weight: 600; text-decoration: none; }
.help-links a:hover { text-decoration: underline; }

/* prompts */
.prompt {
  margin: 10px 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}
.prompt summary {
  cursor: pointer;
  padding: 11px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  list-style-position: inside;
  border-radius: 12px;
  transition: background 0.15s;
}
.prompt summary:hover { background: var(--panel-2); }
.prompt-body { padding: 0 14px 14px; }
.prompt-body > p { margin: 8px 0; font-size: 12.5px; }
.prompt pre {
  background: var(--ink);
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  font: 400 11px/1.6 ui-monospace, "SF Mono", Menlo, monospace;
  color: #cfcaba;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
}
.prompt .copy { margin-top: 10px; padding: 6px 14px; font-size: 12px; }

/* ---------- Print (PDF export) ---------- */

@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; }
  .topbar, .sidebar, .drop-hint, .guides, .toast, .help-fab, .help-panel { display: none !important; }
  main { display: block; }
  .canvas { overflow: visible; background: #fff; background-image: none; padding: 0; }
  .sheet { width: auto; min-height: 0; margin: 0; box-shadow: none; }
  /* Per-page margins come from the @page rule (injected in app.js) so that
     page 2 gets the same top/side margins as page 1. */
  .doc { padding: 0; }
  .doc h2:first-child { margin-top: 0; }
}
