/* ============================================================
   Stripify
   Two flat inks on paper, hard offset registration.
   A ruler to set the limit, a shared limit line down the results.
   ============================================================ */

:root {
  --paper:    #e6e8ec;
  --card:     #fbfbfa;
  --ink:      #111621;
  --ink-soft: #596173;
  --line:     #c6cbd5;
  --wash:     #d8dce4;
  --blue:     #2440c8;
  --blue-2:   #1b31a0;
  --red:      #d32a3e;
  --on-blue:  #ffffff;
  --slab:     #111621;

  --dial-bg:    var(--blue);
  --dial-fg:    #ffffff;
  --dial-soft:  rgba(255, 255, 255, .66);
  --dial-track: rgba(255, 255, 255, .28);

  --wrap: 1180px;
  --r: 4px;
  --ease: cubic-bezier(.2, .85, .25, 1);
}

[data-theme="dark"] {
  --paper:    #0e1116;
  --card:     #171b23;
  --ink:      #e8ebf2;
  --ink-soft: #98a1b3;
  --line:     #2c3340;
  --wash:     #232936;
  --blue:     #7f95ff;
  --blue-2:   #a3b3ff;
  --red:      #ff7c88;
  --on-blue:  #0e1116;
  --slab:     #333d57;

  --dial-bg:    #6f88ff;
  --dial-fg:    #0b0e14;
  --dial-soft:  rgba(11, 14, 20, .68);
  --dial-track: rgba(11, 14, 20, .26);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: Archivo, "Helvetica Neue", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Paper grain. Riso stock is never perfectly flat. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: .3;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
}
[data-theme="dark"] body::after { mix-blend-mode: screen; opacity: .12; }

img { max-width: 100%; }
button, input { font: inherit; color: inherit; }

/* Layout rules below set display on elements that also toggle [hidden]. */
[hidden] { display: none !important; }

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

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 40px;
}

/* ── Top bar ──────────────────────────────────────────────── */
.topbar { border-bottom: 2px solid var(--ink); }

.topbar-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 68px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: .95rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-variation-settings: "wdth" 108;
}

/* The mark is artwork on its own near-black ground, so it reads as a printed
   chip rather than a floating glyph. Rounded to the same radius as the panels
   and outlined in ink so the chip has an edge on the dark theme too. */
.brand-mark {
  display: block;
  width: 34px;
  height: 34px;
  border-radius: var(--r);
  border: 1.5px solid var(--slab);
  background: #010104;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink); }
.icon-btn.tiny { width: 30px; height: 30px; border-color: transparent; }
.icon-btn.tiny:hover { border-color: var(--line); }

.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* ── Hero ─────────────────────────────────────────────────── */
main { flex: 1; }

.hero { padding-top: 64px; padding-bottom: 8px; }

.ask {
  margin: 0 0 34px;
  font-size: clamp(2.5rem, 6.2vw, 5.1rem);
  line-height: .98;
  font-weight: 800;
  letter-spacing: -.03em;
  font-variation-settings: "wdth" 116;
  text-wrap: balance;
  text-align: center;
}

/* The joke is the size: the word "file" is set small enough to read as an
   instruction and still be legible. */
.ask .shrunk {
  font-size: max(14px, .2em);
  letter-spacing: .01em;
  color: var(--blue);
  font-variation-settings: "wdth" 104;
}
/* The spaces either side are set at display size, so they dwarf the small
   word. Pull them in — only where the headline is actually large. */
@media (min-width: 901px) {
  .ask .shrunk { margin: 0 -.55em; }
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 28px;
  align-items: stretch;
  min-height: min(42vh, 360px);
}

.panel {
  border: 2px solid var(--ink);
  border-radius: var(--r);
}

/* ── The dial ─────────────────────────────────────────────── */
.dial {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 34px 38px 30px;
  background: var(--dial-bg);
  border-color: var(--dial-bg);
  color: var(--dial-fg);
  box-shadow: 9px 9px 0 var(--slab);
}

.dial-top { display: block; }

.dial-label {
  margin: 0 0 16px;
  color: var(--dial-soft);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding-bottom: 30px;
}

.value {
  width: 3ch;
  padding: 0;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: inherit;
  font-size: clamp(3.8rem, 8vw, 6.4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.045em;
  font-variation-settings: "wdth" 118;
  font-variant-numeric: tabular-nums;
  text-align: left;
}
.value:focus { outline: none; border-bottom-color: var(--dial-fg); }

.units { display: flex; gap: 6px; }

.unit {
  padding: 7px 13px;
  border: 1.5px solid var(--dial-track);
  border-radius: var(--r);
  background: transparent;
  color: var(--dial-soft);
  font-weight: 700;
  font-size: .85rem;
  letter-spacing: .06em;
  cursor: pointer;
  transition: color .14s, background .14s, border-color .14s;
}
.unit:hover { color: var(--dial-fg); border-color: var(--dial-fg); }
.unit.is-on {
  background: var(--dial-fg);
  border-color: var(--dial-fg);
  color: var(--dial-bg);
}

/* Range: drawn as an instrument, not a widget. */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 1px;
  background:
    linear-gradient(to right, var(--dial-fg) 0 var(--pct, 20%), var(--dial-track) var(--pct, 20%) 100%);
}
.slider::-moz-range-track {
  height: 8px;
  border-radius: 1px;
  background: var(--dial-track);
}
.slider::-moz-range-progress { height: 8px; border-radius: 1px; background: var(--dial-fg); }

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 26px;
  margin-top: -9px;
  border: 4px solid var(--dial-bg);
  border-radius: 2px;
  background: var(--dial-fg);
}
.slider::-moz-range-thumb {
  width: 22px;
  height: 26px;
  border: 4px solid var(--dial-bg);
  border-radius: 2px;
  background: var(--dial-fg);
}
.slider:focus-visible { outline: none; }
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--dial-fg); }
.slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--dial-fg); }

