/* murmuration demo — an evening sky: pearl grey by day, blue at nightfall. One accent, a street-lamp yellow, only for what just changed. */
:root {
  color-scheme: light;
  --sky: #E4E9ED; --horizon: #CAD4DC; --ink: #16202A; --muted: #55636F; --line: rgba(22, 32, 42, .14);
  --panel: rgba(246, 248, 250, .88); --solid: #F6F8FA; --lamp: #F3CF63;
  --t-kw: #6A3B95; --t-str: #2E6A36; --t-num: #9A4510; --t-com: #74838F;
  --font: 'Archivo', system-ui, sans-serif; --mono: ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, monospace;
  /* motion: the same durations and curves everywhere (flash: hover, press, tooltip; short: a control changes state, a popover;
     medium: a panel; long: what is rare). What leaves goes in about two thirds of the time of what arrives. */
  --dur-flash: 130ms; --dur-short: 250ms; --dur-medium: 450ms; --dur-long: 650ms;
  /* ease-out for what enters, leaves or answers; ease-in-out for what moves across the screen; the drawer curve for the panel */
  --ease-out: cubic-bezier(.2, .8, .2, 1); --ease-in-out: cubic-bezier(.65, 0, .35, 1); --ease-drawer: cubic-bezier(.32, .72, 0, 1); --ease-overshoot: cubic-bezier(.3, 1.6, .5, 1);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --sky: #131A25; --horizon: #222D3F; --ink: #E6ECF1; --muted: #93A1AD; --line: rgba(230, 236, 241, .14);
  --panel: rgba(24, 32, 45, .9); --solid: #1A2331; --lamp: #8A6A12;
  --t-kw: #C9A6F0; --t-str: #A6D99A; --t-num: #F2B27A; --t-com: #7F8E9B;
}

