/* The Patch Garden's page (#393). The colours are docs/theme/custom.css's
   tokens, and the page's own dark blues are the app's and 404.html's */
:root {
    color-scheme: dark;

    /* Signal colors, from SignalType::color() in src/dsp/signal.rs */
    --signal-audio: #4287f5;
    --signal-control: #f59e42;
    --signal-gate: #42f587;
    --signal-midi: #b266ff;
    --signal-bus: #c8cdd7;

    /* Header colors, from ModuleCategory::color() in src/dsp/module_trait.rs */
    --category-source: #42a5f5;
    --category-filter: #26a69a;
    --category-modulation: #ffb74d;
    --category-effect: #4dd0e1;
    --category-utility: #9e9e9e;
    --category-output: #7e57c2;

    --page: #1a1a2e;
    --card: #22223a;
    --edge: #2e2e4a;
    --ink: #c8c8d8;
    --faint: #8a8aa6;
    --bright: #ececf6;
    --heavy: var(--category-modulation);
    /* The vines' green: the gate signal's, softened */
    --vine: #7ee0a0;
    --vine-edge: #7ee0a055;
    --vine-wash: #42f58722;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--page) radial-gradient(circle at 1px 1px, #ffffff0d 1px, transparent 0) 0 0 / 24px 24px;
    color: var(--ink);
    font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.masthead, main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 16px;
}

.masthead { padding-top: 32px; padding-bottom: 8px; }
.home {
    color: var(--faint);
    text-decoration: none;
    font-size: 0.875rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.home:hover { color: var(--bright); }
h1 {
    margin: 4px 0 8px;
    color: var(--bright);
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    font-weight: 600;
    letter-spacing: -0.01em;
}
.lede { margin: 0; max-width: 38rem; color: var(--ink); }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin: 16px 0 0;
    padding: 0;
    list-style: none;
    font-size: 0.8125rem;
    color: var(--faint);
}
.legend li::before {
    content: "";
    display: inline-block;
    width: 18px;
    height: 3px;
    margin-right: 6px;
    vertical-align: middle;
    border-radius: 2px;
    background: currentColor;
    box-shadow: 0 0 6px currentColor;
}
.legend li { color: var(--faint); }
.legend .audio::before { background: var(--signal-audio); box-shadow: 0 0 6px var(--signal-audio); }
.legend .control::before { background: var(--signal-control); box-shadow: 0 0 6px var(--signal-control); }
.legend .gate::before { background: var(--signal-gate); box-shadow: 0 0 6px var(--signal-gate); }
.legend .midi::before { background: var(--signal-midi); box-shadow: 0 0 6px var(--signal-midi); }
.legend .bus::before { background: var(--signal-bus); box-shadow: 0 0 6px var(--signal-bus); }