.ticks {
  position: relative;
  height: 30px;
  margin-top: 4px;
}

.tick {
  position: absolute;
  top: 0;
  display: grid;
  justify-items: center;
  gap: 6px;
  transform: translateX(-50%);
  color: var(--dial-soft);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .05em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tick::before {
  content: "";
  width: 1px;
  height: 6px;
  background: var(--dial-track);
}

/* ── The plate ────────────────────────────────────────────── */
.plate {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 44px 28px;
  background: var(--card);
  color: var(--ink);
  text-align: center;
  cursor: pointer;
  /* Hard offset ink rather than a soft shadow: two plates, out of register. */
  box-shadow: 9px 9px 0 var(--slab);
  transition: box-shadow .16s var(--ease), transform .16s var(--ease);
}
.plate:hover { box-shadow: 13px 13px 0 var(--slab); }
.plate.is-over {
  transform: translate(5px, 5px);
  border-color: var(--blue);
  box-shadow: 4px 4px 0 var(--blue);
}

.plate-icon { color: var(--blue-2); margin-bottom: 14px; }
[data-theme="dark"] .plate-icon { color: var(--blue); }

.plate-title {
  margin: 0;
  font-size: clamp(1.3rem, 2.2vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -.02em;
  font-variation-settings: "wdth" 112;
}

.plate-act { margin: 8px 0 0; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--blue-2);
  font-weight: 600;
  font-size: 1.02rem;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
[data-theme="dark"] .link { color: var(--blue); }

.plate-meta {
  margin: 24px 0 0;
  color: var(--ink-soft);
  font-size: .73rem;
  letter-spacing: .09em;
  text-transform: uppercase;
}

/* ── Results ──────────────────────────────────────────────── */
.results { padding-top: 66px; padding-bottom: 20px; }

.results-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
}

.sect {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-variation-settings: "wdth" 108;
}

.count {
  margin-left: 10px;
  font-weight: 500;
  font-size: .88rem;
  letter-spacing: .02em;
  text-transform: none;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.results-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  padding: 10px 17px;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: .9rem;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .14s, background .14s, opacity .14s;
}
.btn:hover { border-color: var(--ink); }

.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--on-blue);
}
.btn-primary:hover { background: var(--blue-2); border-color: var(--blue-2); }

.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--line); background: transparent; }
.btn-primary:disabled:hover { background: var(--blue); border-color: var(--blue); }

.files { list-style: none; margin: 0; padding: 0; }

