/* Animate: colour tokens (light, then dark), the gallery, the editor (top bar, tool bar, stage, the timeline dock,
   the panel), the picker, dialogs and menus, then phones. */

:root {
    --bg: #ffffff;
    --bg-2: #f4f4f2;
    --bg-3: #ebebe8;
    --ink: #2b2a27;
    --ink-2: #6f6e69;
    --ink-3: #a5a49f;
    --line: #e4e3df;
    --hover: rgba(0, 0, 0, 0.05);
    --accent: #3b63fb;
    --accent-ink: #ffffff;
    --accent-soft: rgba(59, 99, 251, 0.12);
    --danger: #e03e3e;
    --pasteboard: #d9d9dc;
    --cell: #ffffff;
    --cell-alt: #f6f6f4;
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.16), 0 1px 3px rgba(0, 0, 0, 0.12);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #232325;
        --bg-2: #1b1b1d;
        --bg-3: #2c2c2f;
        --ink: #ededeb;
        --ink-2: #a9a8a4;
        --ink-3: #75746f;
        --line: #38383b;
        --hover: rgba(255, 255, 255, 0.07);
        --accent: #6d8cff;
        --accent-soft: rgba(109, 140, 255, 0.18);
        --pasteboard: #3a3a3e;
        --cell: #26262a;
        --cell-alt: #2b2b2f;
        --shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #232325;
    --bg-2: #1b1b1d;
    --bg-3: #2c2c2f;
    --ink: #ededeb;
    --ink-2: #a9a8a4;
    --ink-3: #75746f;
    --line: #38383b;
    --hover: rgba(255, 255, 255, 0.07);
    --accent: #6d8cff;
    --accent-soft: rgba(109, 140, 255, 0.18);
    --pasteboard: #3a3a3e;
    --cell: #26262a;
    --cell-alt: #2b2b2f;
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { opacity: 0.35; cursor: default; }
select option { background: var(--bg); color: var(--ink); }
input[type=number], input[type=text], select, textarea {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 6px;
    min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.ic { display: block; flex: none; }
.screen[hidden], [hidden] { display: none !important; }


/* ---------- Gallery ---------- */

#gallery { height: 100%; overflow: auto; background: var(--bg-2); }
.g-head {
    position: sticky; top: 0; z-index: 2;
    display: flex; align-items: center; gap: 16px;
    padding: 14px 24px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.g-head h1 { margin: 0; font-size: 20px; font-weight: 650; }
.g-home { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); text-decoration: none; font-weight: 600; }
.logo { display: block; width: 24px; height: 24px; border-radius: 6px; flex: none; }
.g-actions { margin-left: auto; display: flex; gap: 8px; }
.g-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line);
    background: var(--bg); color: var(--ink); text-decoration: none; font-weight: 600;
}
.g-btn:hover { background: var(--hover); }
.g-new { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.g-new:hover { background: var(--accent); filter: brightness(1.08); }
.g-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px;
    padding: 24px; max-width: 1400px; margin: 0 auto;
}
.g-card { position: relative; background: var(--bg); border-radius: 12px; border: 1px solid var(--line); overflow: hidden; }
.g-thumb { display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 16 / 10; background: var(--bg-3); cursor: pointer; }
.g-thumb img { max-width: 90%; max-height: 86%; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); background: #fff; }
.g-meta { padding: 10px 40px 12px 12px; }
.g-meta b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-meta small { color: var(--ink-2); }
.g-more { position: absolute; right: 6px; bottom: 12px; }
.g-empty { text-align: center; padding: 80px 24px; color: var(--ink-2); }
.g-empty h2 { color: var(--ink); margin: 16px 0 6px; }
.g-empty-art { display: inline-flex; padding: 22px; border-radius: 24px; background: var(--accent-soft); color: var(--accent); }
.g-empty-btns { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }


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

