@font-face {
  font-family: Fraunces;
  src: url("../fonts/fraunces.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: Outfit;
  src: url("../fonts/outfit.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #14181f;
  --bg-raise: #1c222c;
  --ink: #f4efe6;
  --muted: #c4baad;
  --line: #313846;
  --accent: #e6b35a;
  --accent-ink: #1c1408;
  --accent-press: #c9963f;
  --paper: #f3ead7;
  --paper-ink: #2a2118;
  --danger: #ffb4a8;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --serif: Fraunces, "Iowan Old Style", Palatino, Georgia, serif;
  --sans: Outfit, "Avenir Next", "Segoe UI", sans-serif;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

* { box-sizing: border-box; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1000px 480px at 10% -10%, rgba(230, 179, 90, 0.16), transparent 55%),
    var(--bg);
  color: var(--ink);
}

button, input { font: inherit; color: inherit; }

button, [role="button"] {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

input, textarea, select { font-size: 16px; }

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

/* ponytail: the shell fills the viewport, and the page scrolls when the cut list no longer fits. Internal panel scrolling would hide Unfold. */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  gap: 14px;
  align-items: center;
  flex: none;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 28px 12px;
  max-width: 1240px;
  margin: 0 auto;
  width: 100%;
}

.mark { width: 42px; height: 42px; flex: none; }

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.9rem;
  font-weight: 560;
  font-optical-sizing: auto;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.kicker {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 46rem;
}

.layout {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 4px 28px calc(16px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: stretch;
}

.panel {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.controls, .notes { padding: 14px 16px 12px; }

.controls {
  grid-column: 1;
  grid-row: 1;
}

.controls h2,
.sheet-head h2,
.view-head h2,
.notes h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 560;
  font-optical-sizing: auto;
  letter-spacing: -0.02em;
}

.step {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.drop {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 88px;
  padding: 14px;
  border: 1.5px dashed #6a6156;
  border-radius: 14px;
  text-align: center;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.16);
  transition: border-color 160ms ease, background-color 160ms ease;
}

.drop:focus-within,
.drop.over {
  border-color: var(--accent);
  background: rgba(230, 179, 90, 0.08);
}

.drop strong {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.drop span, .hint { color: var(--muted); font-size: 0.82rem; }

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.row { display: flex; gap: 8px; margin-top: 8px; }
.row button { flex: 1; }

.row button, .primary, .ghost {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 0 12px;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), background-color 160ms ease, border-color 160ms ease;
}

.row button:active:not(:disabled),
.primary:active:not(:disabled),
.ghost:active:not(:disabled) {
  transform: scale(0.97);
}

.ghost { background: transparent; border-color: var(--line); }

.primary {
  width: 100%;
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.primary:disabled {
  opacity: 1;
  cursor: progress;
  background: var(--accent-press);
}

.primary:disabled::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 500ms linear infinite;
}

.ghost:disabled { opacity: 0.5; cursor: not-allowed; }

.controls > .ghost { width: 100%; margin-top: 8px; }

.slider {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.slider input[type="range"] {
  --fill: 0%;
  flex: 1;
  accent-color: var(--accent);
  min-height: 28px;
  appearance: none;
  height: 28px;
  background: transparent;
  cursor: pointer;
}

.slider input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill), #3a4252 var(--fill));
}

.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--accent-ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.slider input[type="range"]::-moz-range-track {
  height: 4px;
  border: none;
  border-radius: 999px;
  background: #3a4252;
}

.slider input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}

.slider input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 2px solid var(--accent-ink);
  border-radius: 50%;
  background: var(--accent);
}

.slider b {
  min-width: 1.6rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--accent);
}

.block { margin-top: 12px; }

.error {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 180, 168, 0.12);
  color: var(--danger);
  font-size: 0.88rem;
}

.stats {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.stage {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 16px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  align-items: stretch;
}

.view, .sheet {
  display: flex;
  flex-direction: column;
  padding: 14px 14px 12px;
  overflow: hidden;
  min-height: 0;
  height: 100%;
}

.view-head, .sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  flex: none;
}

.view-head p, .sheet-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.view svg, .sheet svg {
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  min-height: 0;
  transition: opacity 160ms ease;
}

.view svg {
  cursor: grab;
  touch-action: none;
}

.view svg:active { cursor: grabbing; }

.sheet svg { touch-action: pan-y; }

.app.is-busy .view svg,
.app.is-busy .sheet svg { opacity: 0.55; }

.sheet {
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(42, 33, 24, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 33, 24, 0.06) 1px, transparent 1px);
  background-size: 18px 18px;
  color: var(--paper-ink);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.sheet h2, .sheet p { color: var(--paper-ink); }
.sheet .sheet-head p, .legend { color: #4e453c; }
.legend { margin: 2px 0 8px; font-size: 0.8rem; flex: none; }

.sheet > p:not(.legend) {
  flex: 1;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 20px;
  text-align: center;
  border: 1px dashed rgba(42, 33, 24, 0.28);
  border-radius: 12px;
  min-height: 140px;
}

.notes {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0;
  max-height: 34dvh;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #3a4252 transparent;
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 22px;
  row-gap: 8px;
  align-content: start;
}

.notes h2 { grid-column: 1 / -1; margin: 0; }
.notes article + article { margin: 0; }

.notes h3 {
  margin: 0 0 2px;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.notes p {
  margin: 0;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.45;
}

.notes > p:not(.live) { color: var(--muted); }

.live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (hover: hover) and (pointer: fine) {
  .drop:hover { border-color: var(--accent); }
  .ghost:hover:not(:disabled) { border-color: var(--accent); }
  .primary:hover:not(:disabled) { background: #f0c56d; }
}

@media (pointer: coarse) {
  .slider input[type="range"]::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
    margin-top: -12px;
  }
  .slider input[type="range"]::-moz-range-thumb {
    width: 28px;
    height: 28px;
  }
}

@media (max-width: 980px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 800px) {
  .app { min-height: 100dvh; }
  .top, .layout { padding-left: 14px; padding-right: 14px; }
  .top { padding-top: calc(10px + env(safe-area-inset-top, 0px)); padding-bottom: 2px; }
  h1 { font-size: 1.4rem; }
  .kicker { font-size: 0.88rem; }
  .layout {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: visible;
  }
  .controls {
    display: flex;
    flex-flow: row wrap;
    align-items: stretch;
    gap: 8px;
    order: 1;
  }
  .controls > * { width: 100%; }
  .controls > .primary,
  .controls > .ghost {
    margin-top: 0;
    order: 2;
    white-space: nowrap;
  }
  .controls > .primary { width: calc(40% - 4px); }
  .controls > .ghost { width: calc(60% - 4px); }
  .stats { order: 3; }
  .stage {
    order: -1;
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 8px;
  }
  .view, .sheet { height: auto; padding: 10px 12px 8px; }
  .view svg { height: 112px; flex: none; }
  .sheet svg { height: 96px; flex: none; max-height: none; }
  .notes {
    order: 2;
    display: block;
    max-height: none;
    overflow: visible;
  }
  .notes article + article { margin-top: 12px; }
  .drop { min-height: 64px; padding: 8px; }
  .block { margin-top: 4px; }
  .legend { margin-bottom: 4px; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .primary:active:not(:disabled),
  .ghost:active:not(:disabled),
  .row button:active:not(:disabled) {
    transform: none;
  }
}
