/* Draci Strakonice: the motion layer. Every layout loads it last.
   Feedback on every control, disclosures, dialogs and flashes in and out, scroll reveal on public pages, a one-time
   entrance in the panel, view transitions between pages and a few scroll-driven extras.
   - Moves animate transform, opacity, clip-path and filter (a disclosure also its height); colours fade.
   - Hover only for fine pointers. No will-change: the browser promotes what animates.
   - A hidden starting state needs html.js, a screen and prefers-reduced-motion: no-preference, so content never waits
     for a script that did not run. Under reduced motion everything is in place and every change is instant (base.css).
   Durations --dur-1…4, easings --ease-*, both in tokens.css. */

/* ================= sibling index for staggers: --n is 0 for a first child … 7 from the eighth on ================= */
@property --n { syntax: "<integer>"; inherits: false; initial-value: 0; }
:where(:nth-child(2)) { --n: 1; }
:where(:nth-child(3)) { --n: 2; }
:where(:nth-child(4)) { --n: 3; }
:where(:nth-child(5)) { --n: 4; }
:where(:nth-child(6)) { --n: 5; }
:where(:nth-child(7)) { --n: 6; }
:where(:nth-child(n + 8)) { --n: 7; }

/* ================= feedback: every control eases between its states ================= */
:root {
  --motion-control:
    transform var(--dur-1) var(--ease-out), background-color var(--dur-2) ease, color var(--dur-2) ease,
    border-color var(--dur-2) ease, box-shadow var(--dur-2) ease, outline-color var(--dur-2) ease,
    text-decoration-color var(--dur-2) ease;
}
/* The focus ring fades in: transparent at rest (outline-style stays none, so forced colours draw nothing). */
:where(a, button, summary, input, select, textarea, [tabindex]) { outline-color: transparent; transition: var(--motion-control); }
:is(.btn, .segmented button, .icon-btn, .flash__close, .seat, .scope, .crew-chip, .side-nav a, .side-nav button, .bottom-nav a, .bottom-nav button) {
  transition: var(--motion-control);
}

/* Press: the control gives under the finger. */
:is(.icon-btn, .flash__close, .menu-btn, .menu-sheet__close, .scope, .crew-chip, .side-nav a, .side-nav button):active { transform: scale(0.97); }
.bottom-nav .bn-icon { transition: background-color var(--dur-2) ease, transform var(--dur-1) var(--ease-out); }
.bottom-nav :is(a, button):active .bn-icon { transform: scale(0.92); }
.blockmark__block { transition: transform var(--dur-3) var(--ease-out), outline-color var(--dur-2) ease; }
.blockmark__block:active { transform: translateY(-2px) scale(0.98); }

/* Fields: border and ring. */
:is(.input, .select, .textarea) {
  transition: border-color var(--dur-2) ease, box-shadow var(--dur-2) ease, background-color var(--dur-2) ease;
}

/* Checkbox: the mark draws itself, short arm then long arm. Radio: the dot grows. */
.check input:not(.switch) { transition: background-color var(--dur-2) ease, border-color var(--dur-2) ease, outline-color var(--dur-2) ease; }
.check input:not(.switch)::after { transition: transform var(--dur-2) var(--ease-out), opacity var(--dur-1) ease; }
.check input[type="checkbox"]:not(.switch)::after { transform: none; }
@media (prefers-reduced-motion: no-preference) {
  .check input[type="checkbox"]:not(.switch):checked::after { animation: check-draw var(--dur-3) var(--ease-out); }
}
@keyframes check-draw {
  0% { clip-path: polygon(14% 44%, 0 65%, 0 65%, 0 65%, 14% 44%, 14% 44%); }
  45% { clip-path: polygon(14% 44%, 0 65%, 50% 100%, 50% 100%, 43% 62%, 43% 62%); }
  100% { clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%); }
}

/* Switch: the thumb slides, and stretches a little while pressed. */
.switch { transition: background-color var(--dur-2) ease, outline-color var(--dur-2) ease; }
.switch::after { transition: transform var(--dur-2) var(--ease-out), scale var(--dur-1) var(--ease-out); }
.switch:active::after { scale: 1.15 1; }

