/*
 * Something Pithy — direction
 *
 * A clearing at dusk. Dark, warm ground; moss and lichen for anything alive; one ember
 * for the things that need care — recording, clipping, deleting. Nature is in the palette
 * and the softness, not in the decoration: no leaf borders, no wood-grain images, one fir
 * in the favicon and that is the lot. The reason is practical as much as aesthetic — the
 * meters and waveforms are the loudest thing on the screen, and they only read that way
 * on a quiet ground.
 *
 * Dark only, declared rather than defaulted. This gets used in the evening, and every
 * canvas in the app is drawn for a dark ground; a light variant would be a second set of
 * colours to keep the meters legible in, for no gain.
 *
 * Canvas colours are read from the custom properties below via getComputedStyle, so the
 * palette lives here and nowhere else. Renaming one means updating readPalette() in
 * assets/studio/meters.js.
 */

:root {
    color-scheme: dark;

    --ground: #131714;
    --hollow: #1a201b;
    --raised: #212a22;
    --rule: #2d382e;
    --bark: #3a352c;

    --ink: #e9efe5;
    --mist: #93a48e;

    /* Alive: levels, connected peers, anything working as it should. */
    --moss: #6f9367;
    --lichen: #c8d6b9;

    /* Care: recording, clipping, deleting. Rationed on purpose — three uses total. */
    --ember: #c96f4a;

    --radius: 10px;
    --radius-sm: 6px;
    --gap: 1rem;

    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --serif: ui-serif, Georgia, "Times New Roman", serif;
}

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

/* The browser's own [hidden] rule is display:none at user-agent weight, so any author
   rule that sets display — .btn below, for one — silently beats it and the element stays
   on screen. Several things here are shown and hidden by the hidden property alone, so
   this has to win. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background-color: var(--ground);

    /* The only texture in the app: a wash of light from above left, and contour lines so
       faint they read as paper grain rather than as a pattern. Both are gradients, so
       there is no image to load and nothing for the CSP to allow. */
    background-image:
        radial-gradient(120% 80% at 20% -10%, rgb(111 147 103 / 12%), transparent 60%),
        repeating-linear-gradient(115deg, rgb(200 214 185 / 2%) 0 1px, transparent 1px 84px);
    background-attachment: fixed;
    min-height: 100vh;
}

h1,
h2,
h3 {
    font-weight: 600;
    line-height: 1.25;
    margin: 0 0 0.5rem;
}

h2 {
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    color: var(--lichen);
}

h3 {
    font-size: 1rem;
}

p {
    margin: 0 0 0.6rem;
}

code {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.9em;
    background: rgb(0 0 0 / 25%);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

a {
    color: var(--lichen);
}

.muted,
small {
    color: var(--mist);
}

small {
    display: block;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.35;
}

.wordmark {
    font-family: var(--serif);
    font-size: 1.35rem;
    letter-spacing: 0.01em;
    margin: 0;
    color: var(--ink);
}

/* --- Controls ----------------------------------------------------------- */

.btn {
    font: inherit;
    font-weight: 500;
    color: var(--ink);
    background: var(--raised);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.9rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.btn:hover:not(:disabled) {
    background: #29332a;
    border-color: var(--moss);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--lichen);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--moss);
    border-color: var(--moss);
    color: #10160f;
}

.btn-primary:hover:not(:disabled) {
    background: #7ba471;
    border-color: #7ba471;
}

.btn-quiet {
    background: transparent;
    font-weight: 400;
    color: var(--mist);
}

.btn-quiet:hover:not(:disabled) {
    color: var(--ink);
}

.btn-record {
    border-color: var(--ember);
    color: var(--ember);
}

.btn-record:hover:not(:disabled) {
    background: rgb(201 111 74 / 15%);
    border-color: var(--ember);
}

.btn-danger:hover:not(:disabled) {
    color: var(--ember);
    border-color: var(--ember);
}

.btn[aria-pressed="true"] {
    background: var(--ember);
    border-color: var(--ember);
    color: #17100c;
}

.field {
    display: block;
    margin-bottom: 0.9rem;
}

.field > span {
    display: block;
    font-size: 0.85rem;
    color: var(--mist);
    margin-bottom: 0.3rem;
}

input[type="text"],
input[type="password"],
select {
    font: inherit;
    width: 100%;
    color: var(--ink);
    background: var(--ground);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.7rem;
}

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

.check {
    display: flex;
    gap: 0.6rem;
    align-items: start;
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
}

.check input {
    margin-top: 0.25rem;
    accent-color: var(--moss);
}

.alert,
.warn {
    border-left: 3px solid var(--ember);
    background: rgb(201 111 74 / 12%);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 0.6rem 0.8rem;
    margin-bottom: 1rem;
}

