@layer reset, base, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, p, ol, dl, dd { margin: 0; }
  button, input, select { font: inherit; }
  button { cursor: pointer; }
  [hidden] { display: none !important; }
}

@layer base {
  :root {
    --paper: #f1eee5;
    --paper-deep: #e7e1d4;
    --ink: #17232b;
    --muted: #6d726d;
    --rule: rgba(23, 35, 43, 0.2);
    --orange: #f0522d;
    --yellow: #f4c950;
    --white: #fffdf8;
    --display: "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
    --sans: "Avenir Next", Avenir, "Gill Sans", "Trebuchet MS", sans-serif;
  }

  body {
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    background:
      linear-gradient(90deg, transparent calc(50% - 1px), rgba(23, 35, 43, 0.045) 50%, transparent calc(50% + 1px)),
      var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    -webkit-tap-highlight-color: transparent;
  }

  .paper-noise {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.22;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.86' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
  }

  ::selection { background: var(--yellow); color: var(--ink); }
}

@layer components {
  .site-header {
    width: min(1420px, calc(100% - 72px));
    margin: 0 auto;
    padding: 26px 0 18px;
    border-bottom: 1px solid var(--ink);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .wordmark {
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.22em;
    text-decoration: none;
  }

  .wordmark-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--ink);
    background: var(--yellow);
    font-family: var(--display);
    font-size: 1.35rem;
    font-style: italic;
    letter-spacing: 0;
    transform: rotate(-3deg);
    box-shadow: 3px 3px 0 var(--ink);
  }

  .folio {
    display: flex;
    align-items: center;
    gap: 18px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
  }

  .folio-number {
    min-width: 34px;
    padding-left: 14px;
    border-left: 1px solid var(--ink);
    color: var(--ink);
    font-family: var(--display);
    font-size: 1rem;
    font-style: italic;
    letter-spacing: 0;
  }

  main {
    width: min(1320px, calc(100% - 72px));
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(500px, 0.78fr);
    gap: clamp(64px, 9vw, 150px);
    align-items: start;
    padding: clamp(62px, 8vw, 118px) 0 88px;
  }

  .intro { position: sticky; top: 48px; padding-top: 18px; }

  .eyebrow, .kicker {
    color: var(--orange);
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    text-transform: uppercase;
  }

  .eyebrow { display: flex; align-items: center; gap: 11px; }
  .eyebrow span { width: 28px; height: 2px; background: var(--orange); }

  .intro h1 {
    max-width: 700px;
    margin: 23px 0 26px;
    font-family: var(--display);
    font-size: clamp(3.7rem, 6.8vw, 7.6rem);
    font-weight: 400;
    letter-spacing: -0.065em;
    line-height: 0.86;
  }

  .intro h1 em {
    position: relative;
    color: var(--orange);
    font-weight: 400;
  }

  .intro h1 em::after {
    content: "";
    position: absolute;
    left: -2%;
    right: -5%;
    bottom: 0.3em;
    height: 0.09em;
    background: var(--orange);
    transform: rotate(-1deg) scaleX(0);
    transform-origin: left;
    animation: underline-in 0.8s 0.7s cubic-bezier(.2,.9,.25,1) forwards;
  }

  .lede {
    max-width: 570px;
    color: #465057;
    font-family: var(--display);
    font-size: clamp(1.05rem, 1.5vw, 1.28rem);
    line-height: 1.55;
  }

  .process-notes {
    max-width: 570px;
    margin-top: 52px;
    padding: 0;
    border-top: 1px solid var(--rule);
    list-style: none;
  }

  .process-notes li {
    padding: 15px 0;
    border-bottom: 1px solid var(--rule);
    display: grid;
    grid-template-columns: 45px 1fr;
    align-items: center;
  }

  .note-number {
    color: var(--orange);
    font-family: var(--display);
    font-size: 0.86rem;
    font-style: italic;
  }

  .process-notes strong { display: block; font-size: 0.83rem; letter-spacing: 0.02em; }
  .process-notes small { color: var(--muted); font-size: 0.72rem; }

  .privacy-note {
    max-width: 570px;
    margin-top: 26px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 0.68rem;
    line-height: 1.45;
  }

  .privacy-note strong { color: var(--ink); }
  .privacy-icon { width: 13px; height: 15px; border: 1.5px solid var(--ink); border-radius: 2px; position: relative; }
  .privacy-icon::before { content: ""; position: absolute; width: 7px; height: 7px; left: 1.5px; top: -7px; border: 1.5px solid var(--ink); border-bottom: 0; border-radius: 8px 8px 0 0; }

  .workbench {
    position: relative;
    min-height: 630px;
    padding: clamp(28px, 3.4vw, 48px);
    background: var(--white);
    border: 1px solid var(--ink);
    box-shadow: 12px 12px 0 var(--ink);
    animation: card-in 0.7s 0.12s cubic-bezier(.2,.85,.25,1) both;
  }

  .workbench::before {
    content: "";
    position: absolute;
    width: 72px;
    height: 18px;
    top: -10px;
    right: 48px;
    background: rgba(244, 201, 80, 0.75);
    transform: rotate(2deg);
  }

  .workbench-head, .analysis-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
  }

  .workbench h2, .analysis-card h3 {
    margin-top: 5px;
    font-family: var(--display);
    font-size: 1.72rem;
    font-weight: 500;
    letter-spacing: -0.025em;
  }

  .status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 3px;
    padding: 7px 10px;
    border: 1px solid var(--rule);
    border-radius: 99px;
    color: var(--muted);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
  }

  .status-pill i { width: 6px; height: 6px; border-radius: 50%; background: #98a09b; }
  .status-pill.loaded i { background: var(--yellow); }
  .status-pill.working i { background: var(--orange); animation: pulse 0.8s infinite alternate; }
  .status-pill.complete i { background: #3a8b65; }
  .status-pill.error i { background: #b62d2d; }

  .drop-zone {
    min-height: 218px;
    margin-top: 30px;
    border: 1px dashed #8c8e87;
    background:
      linear-gradient(135deg, rgba(244,201,80,.1), transparent 45%),
      #f8f5ed;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 35px;
    padding: 28px;
    outline: none;
    transition: border-color .18s, background .18s, transform .18s;
    touch-action: manipulation;
  }

  .drop-zone:hover, .drop-zone:focus-visible, .drop-zone.is-dragging {
    border-color: var(--orange);
    background-color: #fff7e5;
    transform: translateY(-2px);
  }

  .page-stack { width: 76px; height: 92px; position: relative; flex: 0 0 auto; }
  .page-stack > span, .page-front { position: absolute; width: 60px; height: 78px; border: 1px solid var(--ink); background: var(--white); }
  .page-stack > span:first-child { inset: 8px auto auto 2px; transform: rotate(-7deg); background: var(--paper-deep); }
  .page-stack > span:nth-child(2) { inset: 5px 3px auto auto; transform: rotate(5deg); background: var(--yellow); }
  .page-front { inset: 7px auto auto 8px; padding: 13px 10px; box-shadow: 3px 3px 0 rgba(23,35,43,.18); }
  .page-front b { color: var(--orange); font-size: .6rem; letter-spacing: .12em; }
  .page-front i { display: block; height: 1px; margin-top: 9px; background: var(--ink); opacity: .6; }
  .page-front i:nth-of-type(2) { width: 82%; }
  .page-front i:nth-of-type(3) { width: 60%; }

  .drop-title { font-family: var(--display); font-size: 1.15rem; font-weight: 600; }
  .drop-copy p:last-child { margin-top: 5px; color: var(--muted); font-size: .72rem; }
  .drop-copy span { color: var(--orange); border-bottom: 1px solid currentColor; font-weight: 700; }

  .file-card {
    margin-top: 30px;
    padding: 17px;
    border: 1px solid var(--ink);
    display: grid;
    grid-template-columns: 44px 1fr 34px;
    gap: 13px;
    align-items: center;
    background: #f8f5ed;
  }

  .file-monogram { width: 44px; height: 52px; display: grid; place-items: center; background: var(--orange); color: white; font-size: .57rem; font-weight: 900; letter-spacing: .1em; box-shadow: 3px 3px 0 var(--ink); }
  .file-meta { min-width: 0; }
  .file-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
  .file-meta span { color: var(--muted); font-size: .67rem; }

  .icon-button { width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); font-family: var(--display); font-size: 1.35rem; }
  .icon-button:hover { color: var(--orange); }

  #book-form { margin-top: 24px; }
  .field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  #book-form label { display: block; }
  #book-form label > span { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: .64rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
  #book-form label small { color: var(--muted); font-size: .55rem; font-weight: 500; letter-spacing: .04em; }
  input, select { width: 100%; height: 44px; border: 0; border-bottom: 1px solid var(--ink); border-radius: 0; outline: none; background: transparent; color: var(--ink); font-family: var(--display); font-size: .88rem; }
  input:focus, select:focus { border-bottom: 2px solid var(--orange); }
  input::placeholder { color: #99978f; }
  .language-field { margin-top: 16px; max-width: calc(50% - 8px); }

  .pipeline { margin-top: 25px; padding: 16px 0 2px; border-top: 1px solid var(--rule); }
  .pipeline-top { display: flex; justify-content: space-between; color: var(--muted); font-size: .65rem; font-weight: 700; }
  .progress-track { height: 3px; margin-top: 10px; background: var(--paper-deep); overflow: hidden; }
  .progress-track span { display: block; width: 25%; height: 100%; background: var(--orange); transition: width .45s ease; }
  .stage-dots { display: flex; justify-content: space-between; margin-top: 5px; }
  .stage-dots i { width: 4px; height: 4px; border-radius: 50%; background: #c9c4b9; }
  .stage-dots i.active { background: var(--orange); }

  .analysis-card { margin-top: 24px; padding: 22px; border: 1px solid var(--ink); background: #f7f1de; animation: reveal .4s ease both; }
  .analysis-card h3 { font-size: 1.28rem; }
  .check-mark { width: 31px; height: 31px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 50%; background: var(--yellow); font-weight: 900; }
  .stats { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 20px; border-block: 1px solid var(--rule); }
  .stats div { padding: 14px 8px; border-right: 1px solid var(--rule); }
  .stats div:first-child { padding-left: 0; }
  .stats div:last-child { border-right: 0; }
  .stats dt { font-family: var(--display); font-size: 1.3rem; }
  .stats dd { margin-top: 1px; color: var(--muted); font-size: .55rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
  .outline { margin-top: 17px; }
  .outline > p { margin-bottom: 8px; color: var(--muted); font-size: .58rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
  .outline ol { max-height: 150px; overflow-y: auto; padding: 0; list-style: none; }
  .outline li { padding: 6px 0; display: grid; grid-template-columns: 28px 1fr; align-items: baseline; border-bottom: 1px dotted var(--rule); }
  .outline li:last-child { border-bottom: 0; }
  .outline li span { color: var(--orange); font-family: var(--display); font-size: .68rem; font-style: italic; }
  .outline li strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--display); font-size: .76rem; font-weight: 500; }

  .error-message { margin-top: 18px; padding: 11px 13px; border-left: 3px solid #b62d2d; background: #f7dfd9; color: #7d211f; font-size: .72rem; line-height: 1.45; }

  .actions { margin-top: 27px; display: grid; grid-template-columns: 1fr 1.15fr; gap: 12px; }
  .button { min-height: 50px; padding: 0 18px; border: 1px solid var(--ink); font-size: .7rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; transition: transform .15s, box-shadow .15s, background .15s; }
  .button:not(:disabled):hover { transform: translate(-2px, -2px); box-shadow: 4px 4px 0 var(--ink); }
  .button:disabled { cursor: not-allowed; opacity: .38; }
  .button-secondary { background: transparent; color: var(--ink); }
  .button-primary { display: flex; align-items: center; justify-content: space-between; background: var(--ink); color: white; }
  .button-primary b { color: var(--yellow); font-size: 1.1rem; }
  .v1-note { margin-top: 13px; color: var(--muted); font-size: .61rem; line-height: 1.4; text-align: center; }

  footer {
    width: min(1420px, calc(100% - 72px));
    margin: 0 auto;
    padding: 20px 0 26px;
    border-top: 1px solid var(--ink);
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: .58rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
  }

  @keyframes underline-in { to { transform: rotate(-1deg) scaleX(1); } }
  @keyframes card-in { from { opacity: 0; transform: translateY(22px) rotate(.3deg); } }
  @keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
  @keyframes pulse { to { transform: scale(1.7); opacity: .5; } }
}

@layer responsive {
  @media (max-width: 980px) {
    body { background: var(--paper); }
    main { grid-template-columns: 1fr; gap: 46px; padding-top: 58px; }
    .intro { position: static; }
    .intro h1 { font-size: clamp(4rem, 12vw, 7rem); }
    .process-notes, .privacy-note, .lede { max-width: 700px; }
    .workbench { max-width: 720px; width: 100%; }
  }

  @media (max-width: 700px) {
    .site-header, main, footer {
      width: auto;
      margin-inline: max(17px, env(safe-area-inset-left)) max(17px, env(safe-area-inset-right));
    }
    .site-header {
      padding-top: max(17px, env(safe-area-inset-top));
      padding-bottom: 14px;
    }
    .folio > span:first-child { display: none; }
    main { gap: 28px; padding-top: 32px; padding-bottom: 58px; }

    .intro { padding-top: 5px; }
    .eyebrow { font-size: .6rem; letter-spacing: .17em; }
    .eyebrow span { width: 20px; }
    .intro h1 {
      margin: 14px 0 17px;
      font-size: clamp(3.2rem, 15.8vw, 4.8rem);
      letter-spacing: -.055em;
      line-height: .88;
    }
    .lede { font-size: .98rem; line-height: 1.45; }

    .process-notes {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      margin-top: 23px;
      border-bottom: 1px solid var(--rule);
    }
    .process-notes li {
      min-width: 0;
      min-height: 62px;
      padding: 9px 8px 9px 0;
      border-right: 1px solid var(--rule);
      border-bottom: 0;
      display: block;
    }
    .process-notes li + li { padding-left: 10px; }
    .process-notes li:last-child { border-right: 0; }
    .note-number { display: block; margin-bottom: 3px; font-size: .7rem; }
    .process-notes strong {
      overflow: hidden;
      display: block;
      font-size: .62rem;
      line-height: 1.25;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .process-notes small { display: none; }
    .privacy-note { margin-top: 16px; font-size: .62rem; }
    .privacy-icon { flex: 0 0 auto; }

    .workbench {
      min-height: 0;
      padding: 25px 20px;
      box-shadow: 7px 7px 0 var(--ink);
    }
    .workbench::before { right: 25px; }
    .workbench h2 { font-size: 1.5rem; }
    .status-pill { padding: 6px 8px; font-size: .55rem; }
    .drop-zone {
      min-height: 170px;
      margin-top: 24px;
      padding: 21px 16px;
      flex-direction: column;
      gap: 13px;
      text-align: center;
    }
    .page-stack { transform: scale(.88); margin-block: -5px; }
    .file-card { margin-top: 24px; }
    #book-form { margin-top: 21px; }
    .field-grid { grid-template-columns: 1fr; gap: 15px; }
    .language-field { max-width: 100%; }
    input, select { height: 48px; font-size: 1rem; }
    .icon-button { width: 44px; height: 44px; }
    .actions { grid-template-columns: 1fr; }
    .button { min-height: 54px; touch-action: manipulation; }
    .button:not(:disabled):hover { transform: none; box-shadow: none; }
    .analysis-card { padding: 18px 16px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stats div { padding: 12px 9px; }
    .stats div:nth-child(2) { border-right: 0; }
    .stats div:nth-child(-n + 2) { border-bottom: 1px solid var(--rule); }
    .stats div:nth-child(3) { padding-left: 0; }
    .stats dt { font-size: 1.18rem; }
    .outline ol { max-height: 190px; }
    .outline li { min-height: 34px; align-items: center; }
    .outline li strong { font-size: .8rem; }
    footer {
      gap: 8px;
      padding-bottom: max(26px, env(safe-area-inset-bottom));
      flex-direction: column;
      line-height: 1.5;
    }
  }

  @media (max-width: 360px) {
    .site-header, main, footer {
      margin-inline: max(13px, env(safe-area-inset-left)) max(13px, env(safe-area-inset-right));
    }
    .wordmark { gap: 9px; font-size: .68rem; }
    .wordmark-mark { width: 31px; height: 31px; }
    .intro h1 { font-size: 3rem; }
    .lede { font-size: .92rem; }
    .process-notes li + li { padding-left: 7px; }
    .process-notes strong { font-size: .56rem; }
    .workbench { padding-inline: 16px; box-shadow: 5px 5px 0 var(--ink); }
    .workbench-head { gap: 10px; }
    .status-pill { padding-inline: 7px; letter-spacing: .04em; }
    .file-card { grid-template-columns: 40px minmax(0, 1fr) 44px; padding: 13px; gap: 10px; }
    .file-monogram { width: 40px; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  }
}