/* Segmented answer: the fill slides to the chosen option and turns white with a navy edge on "no". */
@supports selector(:has(*)) {
  .segmented { position: relative; isolation: isolate; }
  .segmented::before {
    content: ""; position: absolute; z-index: -1; top: 4px; bottom: 4px; left: 4px;
    width: calc((100% - 12px) / 2);
    border-radius: var(--radius-control);
    background: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); /* taste-skill-ignore: the chosen option's edge, not elevation */
    opacity: 0; transform: scale(0.94);
    transition: transform var(--dur-3) var(--ease-out), opacity var(--dur-2) ease, background-color var(--dur-2) ease;
  }
  .segmented:has(> :nth-child(3))::before { width: calc((100% - 16px) / 3); }
  .segmented:has(> [aria-pressed="true"])::before { opacity: 1; transform: none; }
  .segmented:has(> :nth-child(2)[aria-pressed="true"])::before { transform: translateX(calc(100% + 4px)); }
  .segmented:has(> :nth-child(3)[aria-pressed="true"])::before { transform: translateX(calc(200% + 8px)); }
  .segmented:has(> .is-no[aria-pressed="true"])::before { background: var(--sheet); }
  .segmented button[aria-pressed="true"], .segmented button[aria-pressed="true"].is-no { background: transparent; border-color: transparent; }
}

/* Pills that change state fade from one tone to the next. */
.pill { transition: background-color var(--dur-2) ease, color var(--dur-2) ease; }

/* ================= the prototype's other controls (Task 4 builds them in Twig; their motion is here by class) ================= */
/* Brand marks: the hull glides a little toward the bow on hover. */
:is(.brand, .app-brand) .brand__mark { transition: transform var(--dur-3) var(--ease-out); }
/* Skip link: slides down into view on focus. */
.skip-link { transition: top var(--dur-2) var(--ease-out), outline-color var(--dur-2) ease; }
/* Related-page tiles: the picture lifts on hover (public.css), gives on press; the title's underline fades in. */
.tile-link .hull-photo { transition: transform var(--dur-3) var(--ease-out); }
.tile-link:active .hull-photo { transform: scale(0.98); }
.tile-link h3 { text-decoration: underline transparent; text-decoration-thickness: 2px; text-underline-offset: 0.15em; transition: text-decoration-color var(--dur-2) ease; }
/* Gallery frame: photos crossfade (public.css); the frame gives on press; a new caption rises in when gallery_frame adds .is-new. */
.frame { transition: transform var(--dur-1) var(--ease-out), outline-color var(--dur-2) ease; }
.frame:active { transform: scale(0.98); }
@media (prefers-reduced-motion: no-preference) { .frame-caption.is-new { animation: caption-in var(--dur-3) var(--ease-out); } }
@keyframes caption-in { from { opacity: 0; transform: translateY(0.25rem); } }
/* Lineup seats in the panel change colour when someone is placed. */
.lu-seat { transition: background-color var(--dur-2) ease, color var(--dur-2) ease, border-color var(--dur-2) ease; }
@media (hover: hover) and (pointer: fine) {
  :is(.brand, .app-brand):hover .brand__mark { transform: translateX(0.2rem); }
}

/* ================= links: the underline grows from the left ================= */
/* Navigation links (one line, 44px tall): a bar under the text, scaled from the left. The current page keeps it. */
:is(.site-nav a, .footer__col a, .menu-sheet nav a, .card__link, .breadcrumbs a, .link, .auth__links a) { position: relative; }
:is(.site-nav a, .footer__col a, .menu-sheet nav a, .card__link, .breadcrumbs a, .link, .auth__links a)::after {
  content: ""; position: absolute; left: 0; right: 0; height: 2px; pointer-events: none;
  top: calc(50% + 0.6em); top: calc(50% + 0.5lh - 0.2em); /* just under the centred line of text */
  background: currentColor;
  transform: scaleX(0); transform-origin: left center;
  transition: transform var(--dur-3) var(--ease-out);
}
.menu-sheet nav a::after { top: auto; bottom: 0.35rem; height: 3px; }
.site-nav a[aria-current="page"]::after { transform: none; background: var(--accent); }
/* Links underlined at rest (.link, breadcrumbs): the thin line gives way to the growing bar. */
:is(.breadcrumbs a, .link, .auth__links a) { transition: text-decoration-color var(--dur-2) ease, color var(--dur-2) ease, outline-color var(--dur-2) ease; }

