/* ============================================================
   base.css — Three.js demo UI base
   Aligned with the rether docs design system (@rether/tokens):
   warm paper aesthetic · JetBrains Mono + Space Grotesk ·
   terracotta accent · hairline borders · light / dark.
   Theme follows html[data-theme="dark"], synced from the host
   docs app (see the standalone page's inline theme script).
   ok  = good/positive · err = bad/negative · warn = caution.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,500;0,700;1,400&family=Space+Grotesk:wght@400;500;700&display=swap");

:root {
    /* ── typography ──────────────────────────────────────────── */
    --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
    --grotesk: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;

    /* ── surfaces (recessed → elevated) ──────────────────────── */
    --bg: #f3f2ee; /* page background */
    --surface: #e8e6df; /* canvas / inset wells (bg-sunken) */
    --panel: #f8f7f3; /* floating control panel (paper) */
    --panel-2: #f8f7f3; /* inputs on panel */
    --head: #f3f2ee; /* card header strips */

    /* ── lines & text ────────────────────────────────────────── */
    --border: #dedbd2;
    --border-soft: #e8e5dd;
    --border-strong: #cac6ba;
    --text: #6f6c63; /* default body (muted) */
    --text-strong: #1c1b18; /* titles / values (ink) */
    --text-faint: #9a978d; /* notes / disabled (faint) */

    /* ── accent (terracotta) ─────────────────────────────────── */
    --accent: #b4622a;
    --accent-strong: #9a5021;
    --accent-soft: #efe7da;

    /* ── text selection ──────────────────────────────────────── */
    --selection: var(--accent);
    --selection-text: #131210;

    /* ── semantics ───────────────────────────────────────────── */
    --bad: #a8483a;
    --good: #5f7d4f;
    --warn: #c07d1e;

    /* ── tinted fills (semantic backgrounds) ─────────────────── */
    --bad-bg: #ecdbd6;
    --bad-line: #cf9b90;
    --good-bg: #e4ebdb;
    --good-line: #a8bd94;
    --warn-bg: #f0e6d0;
    --warn-line: #d9bb85;

    /* ── shape ───────────────────────────────────────────────── */
    --radius: 7px;
    --radius-sm: 5px;
    --gap: 0.6rem;

    --shadow-panel: 0 2px 0 rgba(28, 27, 24, 0.04);
}

html[data-theme="dark"] {
    --bg: #131210;
    --surface: #0d0c0a;
    --panel: #191815;
    --panel-2: #191815;
    --head: #131210;

    --border: #2c2a25;
    --border-soft: #211f1b;
    --border-strong: #3c3a33;
    --text: #a8a498;
    --text-strong: #ececdf;
    --text-faint: #7c786d;

    --accent: #d6884a;
    --accent-strong: #e0a067;
    --accent-soft: #241d14;

    --bad: #d07a68;
    --good: #8fae6f;
    --warn: #d39a3e;

    --bad-bg: #2b1712;
    --bad-line: #5a2d24;
    --good-bg: #1a2013;
    --good-line: #35442a;
    --warn-bg: #251c0e;
    --warn-line: #4d3a1a;

    --shadow-panel: 0 2px 0 rgba(0, 0, 0, 0.2);
}

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

body {
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--selection);
    color: var(--selection-text);
}

/* ─── App shell ──────────────────────────────────────────────────── */
.app {
    max-width: 600px;
    margin: 0 auto;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

/* ─── Demo card (kit frame) ──────────────────────────────────────────
   The bordered shell every kit demo sits in: a header strip with a
   status dot + eyebrow label, over a padded body. Fills its container
   so the canvas comparison can grow. */
.demo-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
}
.demo-card-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 22px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--head);
}
.demo-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--good);
    flex: 0 0 auto;
}
.demo-card-eyebrow {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.demo-card-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    padding: 18px 22px 20px;
}

/* ─── Typography ─────────────────────────────────────────────────── */
.t-title {
    margin: 0;
    font-family: var(--grotesk);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-strong);
    letter-spacing: -0.01em;
}

.t-subtitle {
    margin: 0;
    font-family: var(--grotesk);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-strong);
}

/* small uppercase tracking label — for control rows, stat keys */
.t-label {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-faint);
}

.t-body {
    font-size: 13px;
    color: var(--text);
}

.t-note {
    font-size: 10.5px;
    color: var(--text-faint);
    line-height: 1.55;
}

.t-mono-num {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--text-strong);
}