.pill {
    font-size: 0.8rem;
    color: var(--mist);
    border: 1px solid var(--rule);
    border-radius: 999px;
    padding: 0.2rem 0.7rem;
}

.pill[data-state="connected"] {
    color: var(--lichen);
    border-color: var(--moss);
}

.pill[data-state="retrying"] {
    color: var(--ember);
    border-color: var(--ember);
}

/* --- The gate ----------------------------------------------------------- */

.gate {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.gate-card {
    width: min(26rem, 100%);
    background: rgb(26 32 27 / 92%);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 1.75rem;
}

.gate-card .wordmark {
    font-size: 1.6rem;
}

.tagline {
    color: var(--mist);
    margin-bottom: 1.5rem;
}

.gate-card .btn-primary {
    width: 100%;
    padding: 0.65rem;
    font-size: 1.02rem;
}

.gate-note {
    margin: 1.1rem 0 0;
    font-size: 0.85rem;
    color: var(--mist);
}

/* --- The studio --------------------------------------------------------- */

.studio {
    max-width: 68rem;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: var(--gap);
    flex-wrap: wrap;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.room {
    margin: 0;
    color: var(--mist);
    font-size: 0.9rem;
}

.room strong {
    color: var(--ink);
    font-weight: 600;
}

.panel,
.stage {
    background: rgb(26 32 27 / 80%);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
}

/* The trace. Tall enough to read a voice in, short enough not to dominate. */
.trace {
    display: block;
    width: 100%;
    height: 108px;
    margin-bottom: 0.9rem;
}

.transport {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.clock {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 1.4rem;
    margin: 0 0 0 auto;
    color: var(--mist);
    font-variant-numeric: tabular-nums;
}

/* Recording is the one state worth shouting about, so the ember shows up in three
   places at once: the clock, the trace edge and the record button. */
.studio[data-recording="true"] .clock {
    color: var(--ember);
}

.studio[data-recording="true"] .trace {
    border-bottom: 2px solid var(--ember);
}

.status {
    margin: 0.9rem 0 0;
    font-size: 0.92rem;
    color: var(--mist);
    min-height: 1.4em;
}

.status[data-level="error"] {
    color: var(--ember);
}

.status[data-level="warn"] {
    color: var(--lichen);
}

.columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
    gap: 1.25rem;
    align-items: start;
}

/* --- Roster ------------------------------------------------------------- */

.roster {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.peer {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "name tags"
        "meter meter"
        "volume volume";
    gap: 0.3rem 0.6rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--rule);
}

.roster > .peer:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.peer-name {
    grid-area: name;
    font-weight: 500;
}

.peer[data-muted="true"] .peer-name {
    color: var(--mist);
}

.peer-tags {
    grid-area: tags;
    font-size: 0.8rem;
    color: var(--mist);
    text-align: right;
}

.peer-meter {
    grid-area: meter;
    display: block;
    width: 100%;
    height: 10px;
}

.peer-volume {
    grid-area: volume;
}

/* --- Takes -------------------------------------------------------------- */

.takes {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.take {
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    padding: 0.85rem 0.95rem;
    background: rgb(19 23 20 / 70%);
}

.take-heading {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.take-heading h3 {
    margin: 0;
}

.take-meta {
    color: var(--mist);
    font-size: 0.85rem;
    margin: 0.2rem 0 0.7rem;
}

.take-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.take-player audio {
    width: 100%;
    margin-top: 0.7rem;
}

.badge {
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    text-transform: lowercase;
    color: var(--mist);
    border: 1px solid var(--rule);
    border-radius: 999px;
    padding: 0.1rem 0.55rem;
}

.badge-mix {
    color: var(--lichen);
    border-color: var(--moss);
}

.badge-warn {
    color: var(--ember);
    border-color: var(--ember);
}

/* --- Editor ------------------------------------------------------------- */

.editor-canvas {
    display: block;
    width: 100%;
    height: 150px;
    background: rgb(19 23 20 / 80%);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    /* A selection is made by dragging, and the browser's own text/image drag would
       fight it. */
    touch-action: none;
    cursor: crosshair;
}

.editor-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.footer {
    color: var(--mist);
    font-size: 0.85rem;
    border-top: 1px solid var(--rule);
    padding-top: 1rem;
}

.footer p {
    margin: 0;
}

@media (max-width: 40rem) {
    .clock {
        margin-left: 0;
        width: 100%;
    }

    .trace {
        height: 84px;
    }
}

/* Meters and the trace are motion by definition, but the transitions and the smooth
   scroll into the editor are not. */
@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0ms !important;
        scroll-behavior: auto !important;
    }
}
