/* Hallmark · shape: app screen · genre: atmospheric · theme: Midnight (deal 1/3, seed template-editor-motion-video-b3da·daf94919·2026-11-16·r0)
 * nav: top bar, wordmark plus one mode switch and export · signature: the live preview beside the template's own fields · states: loading, empty, error, full
 * axes: dark/grotesk-sans/cool · posture: committed · contrast: pass · v2.0.0 */
/* Hallmark · pre-emit critique: P2 H2 E2 S2 R1 V2 · weakest: R, the editor is one panel of fields, so the timeline waits behind Advanced instead of crowding the page */
/* Hallmark · redesign: polish (owner's brief) · home: four small cards in one row that play their own muted previews after 2.5 s · the panel has two tabs, Photos and Text · phone editor keeps the preview fixed on top and scrolls only the panel */
@import url("./tokens.css");
@import url("./base.css");

:root {
  --bar-h: 56px;
  --panel-w: 400px;
  --control-h: 36px;
  --tl-row: 28px;
  --tl-name: 200px;
  --k-media: var(--color-accent-2);
  --k-text: var(--color-ink-2);
  --k-group: var(--color-muted);
  --k-null: var(--color-rule-2);
  --font-mona: "Mona Sans", ui-sans-serif, system-ui, sans-serif;
  --well: oklch(10% 0.04 264);
}

body { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  min-height: var(--control-h); padding: 0 var(--space-md);
  border: 1px solid var(--color-rule-2); border-radius: var(--radius-pill);
  background: transparent; color: var(--color-ink); font-weight: 500; font-size: var(--text-sm);
  cursor: pointer; transition: background-color var(--dur-micro) var(--ease-out), opacity var(--dur-micro) var(--ease-out);
}
.btn:hover { background: var(--color-paper-3); }
.btn:active { opacity: 0.8; }
.btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; transition: none; }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--color-paper-2); border-color: var(--color-rule); color: var(--color-muted); cursor: not-allowed; }
.btn.primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-ink); }
.btn.primary:hover { background: var(--color-ink-2); border-color: var(--color-ink-2); }
.btn.quiet { border-color: transparent; }
.btn.quiet:hover { background: var(--color-paper-3); }
.icon-btn { width: var(--control-h); padding: 0; }
.icon-btn svg { width: 18px; height: 18px; }

.seg { display: inline-flex; border: 1px solid var(--color-rule-2); }
.seg button {
  min-height: calc(var(--control-h) - 2px); padding: 0 var(--space-md); border: 0; background: transparent;
  color: var(--color-muted); font-weight: 500; font-size: var(--text-sm); cursor: pointer;
}
.seg button:hover { color: var(--color-ink); background: var(--color-paper-3); }
.seg button[aria-pressed="true"] { background: var(--color-paper-3); color: var(--color-ink); box-shadow: inset 0 -2px 0 var(--color-accent); }
.seg button:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; }

.field { display: grid; gap: var(--space-2xs); }
.field label, .label { font-size: var(--text-sm); font-weight: 500; color: var(--color-muted); }
.field .font-name { font-size: var(--text-xs); color: var(--color-muted); }
.input {
  width: 100%; min-height: 40px; padding: var(--space-xs) var(--space-sm);
  background: var(--well); color: var(--color-ink); border: 1px solid var(--color-rule-2); border-radius: 0;
  font-size: 1.125rem; line-height: 1.3; resize: vertical;
}
.input:hover { border-color: var(--color-muted); }
.input:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 0; border-color: var(--color-focus); }
.input:disabled { background: var(--color-paper-2); color: var(--color-muted); border-color: var(--color-rule); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--color-error); }