* { box-sizing: border-box; }
html { background: var(--sky); -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
/* controls: no double-tap zoom delay, no text selection on a long press */
button, a, [role="radio"] { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
body { margin: 0; color: var(--ink); font: 400 16px/1.55 var(--font); background: linear-gradient(var(--sky) 0, var(--sky) 60vh, var(--horizon) 100vh, var(--sky) 160vh) no-repeat; transition: background-color .4s; }
a { color: inherit; text-underline-offset: 3px; }
code { font: 13px/1.6 var(--mono); font-variant-ligatures: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#flock { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
main, .top, .toolbar, .code-panel { position: relative; z-index: 1; }

/* ——— Top bar ——— */
.top { position: fixed; z-index: 2; inset: 0 0 auto; background: linear-gradient(var(--sky) 55%, transparent); display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px; }
.package { font: 500 13px var(--mono); color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 4px; }
button { font: inherit; color: inherit; cursor: pointer; }
.ghost { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 10px; background: none; color: var(--ink); font-weight: 500; text-decoration: none; }
.ghost.icon { width: 40px; justify-content: center; padding: 0; }
.code-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px 0 12px; border: 0; border-radius: 10px; background: var(--ink); color: var(--sky); font-weight: 600; }
.code-toggle[aria-expanded="true"] { background: var(--line); color: var(--ink); }
/* every control answers: background on hover (mouse only), pressed in on press */
.ghost, .code-toggle, .tool { transition: background-color var(--dur-flash) var(--ease-out), color var(--dur-flash) var(--ease-out), transform var(--dur-short) var(--ease-out); }
.ghost:active, .code-toggle:active, .tool:active { transform: scale(.96); transition-duration: var(--dur-flash); }
@media (hover: hover) and (pointer: fine) {
  .ghost:hover { background: var(--line); }
  .code-toggle:not([aria-expanded="true"]):hover { background: color-mix(in srgb, var(--ink) 86%, var(--sky)); }
  .tool:not([aria-checked="true"]):not([aria-expanded="true"]):hover { background: var(--line); color: var(--ink); }
}
:root:not([data-theme="dark"]) #theme .sun, :root[data-theme="dark"] #theme .moon { display: none; }
/* Copy → Copied: the check mark draws itself, the button bounces once (in JS) */
.copy[data-state="copied"], .copy[data-state="selected"] { background: var(--line); }
.check-draw { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-dasharray: 1; stroke-dashoffset: 1; animation: check-draw var(--dur-medium) var(--ease-out) forwards; }
@keyframes check-draw { to { stroke-dashoffset: 0; } }

/* ——— Stage: the first screen, the flock is the title ——— */
.stage { position: relative; height: 100svh; min-height: 520px; touch-action: pan-y; cursor: crosshair; -webkit-user-select: none; user-select: none; } /* a drag draws, it never selects text */
.stage.drawing { touch-action: none; }
.ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.hint { position: absolute; left: 0; right: 0; bottom: 132px; margin: 0; text-align: center; color: var(--muted); font-size: 15px; transition: opacity var(--dur-medium) var(--ease-out); }
.hint.gone { opacity: 0; }

/* ——— Scenes: the engine explained while the flock follows the page ——— */
/* each section at its own height, spaced like the site's sections: no screen-high gap between two of them */
.scene { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); align-items: center; gap: 48px; padding: clamp(32px, 4.5vw, 56px) max(24px, 6vw); }
.perch { position: relative; height: min(60svh, 520px); }
.wire { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.wire path { stroke: var(--muted); stroke-width: 1.5; vector-effect: non-scaling-stroke; fill: none; }
.copy { max-width: 34rem; }
h2 { margin: 0 0 16px; font: 750 clamp(30px, 4.2vw, 52px)/1.02 var(--font); font-stretch: 125%; letter-spacing: -.01em; }
.copy p { margin: 0 0 24px; color: var(--muted); font-size: 18px; max-width: 32em; }
.copy p code, .end code { color: var(--ink); }
.copy pre { margin: 0; padding: 14px 16px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); overflow-x: auto; }

/* the end, like the site's footer: the title, the install command with room above it for the birds that perch on it,
   then a quiet bottom bar, far below, clear of the toolbar */
.end { position: relative; z-index: 1; padding: clamp(64px, 9vw, 112px) max(24px, 6vw) 0; text-align: center; }
.end h2 { margin-bottom: 40px; font-size: clamp(26px, 3.4vw, 40px); }
.end-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; margin-top: clamp(72px, 10vw, 120px); padding: 20px 0 120px; border-top: 1px solid var(--line); font: 500 14px var(--mono); color: var(--muted); }
.heart { width: 1em; height: 1em; vertical-align: -.15em; fill: var(--t-kw); stroke: none; }
.install { display: inline-flex; align-items: center; gap: 8px; padding: 6px 6px 6px 18px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.install code { font-size: 15px; }

/* ——— Toolbar: floating, the controls of the flock ——— */
.toolbar { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 3; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 12px 32px -12px rgba(10, 20, 30, .35); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); max-width: calc(100vw - 24px); }
.word input { width: 168px; min-height: 44px; padding: 0 14px; border: 0; border-radius: 11px; background: var(--line); color: var(--ink); font: 650 16px var(--font); font-stretch: 112%; }
.word input::placeholder { color: var(--muted); font-weight: 400; }
.word input:focus-visible { outline-offset: 0; }
.group { position: relative; display: flex; gap: 2px; padding-left: 6px; margin-left: 2px; border-left: 1px solid var(--line); }
.tool { position: relative; z-index: 1; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 11px; background: none; color: var(--muted); }
.tool[aria-checked="true"], .tool[aria-expanded="true"] { color: var(--sky); }
.tool[aria-expanded="true"] { background: var(--ink); }
.tool svg.glyph { fill: currentColor; stroke: none; }
/* the pill slides under the chosen tool */
.pill { position: absolute; top: 0; left: 0; width: 44px; height: 44px; border-radius: 11px; background: var(--ink); opacity: 0; transition: transform var(--dur-short) var(--ease-in-out), opacity var(--dur-flash) var(--ease-out); }
.pill.on { opacity: 1; }
/* a keyboard action is never animated */
.pill.instant, .instant, .instant * { transition: none !important; animation: none !important; }
#settings-toggle { margin-left: 2px; }
/* the code panel open: the toolbar stays centred on the sky that is left */
.toolbar { transition: left calc(var(--dur-medium) * .66) var(--ease-drawer); }