#editor { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
#topbar {
    flex: none; display: flex; align-items: center; gap: 4px;
    height: 44px; padding: 0 8px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.tb { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 34px; height: 32px; padding: 0 6px; border-radius: 7px; color: var(--ink); }
.tb:hover:not(:disabled) { background: var(--hover); }
.tb.primary { background: var(--accent); color: var(--accent-ink); padding: 0 12px; font-weight: 600; }
.tb.primary:hover { background: var(--accent); filter: brightness(1.08); }
.tb.zoom { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink-2); min-width: 52px; }
.tb-home { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-2); text-decoration: none; font-weight: 650; padding: 0 6px; }
.name-wrap { position: relative; display: flex; align-items: center; }
#doc-name { width: 170px; border-color: transparent; background: none; font-weight: 600; }
#doc-name:hover, #doc-name:focus { border-color: var(--line); background: var(--bg-2); }
#saved { position: absolute; right: -2px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); opacity: 0.6; }
#saved.on { background: #30a46c; }
#menubar { display: flex; gap: 0; margin-left: 6px; }
#menubar button { height: 30px; padding: 0 9px; border-radius: 6px; color: var(--ink); }
#menubar button:hover, #menubar button.on { background: var(--hover); }
.grow { flex: 1; }
.phone-only { display: none !important; }

#main { flex: 1; display: flex; min-height: 0; position: relative; }

/* the tool bar */
#tools {
    flex: none; width: 52px; padding: 6px 5px; overflow-y: auto; overflow-x: hidden;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    border-right: 1px solid var(--line); background: var(--bg); scrollbar-width: none;
}
.tool { position: relative; display: flex; align-items: center; justify-content: center; width: 40px; height: 36px; border-radius: 8px; color: var(--ink); flex: none; }
.tool:hover { background: var(--hover); }
.tool.on { background: var(--accent-soft); color: var(--accent); }
.tool.more::after { content: ''; position: absolute; right: 3px; bottom: 3px; border: 3px solid transparent; border-right-color: currentColor; border-bottom-color: currentColor; opacity: 0.6; }
.tool .tname { display: none; }
.tool-sep { width: 28px; height: 1px; background: var(--line); margin: 3px 0; flex: none; }
.paint-chips { position: relative; width: 44px; height: 58px; margin-top: 8px; flex: none; }
.pc { position: absolute; width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--ink-3); overflow: hidden; background: #fff linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%) 0 0 / 8px 8px; }
.pc span { position: absolute; inset: 0; }
.pc.line { left: 2px; top: 2px; z-index: 1; }
.pc.fill { left: 16px; top: 18px; }
.pc.line::after { content: ''; position: absolute; inset: 7px; border-radius: 2px; background: var(--bg); border: 1px solid var(--ink-3); }
.pc.none span { background: #fff linear-gradient(to top right, transparent calc(50% - 1px), var(--danger) calc(50% - 1px), var(--danger) calc(50% + 1px), transparent calc(50% + 1px)) !important; }
.pc.linked::before { content: ''; position: absolute; right: 0; bottom: 0; z-index: 1; border: 5px solid transparent; border-right-color: #fff; border-bottom-color: #fff; }

/* the centre: stage above the dock */
#centre { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#stage { flex: 1; position: relative; min-height: 80px; overflow: hidden; background: var(--pasteboard); touch-action: none; }
#art, #over { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#over[data-tool=brush], #over[data-tool=pencil], #over[data-tool=pen], #over[data-tool=line], #over[data-tool=rect], #over[data-tool=ellipse],
#over[data-tool=polygon], #over[data-tool=star], #over[data-tool=bucket], #over[data-tool=eyedropper], #over[data-tool=path], #over[data-tool=bone],
#over[data-tool=curve] { cursor: crosshair; }
#over[data-tool=eraser] { cursor: cell; }
#over[data-tool=hand], #over.space { cursor: grab; }
#over.panning { cursor: grabbing !important; }
#over[data-tool=zoom] { cursor: zoom-in; }
#crumbs {
    position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; max-width: calc(100% - 24px);
    padding: 3px 6px; border-radius: 8px; background: var(--bg); box-shadow: var(--shadow); font-size: 12px; white-space: nowrap; overflow: hidden; z-index: 3;
}
#crumbs button { padding: 3px 6px; border-radius: 5px; color: var(--ink-2); }
#crumbs button:hover { background: var(--hover); }
#crumbs button.on { color: var(--ink); font-weight: 600; }
#crumbs span { color: var(--ink-3); }
#hint {
    position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: calc(100% - 24px);
    padding: 5px 12px; border-radius: 14px; background: rgba(20, 20, 22, 0.78); color: #fff; font-size: 12px;
    pointer-events: none; opacity: 0; transition: opacity 0.2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 3;
}
#hint.show { opacity: 1; }
#quick { display: none; }