/* One card to a row on a phone, two from about 480 px, more on a desk */
.garden {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-top: 24px;
}
@media (min-width: 480px) { .garden { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 960px) { .garden { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; } }
@media (min-width: 1320px) { .garden { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--card);
    border: 1px solid var(--edge);
    border-radius: 10px;
    overflow: hidden;
    animation: sprout 420ms ease-out both;
    transition: border-color 160ms ease, transform 160ms ease;
}
.card:hover { border-color: #43436a; }
@keyframes sprout {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .card { animation: none; transition: none; }
}

.drawing {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #16162a radial-gradient(circle at 1px 1px, #ffffff0a 1px, transparent 0) 0 0 / 12px 12px;
    border-bottom: 1px solid var(--edge);
}
.drawing svg { display: block; width: 100%; height: 100%; }
.cable { fill: none; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.cable.glow { stroke-width: 4px; opacity: 0.22; }
.cable.line { stroke-width: 1.25px; opacity: 0.95; }
.frame { vector-effect: non-scaling-stroke; stroke-width: 1px; }

.about {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    padding: 12px 14px 14px;
}
.about h2 {
    margin: 0;
    color: var(--bright);
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
.by { margin: 0; color: var(--ink); font-size: 0.875rem; overflow-wrap: anywhere; }
.meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    margin: 2px 0 0;
    color: var(--faint);
    font-size: 0.8125rem;
}
.badge {
    padding: 0 7px;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 0.75rem;
    line-height: 1.5;
}
.badge.heavy { color: var(--heavy); }

.open {
    align-self: flex-start;
    margin-top: auto;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #4fc3f7;
    color: #4fc3f7;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease;
}
.about .open { margin-top: 12px; }
.open:hover { background: #4fc3f7; color: var(--page); }
.open:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.status {
    margin: 32px 0 48px;
    text-align: center;
    color: var(--faint);
    font-size: 0.9375rem;
}
.status button {
    margin-left: 8px;
    padding: 2px 10px;
    border: 1px solid var(--faint);
    border-radius: 6px;
    background: none;
    color: var(--ink);
    font: inherit;
    cursor: pointer;
}
#more { height: 1px; }

/* Listening (#394). The sounding card's ring is the audio cable's blue, as
   wide and as bright as its level (--level, 0 to 1, from listen.js) */
.card { --level: 0; }
/* A card no longer sounding lets its ring go as the sound fades (listen::STOP_FADE_SECONDS) */
.card:not(.sounding) { transition: border-color 160ms ease, transform 160ms ease, box-shadow 400ms ease; }
.card.sounding {
    border-color: var(--signal-audio);
    box-shadow:
        0 0 0 calc(1px + var(--level) * 2.5px) color-mix(in srgb, var(--signal-audio) calc(35% + var(--level) * 55%), transparent),
        0 0 calc(6px + var(--level) * 26px) color-mix(in srgb, var(--signal-audio) calc(var(--level) * 45%), transparent);
}
/* Until its sound arrives (the first card wakes the whole app) the drawing breathes */
.card.sounding.waking .drawing { animation: waking 1.4s ease-in-out infinite; }
@keyframes waking {
    50% { box-shadow: inset 0 0 28px color-mix(in srgb, var(--signal-audio) 22%, transparent); }
}
.drawing { position: relative; cursor: default; }
.drawing:focus-visible { outline: 2px solid var(--signal-audio); outline-offset: -2px; }
.card.heavy .drawing { cursor: pointer; }
.hint {
    position: absolute;
    right: 10px;
    bottom: 8px;
    padding: 1px 8px;
    border-radius: 999px;
    background: #16162acc;
    color: var(--heavy);
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 160ms ease;
    pointer-events: none;
}
.card.heavy:hover .hint, .card.heavy .drawing:focus-visible .hint { opacity: 1; }
.card.sounding .hint { opacity: 0; }

/* Asked once a visit, when the browser holds the sound until a tap */
.allow {
    position: fixed;
    left: 50%;
    bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    padding: 10px 20px;
    border: 1px solid var(--signal-audio);
    border-radius: 999px;
    background: #1a1a2ef2;
    box-shadow: 0 6px 24px #0008, 0 0 18px color-mix(in srgb, var(--signal-audio) 30%, transparent);
    color: var(--bright);
    font: inherit;
    font-size: 0.9375rem;
    cursor: pointer;
    animation: sprout 320ms ease-out both;
    z-index: 2;
}
.allow:hover { background: color-mix(in srgb, var(--signal-audio) 25%, #1a1a2e); }
.allow:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* The listener: kept in the viewport, as a browser may stop drawing a frame it can't see */
.listener {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 1px;
    height: 1px;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .card.sounding.waking .drawing { animation: none; }
    .allow { animation: none; }
}

/* Vines (#397): a card's stem count and what it grew from, and the lineage
   they open. The stem is the gate green, softened, as a cable is drawn */
.grown {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 2px 0 0;
    color: var(--faint);
    font-size: 0.8125rem;
    overflow-wrap: anywhere;
}
.grown button, .stems {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--vine);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.grown button:hover { text-decoration: underline; text-underline-offset: 2px; }
.stems {
    padding: 0 8px 0 6px;
    border: 1px solid var(--vine-edge);
    border-radius: 999px;
    font-size: 0.75rem;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    transition: background 120ms ease, border-color 120ms ease;
}
.stems:hover { background: var(--vine-wash); border-color: var(--vine); }
.grown button:focus-visible, .stems:focus-visible { outline: 2px solid #fff; outline-offset: 2px; border-radius: 4px; }
.sprig {
    flex: none;
    width: 14px;
    height: 14px;
    fill: var(--vine-wash);
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.grown > .sprig { color: var(--faint); }

dialog.vine {
    width: min(600px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    overflow: auto;
    background: var(--page);
    color: var(--ink);
    border: 1px solid var(--edge);
    border-radius: 12px;
    box-shadow: 0 24px 64px #00000080;
}
dialog.vine::backdrop { background: #0b0b18c0; backdrop-filter: blur(3px); }
dialog.vine[open] { animation: sprout 260ms ease-out both; }
dialog.vine header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 12px;
    background: linear-gradient(var(--page) 80%, transparent);
}
dialog.vine h2 { margin: 0; color: var(--bright); font-size: 1.25rem; font-weight: 600; overflow-wrap: anywhere; }
dialog.vine .lede { margin: 2px 0 0; color: var(--faint); font-size: 0.875rem; }
dialog.vine .close {
    flex: none;
    width: 32px;
    height: 32px;
    border: 1px solid var(--edge);
    border-radius: 8px;
    background: none;
    color: var(--ink);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}
dialog.vine .close:hover { border-color: var(--faint); color: var(--bright); }

.vine-rows {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 16px 16px;
}
.vine-rows .card {
    position: relative;
    z-index: 1;
    flex-direction: row;
    margin-left: calc(28px + var(--depth, 0) * 22px);
}
.vine-rows .card .drawing {
    flex: none;
    width: 132px;
    border-bottom: 0;
    border-right: 1px solid var(--edge);
}
.vine-rows .card .about { padding: 10px 12px; }
.vine-rows .card .about h2 { font-size: 1rem; }
.vine-rows .card .about .open { margin-top: 8px; padding: 4px 10px; font-size: 0.8125rem; }
.vine-rows .card.here:not(.sounding) { border-color: var(--vine); box-shadow: 0 0 0 1px var(--vine-edge), 0 0 18px #42f58726; }
.vine-rows .card.withered { padding: 12px 14px; color: var(--faint); font-style: italic; }
@media (max-width: 479px) {
    .vine-rows .card .drawing { width: 96px; }
}

.stem { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.vine-stem { fill: none; stroke: var(--vine); stroke-linecap: round; stroke-linejoin: round; }
.vine-stem.glow { stroke-width: 5px; opacity: 0.18; }
.vine-stem.line { stroke-width: 1.75px; opacity: 0.9; }
.vine-stem.growing { animation: vine-grow 560ms ease-out forwards; }
.stem .leaf { fill: var(--vine); opacity: 0.55; }
.stem .seed { fill: var(--page); stroke: var(--vine); stroke-width: 1.75px; }
.stem .jack { fill: var(--vine); }
.stem .budding { animation: vine-bud 360ms ease-out both; transform-box: fill-box; }
@keyframes vine-grow { to { stroke-dashoffset: 0; } }
@keyframes vine-bud { from { opacity: 0; } }

.vine-status { margin: 0 16px 16px; color: var(--faint); font-size: 0.875rem; text-align: center; }
.vine-status:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
    dialog.vine[open] { animation: none; }
}