/* Fixed columns, not content-sized, so every row lines up down the list. */
.file {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 240px 148px;
  grid-template-areas:
    "shot name  line actions"
    "shot meter line actions";
  align-items: center;
  gap: 9px 20px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.shot        { grid-area: shot; }
.file-name   { grid-area: name; align-self: end; }
.meter       { grid-area: meter; align-self: start; }
.file-line   { grid-area: line; }
.file-actions { grid-area: actions; }

.shot {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  align-self: center;
  padding: 0;
  overflow: hidden;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: var(--wash);
  color: var(--ink-soft);
  cursor: default;
}
.shot:not(:disabled) { cursor: zoom-in; }
.shot:not(:disabled):hover { border-color: var(--ink); }
.shot img { width: 100%; height: 100%; object-fit: cover; }

.file-name {
  margin: 0;
  font-weight: 600;
  font-size: .98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Every bar is drawn against the limit, so the dashed marker sits at the
   same place in every row and reads as one line down the whole list:
   bars stop short of it, or run past it in red. */
.meter {
  position: relative;
  height: 12px;
  border: 1.5px solid var(--line);
  border-radius: 2px;
  background: var(--wash);
  overflow: hidden;
}

/* Everything past the limit is hatched: the no-go zone is visible even on an
   empty track, and a bar that runs into it is unmistakable. */
.meter::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 62%;
  right: 0;
  background: repeating-linear-gradient(45deg, var(--line) 0 1px, transparent 1px 5px);
  pointer-events: none;
}

.meter-fill {
  display: block;
  width: 0;
  height: 100%;
  background: var(--blue);
  transition: width .7s var(--ease), background-color .2s;
}

.meter-limit {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 62%;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
}

.file-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 9px;
  margin: 0;
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}
.file-line .to {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--ink);
}
.file-line .to::before {
  content: "→";
  margin-right: 9px;
  font-weight: 400;
  font-size: .92rem;
  color: var(--ink-soft);
}
.file-line span:empty { display: none; }
.file-line .note {
  width: 100%;
  font-size: .84rem;
}

.file-actions { display: flex; align-items: center; gap: 6px; }

/* States */
.file[data-state="queued"] .meter-fill,
.file[data-state="uploading"] .meter-fill,
.file[data-state="working"] .meter-fill {
  width: 100%;
  background-image: repeating-linear-gradient(115deg, var(--blue) 0 10px, transparent 10px 20px);
  background-color: var(--wash);
  animation: march 1.1s linear infinite;
  transition: none;
}
.file[data-state="queued"] .meter-fill { opacity: .4; animation-play-state: paused; }

@keyframes march { to { background-position: -40px 0; } }

.file.is-over .meter-fill { background: var(--red); }

/* An error has no result, so the track stays empty rather than drawing a
   bar that would read as a size. */
.file[data-state="error"] .meter { border-color: var(--red); }
.file[data-state="error"] .meter-fill { width: 0; animation: none; }
.file[data-state="error"] .meter-limit { display: none; }
.file[data-state="error"] .note,
.file.is-over .note { color: var(--red); font-weight: 600; }

/* ── Preview ──────────────────────────────────────────────── */
.preview {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}
.preview[hidden] { display: none; }

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 20, .74);
}

.preview-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(820px, 100%);
  max-height: calc(100vh - 48px);
  border: 2px solid var(--ink);
  border-radius: var(--r);
  background: var(--card);
  box-shadow: 10px 10px 0 var(--blue);
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}
.preview-head p {
  margin: 0;
  font-weight: 600;
  font-size: .95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A page scan is far taller than the screen, so the stage is a fixed box and
   both images are contained inside it — identical geometry keeps the wipe
   lined up. */
.stage {
  position: relative;
  height: min(64vh, 620px);
  overflow: hidden;
  background: var(--wash);
  touch-action: none;
  user-select: none;
  cursor: ew-resize;
}
.stage img {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.stage-clip { position: absolute; inset: 0; width: 50%; overflow: hidden; }
.stage-clip img { max-width: none; }

.stage-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: var(--card);
}
.stage-handle span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 2px solid var(--card);
  border-radius: 2px;
  background: var(--blue);
}

.stage-tag {
  position: absolute;
  bottom: 12px;
  padding: 4px 9px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.stage-tag-l { left: 12px; }
.stage-tag-r { right: 12px; }

/* ── Toasts ───────────────────────────────────────────────── */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  display: grid;
  gap: 8px;
  max-width: min(400px, calc(100vw - 40px));
}

.toast {
  padding: 12px 15px;
  border: 1.5px solid var(--ink);
  border-radius: var(--r);
  background: var(--card);
  box-shadow: 5px 5px 0 var(--slab);
  font-size: .9rem;
}
.toast.is-error { border-color: var(--red); box-shadow: 5px 5px 0 var(--red); }

/* ── Narrower ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .wrap { padding: 0 24px; }
  .hero { padding-top: 44px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 22px; min-height: 0; }
  .dial { padding: 26px 26px 22px; box-shadow: 6px 6px 0 var(--slab); }
  .plate { padding: 46px 22px; box-shadow: 6px 6px 0 var(--slab); }
  .plate:hover { box-shadow: 6px 6px 0 var(--slab); }
  .results { padding-top: 46px; }

  .file {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    grid-template-areas:
      "shot  name  name"
      "meter meter meter"
      "line  line  actions";
    gap: 11px 14px;
  }
  .shot { width: 44px; height: 44px; }
  .file-name { align-self: center; }
  .file-line .note { width: auto; }
}

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