/* Harbour scene, Word templates and AI toolkit. Tokens come from styles.css. */

/* ===== Harbour scene: 24 s story — the ship berths, one container is unloaded, the ship leaves ===== */
.harbour { position: relative; height: clamp(220px, 27vw, 400px); overflow: hidden; background: var(--port-blue); }
.harbour > svg { display: block; width: 100%; height: 100%; direction: ltr; }
.h-white { fill: #fff; }
.h-soft { fill: var(--port-blue-soft); }
.h-mid { fill: #8C99DD; }
.h-deep { fill: var(--port-blue-deep); }
.h-quay { fill: var(--port-blue-deep); }
.h-skyline { fill: #1B33BC; }
.h-soft-wave { fill: #2C43C0; }
.h-foam { fill: var(--surface); }
.h-rib { fill: none; stroke: var(--port-blue); stroke-width: 2; opacity: .45; }
.h-steel { fill: none; stroke: var(--port-blue-soft); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.h-steel.thin { stroke-width: 4; }
.h-cable { fill: none; stroke: #fff; stroke-width: 2; }
.h-beam { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; animation: h-beam 4s ease-in-out infinite; }

.h-sea-back { animation: h-drift-back 9s linear infinite; }
.h-sea-mid { animation: h-drift 7s linear infinite; }
.h-sea-front { animation: h-drift-back 11s linear infinite; }
/* Phones show a narrower part of the harbour, so the ship starts closer. Only the variable changes with the
   screen size: the animation keeps running, and the ship stays in step with the crane. */
.h-ship { --sail: -1500px; animation: h-sail 24s linear infinite; }
@media (max-width: 760px) { .h-ship { --sail: -720px; } }
.h-bob { animation: h-bob 4s ease-in-out infinite; }
.h-hoist { animation: h-hoist 24s ease-in-out infinite; }
.h-trolley { animation: h-trolley 24s ease-in-out infinite; }
.h-load { animation: h-load 24s linear infinite; }
.h-carried { opacity: 0; animation: h-carried 24s linear infinite; }
.h-delivered { opacity: 0; animation: h-delivered 24s linear infinite; }

@keyframes h-drift { from { transform: translateX(0); } to { transform: translateX(48px); } }
@keyframes h-drift-back { from { transform: translateX(48px); } to { transform: translateX(0); } }
@keyframes h-beam { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes h-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }
/* The ship berths at 22% (5.3 s), then the crane starts at once. */
@keyframes h-sail {
  0% { transform: translateX(var(--sail)); animation-timing-function: cubic-bezier(.2, .55, .35, 1); }
  22%, 66% { transform: translateX(0); animation-timing-function: cubic-bezier(.5, 0, .75, .5); }
  92%, 100% { transform: translateX(var(--sail)); }
}
@keyframes h-hoist {
  0%, 23% { transform: translate(0, -52px); }
  29% { transform: translate(0, 0); }
  35% { transform: translate(0, -52px); }
  44% { transform: translate(276px, -52px); }
  49% { transform: translate(276px, 48px); }
  54% { transform: translate(276px, -52px); }
  62%, 100% { transform: translate(0, -52px); }
}
@keyframes h-trolley { 0%, 35% { transform: translateX(0); } 44%, 54% { transform: translateX(276px); } 62%, 100% { transform: translateX(0); } }
@keyframes h-load { 0%, 29% { opacity: 1; } 29.01%, 94% { opacity: 0; } 94.01%, 100% { opacity: 1; } }
@keyframes h-carried { 0%, 29% { opacity: 0; } 29.01%, 49% { opacity: 1; } 49.01%, 100% { opacity: 0; } }
@keyframes h-delivered { 0%, 49% { opacity: 0; } 49.01%, 92% { opacity: 1; } 98%, 100% { opacity: 0; } }

/* On opening, the harbour is empty for a moment, then the ship sails in. All parts share the delay. */
.h-ship, .h-hoist, .h-trolley, .h-load, .h-carried, .h-delivered { animation-delay: 1s; animation-fill-mode: backwards; }

.harbour.paused * { animation-play-state: paused !important; }
.harbour-pause { position: absolute; bottom: 8px; left: 12px; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; background: var(--port-blue-deep); border: 1px solid #fff; border-radius: 50%; cursor: pointer; }
.harbour-pause svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.harbour-pause .i-play, .harbour-pause[aria-pressed="true"] .i-pause { display: none; }
.harbour-pause[aria-pressed="true"] .i-play { display: inline; }
.harbour-pause:focus-visible { outline-color: #fff; }

/* Reduced motion: a still scene with the ship at its berth. */
@media (prefers-reduced-motion: reduce) {
  .harbour * { animation: none !important; }
  .h-hoist { transform: translate(0, -52px); }
  .harbour-pause { display: none; }
}

/* ===== Word templates ===== */
.word-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--space-6); align-items: start; margin-top: var(--space-6); }
fieldset { border: 0; padding: 0; margin: 0 0 var(--space-6); min-width: 0; }
legend { font-weight: 700; color: var(--port-blue); padding: 0; margin-bottom: var(--space-2); }
.choices { display: grid; gap: var(--space-2); }
.choices.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choices.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choices label { position: relative; cursor: pointer; }
.choices input { position: absolute; opacity: 0; }
.choices label > span { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; min-height: 48px; padding: var(--space-2); text-align: center; font-size: .875rem; border: 1px solid var(--ink-muted); border-radius: var(--radius-md); }
.choices small { color: var(--ink-muted); font-size: .75rem; }
.choices input:checked + span { background: var(--port-blue-soft); border: 2px solid var(--port-blue); color: var(--port-blue); font-weight: 700; }
.choices input:focus-visible + span { outline: 2px solid var(--port-blue); outline-offset: 2px; }
.wf-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2) var(--space-4); }
.wf-field:first-child { grid-column: 1 / -1; }
.wf-field label { display: block; font-size: .8125rem; font-weight: 500; }
.req { color: var(--ink-muted); font-weight: 400; }
.wf-field input { width: 100%; min-height: 44px; padding: var(--space-2) 12px; font: 400 1rem "Marsa", Tahoma, sans-serif; color: var(--ink); background: #fff; border: 1px solid var(--ink-muted); border-radius: var(--radius-sm); }
.wf-field input[dir="ltr"] { text-align: right; }
.wf-field input::placeholder { color: var(--ink-muted); font-size: .8125rem; direction: rtl; }
.wf-field input[aria-invalid="true"] { border: 2px solid var(--alert); }
.wf-field .error-text { margin: 0; }
.wf-field .error-text:empty { display: none; }
.btn-block { width: 100%; font: 500 1rem "Marsa", Tahoma, sans-serif; cursor: pointer; }
.btn-block:hover { background: var(--port-blue-deep); }
.btn-block:disabled { opacity: .6; cursor: wait; }
.word-status { margin: var(--space-2) 0 0; font-size: .875rem; font-weight: 500; overflow-wrap: anywhere; }
.word-status:empty { margin: 0; }
.word-status.ok { color: var(--port-blue); }
.word-status.fail { color: var(--alert); }

.word-side { position: sticky; top: calc(var(--header-h) + 16px); }

/* ===== AI toolkit ===== */
.ai-safety { margin-top: var(--space-6); padding: var(--space-4) var(--space-6); background: #fff; border: 1px solid var(--line); border-inline-start: 4px solid var(--port-blue); border-radius: var(--radius-md); }
.ai-safety h3 { margin-bottom: var(--space-2); color: var(--port-blue); font-weight: 700; }
.ai-safety ul { padding-inline-start: 20px; font-size: .9375rem; }
.kit { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); margin-top: var(--space-6); }
.kit article { display: flex; flex-direction: column; align-items: stretch; }
.kit p { flex: 1; font-size: .875rem; }
.kit .downloads { flex-wrap: nowrap; gap: var(--space-2); }
.kit .downloads > * { flex: 1; }
button.btn { font: 500 .9375rem "Marsa", Tahoma, sans-serif; cursor: pointer; }
button.btn-primary:hover { background: var(--port-blue-deep); }
.core-details { margin-top: var(--space-4); }
summary { cursor: pointer; font-weight: 500; color: var(--port-blue); min-height: 44px; display: flex; align-items: center; gap: var(--space-2); }
summary::before { content: "+"; font-weight: 700; }
details[open] > summary::before { content: "−"; }
pre { margin: 0 0 var(--space-4); padding: var(--space-4); max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 400 .8125rem/24px "Marsa", Tahoma, sans-serif; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); text-align: start; }
.filters { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-block: var(--space-4); }
.filters button { min-height: 44px; padding: 0 var(--space-6); font: 500 .875rem "Marsa", Tahoma, sans-serif; color: var(--ink); background: #fff; border: 1px solid var(--ink-muted); border-radius: 9999px; cursor: pointer; }
.filters button[aria-pressed="true"] { background: var(--port-blue); border-color: var(--port-blue); color: #fff; }
.prompt-list { list-style: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); align-items: start; }
.prompt { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-4); }
.prompt[hidden] { display: none; }
.prompt-group { align-self: flex-start; padding: 0 12px; margin-bottom: var(--space-2); font-size: .75rem; font-weight: 500; color: var(--port-blue); background: var(--port-blue-soft); border-radius: 9999px; }
.prompt h3 { margin-bottom: 4px; font-weight: 700; }
.prompt p { font-size: .875rem; color: var(--ink-muted); margin-bottom: var(--space-2); }
.prompt pre { max-height: 240px; margin-bottom: var(--space-2); }
.ai-toast { position: fixed; z-index: 14; left: 50%; bottom: 24px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); margin: 0; padding: var(--space-2) var(--space-4); background: var(--ink); color: #fff; border-radius: var(--radius-md); font-size: .875rem; text-align: center; }
.ai-toast:empty { display: none; }
.offscreen { position: fixed; opacity: 0; pointer-events: none; }

/* ===== Header: ten sections need the drop-down earlier ===== */
@media (min-width: 761px) and (max-width: 1260px) {
  .menu-btn { display: block; }
  .site-header nav { display: none; position: absolute; top: 100%; inset-inline: 0; flex-direction: column; background: var(--port-blue-deep); padding: var(--space-2); border-radius: 0 0 var(--radius-md) var(--radius-md); max-height: calc(100vh - var(--header-h)); overflow-y: auto; }
  .site-header nav.open { display: flex; }
  .site-header nav a { font-size: 1rem; padding: var(--space-2) var(--space-4); }
}

@media (max-width: 900px) {
  .word-layout { grid-template-columns: minmax(0, 1fr); }
  .word-side { position: static; }
  .kit, .prompt-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .harbour { height: 176px; }
  .harbour-pause { bottom: 4px; left: 8px; background: transparent; border-color: transparent; opacity: .8; }
  .harbour-pause svg { width: 16px; height: 16px; }
  .word-layout { margin-top: var(--space-4); gap: var(--space-4); }
  #word-form { border: 0; }
  fieldset { margin-bottom: var(--space-6); }
  .wf-grid { row-gap: 12px; }
  .choices.three label > span { font-size: .8125rem; padding: 4px; line-height: 20px; }
  .wf-grid { grid-template-columns: minmax(0, 1fr); }
  .ai-safety { padding: var(--space-4); margin-top: var(--space-4); border-block: 0; border-inline-end: 0; }
  .ai-safety ul { font-size: .8125rem; line-height: 24px; }
  .kit { grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: var(--space-4); }
  .kit .card { padding: var(--space-4); border: 0; }
  .kit p { font-size: .8125rem; line-height: 24px; color: var(--ink-muted); margin-bottom: 12px; }
  .filters { flex-wrap: nowrap; gap: 4px; margin-block: var(--space-2) 12px; }
  .filters button { flex: 1; padding: 0 4px; }
  .prompt-list { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .prompt { padding: var(--space-4); border: 0; }
  .prompt-group { display: none; }
  .ai-toast { bottom: calc(var(--tabbar-h) + 8px); }
}

@media print {
  .harbour, #templates form, .filters, .ai-toast { display: none; }
}

/* Wide displays: header + hero equal one screen, with the harbour along the bottom edge.
   The artwork keeps its 1440 x 320 shape and shrinks on short screens instead of being cut. */
@media (min-width: 901px) {
  .hero { display: flex; flex-direction: column; height: calc(100vh - var(--header-h)); height: calc(100svh - var(--header-h)); min-height: 500px; max-height: 960px; }
  .hero-grid { flex: 1 0 auto; align-content: center; padding-block: clamp(8px, 2vh, 32px); }
  .hero .eyebrow { margin-bottom: clamp(0px, .8vh, 8px); }
  .hero h1 { font-size: clamp(2rem, min(6.4vh, 4.4vw), 3.5rem); line-height: 1.3; margin-bottom: clamp(4px, 1.2vh, 16px); }
  .hero .lead { font-size: clamp(.9375rem, 2.3vh, 1.1875rem); line-height: 1.75; max-width: 40em; margin-bottom: 0; }
  .hero .actions { margin-top: clamp(12px, 2.2vh, 24px); }
  .hero .btn { min-height: 44px; }
  .hero .logo-disc.xl img { width: clamp(150px, 31vh, 260px); }
  .harbour { flex: 0 0 clamp(150px, 13vw, 240px); height: auto; min-height: 0; container-type: size; }
  .harbour > svg { position: absolute; right: 0; bottom: 0; width: min(100cqw, 450cqh); height: min(100cqh, 22.2223cqw); overflow: visible; }
}

/* Phones: app bar + hero equal one screen; the harbour sits on the bottom edge. */
@media (max-width: 760px) {
  .hero {
    display: flex; flex-direction: column;
    height: calc(100vh - var(--header-h) - env(safe-area-inset-top, 0px));
    height: calc(100svh - var(--header-h) - env(safe-area-inset-top, 0px));
    min-height: 430px;
  }
  .hero-grid { flex: 1 0 auto; align-content: center; padding-block: var(--space-2); }
  /* The height follows the width, so the whole ship stays in view. */
  .harbour { flex: none; height: clamp(144px, 46vw, 200px); }
}
/* Short phones */
@media (max-width: 760px) and (max-height: 660px) {
  .hero h1 { font-size: 1.75rem; line-height: 42px; margin-bottom: var(--space-2); }
  .hero .lead-short { font-size: .875rem; line-height: 26px; }
  .hero .actions { margin-top: 12px; gap: 0; }
  .hero .btn { min-height: 44px; }
  .harbour { height: clamp(128px, 40vw, 170px); }
}

/* The tab bar stays out of the first screen. Without JavaScript it is always visible. */
@media (max-width: 760px) {
  .tabbar { transition: transform .25s ease-out, visibility .25s; }
  html.js .tabbar:not(.shown) { transform: translateY(100%); visibility: hidden; }
}
@media (max-width: 760px) and (prefers-reduced-motion: reduce) {
  .tabbar { transition: none; }
}



/* ===== Hero background: modern, built only from the identity blues =====
   A soft light from the emblem side, contour rings around the emblem (an echo of the guilloche in the
   letters), and a fine dot grid that fades out. All layers are static and sit behind the content. */
.hero { position: relative; isolation: isolate; overflow: hidden;
  background:
    radial-gradient(60% 70% at 26% 40%, rgba(64, 92, 230, .55) 0%, transparent 70%),
    radial-gradient(45% 55% at 96% 4%, rgba(27, 51, 188, .9) 0%, transparent 70%),
    linear-gradient(180deg, var(--port-blue) 0%, #0A25BA 45%, #071C9E 100%);
}
.hero::before, .hero::after { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.hero::before {
  --ring-x: 26%; --ring-y: 40%;
  background: repeating-radial-gradient(circle at var(--ring-x) var(--ring-y),
    rgba(255, 255, 255, .07) 0 1px, transparent 1.5px 34px);
  -webkit-mask-image: radial-gradient(42% 60% at var(--ring-x) var(--ring-y), #000 15%, transparent 75%);
  mask-image: radial-gradient(42% 60% at var(--ring-x) var(--ring-y), #000 15%, transparent 75%);
}
.hero::after {
  background: radial-gradient(circle, rgba(255, 255, 255, .16) 1px, transparent 1.6px) 0 0 / 24px 24px;
  -webkit-mask-image: linear-gradient(200deg, #000 0%, transparent 45%);
  mask-image: linear-gradient(200deg, #000 0%, transparent 45%);
}
.hero > .hero-grid { position: relative; }
.hero .harbour { background: transparent; }
@media (max-width: 760px) {
  .hero { background:
    radial-gradient(90% 55% at 85% 18%, rgba(64, 92, 230, .5) 0%, transparent 70%),
    linear-gradient(180deg, var(--port-blue) 0%, #0A25BA 50%, #071C9E 100%); }
  .hero::before { --ring-x: 92%; --ring-y: 16%; }
  .hero::after { background-size: 20px 20px; }
}
@media print { .hero::before, .hero::after { display: none; } }
