/* ============================================================
   PHOTOSYNTHESIZER
   Self-contained like Honeychroma: no dependency on the main
   site's theme, header or footer.
   ============================================================ */

@font-face {
    font-family: 'Clarendon';
    src: url('/Clarendon.woff') format('woff');
}

:root {
    --ps-orange:  #ff5f00;  /* orangeworker.com's brand orange */
    --ps-bg:     #15161a;
    --ps-panel:   #1f2127;
    --ps-line:    #34363f;
    --ps-ink:     #e8e6e0;
    --ps-muted:   #9a988f;
    --ps-accent:  #7fd36b;  /* chlorophyll green */
    --ps-accent-ink: #10200c;
    --ps-danger:  #ff8a7a;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* panels set their own display, which would otherwise override [hidden] */
[hidden] { display: none !important; }

body {
    background: var(--ps-bg);
    color: var(--ps-ink);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    line-height: 1.45;
}

.ps-page {
    max-width: 920px;
    margin: 0 auto;
    padding: 2rem 1rem 4rem;
}

h1 {
    margin: 0;
    font-size: 2rem;
    letter-spacing: 0.01em;
}

h2 {
    margin: 0 0 0.25rem;
    font-size: 1.05rem;
}

.ps-lede, .ps-hint {
    color: var(--ps-muted);
    margin: 0.25rem 0 1rem;
}

.ps-hint { font-size: 0.85rem; }

/* ---------- upload ---------- */

.ps-drop {
    display: block;
    padding: 1.1rem;
    border: 2px dashed var(--ps-line);
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    margin: 0 0 1.25rem;
}

.ps-drop:hover, .ps-drop.is-over, .ps-drop:focus-within {
    border-color: var(--ps-accent);
}

.ps-drop input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.ps-error { color: var(--ps-danger); }

/* ---------- form bits ---------- */

.ps-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.85rem;
    color: var(--ps-muted);
}

.ps-field output { color: var(--ps-ink); font-weight: 600; }

.ps-check {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
}

input[type="range"] { accent-color: var(--ps-accent); width: 100%; }
input[type="checkbox"] { accent-color: var(--ps-accent); }

select, .ps-num {
    background: var(--ps-panel);
    color: var(--ps-ink);
    border: 1px solid var(--ps-line);
    border-radius: 5px;
    padding: 0.25rem 0.35rem;
    font: inherit;
    font-size: 0.9rem;
}

/* ---------- rail: play, faders, monitor (left of the grid) ---------- */

.ps-rail {
    flex-shrink: 0;
    width: 92px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.9rem;
    padding: 0.75rem 0.5rem;
    background: var(--ps-panel);
    border-radius: 10px;
}

.ps-faders {
    flex: 1;
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    min-height: 150px;
}

.ps-fader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    line-height: 1.2;
    text-align: center;
    color: var(--ps-muted);
}

.ps-fader output { color: var(--ps-ink); font-weight: 600; font-size: 0.8rem; }

/* vertical slider, top = high */
.ps-fader input[type="range"] {
    flex: 1;
    width: 24px;
    min-height: 100px;
    writing-mode: vertical-lr;
    direction: rtl;
}

.ps-play {
    width: 64px;
    height: 64px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--ps-accent);
    color: var(--ps-accent-ink);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.ps-monitor-toggle {
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--ps-line);
    border-radius: 999px;
    background: transparent;
    color: var(--ps-muted);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.ps-monitor-toggle[aria-pressed="true"] {
    border-color: var(--ps-accent);
    color: var(--ps-accent);
}

/* ---------- monitor ---------- */

.ps-monitor {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 2rem;
    align-items: center;
    margin: 0 0 1.25rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--ps-line);
    border-radius: 10px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.8rem;
}


.ps-monitor-stats {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.15rem 1rem;
    margin: 0;
    flex: 1 1 340px;
}

.ps-monitor-stats dt { color: var(--ps-muted); }
.ps-monitor-stats dd { margin: 0; }
.ps-monitor-stats small { color: var(--ps-muted); font-size: 0.7rem; }
.ps-monitor .is-warn { color: var(--ps-danger); }

.ps-monitor-graph {
    margin: 0;
    flex: 1 1 200px;
}