.t-bad {
    color: var(--bad);
}
.t-good {
    color: var(--good);
}
.t-warn {
    color: var(--warn);
}
.t-strong {
    color: var(--text-strong);
    font-weight: 700;
}

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text-strong);
    cursor: pointer;
    user-select: none;
    transition:
        background 0.12s ease,
        border-color 0.12s ease,
        color 0.12s ease,
        transform 0.04s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--border-strong);
}
.btn:active {
    transform: translateY(1px);
}
.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* primary — terracotta accent fill */
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

/* secondary — same as base .btn but explicit for clarity */
.btn-secondary {
    /* inherits .btn */
}

/* semantic action buttons */
.btn-danger {
    color: var(--bad);
    border-color: var(--bad-line);
    background: var(--bad-bg);
}
.btn-danger:hover {
    background: var(--bad);
    border-color: var(--bad);
    color: #fff;
}
.btn-go {
    color: var(--good);
    border-color: var(--good-line);
    background: var(--good-bg);
}
.btn-go:hover {
    background: var(--good);
    border-color: var(--good);
    color: #fff;
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* toggle button — pressed state via aria-pressed */
.btn-toggle[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-sm {
    padding: 5px 9px;
    font-size: 10px;
}
.btn-icon {
    padding: 6px;
    width: 28px;
    height: 28px;
    justify-content: center;
}

/* ─── Control row (label + control) ──────────────────────────────── */
.control {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 26px;
}

.control > .t-label {
    flex: 0 0 auto;
    min-width: 84px;
}

.control-grow {
    flex: 1;
    min-width: 0;
}

/* ─── Slider + numeric input ─────────────────────────────────────── */
.slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 3px;
    border-radius: 3px;
    background: var(--border-strong);
    outline: none;
    cursor: pointer;
    min-width: 0;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--panel);
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--border-strong);
    transition: background 0.12s ease;
}
.slider::-webkit-slider-thumb:hover {
    background: var(--accent-strong);
}

.slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--panel);
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--border-strong);
}

/* numeric value chip shown beside a slider */
.slider-value {
    flex: 0 0 auto;
    min-width: 44px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 12px;
    color: var(--text-strong);
}

/* number / text input */
.input {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-strong);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    width: 72px;
    outline: none;
    font-variant-numeric: tabular-nums;
    transition: border-color 0.12s ease;
}
.input:focus {
    border-color: var(--accent);
}
.input::-webkit-outer-spin-button,
.input::-webkit-inner-spin-button {
    opacity: 0.4;
}

/* ─── Toggle switch ──────────────────────────────────────────────── */
.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}
.switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch-track {
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: var(--border-strong);
    border: 1px solid var(--border-soft);
    transition: background 0.15s ease;
    flex: 0 0 auto;
    position: relative;
}
.switch-track::after {
    content: "";
    position: absolute;
    top: 1px;
    left: 1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--panel-2);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
    transition: transform 0.15s ease;
}
.switch input:checked + .switch-track {
    background: var(--accent);
}
.switch input:checked + .switch-track::after {
    transform: translateX(14px);
}
.switch input:focus-visible + .switch-track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ─── Checkbox ───────────────────────────────────────────────────── */
.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: var(--text);
}
.check input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.check-box {
    width: 15px;
    height: 15px;
    border-radius: 3px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    transition:
        background 0.12s ease,
        border-color 0.12s ease;
}
.check-box::after {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 1px;
    background: #fff;
    transform: scale(0);
    transition: transform 0.12s ease;
}
.check input:checked + .check-box {
    background: var(--accent);
    border-color: var(--accent);
}
.check input:checked + .check-box::after {
    transform: scale(1);
}
.check input:focus-visible + .check-box {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ─── Select (dropdown) ──────────────────────────────────────────── */
.select {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-strong);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 26px 5px 9px;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236f6c63' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    transition: border-color 0.12s ease;
}
.select:focus {
    border-color: var(--accent);
}

/* ─── Segmented control ──────────────────────────────────────────── */
.segmented {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}
.segmented button {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
    background: transparent;
    border: none;
    border-radius: 3px;
    padding: 4px 10px;
    cursor: pointer;
    transition:
        background 0.12s ease,
        color 0.12s ease;
    white-space: nowrap;
}
.segmented button:hover {
    color: var(--text-strong);
}
.segmented button[aria-pressed="true"] {
    background: var(--panel-2);
    color: var(--text-strong);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ─── Stat bar ───────────────────────────────────────────────────── */
.stats-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: baseline;
    font-size: 10px;
}
.stat {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
}
.stat-key {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
}
.stat-val {
    font-weight: 700;
    font-size: 12px;
    color: var(--text-strong);
    font-variant-numeric: tabular-nums;
}
.stat-val.bad {
    color: var(--bad);
}
.stat-val.good {
    color: var(--good);
}