/* Links inside running text wrap over lines, so their bar is a background that grows across every line. */
:is(.prose a, .footer__base a:not(.btn), .footer__contact a, .facts a, .map__credit a, .news-item h3 a) {
  background: linear-gradient(currentColor, currentColor) 0 100% / 0 2px no-repeat; /* taste-skill-ignore: a solid 2px line, not a gradient */
  transition: background-size var(--dur-3) var(--ease-out), text-decoration-color var(--dur-2) ease, color var(--dur-2) ease, outline-color var(--dur-2) ease;
}

@media (hover: hover) and (pointer: fine) {
  :is(.site-nav a, .footer__col a, .menu-sheet nav a, .card__link, .breadcrumbs a, .link, .auth__links a):hover::after { transform: none; }
  :is(.breadcrumbs a, .link, .auth__links a):hover { text-decoration-color: transparent; }
  :is(.prose a, .footer__base a:not(.btn), .footer__contact a, .facts a, .map__credit a, .news-item h3 a):hover {
    background-size: 100% 2px; text-decoration-color: transparent;
  }
}

/* ================= disclosures: every <details> opens and closes smoothly ================= */
/* Where CSS can animate to an auto height, ::details-content grows and fades; elsewhere disclosure_controller.js
   animates the same with the Web Animations API. */
@supports (interpolate-size: allow-keywords) and selector(::details-content) {
  @media (prefers-reduced-motion: no-preference) {
    details { interpolate-size: allow-keywords; }
    details::details-content {
      block-size: 0; overflow-y: clip; opacity: 0;
      transition: block-size var(--dur-3) var(--ease-out), opacity var(--dur-3) var(--ease-out), content-visibility var(--dur-3) allow-discrete;
    }
    details[open]::details-content { block-size: auto; opacity: 1; }
  }
}
.tile { transition: background-color var(--dur-3) ease, color var(--dur-3) ease; }
.tile > summary { transition: var(--motion-control); }
:is(.tile__plus, .disclosure__plus)::before, :is(.tile__plus, .disclosure__plus)::after { transition: transform var(--dur-3) var(--ease-out); }
/* While disclosure_controller closes one, it already looks closed. */
.tile.is-closing[open] { background: var(--surface); color: var(--ink); }
.tile.is-closing[open] .tile__plus::after, .disclosure.is-closing[open] .disclosure__plus::after { transform: rotate(90deg); }

/* ================= dialogs, bottom sheets and the menu sheet: in and out ================= */
/* In: from @starting-style (it cascades like any rule, so it repeats the open state's selector). Out: the browser keeps
   them shown (display and overlay transition discretely); where it cannot (no overlay), sheet_controller.js sets
   data-closing, waits for these transitions, then closes. */
@media (prefers-reduced-motion: no-preference) {
  .sheet {
    opacity: 0; transform: translateY(0.5rem) scale(0.98);
    transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out),
      display var(--dur-2) allow-discrete, overlay var(--dur-2) allow-discrete;
  }
  .sheet[open]:not([data-closing]) { opacity: 1; transform: none; transition-duration: var(--dur-3); }
  @starting-style { .sheet[open]:not([data-closing]) { opacity: 0; transform: translateY(0.5rem) scale(0.98); } }
  @media (max-width: 47.99em) {
    .sheet { opacity: 1; transform: translateY(100%); }
    @starting-style { .sheet[open]:not([data-closing]) { opacity: 1; transform: translateY(100%); } }
  }
  .sheet::backdrop {
    background-color: rgb(11 31 58 / 0);
    transition: background-color var(--dur-2) ease, display var(--dur-2) allow-discrete, overlay var(--dur-2) allow-discrete;
  }
  .sheet[open]:not([data-closing])::backdrop { background-color: rgb(11 31 58 / 0.5); transition-duration: var(--dur-3); }
  @starting-style { .sheet[open]:not([data-closing])::backdrop { background-color: rgb(11 31 58 / 0); } }

  .menu-sheet, .menu-sheet::backdrop {
    opacity: 0;
    transition: opacity var(--dur-2) var(--ease-out), display var(--dur-2) allow-discrete, overlay var(--dur-2) allow-discrete;
  }
  .menu-sheet[open]:not([data-closing]), .menu-sheet[open]:not([data-closing])::backdrop { opacity: 1; transition-duration: var(--dur-3); }
  @starting-style { .menu-sheet[open]:not([data-closing]), .menu-sheet[open]:not([data-closing])::backdrop { opacity: 0; } }
  .menu-sheet__inner { transform: translateY(-0.75rem); transition: transform var(--dur-2) var(--ease-out); }
  .menu-sheet[open]:not([data-closing]) .menu-sheet__inner { transform: none; transition-duration: var(--dur-3); }
  @starting-style { .menu-sheet[open]:not([data-closing]) .menu-sheet__inner { transform: translateY(-0.75rem); } }
  /* the links rise one after another, 30ms apart */
  .menu-sheet nav a {
    opacity: 0; transform: translateY(0.75rem);
    transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out), color var(--dur-2) ease, outline-color var(--dur-2) ease;
  }
  .menu-sheet[open]:not([data-closing]) nav a {
    opacity: 1; transform: none;
    transition-duration: var(--dur-3), var(--dur-3), var(--dur-2), var(--dur-2);
    transition-delay: calc(60ms + var(--n) * 30ms), calc(60ms + var(--n) * 30ms), 0s, 0s;
  }
  @starting-style { .menu-sheet[open]:not([data-closing]) nav a { opacity: 0; transform: translateY(0.75rem); } }
  .menu-icon::before, .menu-icon::after { transition: transform var(--dur-2) var(--ease-out); }
  .menu-sheet[open]:not([data-closing]) .menu-icon::before, .menu-sheet[open]:not([data-closing]) .menu-icon::after { transition-duration: var(--dur-3); }
  @starting-style { .menu-sheet[open]:not([data-closing]) .menu-icon::before, .menu-sheet[open]:not([data-closing]) .menu-icon::after { transform: none; } }
}