input[type="range"] { accent-color: var(--color-accent); width: 100%; min-height: 28px; background: transparent; }
input[type="range"]:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
select.input { font-size: var(--text-sm); }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: var(--z-sticky-nav);
  height: var(--bar-h); display: flex; align-items: center; gap: var(--space-md);
  padding: 0 var(--space-md); background: var(--color-paper); border-bottom: 1px solid var(--color-rule);
}
.wordmark {
  font-family: var(--font-mona); font-weight: 300; font-stretch: 125%; font-size: var(--text-lg);
  letter-spacing: var(--tracking-display); white-space: nowrap; color: var(--color-ink);
  background: none; border: 0; padding: 0; cursor: pointer;
}
.wordmark:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 4px; }
.bar .crumb { color: var(--color-muted); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar .grow { flex: 1; }

/* ---------- in-app browser notice ---------- */
.inapp { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-sm) var(--space-md); background: var(--color-paper-3); border-bottom: 1px solid var(--color-rule-2); }
.inapp[hidden] { display: none; }
.inapp p { flex: 1; min-width: 0; font-size: var(--text-sm); color: var(--color-ink); }
.inapp .btn { flex: none; }

/* ---------- home ---------- */
.home { width: 100%; max-width: var(--container); margin-inline: auto; padding: var(--space-2xl) var(--gutter) var(--space-3xl); }
.home-head { display: flex; align-items: end; justify-content: space-between; gap: var(--space-lg); flex-wrap: wrap; margin-bottom: var(--space-xl); }
.home-head h1 { font-size: var(--text-3xl); font-stretch: 125%; }
.home-head p { color: var(--color-muted); margin-top: var(--space-xs); }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-lg); max-width: 960px; }
.tcard {
  display: grid; gap: var(--space-sm); padding: 0; border: 0; background: none; color: inherit; text-align: left; cursor: pointer;
}
.tcard .pic { position: relative; display: block; aspect-ratio: var(--ar, 4 / 5); background: var(--color-paper-2); color: var(--color-ink); overflow: hidden; box-shadow: var(--shadow-card); outline: 1px solid transparent; outline-offset: 3px; }
.tcard .pic img { width: 100%; height: 100%; object-fit: cover; }
.tcard .pic video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity var(--dur-long) var(--ease-out); }
.tcard.live .pic video { opacity: 1; }
.tcard:hover .pic { outline-color: var(--color-rule-2); }
.tcard:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 4px; }
.tcard .name { font-weight: 500; }
.tcard .meta { font-size: var(--text-sm); color: var(--color-muted); font-variant-numeric: tabular-nums; }
.skeleton .pic { animation: pulse 1.4s var(--ease-in-out) infinite; }
.skeleton .line { height: 12px; background: var(--color-paper-2); width: 60%; }
@keyframes pulse { 50% { opacity: 0.55; } }
.note { padding: var(--space-xl); background: var(--color-paper-2); display: grid; gap: var(--space-sm); justify-items: start; }
.note.error { border-left: 2px solid var(--color-error); }

/* ---------- editor ---------- */
.editor { height: calc(100dvh - var(--bar-h)); min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); grid-template-rows: minmax(0, 1fr) auto; }
.editor[hidden] { display: none; }
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--color-paper-2); }
.frame-wrap { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: var(--space-lg); overflow: hidden; }
#c { display: block; background: var(--well); box-shadow: var(--shadow-card); }
.stage-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--color-ink); background: var(--color-paper-2) center / contain no-repeat; }
.transport { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-xs) var(--space-md); border-top: 1px solid var(--color-rule); background: var(--color-paper); }
.transport .time { font-variant-numeric: tabular-nums; font-size: var(--text-sm); color: var(--color-muted); white-space: nowrap; min-width: 9.5em; text-align: right; }