/* big readout (FPS hero) */
.readout {
    display: inline-flex;
    align-items: baseline;
    gap: 0.4rem;
}
.readout-num {
    font-family: var(--grotesk);
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--text-strong);
}
.readout-num.bad {
    color: var(--bad);
}
.readout-num.good {
    color: var(--good);
}
.readout-unit {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
}

/* speedup / delta badge */
.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-variant-numeric: tabular-nums;
}
.badge-good {
    background: var(--good-bg);
    color: var(--good);
    border: 1px solid var(--good-line);
}
.badge-bad {
    background: var(--bad-bg);
    color: var(--bad);
    border: 1px solid var(--bad-line);
}
.badge-neutral {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

/* ─── Banner / callout ───────────────────────────────────────────── */
.banner {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 11px;
    padding: 9px 12px;
    border-radius: var(--radius);
    line-height: 1.5;
}
.banner-icon {
    flex: 0 0 auto;
    font-weight: 700;
}
.banner-warn {
    color: var(--warn);
    background: var(--warn-bg);
    border: 1px solid var(--warn-line);
}
.banner-bad {
    color: var(--bad);
    background: var(--bad-bg);
    border: 1px solid var(--bad-line);
}
.banner-good {
    color: var(--good);
    background: var(--good-bg);
    border: 1px solid var(--good-line);
}
.banner-info {
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
}
.banner code {
    font-family: var(--mono);
    background: var(--panel);
    border: 1px solid var(--border-soft);
    border-radius: 3px;
    padding: 0 4px;
}

/* ─── Canvas zone ────────────────────────────────────────────────── */
.canvas-zone {
    position: relative;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 0;
}
.canvas-zone canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* placeholder striping for an empty zone */
.canvas-zone.is-empty::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 9px,
        var(--border-soft) 9px,
        var(--border-soft) 10px
    );
}
.canvas-zone .zone-label {
    position: absolute;
    left: 8px;
    bottom: 7px;
    font-size: 10px;
    color: var(--text-faint);
    background: color-mix(in srgb, var(--surface) 80%, transparent);
    padding: 2px 6px;
    border-radius: 3px;
    backdrop-filter: blur(2px);
}

/* per-panel error notice (shown in place of a canvas) */
.panel-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 120px;
    padding: 14px;
    text-align: center;
    font-size: 11px;
    line-height: 1.5;
    color: var(--bad);
    background: var(--bad-bg);
}

/* side-by-side comparison */
.compare {
    display: flex;
    gap: var(--gap);
    min-height: 0;
}
.compare > .panel-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
    min-height: 0;
}
.compare-divider {
    width: 1px;
    background: var(--border);
    flex: 0 0 auto;
}

.panel-col-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
}

/* ─── Control panel (container) ──────────────────────────────────── */
.control-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.control-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-soft);
}
.control-divider {
    height: 1px;
    background: var(--border-soft);
    margin: 0.1rem 0;
}

/* floating variant — sits over a canvas */
.control-panel.floating {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 230px;
    z-index: 5;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(6px);
    box-shadow: var(--shadow-panel);
}

/* collapse toggle for floating panel */
.panel-collapse {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-faint);
    font-family: var(--mono);
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
}
.panel-collapse:hover {
    color: var(--text-strong);
}
.control-panel.collapsed .control-panel-body {
    display: none;
}
.control-panel.collapsed .control-panel-head {
    padding-bottom: 0;
    border-bottom: none;
}
.control-panel-body {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

/* ─── Console / log output ───────────────────────────────────────── */
.console {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    font-size: 11px;
    line-height: 1.65;
    color: var(--text);
    height: 110px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
.console-line {
    display: flex;
    gap: 9px;
}
.console-time {
    color: var(--accent);
    flex: 0 0 auto;
    user-select: none;
}
.console .c-bad {
    color: var(--bad);
}
.console .c-good {
    color: var(--good);
}
.console .c-warn {
    color: var(--warn);
}
.console .c-info {
    color: var(--text);
}

/* ─── Misc helpers ───────────────────────────────────────────────── */
.row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}
.spacer {
    flex: 1;
}

/* kit-only section scaffolding */
.kit-section {
    border-top: 1px solid var(--border-soft);
    padding-top: 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.kit-section:first-of-type {
    border-top: none;
}
.kit-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-faint);
    font-weight: 700;
}
