/*
 * motor.css – layoutet for plakatmotoren (/kortkunst/ og senere /plakat/). Farver, knapper, valgbare felter,
 * paneler, felter og beskeder kommer fra designsystemet /css/latl.css.
 *
 * Mobil først: standardlayoutet er til ~380 px; breakpoints udvider. Touch-mål er mindst 44 px.
 * På mobil står trinnets primære knap i en fast bjælke i bunden (.cta-bar); fra 900 px står den i panelet.
 */

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 400 1rem/1.5 var(--sans);
    color: var(--text);
    background: var(--paper);
}

[hidden] { display: none !important; }

.motor { max-width: var(--wrap); margin: 0 auto; padding: 12px var(--gutter) calc(112px + env(safe-area-inset-bottom)); }

/* Intro (kun trin 1) */
.intro { margin: 4px 0 14px; }
.intro .kicker { margin-bottom: 4px; }
.intro__title { margin: 0 0 10px; font: 400 clamp(1.75rem, 7vw, 2.75rem)/1.08 var(--stencil); color: var(--ink); }
.intro__steps { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; counter-reset: intro; font-size: .9375rem; }
.intro__steps li { display: flex; align-items: center; gap: 10px; counter-increment: intro; }
.intro__steps li::before {
    content: counter(intro); flex: none; display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--on-dark); font-size: .75rem; font-weight: 700;
}

/* Trin */
.steps { display: flex; gap: 6px; margin: 0 0 12px; padding: 0 0 2px; list-style: none; font-size: .8125rem; overflow-x: auto; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.step { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--surface); white-space: nowrap; }
.step span { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--cream); color: var(--ink); font-size: .6875rem; font-weight: 700; }
.step.is-current { border-color: var(--ink); background: var(--ink); color: var(--on-dark); }
.step.is-current span { background: var(--lime, #c8d92f); color: var(--ink); }
.step.is-done { border-color: var(--ink); color: var(--ink); }

.motor-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.pane-title { margin: 0 0 4px; font: 400 1.375rem/1.15 var(--stencil); color: var(--ink); }

/* Panelet */
.panel-summary { margin: 6px 0 0; font-size: .875rem; color: var(--ink-soft); }
.motor-panel .button--block + .button--block { margin-top: 8px; }
.motor-panel .hint { margin: 0 0 10px; }
.motor-panel .button--small { min-height: 44px; }
.option { min-height: 44px; }

/* Primær knap: fast bjælke i bunden på mobil */
.cta-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;        /* under cookiebanneret (50/51 i latl.css) */
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--cream); box-shadow: 0 -4px 16px rgba(4, 41, 64, .12);
}
.cta-bar .messages:not(:empty) { margin-top: 8px; }

/* Trin 1: søgning, kort med ramme */
.search { margin-bottom: 8px; }
.search .input { min-height: 44px; font-size: 1rem; }
.search .button { min-height: 44px; }
.search-results { margin: 0 0 8px; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: var(--radius-small); max-height: 240px; overflow: auto; background: var(--surface); }
.search-results li + li { border-top: 1px solid var(--cream); }
.search-results button { display: block; width: 100%; min-height: 44px; padding: 10px 12px; border: 0; background: none; text-align: left; font: inherit; font-size: .9375rem; color: var(--text); cursor: pointer; }
.search-results button:hover, .search-results button:focus-visible { background: var(--selected-bg); }

.map-wrap {
    position: relative; height: 62vh; height: 62svh; min-height: 320px; max-height: 760px;
    border-radius: var(--radius); overflow: hidden; border: 1px solid var(--cream); touch-action: none;
    isolation: isolate;     /* Leaflets z-index (op til 1000) holdes inde i kortet, under den faste knapbjælke */
}
.map { position: absolute; inset: 0; }
.frame {
    position: absolute; left: 50%; top: 50%; z-index: 500; pointer-events: none;
    width: 60%; height: 80%; transform: translate(-50%, -50%);
    box-shadow: 0 0 0 9999px rgba(246, 245, 230, .62), inset 0 0 0 2px var(--ink);
}
.pane .hint { margin: 8px 0 0; }

/* Formater: 3 pr. række, med en lille figur i formatets forhold */
.formats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.formats .option { min-height: 64px; font-size: .9375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.format-shape { display: block; height: 22px; aspect-ratio: var(--r); border: 2px solid currentColor; border-radius: 2px; opacity: .55; }
.option[aria-pressed="true"] .format-shape { opacity: 1; }

.swatches { display: flex; gap: 3px; }
.swatches i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(4, 41, 64, .2); }

/* Trin 2: forslag */
.forslag-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.underpaint { margin: 0; flex: none; width: 64px; }
.underpaint canvas { display: block; width: 100%; height: auto; border-radius: 3px; box-shadow: 0 1px 4px rgba(4, 41, 64, .25); }
.underpaint figcaption { margin-top: 2px; text-align: center; font-size: .6875rem; color: var(--muted); }
.forslag-status { flex: 1; min-width: 0; }
.forslag-msg { margin: 0 0 6px; font-size: .9375rem; min-height: 1.5em; }
.progress { height: 6px; border-radius: 3px; background: var(--cream); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--secondary); transition: width .3s; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; }