.panel { background: var(--color-paper); color: var(--color-ink); border-left: 1px solid var(--color-rule); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.panel > section { flex: 1; min-height: 0; overflow-y: auto; align-content: start; }
.panel section { padding: var(--space-lg) var(--space-md); display: grid; gap: var(--space-md); }
.panel section + section { border-top: 1px solid var(--color-rule); }
.panel h2 { font-size: var(--text-lg); font-stretch: 125%; }
.panel .sub { font-size: var(--text-sm); color: var(--color-muted); }
.field.on .input { border-color: var(--color-accent-2); }
.ptabs { flex: none; display: grid; grid-template-columns: 1fr 1fr; background: var(--color-paper); border-bottom: 1px solid var(--color-rule); }
.ptabs button {
  min-height: 48px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--color-muted);
  font-weight: 500; font-size: var(--text-md); cursor: pointer; transition: color var(--dur-micro) var(--ease-out);
}
.ptabs button:hover { color: var(--color-ink); background: var(--color-paper-2); }
.ptabs button[aria-selected="true"] { color: var(--color-ink); border-bottom-color: var(--color-accent); }
.ptabs button:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; transition: none; }
.panel section[hidden] { display: none; }
.panel section { grid-template-columns: minmax(0, 1fr); } /* long captions never push the panel sideways */

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-sm); }
.tile {
  position: relative; padding: 0; border: 1px solid var(--color-rule); background: var(--well); cursor: pointer; color: var(--color-ink);
  display: grid; gap: 0; text-align: left;
}
.tile .shot { position: relative; display: block; aspect-ratio: var(--ar, 3 / 4); overflow: hidden; }
.tile .shot img, .tile .shot video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile .shot .missing { position: absolute; inset: 0; display: grid; place-items: center; }
.tile .shot .missing { font-size: var(--text-xs); color: var(--color-muted); padding: var(--space-xs); text-align: center; }
.tile .cap { white-space: nowrap; display: flex; justify-content: space-between; gap: var(--space-2xs); padding: var(--space-2xs) var(--space-xs); font-size: var(--text-xs); color: var(--color-muted); }
.tile:hover { border-color: var(--color-rule-2); background: var(--color-paper-3); }
.tile:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.tile.on { border-color: var(--color-accent-2); }
.tile.changed .cap .k { color: var(--color-accent); }

/* ---------- advanced ---------- */
.adv { grid-column: 1 / -1; border-top: 1px solid var(--color-rule); background: var(--color-paper); display: grid; grid-template-rows: auto minmax(0, 1fr); height: 280px; }
.adv-tabs { display: flex; gap: var(--space-2xs); padding: var(--space-xs) var(--space-md); border-bottom: 1px solid var(--color-rule); align-items: center; }
.adv-tabs button { min-height: 32px; padding: 0 var(--space-sm); background: none; border: 0; color: var(--color-muted); font-weight: 500; font-size: var(--text-sm); cursor: pointer; border-bottom: 2px solid transparent; }
.adv-tabs button:hover { color: var(--color-ink); }
.adv-tabs button[aria-selected="true"] { color: var(--color-ink); border-bottom-color: var(--color-accent); }
.adv-tabs button:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; }
.adv-pane { overflow: auto; min-height: 0; }
.tl-head { display: flex; height: 26px; background: var(--color-paper); border-bottom: 1px solid var(--color-rule); }
.tl-head .names { width: var(--tl-name); flex: none; padding: 0 var(--space-sm); display: flex; align-items: center; font-size: var(--text-xs); color: var(--color-muted); border-right: 1px solid var(--color-rule); }
.ruler { position: relative; flex: 1; cursor: ew-resize; touch-action: none; }
.ruler span { position: absolute; top: 5px; font-size: var(--text-xs); color: var(--color-muted); transform: translateX(4px); font-variant-numeric: tabular-nums; }
.ruler i { position: absolute; bottom: 0; width: 1px; height: 6px; background: var(--color-rule-2); }
#tab-timeline:not([hidden]) { display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.tl-rows { position: relative; overflow: auto; min-height: 0; }
.lrow { display: flex; height: var(--tl-row); border-bottom: 1px solid var(--color-rule); cursor: pointer; background: var(--color-paper); width: 100%; padding: 0; border-left: 0; border-right: 0; border-top: 0; color: var(--color-ink); text-align: left; }
.lrow:hover { background: var(--color-paper-2); }
.lrow:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; }
.lrow[aria-current="true"] { background: var(--color-paper-3); }
.lrow .nm { width: var(--tl-name); flex: none; display: flex; align-items: center; gap: var(--space-xs); padding: 0 var(--space-sm); font-size: var(--text-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--color-rule); }
.lrow .kind { flex: none; width: 3.6em; color: var(--color-muted); }
.lrow .track { position: relative; flex: 1; }
.bar-seg { position: absolute; top: 6px; bottom: 6px; background: var(--k, var(--color-muted)); opacity: 0.75; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--color-ink); pointer-events: none; z-index: var(--z-raised); transform: translateX(var(--x, 0px)); }
.ph-wrap { position: absolute; top: 0; bottom: 0; left: var(--tl-name); right: 0; pointer-events: none; }
.list { display: grid; }
.list .row { display: flex; justify-content: space-between; align-items: center; gap: var(--space-md); padding: var(--space-xs) var(--space-md); border-bottom: 1px solid var(--color-rule); font-size: var(--text-sm); }
.list .row .muted { color: var(--color-muted); }
.status-ok { color: var(--color-success); } .status-approx { color: var(--color-accent); } .status-none { color: var(--color-error); }

