/* Apps (public/apps.js). The work is the only thing in colour (DESIGN.md §0): a contact sheet
   of prints (§3), each card one surface with its before and after full bleed on top and a
   caption under it. Hover is a border and shadow shift only: nothing moves, nothing hides.
   Sources, redrawn with the Atelier tokens: 21st.dev « Image Compare » (0xuser64bit: the
   clipped after-layer, the line and its knob, a range input under the stage) and
   « Multi-Step Progress » (sean0205: dot, label and time per step); Kokonut UI « File
   Upload » (the dashed zone, the underlined link, the status line under the file). */

#appsPane .page-head, #appsPane .page-body { max-width: 1120px; }
#appsPane.is-app-open .page-head { display: none; }
#appsPane.is-app-open .page-body { padding-top: var(--s5); }
.ap-shell { display: flex; flex-direction: column; gap: var(--s5); }
.ap-note { margin: 0; font-size: 12.5px; color: var(--warn); }

/* ------------------------------------------------------------ the sheet */
.ap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: var(--s4); }
.ap-card {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left;
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--panel);
  color: var(--text); font: inherit; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ap-card:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.ap-card:focus-visible { outline: none; box-shadow: var(--focus); }
.ap-card.is-soon { cursor: default; }
.ap-card.is-soon:hover { border-color: var(--border); box-shadow: none; }
.ap-card.is-soon .ap-art { filter: saturate(.5); opacity: .8; }
.ap-card.is-soon .ap-name { color: var(--text-2); }