.card { position: relative; margin: 0; }
.canvas-frame {
    position: relative; overflow: hidden; border-radius: 4px; background: #efe9dd;
    box-shadow: 0 2px 10px rgba(4, 41, 64, .18); cursor: pointer; aspect-ratio: var(--ratio, 3 / 4);
    -webkit-tap-highlight-color: transparent;
}
.card.is-selected .canvas-frame { outline: 3px solid var(--ink); outline-offset: 3px; }
.card .canvas-frame:focus-visible { outline: 3px solid var(--secondary); outline-offset: 3px; }
.canvas-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* Skelet, mens kortet venter på sin tur */
.canvas-frame.is-skeleton {
    background: linear-gradient(100deg, #efe9dd 30%, #f8f4ec 50%, #efe9dd 70%) 0 0 / 300% 100%;
    animation: shimmer 1.6s linear infinite;
}
.card.is-painting .canvas-frame { box-shadow: 0 0 0 2px var(--secondary), 0 2px 10px rgba(4, 41, 64, .18); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* Udgangsbilledet (undermaleri eller det valgte forslag) står på kortet fra start. Når kortets variant begynder,
   "bliver det vådt" over 3 s: blur 0→6 px, lidt mere mætning, og lærredstonen (.wash) toner ind. */
.canvas-frame img.base { transform: scale(1.04); }
.canvas-frame .wash { position: absolute; inset: 0; z-index: 1; background: #F1EADF; opacity: 0; pointer-events: none; }
.card.is-wet img.base { animation: wet 3s ease-out forwards; }
.card.is-wet .wash { animation: wash 3s ease-out forwards; }
@keyframes wet { from { filter: blur(0) saturate(1); } to { filter: blur(6px) saturate(1.25); } }
@keyframes wash { from { opacity: 0; } to { opacity: .35; } }

/* Previews fra trin 5 tones ind oven på hinanden ("maleriet kommer frem") */
.canvas-frame img.layer, .canvas-frame img.final { z-index: 2; }
.canvas-frame img.layer { animation: fade-in .4s ease-out both; }
/* Det færdige billede males på med en penselafsløring fra venstre mod højre */
.canvas-frame img.final.is-revealing {
    -webkit-mask-image: linear-gradient(100deg, #000 40%, transparent 60%);
            mask-image: linear-gradient(100deg, #000 40%, transparent 60%);
    -webkit-mask-size: 300% 100%;
            mask-size: 300% 100%;
    -webkit-mask-position: 100% 0;
            mask-position: 100% 0;
    animation: brush-reveal 2s cubic-bezier(.45, .05, .3, 1) forwards;
}
.canvas-frame img.final:not(.is-revealing) { animation: fade-in .3s ease-out both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes brush-reveal {
    from { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
    to   { -webkit-mask-position: 0 0;    mask-position: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
    .canvas-frame.is-skeleton, .canvas-frame img.layer, .canvas-frame img.final { animation: none !important; -webkit-mask-image: none !important; mask-image: none !important; }
    .card.is-wet img.base { animation: none; filter: blur(6px) saturate(1.25); }
    .card.is-wet .wash { animation: none; opacity: .35; }
}

.card-note { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; padding: 8px; text-align: center; color: var(--muted); font-size: .8125rem; }
.card.is-error .canvas-frame { background: var(--error-bg); cursor: default; }
.card figcaption { margin-top: 6px; }
.card .more {
    display: flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; padding: 6px 10px;
    border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
    font: inherit; font-size: .875rem; font-weight: 600; color: var(--ink); cursor: pointer;
}
.card .more:hover:not([disabled]) { border-color: var(--ink); }
.card .more[disabled] { opacity: .35; cursor: default; }

/* Trin 3: det valgte i stor visning */
.selected-big { margin: 0; display: flex; justify-content: center; }
.selected-big img { display: block; width: 100%; max-width: 640px; max-height: 78vh; object-fit: contain; border-radius: 4px; background: #efe9dd; box-shadow: 0 6px 24px rgba(4, 41, 64, .25); }

@media (min-width: 640px) {
    .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 14px; }
    .underpaint { width: 88px; }
}

@media (min-width: 900px) {
    .motor { padding-bottom: 48px; }
    .motor-layout { grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; }
    .motor-panel { position: sticky; top: 16px; }
    .cta-bar { position: static; padding: 14px 16px; background: none; box-shadow: none; }
    .map-wrap { height: min(76vh, 820px); max-height: none; min-height: 460px; }
    .intro { display: grid; grid-template-columns: auto 1fr; gap: 4px 32px; align-items: end; }
    .intro .kicker, .intro__title { grid-column: 1; }
    .intro__steps { grid-column: 2; grid-row: 1 / span 2; justify-self: start; }
}

@media (min-width: 1100px) {
    .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