/* ---------- dialogs ---------- */
dialog { padding: 0; border: 0; background: var(--color-paper-2); color: var(--color-ink); box-shadow: var(--shadow-card); max-width: min(720px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: color-mix(in oklab, var(--color-paper) 75%, transparent); }
dialog[open] { animation: settle var(--dur-short) var(--ease-out); }
@keyframes settle { from { opacity: 0.6; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-md) var(--space-lg); border-bottom: 1px solid var(--color-rule); }
.dlg-head h2 { font-size: var(--text-lg); font-stretch: 125%; }
.dlg-body { padding: var(--space-lg); display: grid; gap: var(--space-md); }
.dlg-foot { display: flex; justify-content: flex-end; gap: var(--space-sm); padding: var(--space-md) var(--space-lg); border-top: 1px solid var(--color-rule); }
.crop-view { justify-self: center; position: relative; background: var(--well); touch-action: none; cursor: grab; max-width: 100%; }
.crop-view:active { cursor: grabbing; }
.crop-view canvas { display: block; width: 100%; height: 100%; }
.crop-busy { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in oklab, var(--well) 80%, transparent); font-size: var(--text-xs); color: var(--color-muted); }
.crop-busy[hidden] { display: none; }
.crop-view::after { content: ""; position: absolute; inset: 0; pointer-events: none; outline: 1px solid color-mix(in oklab, var(--color-ink) 35%, transparent); outline-offset: -1px;
  background: linear-gradient(to right, transparent 33.2%, color-mix(in oklab, var(--color-ink) 18%, transparent) 33.3%, transparent 33.4%, transparent 66.6%, color-mix(in oklab, var(--color-ink) 18%, transparent) 66.7%, transparent 66.8%),
              linear-gradient(to bottom, transparent 33.2%, color-mix(in oklab, var(--color-ink) 18%, transparent) 33.3%, transparent 33.4%, transparent 66.6%, color-mix(in oklab, var(--color-ink) 18%, transparent) 66.7%, transparent 66.8%); }
.parts { border: 0; padding: 0; margin: 0; display: grid; gap: var(--space-sm); }
.part-opts { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
.part-opt { display: inline-flex; align-items: center; gap: var(--space-xs); min-height: 44px; padding: 0 var(--space-sm); border: 1px solid var(--color-rule); border-radius: 8px; cursor: pointer; }
.part-opt .k { color: var(--color-muted); font-variant-numeric: tabular-nums; }
#cutDlg[open] { display: flex; flex-direction: column; max-height: calc(100dvh - 16px); }
#cutDlg .dlg-head, #cutDlg .dlg-foot { flex: none; padding-block: var(--space-sm); }
#cutDlg .dlg-body { flex: 1; min-height: 0; overflow-y: auto; padding-block: var(--space-sm); gap: var(--space-sm); grid-auto-rows: max-content; }
.cut-view { justify-self: center; position: relative; background: var(--well); min-width: 160px; min-height: 160px; max-width: 100%; display: grid; place-items: center; }
.cut-view canvas { display: block; max-width: 100%; height: auto; cursor: pointer; touch-action: manipulation; }
.crop-tools { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); gap: var(--space-sm); align-items: center; }
.crop-presets { display: flex; justify-content: center; gap: var(--space-sm); }
/* the photo dialog never grows past the screen: its middle scrolls, Apply stays in sight */
#cropDlg[open] { display: flex; flex-direction: column; max-height: calc(100dvh - 16px); }
#cropDlg .dlg-head, #cropDlg .dlg-foot { flex: none; padding-block: var(--space-sm); }
#cropDlg .dlg-body { flex: 1; min-height: 0; overflow-y: auto; padding-block: var(--space-sm); gap: var(--space-sm); grid-auto-rows: max-content; }
.opt { display: grid; grid-template-columns: 8rem minmax(0, 1fr); gap: var(--space-sm); align-items: center; }
.meter { height: 2px; background: var(--color-rule-2); }
.meter div { height: 100%; width: 0; background: var(--color-accent); transform-origin: left; }
.msg { font-size: var(--text-sm); color: var(--color-muted); min-height: 1.4em; }

