:root {
  color-scheme: light;
  --black: #111111;
  --white: #ffffff;
  --line: #d8d8d8;
  --soft: #f4f4f1;
  --muted: #646464;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html {
  max-width: 100%;
  overflow-x: hidden;
  background: var(--white);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--white);
  color: var(--black);
}

button, input { font: inherit; }

button,
.action {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.masthead,
main,
footer {
  width: min(100% - 40px, 1500px);
  margin-inline: auto;
}

.masthead > *,
.input-panel > *,
.process-heading > * { min-width: 0; }

.masthead {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
  align-items: end;
  padding: 34px 0 28px;
  border-bottom: 1px solid var(--black);
}

.eyebrow,
.step {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 5vw, 70px);
  font-weight: 500;
  letter-spacing: -.045em;
  line-height: .95;
}

.intro {
  max-width: 720px;
  margin: 0;
  font-size: clamp(16px, 2vw, 22px);
  line-height: 1.35;
}

.input-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 28px;
  align-items: end;
  padding: 48px 0;
  border-bottom: 1px solid var(--line);
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(25px, 3vw, 40px);
  font-weight: 500;
  letter-spacing: -.035em;
}

.support,
.status,
footer {
  color: var(--muted);
}

.support { margin-bottom: 0; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.action,
.scroll-controls button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--black);
  border-radius: 0;
  padding: 0 21px;
  cursor: pointer;
  user-select: none;
  transition: background .15s ease, color .15s ease;
}

.action.primary {
  background: var(--black);
  color: var(--white);
}

.action.secondary,
.scroll-controls button {
  background: var(--white);
  color: var(--black);
}

.action:hover,
.action:focus-visible,
.scroll-controls button:hover,
.scroll-controls button:focus-visible {
  background: #333333;
  color: var(--white);
  outline: 2px solid var(--black);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.status {
  grid-column: 1 / -1;
  margin: -8px 0 0;
  min-height: 20px;
  font-size: 14px;
}

.process { padding: 42px 0 56px; }

.process-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.process-heading h2 { margin-bottom: 0; }

.scroll-controls { display: flex; gap: 8px; }

.scroll-controls button {
  width: 48px;
  padding: 0;
  font-size: 22px;
}

.timeline {
  display: flex;
  gap: 16px;
  width: 100%;
  min-height: 430px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-color: var(--black) var(--soft);
  scrollbar-width: thin;
  padding: 0 0 18px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
}

.timeline:focus-visible {
  outline: 2px solid var(--black);
  outline-offset: 5px;
}

.image-state,
.empty-state,
.next-state {
  flex: 0 0 min(72vw, 330px);
  scroll-snap-align: start;
}

.image-state {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 400px;
  border-top: 1px solid var(--black);
  padding-top: 10px;
}

.image-state.source-selected {
  border-top-width: 3px;
  padding-top: 8px;
}

.state-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 13px;
}

.state-number { font-weight: 700; }

.state-kind { color: var(--muted); }
.state-kind { text-align: right; }

.image-frame {
  display: grid;
  place-items: center;
  min-height: 300px;
  overflow: hidden;
  background: var(--soft);
  border: 1px solid var(--line);
}

.image-frame img {
  display: block;
  width: 100%;
  height: 330px;
  object-fit: contain;
}

.state-meta {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-footer {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.state-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.state-action,
.download-image {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--black);
  border-radius: 0;
  background: var(--white);
  color: var(--black);
  padding: 0 9px;
  font-size: 11px;
  text-decoration: none;
  cursor: pointer;
}

.download-image {
  width: fit-content;
}

.download-image:hover,
.download-image:focus-visible,
.state-action:hover,
.state-action:focus-visible {
  background: var(--black);
  color: var(--white);
  outline: none;
}

.empty-state {
  display: grid;
  min-height: 400px;
  place-content: center;
  border: 1px dashed #a8a8a8;
  background: var(--soft);
  text-align: center;
}

.empty-number {
  display: block;
  margin-bottom: 12px;
  font-size: 48px;
  font-weight: 500;
}

.empty-state p { margin-bottom: 0; color: var(--muted); }

.next-state {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 400px;
  border-top: 1px solid var(--black);
  padding-top: 10px;
}

.next-state-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 350px;
  border: 1px dashed #8b8b8b;
  padding: 24px;
}

.next-state h3 {
  margin: 0 0 10px;
  font-size: 29px;
  font-weight: 500;
  letter-spacing: -.03em;
}