/* the dock: timeline, X-sheet or graph */
#dock { flex: none; height: var(--dock-h, 240px); display: flex; flex-direction: column; border-top: 1px solid var(--line); background: var(--bg); position: relative; min-height: 0; }
#dock-grip { position: absolute; left: 0; right: 0; top: -4px; height: 8px; cursor: ns-resize; z-index: 4; touch-action: none; }
#tl-bar { flex: none; display: flex; align-items: center; gap: 2px; padding: 3px 6px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
#tl-bar .ib { width: 30px; height: 28px; }
#tl-bar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; flex: none; }
#tl-bar .fnum { flex: none; width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
#tl-bar .fps { width: 52px; }
#tl-bar .lbl { flex: none; }
#tl-bar .seg { flex: none; }
#tl-bar .seg button { padding: 0 8px; }
#tl-wrap { flex: 1; position: relative; min-height: 0; display: flex; }
#tl-names { flex: none; width: var(--names-w, 210px); overflow: hidden; position: relative; border-right: 1px solid var(--line); user-select: none; -webkit-user-select: none; touch-action: none; }
#tl-names-in { position: absolute; left: 0; right: 0; top: 0; }
#tl-grid { flex: 1; min-width: 0; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#tl-hscroll { position: absolute; left: var(--names-w, 210px); right: 0; bottom: 0; height: 9px; touch-action: none; }
#tl-hscroll i { position: absolute; top: 2px; height: 6px; border-radius: 3px; background: var(--ink-3); opacity: 0.5; min-width: 24px; }
.tl-head { position: sticky; top: 0; height: 22px; display: flex; align-items: center; gap: 4px; padding: 0 6px; font-size: 11px; color: var(--ink-3); background: var(--bg); border-bottom: 1px solid var(--line); z-index: 1; }
.tl-row { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 1px; padding-left: calc(4px + var(--d, 0) * 14px); padding-right: 2px; font-size: 13px; border-bottom: 1px solid var(--line); background: var(--bg); }
.tl-row.on { background: var(--accent-soft); }
.tl-row .lc { width: 4px; align-self: stretch; margin-right: 4px; background: var(--lc); border-radius: 2px; flex: none; }
.tl-row .tw { width: 16px; display: inline-flex; justify-content: center; color: var(--ink-2); flex: none; }
.tl-row .ty { color: var(--ink-2); display: inline-flex; flex: none; margin-right: 4px; }
.tl-row .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 0; }
.tl-row .nm input { width: 100%; padding: 1px 4px; }
.tl-row .ib { width: 24px; height: 24px; color: var(--ink-3); }
.tl-row .ib.lit { color: var(--ink); }
.tl-row.hid .nm { opacity: 0.45; }
.tl-row.special { color: var(--ink-2); font-style: italic; }
.tl-row.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.tl-row.drop-below { box-shadow: inset 0 -2px 0 var(--accent); }
.tl-row.drop-into { box-shadow: inset 0 0 0 2px var(--accent); }