/* ================= flashes: slide in on load; dismissing one collapses it (dismiss_controller.js) ================= */
@media (prefers-reduced-motion: no-preference) {
  .flash { animation: flash-in var(--dur-3) var(--ease-out) backwards; animation-delay: calc(var(--n) * 60ms); }
}
@keyframes flash-in { from { opacity: 0; transform: translateY(-0.5rem); } }

/* ================= scroll reveal (public pages, reveal_controller.js) ================= */
/* The controller marks what starts below the fold .is-pending and swaps it to .is-in as it scrolls into view.
   [data-reveal]: rises 24px and fades in (--i on the element staggers siblings by 80ms, up to 7).
   [data-reveal-stagger]: its children rise one after another, 80ms apart, at most 8 steps.
   [data-reveal="hull"]: the picture opens from the bow (right; the top for vertical hulls) and settles. */
[data-reveal="hull"] { --hull-closed: inset(0 0 0 100%); --hull-opening: reveal-hull; }
[data-reveal="hull"].hull-v { --hull-closed: inset(0 0 100% 0); --hull-opening: reveal-hull-v; }
@media (max-width: 47.99em) { [data-reveal="hull"].hull--v-phone { --hull-closed: inset(0 0 100% 0); --hull-opening: reveal-hull-v; } }
@media screen and (prefers-reduced-motion: no-preference) {
  .js [data-reveal]:not([data-reveal="hull"]).is-pending, .js [data-reveal-stagger].is-pending > * { opacity: 0; }
  .js [data-reveal]:not([data-reveal="hull"]).is-in {
    animation: reveal-rise var(--dur-4) var(--ease-expo) backwards;
    animation-delay: calc(min(var(--i, 0), 7) * var(--stagger));
  }
  .js [data-reveal-stagger].is-in > * { animation: reveal-rise var(--dur-4) var(--ease-expo) backwards; animation-delay: calc(var(--n) * var(--stagger)); }

  .js [data-reveal="hull"].is-pending { background-color: transparent; }
  .js [data-reveal="hull"].is-pending :is(img, video) { clip-path: var(--hull-closed); }
  .js [data-reveal="hull"].is-in { animation: reveal-frame var(--t-open) linear backwards; }
  .js [data-reveal="hull"].is-in :is(img, video) { animation: var(--hull-opening) var(--t-open) var(--ease-in-out) backwards; }
}
@keyframes reveal-rise { from { opacity: 0; transform: translateY(24px); } }
/* clip-path needs both ends: inset() does not interpolate to the resting none */
@keyframes reveal-hull { from { clip-path: inset(0 0 0 100%); transform: scale(1.08); } to { clip-path: inset(0); transform: none; } }
@keyframes reveal-hull-v { from { clip-path: inset(0 0 100% 0); transform: scale(1.08); } to { clip-path: inset(0); transform: none; } }
@keyframes reveal-frame { from, to { background-color: transparent; } } /* the frame's ground stays hidden while the picture opens */