.next-description {
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.route-list {
  display: grid;
  gap: 8px;
}

.route {
  display: grid;
  gap: 5px;
  width: 100%;
  border: 1px solid var(--black);
  border-radius: 0;
  background: var(--white);
  color: var(--black);
  padding: 13px;
  text-align: left;
  cursor: pointer;
}

.route strong { font-size: 14px; }
.route span { color: var(--muted); font-size: 12px; line-height: 1.35; }

.route:hover,
.route:focus-visible,
.route.selected {
  background: var(--black);
  color: var(--white);
  outline: none;
}

.route:hover span,
.route:focus-visible span,
.route.selected span { color: #d8d8d8; }

.physical-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.physical-actions[hidden],
.digital-actions[hidden],
.operation-panel[hidden],
.route-note[hidden] { display: none; }

.digital-actions { margin-top: 10px; }

.cartridge {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 92px;
  border: 1px solid var(--black);
  border-radius: 0;
  background: var(--white);
  color: var(--black);
  padding: 13px;
  text-align: left;
  cursor: pointer;
}

.cartridge span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
}

.cartridge strong { font-size: 15px; }
.cartridge small { color: var(--muted); font-size: 12px; line-height: 1.35; }

.cartridge:hover,
.cartridge:focus-visible,
.cartridge.selected {
  background: var(--black);
  color: var(--white);
  outline: none;
}

.cartridge:hover small,
.cartridge:focus-visible small,
.cartridge.selected small { color: #d8d8d8; }

.mini-action {
  flex: 1 1 120px;
  min-height: 38px;
  border: 1px solid var(--black);
  border-radius: 0;
  background: var(--white);
  color: var(--black);
  padding: 0 12px;
  cursor: pointer;
}

.mini-action.dark { background: var(--black); color: var(--white); }

.print-action { flex-basis: 100%; }

.route-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.operation-panel {
  padding: 42px 0 56px;
  border-top: 1px solid var(--black);
}

.operation-intro {
  display: grid;
  grid-template-columns: minmax(220px, .75fr) minmax(280px, 1.25fr);
  gap: 12px 28px;
  padding-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.operation-intro .step { grid-column: 1 / -1; }
.operation-intro h2 { margin-bottom: 0; }

.operation-intro > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.parameter-heading {
  display: grid;
  grid-template-columns: minmax(220px, .75fr) minmax(280px, 1.25fr);
  gap: 28px;
  padding: 34px 0 22px;
}

.parameter-heading h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
}

.parameter-heading p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.parameter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.parameter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  min-width: 0;
  padding: 20px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.parameter-name { font-weight: 700; }
.parameter-value { font-variant-numeric: tabular-nums; }

.parameter input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--black);
}

.parameter-help {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.operation-apply {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: 24px;
}

.operation-apply p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.apply-operation {
  flex: 0 0 auto;
  min-height: 52px;
  border: 1px solid var(--black);
  border-radius: 0;
  background: var(--black);
  color: var(--white);
  padding: 0 22px;
  cursor: pointer;
}

.apply-operation:disabled {
  cursor: wait;
  opacity: .55;
}

footer {
  padding: 20px 0 34px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

footer p { margin-bottom: 0; }

@media (max-width: 760px) {
  .masthead,
  main,
  footer {
    width: calc(100% - 28px);
  }

  .masthead {
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: start;
    padding: 24px 0 22px;
  }

  .input-panel {
    grid-template-columns: 1fr;
    gap: 24px;
    align-items: start;
    padding: 32px 0;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .action {
    width: 100%;
    min-height: 52px;
    padding-inline: 14px;
  }

  .status { grid-column: auto; margin-top: 0; }
  .scroll-controls { display: none; }
  .process { padding: 32px 0 42px; }
  .process-heading { align-items: start; }
  .timeline {
    gap: 12px;
    min-height: 380px;
    scroll-snap-type: x mandatory;
  }

  .image-state,
  .empty-state,
  .next-state {
    flex-basis: min(88vw, 360px);
    min-height: 360px;
  }

  .image-frame img { height: clamp(260px, 52vh, 330px); }
  .next-state-body { min-height: 330px; padding: 20px; }
  .next-state h3 { font-size: clamp(25px, 8vw, 29px); }
  .mini-action { min-height: 46px; }

  .operation-panel { padding: 32px 0 42px; }
  .operation-intro,
  .parameter-heading { grid-template-columns: 1fr; gap: 14px; }
  .operation-intro .step { grid-column: auto; }
  .parameter-grid { grid-template-columns: 1fr; }
  .parameter { padding: 18px 16px; }
  .operation-apply { align-items: stretch; flex-direction: column; }
  .apply-operation { width: 100%; }
}

@media (max-width: 430px) {
  .masthead,
  main,
  footer {
    width: calc(100% - 24px);
  }

  h1 { font-size: clamp(34px, 12vw, 48px); }
  .intro { font-size: 16px; }
  .actions { grid-template-columns: 1fr; }
  .process-heading { margin-bottom: 16px; }

  .image-state,
  .empty-state,
  .next-state {
    flex-basis: calc(100vw - 36px);
  }

  .state-head { gap: 10px; }
  .state-actions { display: grid; grid-template-columns: 1fr; }
  .state-action, .download-image { width: 100%; min-height: 40px; }
  .next-state-body { padding: 18px; }
  .physical-actions { display: grid; grid-template-columns: 1fr; }
  .mini-action, .print-action { width: 100%; }
}

@media (max-width: 760px) and (orientation: landscape) {
  .image-state,
  .empty-state,
  .next-state { flex-basis: min(68vw, 360px); }

  .image-frame img { height: min(68vh, 300px); }
}

#print-stage { display: none; }

@media print {
  @page { margin: 0; }

  html,
  body.printing-single-state {
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    overflow: hidden;
  }

  body.printing-single-state > * { display: none !important; }

  body.printing-single-state > #print-stage {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
  }

  #print-stage img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
}