/* X-sheet */
#xsheet { flex: 1; overflow: auto; min-height: 0; font-size: 12px; }
.xs { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.xs th { position: sticky; top: 0; z-index: 1; background: var(--bg); border: 1px solid var(--line); padding: 3px 6px; font-weight: 600; min-width: 74px; white-space: nowrap; }
.xs th.fr, .xs td.fr { position: sticky; left: 0; z-index: 2; background: var(--bg-2); min-width: 44px; width: 44px; text-align: right; color: var(--ink-3); }
.xs td { border: 1px solid var(--line); height: 20px; padding: 0 6px; cursor: cell; background: var(--cell); position: relative; }
.xs tr.sec td { border-bottom: 2px solid var(--ink-3); }
.xs td.hold::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; border-left: 1px solid var(--ink-2); }
.xs td.blank { color: var(--ink-3); text-align: center; }
.xs td.on { outline: 2px solid var(--accent); outline-offset: -2px; }
.xs tr.now td { background: var(--accent-soft); }
.xs td input { width: 100%; border: 0; padding: 0; height: 18px; background: var(--bg); }

/* graph editor */
#graph { flex: 1; display: flex; min-height: 0; }
#graph .g-list { flex: none; width: 210px; overflow: auto; border-right: 1px solid var(--line); padding: 6px; font-size: 13px; }
#graph .g-list label { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 5px; }
#graph .g-list label i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
#graph canvas { flex: 1; min-width: 0; height: 100%; display: block; touch-action: none; }