/* ================= panel: a one-time entrance per page, no scroll reveal ================= */
@media (prefers-reduced-motion: no-preference) {
  .app-main :is(.app-title, .card, .empty, .rows > li, .data-table tbody > tr) {
    animation: panel-in var(--dur-2) var(--ease-out) backwards;
    animation-delay: calc(var(--n) * 30ms);
  }
}
@keyframes panel-in { from { opacity: 0; transform: translateY(0.5rem); } }

/* ================= page to page: a short crossfade; header, panel shell and the current item stay put ================= */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
::view-transition-old(root) { animation: vt-leave var(--dur-2) var(--ease-out) both; }
::view-transition-new(root) { animation: vt-arrive var(--dur-3) var(--ease-out) both; }
::view-transition-group(*) { animation-duration: var(--dur-3); animation-timing-function: var(--ease-in-out); }
@keyframes vt-leave { to { opacity: 0; } }
@keyframes vt-arrive { from { opacity: 0; } }
.site-header { view-transition-name: site-header; }
.app-sidebar { view-transition-name: app-sidebar; }
.app-topbar { view-transition-name: app-topbar; }
.bottom-nav { view-transition-name: bottom-nav; }
/* the current item's highlight slides from the old page's item to the new one */
.side-nav a[aria-current="page"]:not(dialog *) { view-transition-name: nav-current; }
.bottom-nav [aria-current="page"] .bn-icon { view-transition-name: nav-pill; }

/* ================= scroll-driven extras, where the browser has scroll timelines ================= */
.reading-progress { display: none; position: fixed; inset: 0 0 auto; z-index: var(--z-nav); height: 4px; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); pointer-events: none; }
/* the panel's sticky top bar: its ground and a 1px line under it fade in once the page scrolls under it (no shadow) */
.app-topbar { background: transparent; }
.app-topbar::after { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; background: var(--ground); border-bottom: 1px solid var(--line); opacity: 0; } /* taste-skill-ignore: app bar edge (app rules) */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* hull photos drift slowly against the scroll inside their frames (held at 110% so no edge shows) */
    [data-reveal="hull"] :is(img, video) { scale: 1.1; animation: hull-drift linear both; animation-timeline: view(); }
    .js [data-reveal="hull"].is-in :is(img, video) {
      animation: var(--hull-opening) var(--t-open) var(--ease-in-out) backwards, hull-drift linear both;
      animation-timeline: auto, view();
    }
    /* the hero pictures lag behind as the page scrolls on (their load animations from public.css, plus the lag) */
    .js .hero__boat { animation: open-boat 1100ms var(--ease-in-out) 120ms both, recede linear both; animation-timeline: auto, view(); animation-range: normal, exit; }
    .js .page-hero__picture { animation: open-boat 1000ms var(--ease-in-out) 120ms both, recede linear both; animation-timeline: auto, view(); animation-range: normal, exit; }
    /* the panel's top bar gets its ground and edge once the page scrolls under it */
    .app-topbar::after { animation: bar-in linear both; animation-timeline: scroll(root); animation-range: 0 4rem; }
    /* how far through a news article the reader is */
    .reading-progress { display: block; animation: read linear both; animation-timeline: scroll(root); }
  }
}
@keyframes hull-drift { from { translate: 0 -4%; } to { translate: 0 4%; } }
@keyframes recede { to { transform: translateY(6%); } }
@keyframes bar-in { to { opacity: 1; } }
@supports not (animation-timeline: view()) { .app-topbar::after { opacity: 1; border-bottom-color: transparent; } }
@media (prefers-reduced-motion: reduce) { .app-topbar::after { opacity: 1; border-bottom-color: transparent; } }
@keyframes read { to { transform: none; } }

/* ================= reduced motion: no travel, no lift, no squeeze ================= */
@media (prefers-reduced-motion: reduce) {
  :is(.btn, .segmented button, .seat, .icon-btn, .flash__close, .menu-btn, .menu-sheet__close, .scope, .crew-chip, .side-nav a, .side-nav button, .blockmark__block):active,
  .bottom-nav :is(a, button):active .bn-icon { transform: none; }
  .switch:active::after { scale: none; }
  .blockmark__block:hover, .tile-link:hover .hull-photo, .tile-link:active .hull-photo, .frame:active { transform: none; }
  :is(.brand, .app-brand):hover .brand__mark { transform: none; }
}