.ps-monitor-graph canvas {
    display: block;
    width: 100%;
    height: 40px;
}

.ps-monitor-graph figcaption {
    color: var(--ps-muted);
    font-size: 0.7rem;
}

/* ---------- top: settings, with the image thumbnail to their right ---------- */

.ps-top {
    display: flex;
    gap: 1.25rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.ps-settings {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.9rem 1.5rem;
    align-items: start;
    padding: 0.75rem 1rem;
    border: 1px solid var(--ps-line);
    border-radius: 10px;
}

/* three columns, two controls stacked in each */
.ps-settings-col {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* the thumbnail doubles as the swap-image button */
.ps-thumb {
    position: relative;
    flex-shrink: 0;
    width: 150px;
    height: 150px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    overflow: hidden;
    background: none;
    cursor: pointer;
}

.ps-thumb canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.ps-thumb-label {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.ps-thumb:hover .ps-thumb-label,
.ps-thumb:focus-visible .ps-thumb-label,
.ps-thumb.is-over .ps-thumb-label { opacity: 1; }

.ps-thumb:focus-visible { outline: 2px solid var(--ps-accent); outline-offset: 2px; }
.ps-thumb.is-over { outline: 2px dashed var(--ps-accent); outline-offset: 2px; }

/* touch screens can't hover, so keep a small label showing */
@media (hover: none) {
    .ps-thumb-label {
        opacity: 1;
        inset: auto 0 0 0;
        padding: 0.2rem;
        font-size: 0.75rem;
    }
}

/* ---------- tablet: rail + grid ---------- */

.ps-tablet {
    display: flex;
    gap: 1rem;
    align-items: stretch;
}

.ps-board { min-width: 0; }

/* The cells always fill a fixed square (--grid-w), whatever the grid size,
   so the tablet keeps its shape; at 16x16 that makes cells ~28px, just over
   the 26px row controls that share each row. */
.ps-grid {
    --grid-w: 480px;
    --gap: 3px;
    --cell: calc((var(--grid-w) - (var(--n) - 1) * var(--gap)) / var(--n));
    display: grid;
    grid-template-columns: repeat(var(--n), var(--cell)) auto;
    gap: var(--gap);
    align-items: center;
}

.ps-cell {
    position: relative;
    aspect-ratio: 1;
    border-radius: 3px;
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    transition: opacity 0.15s;
    cursor: default;
}

.ps-cell.is-light { color: rgba(0, 0, 0, 0.75); }

.ps-grid[data-n="12"] .ps-cell { font-size: 0.7rem; }
.ps-grid[data-n="16"] .ps-cell { font-size: 0.6rem; }
.ps-grid[data-n="16"] { --gap: 2px; }

/* a notch on the left edge marks where a note starts; cells without one
   continue the note held from their left */
.ps-cell:not(.is-held)::before {
    content: "";
    position: absolute;
    left: 0;
    top: 22%;
    bottom: 22%;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: currentColor;
    opacity: 0.6;
}

.ps-cell.is-on {
    outline: 3px solid var(--ps-ink);
    outline-offset: -1px;
    z-index: 1;
}

.ps-cell.is-muted, .ps-cell.is-resting { opacity: 0.3; }

.ps-row-ctl {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding-left: 0.4rem;
    font-size: 0.85rem;
    color: var(--ps-muted);
}

.ps-row-ctl.is-resting { opacity: 0.6; }

/* Row controls are kept to 26px tall. Beside the grid they share a row with
   its cells, so a control taller than a cell would stretch the row and
   leave gaps that distort the picture; the media queries at the bottom move
   them beneath their row before cells get smaller than this. */
.ps-num {
    width: 2.5rem;
    height: 26px;
    padding: 0 0.15rem;
    text-align: center;
    font-size: 0.85rem;
}

.ps-wait-label { font-size: 0.75rem; margin-left: 0.2rem; }

.ps-vol { width: 56px !important; }

.ps-mute {
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--ps-line);
    border-radius: 5px;
    background: var(--ps-panel);
    color: var(--ps-muted);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.ps-mute[aria-pressed="true"] {
    background: var(--ps-danger);
    border-color: var(--ps-danger);
    color: #2a0d08;
}

/* ---------- lightness axis ---------- */

.ps-spectrum { margin-top: 2rem; }

.ps-axis {
    position: relative;
    height: 44px;
    margin: 2rem 0 1rem;
    border-radius: 6px;
    background: linear-gradient(to right, #000, #fff);
    background: linear-gradient(to right in oklab, #000, #fff);
}

.ps-band-labels span {
    position: absolute;
    bottom: 100%;
    padding-bottom: 0.2rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--ps-muted);
}

.ps-dot {
    position: absolute;
    top: 50%;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid var(--ps-bg);
    box-shadow: 0 0 0 1px var(--ps-ink);
}

.ps-handle {
    position: absolute;
    top: -8px;
    bottom: -8px;
    width: 24px;
    transform: translateX(-50%);
    cursor: ew-resize;
    touch-action: none;
}

.ps-handle::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 4px;
    transform: translateX(-50%);
    border-radius: 2px;
    background: var(--ps-accent);
    box-shadow: 0 0 0 1px var(--ps-bg);
}

.ps-handle:focus-visible { outline: 2px solid var(--ps-accent); outline-offset: 2px; }

.ps-chips {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ps-chip {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    column-gap: 0.5rem;
    align-items: center;
    padding: 0.45rem 0.6rem;
    background: var(--ps-panel);
    border-radius: 8px;
    min-width: 7.5rem;
}

.ps-swatch {
    grid-row: span 2;
    width: 28px;
    height: 28px;
    border-radius: 5px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.ps-chip-note { font-weight: 700; }

.ps-chip-meta {
    font-size: 0.75rem;
    color: var(--ps-muted);
    line-height: 1.3;
}

/* ---------- explainer ---------- */

.ps-how {
    margin-top: 2rem;
    padding: 0.75rem 1rem;
    background: var(--ps-panel);
    border-radius: 10px;
    font-size: 0.9rem;
}

.ps-how summary { cursor: pointer; font-weight: 600; }

.ps-how li { margin: 0.4rem 0; }

/* ---------- footer: link home ---------- */

.ps-footer {
    padding: 0 1rem 2.5rem;
    text-align: center;
}

.ps-home {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    font-family: 'Clarendon', Georgia, 'Times New Roman', serif;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
    color: var(--ps-orange);
    text-decoration: none;
}

.ps-home:hover, .ps-home:focus-visible { text-decoration: underline; }

/* the favicon's double ring, in the main site's header-logo proportions
   (64px box, 8px strokes, inner ring inset 12px). Drawn as SVG rather than
   CSS borders: scaled to the text, borders land on fractional pixels and
   get rounded unevenly, which squashes the rings into ovals at some widths. */
.ps-home-mark {
    flex-shrink: 0;
    width: 1.1em;
    height: 1.1em;
    fill: none;
    stroke: var(--ps-orange);
    stroke-width: 8;
}

/* ---------- narrower screens ---------- */

/* Not enough room for rail + grid + row controls side by side: each row's
   controls drop beneath its cells. */
@media (max-width: 920px) {
    .ps-grid { grid-template-columns: repeat(var(--n), var(--cell)); }
    .ps-row-ctl { grid-column: 1 / -1; padding: 0 0 0.5rem; }
    .ps-vol { flex: 1; width: auto !important; }
}

/* Phone width: the rail turns into a horizontal bar above the grid, and the
   grid fills the width. */
@media (max-width: 640px) {
    .ps-tablet { flex-direction: column; }

    .ps-rail {
        width: auto;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0.6rem 0.75rem;
    }

    .ps-play { width: 56px; height: 56px; }

    .ps-faders {
        flex-direction: column;
        gap: 0.4rem;
        min-height: 0;
        min-width: 0;
    }

    .ps-fader { flex-direction: row-reverse; gap: 0.6rem; text-align: left; }
    .ps-fader br { display: none; }

    .ps-fader input[type="range"] {
        writing-mode: horizontal-tb;
        direction: ltr;
        width: 100%;
        min-height: 0;
    }

    .ps-grid { --grid-w: min(480px, calc(100vw - 2rem)); }

    .ps-thumb { width: 96px; height: 96px; }
}