/* the panel */
#panel { flex: none; width: 290px; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--bg); min-height: 0; }
#panel-tabs { flex: none; display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--line); }
#panel-tabs [data-tab] { padding: 6px 6px 8px; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; font-size: 13px; }
#panel-tabs [data-tab].on { color: var(--ink); border-bottom-color: var(--accent); }
#panel-body { flex: 1; overflow-y: auto; padding: 4px 12px 40px; overscroll-behavior: contain; }
.kind { padding: 10px 0 2px; font-weight: 650; display: flex; align-items: center; gap: 6px; }
.kind small { color: var(--ink-2); font-weight: 400; }
.ps { border-bottom: 1px solid var(--line); padding: 8px 0 10px; }
.ps:last-child { border-bottom: 0; }
.ps h3 { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
.ps h3[data-fold] { cursor: pointer; }
.ps.shut .ps-body { display: none; }
.ps-body > * + * { margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.row { display: flex; align-items: center; gap: 6px; }
.row.wrap { flex-wrap: wrap; }
.nf { display: flex; align-items: center; gap: 6px; min-width: 0; }
.nf > span { color: var(--ink-2); font-size: 12px; min-width: 12px; display: flex; white-space: nowrap; }
.nf input { width: 100%; }
.nf.key > span::after { content: '◆'; margin-left: 3px; color: var(--ink-3); font-size: 9px; }
.nf.key.keyed > span::after { color: #f76b15; }
.sf { display: flex; flex-direction: column; gap: 3px; }
.sf > span { color: var(--ink-2); font-size: 12px; }
.sf input, .sf select, .sf textarea { width: 100%; }
.rf { display: grid; grid-template-columns: 78px 1fr 44px; align-items: center; gap: 6px; }
.rf > span { color: var(--ink-2); font-size: 12px; }
.rf output { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { accent-color: var(--accent); margin: 0; }
.ib { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; color: var(--ink); flex: none; }
.ib:hover { background: var(--hover); }
.ib.on { background: var(--accent-soft); color: var(--accent); }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-s { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border-radius: 15px; border: 1px solid var(--line); font-size: 13px; }
.btn-s:hover { background: var(--hover); }
.btn-s.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-s.danger { color: var(--danger); }
.hint { color: var(--ink-2); font-size: 12px; margin: 0; }
.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { flex: 1; height: 26px; border-radius: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.seg button.on { background: var(--bg); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); }
.chip { position: relative; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--ink-3); overflow: hidden; flex: none; background: #fff linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%) 0 0 / 8px 8px; }
.chip span { position: absolute; inset: 0; }
.chip.none span { background: #fff linear-gradient(to top right, transparent calc(50% - 1px), var(--danger) calc(50% - 1px), var(--danger) calc(50% + 1px), transparent calc(50% + 1px)) !important; }
.ease-box { position: relative; width: 100%; aspect-ratio: 1.6; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; touch-action: none; }
.ease-box canvas { width: 100%; height: 100%; display: block; }
.eases { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.eases button { height: 34px; border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.eases button.on { border-color: var(--accent); background: var(--accent-soft); }
.eases svg { width: 28px; height: 22px; }
.eases path { fill: none; stroke: currentColor; stroke-width: 1.8; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.thumb-b { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; font-size: 11px; color: var(--ink-2); min-width: 0; }
.thumb-b img, .thumb-b i { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 5px; display: block; }
.thumb-b span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb-b.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.lib-row { display: flex; align-items: center; gap: 8px; padding: 4px; border-radius: 8px; }
.lib-row:hover { background: var(--hover); }
.lib-row img, .lib-row > i { width: 48px; height: 36px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 5px; flex: none; display: flex; align-items: center; justify-content: center; color: var(--ink-3); }
.lib-row span { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.lib-row small { color: var(--ink-2); font-size: 11px; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 5px; }
.swatch { aspect-ratio: 1; border-radius: 5px; border: 1px solid rgba(0, 0, 0, 0.15); position: relative; }
.swatch:hover { transform: scale(1.1); }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.pal-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.pal-row .chip { cursor: pointer; }
.pal-row input[type=text] { flex: 1; }
.pal-row small { color: var(--ink-3); font-size: 11px; min-width: 22px; text-align: right; }
.fx-item { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; gap: 6px; }
.fx-item.off { opacity: 0.55; }
.fx-head { display: flex; align-items: center; gap: 4px; }
.fx-head b { flex: 1; font-size: 13px; }
.scene-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scene-card { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.scene-card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.scene-card img, .scene-card > i { width: 100%; aspect-ratio: 16 / 10; object-fit: contain; background: #fff; display: block; cursor: pointer; }
.scene-card .sc-meta { padding: 4px 6px; display: flex; align-items: center; gap: 2px; font-size: 12px; }
.scene-card .sc-meta b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-card textarea { border: 0; border-top: 1px solid var(--line); border-radius: 0; font-size: 12px; resize: vertical; min-height: 40px; }
.wave { width: 100%; height: 48px; background: var(--bg-2); border-radius: 6px; display: block; }

/* the colour picker */
.picker {
    position: fixed; z-index: 40; width: 248px; padding: 10px; border-radius: 12px;
    background: var(--bg); border: 1px solid var(--line); box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 8px;
}
.pk-head { display: flex; align-items: center; justify-content: space-between; }
.pk-sv { position: relative; height: 150px; border-radius: 6px; cursor: crosshair; touch-action: none; }
.pk-sv-w, .pk-sv-b { position: absolute; inset: 0; border-radius: 6px; }
.pk-sv-w { background: linear-gradient(90deg, #fff, rgba(255, 255, 255, 0)); }
.pk-sv-b { background: linear-gradient(0deg, #000, rgba(0, 0, 0, 0)); }
.pk-sv i, .pk-hue i, .pk-alpha i { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); pointer-events: none; }
.pk-hue, .pk-alpha { position: relative; height: 14px; border-radius: 7px; cursor: pointer; touch-action: none; }
.pk-hue { background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.pk-alpha { background: linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%) 0 0 / 8px 8px, #fff; }
.pk-alpha b { position: absolute; inset: 0; border-radius: 7px; }
.pk-hue i, .pk-alpha i { top: 7px; }
.pk-row { display: flex; align-items: center; gap: 6px; }
.pk-now { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.pk-hex { flex: 1; font-family: ui-monospace, monospace; }
.pk-none { color: var(--ink-2); text-align: center; margin: 14px 0; }

/* dialogs */
.dialog { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.35); padding: 16px; }
.dlg-box { width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); overflow: auto; margin: auto; padding: 18px 20px; border-radius: 14px; background: var(--bg); box-shadow: var(--shadow); }
.dlg-box.wide { max-width: 620px; }
.dlg-box h2 { margin: 0 0 14px; font-size: 18px; }
.dlg-body { display: flex; flex-direction: column; gap: 12px; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn { height: 36px; padding: 0 16px; border-radius: 18px; border: 1px solid var(--line); font-weight: 600; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.preset { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; }
.preset.on, .preset:hover { border-color: var(--accent); background: var(--accent-soft); }
.preset i { display: block; height: 34px; max-width: 64px; border: 1.5px solid var(--ink-2); border-radius: 3px; }
.preset b { font-size: 12px; text-align: center; }
.preset small { color: var(--ink-2); font-size: 11px; }
.progress { height: 6px; border-radius: 3px; background: var(--bg-3); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.1s; }

/* menus */
.menu.pop {
    position: fixed; z-index: 45; min-width: 210px; max-height: calc(100dvh - 16px); overflow: auto; padding: 5px;
    background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu.pop button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 10px; border-radius: 6px; text-align: left; white-space: nowrap; }
.menu.pop button:hover:not(:disabled) { background: var(--hover); }
.menu.pop button.on { color: var(--accent); }
.menu.pop button.danger { color: var(--danger); }
.menu.pop button span { flex: 1; }
.menu.pop kbd { font: 11px ui-monospace, monospace; color: var(--ink-3); }
.menu.pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.menu.pop .mh { padding: 8px 10px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); }
.ic-space { width: 16px; flex: none; }
#scrim { position: fixed; inset: 0; z-index: 44; background: rgba(0, 0, 0, 0.3); }
#toast {
    position: fixed; left: 50%; bottom: 64px; z-index: 60; transform: translate(-50%, 20px); opacity: 0;
    padding: 8px 16px; border-radius: 18px; background: #222; color: #fff; font-size: 13px; pointer-events: none;
    transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#editor.playing #over { cursor: default; }


/* ---------- Phones ---------- */

/* phones held either way: narrow, or short (on its side) */
@media (max-width: 767px), (max-height: 499px) {
    .wide-only { display: none !important; }
    .phone-only { display: inline-flex !important; }
    .g-head { padding: 10px 14px; gap: 10px; }
    .g-home-t { display: none; }
    .g-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 14px; }
    #topbar { height: 50px; padding: 0 4px; gap: 2px; }
    .tb-home span { display: none; }
    .tb { min-width: 38px; height: 40px; padding: 0 4px; }
    .tb.primary { min-width: 40px; padding: 0; }
    .tb-home { padding: 0 4px; }
    .name-wrap { flex: 1; min-width: 0; }
    #topbar .grow { display: none; }
    #doc-name { width: 100%; }
    #main { flex-direction: column-reverse; }
    #tools {
        width: auto; height: 60px; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 3px 6px;
        border-right: 0; border-top: 1px solid var(--line); padding-bottom: max(3px, env(safe-area-inset-bottom));
        box-sizing: content-box;
    }
    .tool { flex-direction: column; width: 50px; height: 54px; gap: 2px; }
    .tool .tname { display: block; font-size: 10px; color: var(--ink-2); white-space: nowrap; }
    .tool.on .tname { color: var(--accent); }
    .tool-sep { width: 1px; height: 30px; margin: 0 3px; }
    .paint-chips { order: -1; position: sticky; left: -6px; z-index: 1; margin: 0 2px 0 -6px; padding-left: 6px; width: 54px; height: 54px; background: var(--bg); box-sizing: content-box; }
    .pc { width: 32px; height: 32px; }
    .pc.line { left: 4px; top: 1px; }
    .pc.fill { left: 20px; top: 20px; }
    .pc.line::after { inset: 8px; }
    /* the end of the row fades while there are more tools that way */
    #tools.more-end { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }
    #dock { height: var(--dock-h, 34dvh); }
    #dock.folded { height: auto; }
    #dock.folded #tl-wrap, #dock.folded #xsheet, #dock.folded #graph { display: none !important; }
    /* a handle over the stage's bottom edge: drag to size the timeline, tap to fold it away */
    #dock-grip { left: calc(50% - 50px); right: auto; width: 100px; top: -18px; height: 18px; }
    #dock-grip::after { content: ''; position: absolute; left: 32px; right: 32px; bottom: 5px; height: 5px; border-radius: 3px; background: var(--ink-3); box-shadow: 0 0 0 2px var(--bg); }
    #tl-bar { gap: 0; padding: 2px 4px; }
    #tl-bar .ib { width: 40px; height: 38px; }
    #tl-bar .fnum { width: 52px; }
    #tl-names { width: var(--names-w, 150px); }
    #tl-hscroll { left: var(--names-w, 150px); }
    .tl-row { padding-left: calc(2px + var(--d, 0) * 10px); }
    .tl-row .ib { width: 30px; height: 32px; }
    .tl-row .lock-ib:not(.lit) { display: none; }
    #panel {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; width: auto; height: var(--sheet-h, 45dvh);
        border: 0; border-radius: 16px 16px 0 0; box-shadow: var(--shadow); transform: translateY(105%); transition: transform 0.22s;
        padding-bottom: env(safe-area-inset-bottom);
    }
    #editor.sheet-open #panel { transform: none; }
    #panel.sizing { transition: none; }
    #sheet-grip { justify-content: center; align-items: center; height: 18px; flex: none; touch-action: none; cursor: ns-resize; }
    #sheet-grip i { width: 40px; height: 5px; border-radius: 3px; background: var(--ink-3); opacity: 0.6; }
    #panel-tabs { padding-top: 0; align-items: center; overflow-x: auto; scrollbar-width: none; }
    #sheet-close { margin-left: auto; }
    #panel-body { padding: 4px 16px 40px; }
    #zoom-pill {
        position: absolute; right: 10px; top: 10px; z-index: 6; height: 32px; min-width: 56px; padding: 0 10px; border-radius: 16px; align-items: center; justify-content: center;
        background: var(--bg); box-shadow: var(--shadow); font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-2);
    }
    #hint { bottom: auto; top: 10px; left: 10px; right: 80px; transform: none; max-width: none; padding: 6px 12px; white-space: normal; font-size: 12px; line-height: 1.35; border-radius: 12px; }
    /* the size slider for the drawing tools */
    #quick.show {
        display: flex; flex-direction: column; align-items: center; gap: 4px; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); z-index: 5;
        padding: 10px 4px 6px; border-radius: 18px; background: var(--bg); box-shadow: var(--shadow);
    }
    #quick input { writing-mode: vertical-lr; direction: rtl; width: 30px; height: min(150px, 34dvh); margin: 0; padding: 0; touch-action: none; accent-color: var(--accent); }
    .q-val { order: 2; font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
    .q-dot { position: absolute; left: calc(100% + 16px); top: 50%; transform: translateY(-50%); border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2px var(--bg); opacity: 0; pointer-events: none; }
    #quick.live .q-dot { opacity: 0.8; }
    #hint.show { animation: hint-out 5s forwards; }
    @keyframes hint-out { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
    #crumbs { top: 50px; }
    .picker.sheet { left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; border-radius: 16px 16px 0 0; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
    .menu.pop.sheet { left: 0; right: 0; bottom: 0; top: auto; max-height: 70dvh; border-radius: 16px 16px 0 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .menu.pop.sheet button { padding: 10px 12px; }
    .menu.pop.sheet kbd { display: none; }
    .dialog { align-items: flex-end; padding: 0; }
    .dlg-box { max-width: none !important; border-radius: 16px 16px 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
    input[type=number], input[type=text], select, textarea { font-size: 16px; padding: 6px 8px; }
    .ib { width: 38px; height: 38px; }
    .presets { grid-template-columns: repeat(2, 1fr); }
    .dlg-box .grid3 { grid-template-columns: 1fr 1fr; }
    .dlg-box .grid3 > :first-child { grid-column: 1 / -1; }
    #graph .g-list { width: 120px; }
}

/* Narrow phones: the bar has no room for the seconds */
@media (max-width: 389px) {
    #tl-bar .secs { display: none; }
}

/* Phones on their side: tools down the left, the sheet from the right */
@media (max-height: 499px) and (min-width: 560px) {
    #topbar { height: 44px; }
    #main { flex-direction: row; }
    #tools {
        width: 52px; height: auto; flex-direction: column; overflow-x: hidden; overflow-y: auto; padding: 4px; padding-left: max(4px, env(safe-area-inset-left));
        border-top: 0; border-right: 1px solid var(--line);
    }
    .tool { width: 44px; height: 40px; }
    .tool .tname { display: none; }
    .tool-sep { width: 30px; height: 1px; margin: 3px 0; }
    .paint-chips { left: auto; top: -4px; margin: -4px 0 2px; padding: 4px 0 0; width: 52px; height: 54px; }
    #tools.more-end { -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent); }
    #dock { height: var(--dock-h, 42dvh); }
    #hint { left: 64px; }
    #panel { top: 44px; left: auto; width: min(340px, 50vw); height: auto; border-radius: 16px 0 0 0; transform: translateX(105%); padding-bottom: 0; padding-right: env(safe-area-inset-right); }
    #sheet-grip.phone-only { display: none !important; }
}

/* Short laptop screens: a smaller dock */
@media (min-width: 768px) and (min-height: 500px) and (max-height: 760px) {
    #dock { height: var(--dock-h, 190px); }
}

/* draw.js: text typed on the stage, gradients, align */
.text-edit { position: absolute; left: 0; top: 0; transform-origin: 0 0; margin: 0; padding: 0; border: 0; outline: 1px dashed #4f8cff; outline-offset: 2px; background: transparent; white-space: pre; overflow: hidden; resize: none; z-index: 3; caret-color: #4f8cff; }
.ps .ta { width: 100%; min-height: 48px; resize: vertical; margin-bottom: 6px; }
.grad-bar { height: 14px; border-radius: 4px; border: 1px solid var(--line); margin: 4px 0 6px; background-color: #fff; }
.grad-stop { gap: 6px; }
.grad-stop input[type=range] { flex: 1; min-width: 0; }
.align-row { flex-wrap: wrap; }
@font-face { font-family: 'Source Sans 3'; src: url('/landing/fonts/source-sans-3.woff2') format('woff2'); font-weight: 200 900; font-style: normal italic; font-display: swap; }
.g-tools { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.g-tools .btn-s { padding: 0 8px; }
.pose-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin-bottom: 6px; }
.pose { display: flex; flex-direction: column; gap: 2px; position: relative; }
.pose > button:first-child { padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.pose img { display: block; width: 100%; }
.pose input { font-size: 11px; height: 24px; padding: 0 4px; }
.pose .ib { position: absolute; top: 2px; right: 2px; background: var(--bg); width: 22px; height: 22px; }
.sw-kids { flex-wrap: wrap; }
.side-view { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; touch-action: none; cursor: ew-resize; }
.trans-chip { display: inline-flex; align-items: center; gap: 2px; margin-left: 6px; color: var(--ink-3); font-weight: 400; }
.text-style { gap: 6px; margin: 6px 0; }
.text-style .seg { flex: 1; }
.text-style .seg button { display: inline-flex; align-items: center; justify-content: center; }