.toast { position: fixed; left: 50%; bottom: var(--space-lg); transform: translateX(-50%); z-index: var(--z-toast); background: var(--color-paper-3); color: var(--color-ink); padding: var(--space-sm) var(--space-md); box-shadow: var(--shadow-card); font-size: var(--text-sm); max-width: calc(100vw - 32px); }

@media (max-width: 60rem) {
  /* one screen, no long page: the preview stays on top, only the photos (or Advanced) scroll under it */
  .editor { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: calc(100dvh - var(--bar-h)); }
  .frame-wrap { height: 50dvh; flex: none; padding: var(--space-sm); }
  .panel { border-left: 0; border-top: 1px solid var(--color-rule); }
  .panel section { padding: var(--space-md); gap: var(--space-sm); }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-xs); }
  .tile .cap { padding: var(--space-3xs) var(--space-2xs); }
  .tile .cap .k { display: none; }
  .tile.changed { border-color: var(--color-accent); }
  body.mode-advanced .editor { grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr); }
  body.mode-advanced .frame-wrap { height: 38dvh; }
  .adv { height: auto; min-height: 0; }
  :root { --tl-name: 130px; }
  .bar .crumb { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  dialog[open] { animation: none; }
  .skeleton .pic { animation: none; }
  .tcard .pic video { transition: none; }
}

.field-list, .stack { display: grid; gap: var(--space-md); }
.check { display: inline-flex; gap: var(--space-xs); align-items: center; font-size: var(--text-sm); color: var(--color-ink); }
.check input { accent-color: var(--color-accent); width: 18px; height: 18px; }
.check input:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.dlg-foot .grow { flex: 1; }

@media (max-width: 40rem) {
  .bar { gap: var(--space-xs); padding: 0 var(--space-sm); }
  .wordmark { font-size: var(--text-md); }
  .seg button { padding: 0 var(--space-sm); }
  .bar .btn { padding: 0 var(--space-sm); }
  .home { padding-top: var(--space-xl); }
  .home-head h1 { font-size: var(--text-2xl); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-md); }
  .dlg-body, .dlg-head, .dlg-foot { padding-inline: var(--space-md); }
  .opt { grid-template-columns: minmax(0, 1fr); }
}

/* narrow phones: the name, the Simple / Advanced switch and Export share one row */
@media (max-width: 25rem) {
  .wordmark { font-size: var(--text-sm); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .seg button, .bar .btn { padding: 0 var(--space-xs); }
  .bar .btn { flex: none; }
}

/* ---------- touch ---------- */
html { -webkit-tap-highlight-color: transparent; }
button, input, label, select { touch-action: manipulation; } /* no double-tap wait */
/* scrolling a list never drags the page behind it */
.panel > section, .dlg-body, .tl-rows, .adv-pane { overscroll-behavior: contain; }
body.in-editor { overscroll-behavior: none; } /* no pull-to-refresh while editing */
.tile { min-width: 0; }
.tile .shot { background: oklch(38% 0.02 264); } /* see-through pictures (logos, cut-outs) stay visible */
.tile .cap { overflow: hidden; }
.tile .cap > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (pointer: coarse) {
  :root { --control-h: 44px; }
  input[type="range"] { min-height: 40px; }
  .tile, .tcard .pic, .btn { transition: transform var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out); }
  /* every press answers at once */
  .tile:active, .btn:active { transform: scale(0.96); }
  .tcard:active .pic { transform: scale(0.98); }
}
@media (prefers-reduced-motion: reduce) { .tile, .tcard .pic, .btn { transition: none; } }

/* export in progress: the preview is not drawn on screen */
body.exporting #c { visibility: hidden; }