/* the print: before | after, two whole squares, a hairline between them */
.ap-art { position: relative; aspect-ratio: 2 / 1; background: var(--panel-3); border-bottom: 1px solid var(--border); overflow: hidden; }
.ap-art.is-big { border: 1px solid var(--border); border-radius: var(--r); }
.ap-pair { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); }
.ap-half { position: relative; display: block; overflow: hidden; background: var(--panel); }
.ap-half-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
/* a cut-out has no ground: the usual checkerboard says so */
.ap-half.is-clear { background: repeating-conic-gradient(#E9EBEF 0 25%, #FFFFFF 0 50%) 50% / 12px 12px; }
.ap-half.is-clear .ap-half-img { object-fit: contain; }

/* Resize: the second half holds the tall format, whole, on the grey ground */
.ap-half.is-formats { display: grid; place-items: center; background: var(--panel-3); }
.ap-frame { position: relative; display: block; height: 84%; aspect-ratio: 9 / 16; border-radius: 3px; overflow: hidden; box-shadow: 0 1px 2px rgba(18, 22, 33, .12), 0 6px 18px rgba(18, 22, 33, .14); }
.ap-frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
/* where the square ad sits inside the story: drawn inside the frame so all four sides show */
.ap-sqline { position: absolute; left: 2px; right: 2px; top: 50%; aspect-ratio: 1; transform: translateY(-50%); border: 1.5px dashed rgba(255, 255, 255, .92); border-radius: 2px; box-shadow: 0 0 0 1px rgba(14, 15, 17, .18); }

.ap-caption { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px 14px; }
.ap-meta { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.ap-name { font-size: 14px; font-weight: 600; letter-spacing: -0.005em; }
.ap-cost { flex: none; font-family: var(--mono); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ap-soon { flex: none; font-size: 11.5px; color: var(--muted); padding: 1px 8px; border-radius: var(--r-xs); border: 1px solid var(--border); background: var(--panel-2); }
.ap-line { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--muted); text-wrap: pretty; }

/* ---------------------------------------------------- recent results */
.ap-recent { display: flex; flex-direction: column; gap: var(--s3); padding-top: var(--s2); }
.ap-recent[hidden] { display: none; }
.ap-recent-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px var(--s3); }
.ap-recent-h { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.ap-recent-sub { margin: 0; font-size: 12.5px; color: var(--muted); }
.ap-shots { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: var(--s3); }
.ap-shot { display: flex; flex-direction: column; gap: 6px; color: inherit; text-decoration: none; border-radius: var(--r-sm); }
.ap-shot:focus-visible { outline: none; box-shadow: var(--focus); }
.ap-shot-frame { display: block; aspect-ratio: 1; border-radius: var(--r-sm); overflow: hidden; background: var(--panel-3); border: 1px solid var(--border); transition: border-color .15s ease, box-shadow .15s ease; }
.ap-shot:hover .ap-shot-frame { border-color: var(--border-2); box-shadow: var(--shadow-xs); }
.ap-shot-frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.ap-shot-cap { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ap-shot-name { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-shot-when { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* ---------------------------------------------------------------- one app */
.ap-head { display: grid; gap: 4px; justify-items: start; }
.ap-back { margin-left: -10px; gap: 4px; }
.ap-back .ico { width: 15px; height: 15px; }
.ap-title { margin: 6px 0 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.ap-sub { margin: 0; font-size: 13px; color: var(--muted); }

.ap-work { display: grid; grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); gap: var(--s5); align-items: start; }
.ap-form { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }

.ap-drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 240px; padding: var(--s5) var(--s4); text-align: center; cursor: pointer;
  border: 1px dashed var(--border-2); border-radius: var(--r-lg); background: var(--panel);
  transition: border-color .15s ease, background-color .15s ease;
}
.ap-drop:hover, .ap-drop.is-over { border-color: var(--accent-line); }
.ap-drop.is-over { background: var(--accent-soft); }
.ap-drop:focus-within { box-shadow: var(--focus); }
.ap-drop-ico { display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r); border: 1px solid var(--border); background: var(--panel-2); color: var(--text-2); }
.ap-drop-ico .ico { width: 18px; height: 18px; }
.ap-drop-h { font-size: 14px; color: var(--text-2); }
.ap-drop-u { color: var(--text); font-weight: 500; text-decoration: underline; text-decoration-color: var(--border-2); text-underline-offset: 3px; transition: text-decoration-color .15s ease; }
.ap-drop:hover .ap-drop-u { text-decoration-color: var(--text); }
.ap-drop-hint { font-size: 12.5px; color: var(--muted); max-width: 34ch; text-wrap: pretty; }
.ap-drop.has-pic { gap: 10px; padding: 8px 8px 10px; min-height: 0; border-style: solid; border-color: var(--border); }
.ap-drop-frame { display: block; width: 100%; border-radius: var(--r-sm); overflow: hidden; background: var(--panel-3); }
.ap-drop-img { display: block; width: 100%; max-height: 380px; object-fit: contain; }
/* under the picture, never on it: an ad's title is often top right */
.ap-drop-swap {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  font-size: 12px; border-radius: var(--r-sm); background: var(--panel); color: var(--text); border: 1px solid var(--border);
  transition: border-color .15s ease;
}
.ap-drop:hover .ap-drop-swap { border-color: var(--border-2); }
.ap-drop-swap .ico { width: 13px; height: 13px; }

.ap-opts { display: flex; flex-direction: column; gap: var(--s3); }
.ap-opts:empty { display: none; }
.ap-field { display: flex; flex-direction: column; gap: 6px; }
.ap-seg { align-self: flex-start; flex-wrap: wrap; }
.ap-seg button { font-size: 12.5px; padding: 4px 12px; }

.ap-chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.ap-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px 7px 10px; font: inherit; font-size: 12.5px;
  border: 1px solid var(--border); border-radius: var(--r); background: var(--panel); color: var(--text-2); cursor: pointer;
  transition: border-color .15s ease;
}
.ap-chip:hover { border-color: var(--border-2); }
.ap-chip.is-sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--text); }
.ap-chip:focus-visible { outline: none; box-shadow: var(--focus); }
.ap-chip-shape { display: block; height: 16px; border: 1.5px solid currentColor; border-radius: 2px; opacity: .7; }
.ap-chip-shape[data-a="1:1"] { width: 16px; }
.ap-chip-shape[data-a="4:5"] { width: 13px; }
.ap-chip-shape[data-a="9:16"] { width: 9px; }

.ap-go { align-self: stretch; justify-content: center; gap: 10px; min-height: 40px; }
.ap-go-cost { font-family: var(--mono); font-size: 12px; opacity: .82; font-variant-numeric: tabular-nums; }
.ap-fine { margin: -8px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.ap-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: ap-spin .8s linear infinite; }
@keyframes ap-spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------- the right side */
.ap-stage { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.ap-stage.is-empty { padding: var(--s4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--panel-2); }
.ap-example { width: 100%; max-width: 480px; margin: 0 auto; }
.ap-cap { margin: 0; font-size: 12.5px; color: var(--muted); text-wrap: pretty; }
.ap-stage.is-empty .ap-cap { text-align: center; }

/* live progress: the picture being worked on, then the steps with their own clocks */
.ap-progress { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 300px); gap: var(--s4); align-items: start; padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--panel); }
.ap-making { position: relative; border-radius: var(--r); overflow: hidden; background: var(--panel-3); }
.ap-making img { display: block; width: 100%; max-height: 60vh; object-fit: contain; filter: saturate(.6) brightness(.94); }
/* a slow light crosses the picture while it is being made */
.ap-scan {
  position: absolute; top: 0; bottom: 0; left: 0; width: 34%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .22), transparent);
  animation: ap-scan 2.4s cubic-bezier(.45, 0, .55, 1) infinite;
}
@keyframes ap-scan { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
.ap-progress-body { display: flex; flex-direction: column; gap: var(--s3); padding: 4px 4px 4px 0; }
.ap-progress-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.ap-progress-h { font-size: 14px; font-weight: 600; }
.ap-clock { font-family: var(--mono); font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.ap-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ap-step { position: relative; display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 10px; padding: 7px 0; font-size: 13px; color: var(--muted); }
/* the rail between two dots */
.ap-step + .ap-step::before { content: ''; position: absolute; left: 8.5px; top: -7px; height: 14px; width: 1px; background: var(--border-2); }
.ap-step.is-done + .ap-step::before { background: var(--ok-line); }
.ap-step-dot { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--border-2); background: var(--panel); box-sizing: border-box; }
.ap-step-dot .ico { width: 11px; height: 11px; }
.ap-step.is-done { color: var(--text-2); }
.ap-step.is-done .ap-step-dot { border-color: var(--ok); background: var(--ok); color: var(--panel); }
.ap-step.is-now { color: var(--text); font-weight: 500; }
.ap-step.is-now .ap-step-dot { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ap-step.is-now .ap-step-dot::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: ap-pulse 1.2s ease-in-out infinite; }
@keyframes ap-pulse { 50% { opacity: .35; } }
.ap-step-t { font-family: var(--mono); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }

/* failure */
.ap-fail { display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding: var(--s4); border: 1px solid var(--danger-line); border-radius: var(--r-lg); background: var(--danger-soft); color: var(--text); }
.ap-fail > .ico { width: 18px; height: 18px; color: var(--danger); margin-top: 1px; }
.ap-fail-h { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.ap-fail-p { margin: 0 0 var(--s3); font-size: 13px; color: var(--text-2); }
.ap-fail .btn .ico { width: 14px; height: 14px; }

/* result */
.ap-view { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.ap-view-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 30px; }
.ap-view-h { font-size: 14px; font-weight: 600; }

/* the compare slider: both pictures in one box of the result's shape, each `contain` */
.ap-cmp { --ratio: 1; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.ap-cmp-stage {
  --pos: 50; position: relative; width: min(100%, calc(70vh * var(--ratio))); margin: 0 auto; overflow: hidden;
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--panel-3);
  cursor: ew-resize; touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.ap-cmp-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.ap-cmp-img.is-after { clip-path: inset(0 0 0 calc(var(--pos) * 1%)); }
.ap-cmp-line {
  position: absolute; top: 0; bottom: 0; left: calc(var(--pos) * 1%); width: 0; pointer-events: none;
  border-left: 1.5px solid rgba(255, 255, 255, .95); filter: drop-shadow(0 0 3px rgba(0, 0, 0, .3));
}
/* low on the picture: never on the ad's title or price */
.ap-cmp-knob {
  position: absolute; top: 86%; left: -.75px; transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border-radius: 50%; background: #FFFFFF; color: #3F444D; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.ap-cmp-knob .ico { width: 12px; height: 12px; margin: 0 -2px; }
.ap-cmp-stage.is-drag .ap-cmp-knob { transform: translate(-50%, -50%) scale(1.08); }
.ap-cmp-range { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ap-cmp:focus-within .ap-cmp-stage { box-shadow: var(--focus); }
.ap-cmp-legend { width: min(100%, calc(70vh * var(--ratio))); margin: 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--s2); font-size: 12px; color: var(--text-2); }
.ap-cmp-legend > :last-child { text-align: right; }
.ap-cmp-hint { color: var(--muted); }

/* side by side: two equal frames, each picture whole */
.ap-sides { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.ap-side { margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ap-side-frame { display: block; width: 100%; max-height: 64vh; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; background: var(--panel-3); }
.ap-side-frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.ap-side figcaption { font-size: 12px; color: var(--text-2); }

/* a format that failed while the others were made */
.ap-check { margin: 0; display: flex; align-items: flex-start; gap: 8px; padding: 9px 12px; border-radius: var(--r); font-size: 13px; }
.ap-check > .ico { flex: none; width: 15px; height: 15px; margin-top: 2px; }
.ap-check.is-warn { border: 1px solid var(--warn-line); background: var(--warn-soft); color: var(--text); }
.ap-check.is-warn > .ico { color: var(--warn); }

.ap-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s3); }
.ap-facts { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 12.5px; color: var(--muted); }
.ap-facts > span { font-variant-numeric: tabular-nums; }
.ap-facts-link { color: var(--text-2); text-decoration: underline; text-decoration-color: var(--border-2); text-underline-offset: 3px; }
.ap-facts-link:hover { color: var(--text); text-decoration-color: var(--text); }
.ap-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.ap-actions .ico, .ap-size .ico { width: 14px; height: 14px; }

.ap-sizes { display: flex; align-items: flex-end; gap: var(--s4); overflow-x: auto; padding-bottom: 4px; }
.ap-size { margin: 0; flex: none; display: flex; flex-direction: column; gap: 8px; }
.ap-size-frame { display: block; height: min(48vh, 380px); border-radius: var(--r); border: 1px solid var(--border); overflow: hidden; background: var(--panel-3); }
.ap-size-frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.ap-size figcaption { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.ap-tag-inline { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.ap-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r); background: var(--panel); }
.ap-lines li { display: grid; grid-template-columns: 1fr 16px 1fr; align-items: center; gap: var(--s2); padding: 8px 12px; font-size: 13px; }
.ap-lines li + li { border-top: 1px solid var(--border); }
.ap-lines .ico { width: 14px; height: 14px; color: var(--muted); }
.ap-from { color: var(--muted); }
.ap-to { color: var(--text); }

@media (max-width: 1080px) {
  .ap-progress { grid-template-columns: 1fr; }
  .ap-making img { max-height: 40vh; }
}
@media (max-width: 760px) {
  .ap-shell { gap: var(--s4); }
  .ap-grid { grid-template-columns: 1fr; gap: var(--s3); }
  .ap-work { grid-template-columns: 1fr; gap: var(--s4); }
  .ap-drop { min-height: 180px; }
  .ap-shots { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
  .ap-sizes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); overflow: visible; }
  .ap-size { flex: initial; min-width: 0; }
  .ap-size-frame { width: 100%; height: auto; }
  .ap-size figcaption { flex-wrap: wrap; }
  .ap-cmp-hint { display: none; }
  .ap-cmp-legend { grid-template-columns: 1fr 1fr; }
  .ap-foot { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  .ap-scan, .ap-spin, .ap-step.is-now .ap-step-dot::after { animation: none; }
  .ap-cmp-knob { transition: none; }
}
