/* ─────────────────────────────────────────────────────────────
   Contract — ink & paper. Warm charcoal chrome, cream type,
   one ochre accent, and the document as the only bright thing.
   ───────────────────────────────────────────────────────────── */

@font-face { font-family: "Instrument Serif"; src: url("fonts/InstrumentSerif-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Instrument Serif"; src: url("fonts/InstrumentSerif-Italic.ttf") format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }

@font-face { font-family: "GreatVibes"; src: url("fonts/GreatVibes-Regular.ttf") format("truetype"); font-display: block; }

:root {
  --ink:      #12110f;
  --ink-2:    #191714;
  --ink-3:    #221f1b;
  --line:     rgba(244, 239, 230, .10);
  --line-2:   rgba(244, 239, 230, .18);
  --cream:    #f4efe6;
  --cream-2:  #cfc7ba;
  --dim:      #8d867a;
  --ochre:    #d99a2b;
  --ochre-2:  #f0b449;
  --danger:   #d9663f;
  --rail-w:   304px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, "Cascadia Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
}

* { box-sizing: border-box; }

/* class selectors below set display:flex/grid, which would out-specify the
   UA rule for [hidden] — this keeps `hidden` authoritative. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* film grain over everything — barely there, but it kills the flatness */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 999;
  pointer-events: none;
  opacity: .022;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

.mono { font-family: var(--mono); font-size: 11px; letter-spacing: .02em; }
.dim  { color: var(--dim); }

.label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 10px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.wordmark {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: 58px;
  line-height: .9;
  letter-spacing: -.015em;
  margin: 0;
}
.wordmark.sm { font-size: 25px; }
.wordmark::after {
  content: "";
  display: block;
  width: 1.4em;
  height: 1px;
  margin-top: .3em;
  background: linear-gradient(90deg, var(--ochre), transparent);
}

/* ── landing ────────────────────────────────────────────────── */

#landing {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 24px;
  overflow-y: auto;
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(217,154,43,.10), transparent 60%),
    radial-gradient(80% 60% at 50% 120%, rgba(217,154,43,.05), transparent 70%);
}

.landing-inner {
  width: 100%;
  max-width: 470px;
  animation: rise .7s cubic-bezier(.2,.8,.2,1) both;
}

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.tagline {
  font-family: var(--sans);
  font-size: 16.5px;
  letter-spacing: -.005em;
  color: var(--cream-2);
  margin: 18px 0 34px;
}

#dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 42px 28px 36px;
  border: 1px dashed var(--line-2);
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(244,239,230,.035), rgba(244,239,230,.012));
  cursor: pointer;
  text-align: center;
  transition: border-color .18s, background .18s, transform .18s;
}
#dropzone:hover, #dropzone:focus-visible {
  border-color: rgba(217,154,43,.55);
  background: linear-gradient(180deg, rgba(217,154,43,.07), rgba(244,239,230,.015));
  outline: none;
}
#dropzone.over {
  border-color: var(--ochre);
  border-style: solid;
  background: rgba(217,154,43,.10);
  transform: scale(1.008);
}
.dz-icon { width: 62px; height: 52px; color: var(--ochre); opacity: .9; margin-bottom: 4px; }
.dz-main { font-size: 15.5px; letter-spacing: -.005em; }
.dz-main em { font-style: normal; color: var(--dim); }
.dz-sub { font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); }

.promises {
  list-style: none;
  margin: 34px 0 0;
  padding: 0;
  display: grid;
  gap: 11px;
}
.promises li {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--dim);
  padding-left: 15px;
  position: relative;
}
.promises li::before {
  content: "";
  position: absolute;
  left: 0; top: .62em;
  width: 5px; height: 1px;
  background: var(--ochre);
}
.promises b { color: var(--cream-2); font-weight: 500; }

/* ── editor shell ───────────────────────────────────────────── */

#editor {
  display: flex;
  height: 100%;
}

#rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  display: flex;
  flex-direction: column;
  background: var(--ink-2);
  border-right: 1px solid var(--line);
  z-index: 5;
}

.rail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 18px 14px;
}

.filebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.16);
}
.file-name {
  font-size: 12.5px;
  color: var(--cream-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 18px;
}

.panel {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}
.panel:last-child { border-bottom: none; }

.field {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 2px;
  color: var(--cream);
  font-family: var(--sans);
  font-size: 14px;
  padding: 9px 11px;
  transition: border-color .15s;
}
.field:focus { outline: none; border-color: var(--ochre); }
.field::placeholder { color: #6f695f; }
.select { appearance: none; cursor: pointer; margin-top: 8px; font-family: var(--mono); font-size: 12px; }

/* live preview of the typed signature */
.sig-preview {
  display: flex;
  align-items: center;
  min-height: 62px;
  margin-top: 8px;
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(0,0,0,.18);
  color: var(--ochre-2);
  font-family: "GreatVibes", cursive;
  font-size: 34px;
  line-height: 1.3;
  overflow: hidden;
  white-space: nowrap;
}
.sig-preview.empty {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
}

/* tool buttons */
.tools { display: grid; gap: 6px; }
.tool {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--cream);
  font-family: var(--sans);
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.tool:hover { border-color: rgba(217,154,43,.5); background: #29251f; }
.tool:active { transform: translateY(1px); }
.tool .k {
  display: grid;
  place-items: center;
  width: 19px; height: 19px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
}

.row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.num { min-width: 26px; text-align: right; color: var(--cream-2); }

.slider {
  flex: 1;
  appearance: none;
  height: 1px;
  background: var(--line-2);
  border-radius: 2px;
}
.slider::-webkit-slider-thumb {
  appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--ochre);
  cursor: pointer;
  border: none;
}
.slider::-moz-range-thumb {
  width: 13px; height: 13px; border: none; border-radius: 50%;
  background: var(--ochre); cursor: pointer;
}

.hint {
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--dim);
  margin: 12px 0 0;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  color: var(--cream-2);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 6px 10px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.ghost-btn:hover { border-color: var(--cream-2); color: var(--cream); }
.ghost-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: rgba(217,102,63,.07); }
.ghost-btn.full { width: 100%; margin-top: 14px; padding: 9px; }

.rail-foot { padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  padding: 13px 16px;
  background: var(--ochre);
  color: #17140e;
  border: none;
  border-radius: 2px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.005em;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.primary-btn:hover { background: var(--ochre-2); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn svg { width: 15px; height: 15px; }

/* ── document stage ─────────────────────────────────────────── */

#stage {
  flex: 1;
  overflow: auto;
  padding: 34px 0 90px;
  background:
    radial-gradient(90% 55% at 50% 0%, rgba(217,154,43,.045), transparent 65%),
    var(--ink);
  overscroll-behavior: contain;
}

#pages { display: flex; flex-direction: column; align-items: center; gap: 26px; }

.page-wrap {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.14), 0 18px 44px -14px rgba(0,0,0,.75);
  animation: pageIn .45s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes pageIn { from { opacity: 0; transform: translateY(10px); } }

.page-wrap canvas { display: block; }

.page-no {
  position: absolute;
  top: 50%;
  left: -34px;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 10px;
  color: #5d574d;
  user-select: none;
}

.overlay { position: absolute; inset: 0; }

/* placed elements */
.el {
  position: absolute;
  cursor: grab;
  touch-action: none;
  outline: 1px solid transparent;
  transition: outline-color .12s;
}
.el:hover { outline-color: rgba(217,154,43,.45); }
.el.sel { outline: 1px solid var(--ochre); cursor: grabbing; }
.el svg { display: block; overflow: visible; pointer-events: none; }
.el text { fill: #14213d; }

/* Handles: round chips for the two actions, a small square for resize — three
   different silhouettes read faster than three identical circles. The white ring
   keeps them legible over any document content, light or dark. */
.el .grip {
  position: absolute;
  display: none;
  place-items: center;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--ochre);
  color: #17140e;
  box-shadow: 0 0 0 1.5px rgba(255,255,255,.92), 0 1px 4px rgba(0,0,0,.35);
  cursor: pointer;
  touch-action: none;
  transition: background .13s, transform .13s, box-shadow .13s;
}
.el.sel .grip { display: grid; }
.el .grip:hover { transform: scale(1.14); }
.el .grip:active { transform: scale(1.02); }

/* icons are SVG, not text glyphs — a "×" character sits off-centre in its em box */
.el .grip svg {
  width: 11px;
  height: 11px;
  display: block;
  pointer-events: none;
}

.el .g-rotate,
.el .g-del {
  width: 17px;
  height: 17px;
  border-radius: 50%;
}

.el .g-rotate { left: -8.5px;  top: -8.5px; cursor: grab; }
.el .g-rotate:active { cursor: grabbing; }

.el .g-del {
  right: -8.5px; top: -8.5px;
  background: var(--ink-3);
  color: var(--cream);
}
.el .g-del:hover { background: var(--danger); color: #fff; }

.el .g-resize {
  right: -5.5px; bottom: -5.5px;
  width: 11px; height: 11px;
  border-radius: 2px;
  cursor: nwse-resize;
}

/* live angle readout while rotating */
.el .angle {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 9px);
  transform: translateX(-50%);
  display: none;
  padding: 2px 6px;
  border-radius: 2px;
  background: var(--ink-3);
  border: 1px solid var(--line-2);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--cream-2);
  white-space: nowrap;
  pointer-events: none;
}
.el.rotating .angle { display: block; }

/* ── overlays: toast + busy ─────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  z-index: 1000;
  max-width: min(440px, 88vw);
  padding: 11px 16px;
  background: var(--ink-3);
  border: 1px solid var(--line-2);
  border-left: 2px solid var(--ochre);
  border-radius: 2px;
  font-size: 13px;
  color: var(--cream);
  box-shadow: 0 16px 40px -12px rgba(0,0,0,.8);
  animation: rise .28s cubic-bezier(.2,.8,.2,1) both;
}
.toast.bad { border-left-color: var(--danger); }

.busy {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: rgba(18,17,15,.72);
  backdrop-filter: blur(3px);
  color: var(--dim);
}
.spinner {
  width: 26px; height: 26px;
  border: 1.5px solid var(--line-2);
  border-top-color: var(--ochre);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── narrow screens: rail becomes a bottom sheet ────────────── */

@media (max-width: 820px) {
  #editor { flex-direction: column-reverse; }
  #rail {
    width: 100%;
    flex: 0 0 auto;
    max-height: 54vh;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  .rail-head { padding: 12px 16px 8px; }
  .wordmark.sm { font-size: 20px; }
  .wordmark.sm::after { display: none; }
  #stage { padding: 16px 0 30px; }
  .page-no { display: none; }
  .tools { grid-template-columns: repeat(3, 1fr); }
  .tool { justify-content: center; }
  .tool .k { display: none; }
  .wordmark { font-size: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