.settings { position: absolute; right: 0; bottom: calc(100% + 10px); width: 280px; padding: 8px 16px 16px; border-radius: 16px; background: var(--solid); border: 1px solid var(--line); box-shadow: 0 16px 40px -16px rgba(10, 20, 30, .4);
  /* it grows from its trigger, bottom right; a transition, not keyframes, so that a quick second click reverses it */
  transform-origin: calc(100% - 22px) calc(100% + 32px); opacity: 0; transform: scale(.96); visibility: hidden;
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out), visibility 0s 140ms; }
.settings.open { opacity: 1; transform: none; visibility: visible; transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out), visibility 0s; }
.setting { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.setting output { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.setting input { grid-column: 1 / -1; width: 100%; margin: 6px 0 0; accent-color: var(--ink); }

/* ——— Code panel: slides in from the right ——— */
.code-panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 4; display: flex; flex-direction: column; width: min(460px, 100vw); padding: 16px 16px 24px 24px; background: var(--solid); border-left: 1px solid var(--line); transform: translateX(100%); transition: transform calc(var(--dur-medium) * .66) var(--ease-drawer); }
.code-panel.open { transform: none; transition-duration: var(--dur-medium); }
/* the panel opens beside the page and pushes it, rather than covering the shapes, when both fit side by side;
   on a narrower window, it covers the page */
@media (min-width: 1280px) {
  .code-open .toolbar { left: calc((100vw - 460px) / 2); transition-duration: var(--dur-medium); }
  main { transition: margin-right calc(var(--dur-medium) * .66) var(--ease-drawer); }
  .top { transition: right calc(var(--dur-medium) * .66) var(--ease-drawer); }
  .code-open main { margin-right: min(460px, 100vw); transition-duration: var(--dur-medium); }
  .code-open .top { right: min(460px, 100vw); transition-duration: var(--dur-medium); }
}
.code-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.code-head h2 { flex: 1; margin: 0; font: 650 16px var(--font); font-stretch: 112%; }
.code-panel pre { flex: 1; margin: 0; overflow: auto; font: 13px/1.65 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.code-panel code { font-size: 12.5px; }
.code-note { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.t-kw { color: var(--t-kw); } .t-str { color: var(--t-str); } .t-num { color: var(--t-num); } .t-com { color: var(--t-com); font-style: italic; }
.v { border-radius: 3px; }
.v.lit { animation: lamp 1.4s var(--ease-out); }
@keyframes lamp { 0%, 30% { background: var(--lamp); } 100% { background: transparent; } }

/* ——— Small screens ——— */
@media (max-width: 860px) {
  .top { padding: 10px 12px; }
  .package { display: none; }
  .top { justify-content: flex-end; }
  .scene { grid-template-columns: 1fr; gap: 24px; padding: 32px 20px; }
  .perch { height: 44svh; }
  .toolbar { left: 12px; right: 12px; bottom: 12px; transform: none; flex-wrap: wrap; justify-content: center; }
  .word { flex: 1 1 100%; }
  .word input { width: 100%; }
  .group { border-left: 0; margin-left: 0; padding-left: 0; }
  .end-bar { justify-content: center; padding-bottom: 160px; }
  .code-open .toolbar { left: 12px; }
  .tool { width: 40px; } .pill { width: 40px; }
  .hint { bottom: 200px; }
  .settings { left: 0; right: 0; width: auto; transform-origin: calc(100% - 40px) calc(100% + 32px); }
  .toolbar { bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* ——— Tooltips: a short delay on the first, then instant while moving along the toolbar ——— */
.tip { position: fixed; z-index: 6; left: 0; top: 0; padding: 5px 9px; border-radius: 7px; background: var(--ink); color: var(--sky); font: 500 13px/1.3 var(--font); white-space: nowrap; pointer-events: none;
  transform-origin: 50% 100%; opacity: 0; transform: translate(-50%, calc(-100% - 6px)) scale(.97);
  transition: opacity 90ms var(--ease-out), transform 90ms var(--ease-out); }
.tip.on { opacity: 1; transform: translate(-50%, calc(-100% - 8px)); transition-duration: 125ms; }
/* no room above (the top bar): below its control, growing from the top */
.tip.below { transform-origin: 50% 0; transform: translate(-50%, 6px) scale(.97); }
.tip.below.on { transform: translate(-50%, 8px); }
.tip.instant { transition-duration: 0ms; }
/* reduced motion: fewer and gentler, not nothing. Colours and fades stay; moves, scales and drawings go. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-property: opacity, color, background-color, border-color, visibility !important; }
  .check-draw { animation: none; stroke-dashoffset: 0; }
  .tool:active, .ghost:active, .code-toggle:active { transform: none; }
}
