/* Plotter Geometry — dark workshop UI with the paper as the hero. */

:root {
    --bg: #0f1113;
    --stage: #16191c;
    --panel: #15181b;
    --panel-2: #1b1f23;
    --panel-3: #22272c;
    --line: #262b31;
    --line-2: #323941;
    --text: #e8eaed;
    --text-2: #b9c0c8;
    --muted: #7f8893;
    --accent: #ff6b3d;
    --accent-2: #ff8a63;
    --accent-ink: #1a0d08;
    --focus: #5aa2ff;
    --ok: #4cc38a;
    --danger: #ff5d5d;
    --radius: 8px;
    --topbar-h: 56px;
    --left-w: 310px;
    --right-w: 300px;
    --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", monospace;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 13px/1.4 var(--font);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
    font: 11px var(--mono);
    padding: 1px 5px;
    border: 1px solid var(--line-2);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--panel-2);
    color: var(--text-2);
}

.ic { width: 18px; height: 18px; flex: none; fill: currentColor; }

/* ------------------------------------------------------------------ top bar */

.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 650;
    letter-spacing: 0.01em;
    font-size: 14px;
    margin-right: 6px;
    white-space: nowrap;
}
.brand .logo { width: 26px; height: 26px; color: var(--accent); }

.spacer { flex: 1; }

.btn, .icon-btn, .design-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    border-radius: var(--radius);
    border: 1px solid var(--line-2);
    background: var(--panel-2);
    color: var(--text);
    padding: 0 12px;
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.06s;
    white-space: nowrap;
}
.btn:hover, .icon-btn:hover, .design-btn:hover { background: var(--panel-3); border-color: #3c444e; }
.btn:active, .icon-btn:active { transform: translateY(1px); }
.icon-btn { width: 34px; padding: 0; justify-content: center; }
#resetParams span { display: none; }
.icon-btn:disabled { opacity: 0.35; pointer-events: none; }
.btn.primary { background: #262c33; border-color: #3a434d; }
.btn.accent {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}
.btn.accent:hover { background: var(--accent-2); border-color: var(--accent-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.design-btn { min-width: 210px; padding: 0 10px; height: 40px; }
.design-btn .ic { color: var(--muted); }
.design-btn .chev { margin-left: auto; }
.design-btn-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.design-cat { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.design-name { font-weight: 600; font-size: 13.5px; }

.seed-box {
    display: flex;
    align-items: center;
    height: 34px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--panel-2);
    overflow: hidden;
}
.seed-box label { padding: 0 8px 0 10px; color: var(--muted); font-size: 12px; }
.seed-box input {
    width: 92px;
    height: 100%;
    border: 0;
    background: transparent;
    font-family: var(--mono);
    font-size: 12.5px;
    -moz-appearance: textfield;
}
.seed-box input::-webkit-outer-spin-button, .seed-box input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.seed-box input:focus { outline: none; }
.seed-box .icon-btn { border: 0; border-left: 1px solid var(--line-2); border-radius: 0; height: 100%; }

.export { position: relative; display: flex; }
.export .btn.accent:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.export .caret { border-radius: 0 var(--radius) var(--radius) 0; padding: 0 7px; border-left: 1px solid rgba(0, 0, 0, 0.25); }

.menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 260px;
    background: var(--panel-2);
    border: 1px solid var(--line-2);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
    z-index: 20;
}
.menu button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 8px 10px;
    border-radius: 6px;
}
.menu button:hover { background: var(--panel-3); }
.menu button small { display: block; color: var(--muted); font-size: 11.5px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

/* ------------------------------------------------------------------ layout */

.tabs { display: none; }

.layout {
    display: grid;
    grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
}

.panel {
    background: var(--panel);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #333a42 transparent;
}
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }

.design-info { padding: 16px 16px 6px; }
.design-info h1 { margin: 0 0 4px; font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
.design-info p { margin: 0; color: var(--muted); font-size: 12.5px; }
.phone-tools { display: none; }

/* ------------------------------------------------------------------ controls */

.controls { padding: 4px 16px 24px; }

.section-label {
    margin: 18px 0 8px;
    font-size: 10.5px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.ctl { margin: 0 0 11px; }
.ctl[hidden] { display: none; }
.ctl-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
    min-height: 18px;
}
.ctl-head label {
    color: var(--text-2);
    font-size: 12.5px;
    user-select: none;
    cursor: default;
}
.ctl-head .hint {
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 1px solid var(--line-2);
    color: var(--muted);
    font-size: 9.5px;
    display: inline-grid;
    place-items: center;
    cursor: help;
}
.lock-btn {
    margin-left: auto;
    width: 20px; height: 20px;
    border: 0;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.12s;
    padding: 0;
}
.lock-btn .ic { width: 13px; height: 13px; }
.ctl:hover .lock-btn, .lock-btn.locked { opacity: 1; }
.lock-btn.locked { color: var(--accent); }

.ctl-row { display: flex; align-items: center; gap: 10px; }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    height: 22px;
    background: transparent;
    margin: 0;
    --from: 0%;
    --to: 50%;
    --track: linear-gradient(to right, #2d333a var(--from), var(--accent) var(--from), var(--accent) var(--to), #2d333a var(--to));
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    margin-top: -5px;
    border-radius: 50%;
    background: #f3f4f6;
    border: 0;
    box-shadow: 0 0 0 3px rgba(255, 107, 61, 0.0), 0 1px 3px rgba(0, 0, 0, 0.6);
    transition: box-shadow 0.12s;
}
input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(255, 107, 61, 0.25), 0 1px 3px rgba(0, 0, 0, 0.6); }
input[type="range"]::-moz-range-thumb {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #f3f4f6;
    border: 0;
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--focus); }

.num {
    width: 66px;
    height: 26px;
    padding: 0 6px;
    border-radius: 6px;
    border: 1px solid var(--line-2);
    background: var(--panel-2);
    font-family: var(--mono);
    font-size: 11.5px;
    text-align: right;
    -moz-appearance: textfield;
}
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

select, .text-input, textarea {
    width: 100%;
    height: 30px;
    padding: 0 9px;
    border-radius: 6px;
    border: 1px solid var(--line-2);
    background: var(--panel-2);
}
select { appearance: none; -webkit-appearance: none; padding-right: 26px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m7 10 5 5 5-5' fill='none' stroke='%237f8893' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 6px center; background-size: 16px; }
select option { background: var(--panel-2); }
textarea { height: auto; min-height: 60px; padding: 6px 9px; resize: vertical; font-family: var(--mono); font-size: 11.5px; }
.text-input { font-family: var(--mono); font-size: 12px; }
select:focus, .text-input:focus, textarea:focus, .num:focus { outline: none; border-color: var(--focus); }

/* toggle switch */
.ctl-check .ctl-row { justify-content: space-between; }
.switch { position: relative; width: 32px; height: 18px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
    position: absolute; inset: 0;
    border-radius: 9px;
    background: #2d333a;
    transition: background 0.15s;
}
.switch span::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #c9ced4;
    transition: transform 0.15s, background 0.15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.color-input {
    width: 34px; height: 26px;
    padding: 0;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    background: none;
    cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 3px; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 3px; }
.color-input::-moz-color-swatch { border: 0; border-radius: 3px; }

.image-ctl .ctl-row { gap: 6px; }
.image-ctl .file-name { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-ctl .btn { height: 28px; padding: 0 10px; font-size: 12px; }
.image-ctl .icon-btn { width: 28px; height: 28px; }

/* right panel sections */
.out-section { border-bottom: 1px solid var(--line); }
.out-section > summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 13px 16px;
    font-weight: 600;
    font-size: 12.5px;
    cursor: pointer;
    user-select: none;
}
.out-section > summary::-webkit-details-marker { display: none; }
.out-section > summary .ic { width: 16px; height: 16px; color: var(--muted); margin-left: auto; transition: transform 0.15s; transform: rotate(-90deg); }
.out-section[open] > summary .ic { transform: none; }
.out-section > summary .badge { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.out-section .controls { padding-top: 0; padding-bottom: 14px; }
.out-note { color: var(--muted); font-size: 11.5px; margin: 2px 0 10px; }
.out-note code { font-family: var(--mono); color: var(--text-2); }

.seg { display: flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; height: 28px; border: 0; background: var(--panel-2); color: var(--text-2); font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--panel-3); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

/* pens */
.pen-row {
    display: grid;
    grid-template-columns: 22px 34px 1fr 60px;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
}
.pen-row.unused { opacity: 0.45; }
.pen-row .eye { width: 22px; height: 22px; border: 0; background: none; color: var(--text-2); padding: 0; display: grid; place-items: center; }
.pen-row .eye.off { color: var(--muted); }
.pen-row .eye .ic { width: 16px; height: 16px; }
.pen-row .pen-name {
    min-width: 0;
    height: 26px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 6px;
    padding: 0 6px;
    font-size: 12.5px;
}
.pen-row .pen-name:hover { border-color: var(--line-2); }
.pen-row .pen-name:focus { outline: none; border-color: var(--focus); background: var(--panel-2); }
.pen-row .pen-meta { grid-column: 3 / 5; margin-top: -4px; padding-left: 7px; color: var(--muted); font-size: 11px; font-family: var(--mono); }
.pen-row .num { width: 60px; }
.pen-width-wrap { position: relative; }
.pen-width-wrap::after { content: "mm"; position: absolute; right: 22px; top: 6px; font-size: 10px; color: var(--muted); pointer-events: none; display: none; }

/* snapshots */
.snaps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.snap {
    position: relative;
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--line-2);
    background: var(--panel-2);
    padding: 0;
}
.snap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.snap .del {
    position: absolute; top: 3px; right: 3px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    place-items: center;
    color: #fff;
}
.snap:hover .del { display: grid; }
.snap .del .ic { width: 12px; height: 12px; }
.snap:hover { border-color: var(--accent); }
.snaps-empty { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ stage */

.stage {
    position: relative;
    overflow: hidden;
    background-color: var(--stage);
    background-image: radial-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px);
    background-size: 18px 18px;
    touch-action: none;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#view { cursor: grab; }
#view.panning { cursor: grabbing; }

.stage-tools {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    border-radius: 10px;
    background: rgba(24, 27, 31, 0.88);
    border: 1px solid var(--line-2);
    backdrop-filter: blur(8px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    z-index: 2;
}
.tool {
    width: 32px; height: 30px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-2);
    display: grid;
    place-items: center;
}
.tool:hover { background: var(--panel-3); color: var(--text); }
.tool.on { color: var(--accent); background: rgba(255, 107, 61, 0.12); }
.tool .ic { width: 17px; height: 17px; }
.stage-tools .sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 4px; }
.stage-tools select { width: auto; height: 28px; font-size: 12px; background-color: transparent; border-color: transparent; padding: 0 22px 0 6px; background-position: right 3px center; }
.stage-tools select:hover { border-color: var(--line-2); }
.zoom-label { font: 11.5px var(--mono); color: var(--muted); min-width: 44px; text-align: center; }

.stage-msg {
    position: absolute;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    padding: 7px 14px;
    border-radius: 20px;
    background: rgba(24, 27, 31, 0.92);
    border: 1px solid var(--line-2);
    color: var(--text-2);
    font-size: 12px;
    z-index: 2;
    pointer-events: none;
}
.stage-msg.error { color: #ffb3b3; border-color: #5b2a2a; background: rgba(50, 20, 20, 0.92); max-width: 70%; pointer-events: auto; }
.drop-hint {
    position: absolute;
    inset: 16px;
    border: 2px dashed var(--accent);
    border-radius: 14px;
    background: rgba(255, 107, 61, 0.08);
    display: grid;
    place-items: center;
    color: var(--text);
    font-size: 15px;
    z-index: 3;
    pointer-events: none;
}
.drop-hint[hidden] { display: none; }

.statusbar {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
    z-index: 2;
}
.stat {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 16px;
    background: rgba(24, 27, 31, 0.88);
    border: 1px solid var(--line-2);
    backdrop-filter: blur(8px);
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
}
.stat b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.stat.dim { color: var(--muted); }

/* ------------------------------------------------------------------ gallery */

.gallery {
    position: fixed;
    inset: 0;
    background: rgba(8, 9, 11, 0.72);
    backdrop-filter: blur(6px);
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 24px;
}
.gallery[hidden] { display: none; }
.gallery-inner, .keys-inner {
    width: min(1180px, 100%);
    height: min(860px, 100%);
    background: var(--panel);
    border: 1px solid var(--line-2);
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.keys-inner { width: min(560px, 100%); height: auto; }
.gallery-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.gallery-head h2 { margin: 0 8px 0 4px; font-size: 16px; font-weight: 650; }
.gallery-head input[type="search"] {
    flex: 1;
    max-width: 340px;
    height: 34px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid var(--line-2);
    background: var(--panel-2);
}
.gallery-head input[type="search"]:focus { outline: none; border-color: var(--focus); }
.gallery-head .icon-btn:last-child { margin-left: auto; }
.gallery-body { overflow-y: auto; padding: 6px 18px 24px; scrollbar-width: thin; scrollbar-color: #333a42 transparent; }
.gallery-cat { margin: 18px 2px 10px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.card {
    display: flex;
    flex-direction: column;
    text-align: left;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--line-2);
    background: var(--panel-2);
    overflow: hidden;
    transition: border-color 0.12s, transform 0.12s, box-shadow 0.12s;
}
@media (hover: hover) {
    .card:hover { border-color: #4a535e; transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35); }
}
.card.current { border-color: var(--accent); }
.card .thumb { aspect-ratio: 1; width: 100%; display: block; background: #fbfaf6; }
.card .card-text { padding: 9px 11px 11px; }
.card .card-name { font-weight: 600; font-size: 13px; }
.card .card-desc { color: var(--muted); font-size: 11.5px; margin-top: 2px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.keys { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; padding: 18px 22px 24px; margin: 0; }
.keys dt { text-align: right; color: var(--text-2); }
.keys dd { margin: 0; color: var(--text-2); }

/* ------------------------------------------------------------------ toasts */

.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 40; }
.toast {
    padding: 9px 14px;
    border-radius: 10px;
    background: var(--panel-3);
    border: 1px solid var(--line-2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    font-size: 12.5px;
    animation: toast-in 0.18s ease-out;
}
.toast.error { border-color: #5b2a2a; color: #ffb3b3; }
.toast.install { display: flex; align-items: center; gap: 12px; padding: 10px; max-width: min(400px, calc(100vw - 36px)); }
.install-icon {
    width: 38px; height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: #171a1e;
    border: 1px solid var(--line-2);
}
.install-logo { width: 26px; height: 26px; color: var(--accent); }
.install-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.install-text b { font-size: 13px; font-weight: 600; color: var(--text); }
.install-text span { font-size: 12px; color: var(--muted); }
.toast.install .btn { height: 30px; padding: 0 12px; }
.toast.install .icon-btn { width: 30px; height: 30px; border-color: transparent; background: transparent; color: var(--muted); }
.toast.install .icon-btn:hover { background: var(--panel-2); color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1280px) {
    .brand span { display: none; }
}

@media (max-width: 1100px) {
    :root { --left-w: 320px; }
    .tabs {
        display: flex;
        position: absolute;
        top: var(--topbar-h);
        left: 0;
        width: var(--left-w);
        height: 38px;
        background: var(--panel);
        border-right: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
        z-index: 3;
    }
    .tabs button {
        flex: 1;
        border: 0;
        background: none;
        color: var(--muted);
        font-size: 12.5px;
        font-weight: 600;
    }
    .tabs button.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
    .tabs button[data-tab="preview"] { display: none; }
    .layout { grid-template-columns: var(--left-w) minmax(0, 1fr); }
    .panel { margin-top: 38px; }
    .panel.left, .panel.right { grid-column: 1; grid-row: 1; border-left: 0; border-right: 1px solid var(--line); }
    .stage { grid-column: 2; grid-row: 1; }
    .layout[data-tab="design"] .panel.right,
    .layout[data-tab="preview"] .panel.right { display: none; }
    .layout[data-tab="output"] .panel.left { display: none; }
    .seed-box label, .hide-sm { display: none; }
    .seed-box input { padding-left: 10px; }
    .btn.primary span { display: none; }
    .btn.primary { width: 34px; padding: 0; justify-content: center; }
}


/* narrow tablets: keep the whole top bar on screen */
@media (max-width: 860px) {
    .export .btn.accent span { display: none; }
    .design-btn { min-width: 170px; }
}

/* phones: fixed app shell — top bar, drawing, the active panel, and a bottom tab bar */
@media (max-width: 720px) {
    :root { --topbar-h: 52px; --tabs-h: 50px; }
    body { display: flex; flex-direction: column; height: 100dvh; }
    .topbar { flex: none; gap: 6px; padding: 0 8px; }
    .brand, .spacer, #snapshotBtn { display: none; }
    .design-btn { min-width: 0; flex: 1 1 auto; padding: 0 8px 0 12px; }
    .design-btn > .ic:first-child, .design-cat { display: none; }
    .design-btn-text { min-width: 0; }
    .design-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .export { margin-left: 2px; }

    .tabs {
        order: 3;
        flex: none;
        position: static;
        width: auto;
        height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        border: 0;
        border-top: 1px solid var(--line);
    }
    .tabs button { font-size: 13px; }
    .tabs button.active { box-shadow: inset 0 2px 0 var(--accent); }
    .tabs button[data-tab="preview"] { display: block; }

    .layout { display: flex; flex-direction: column; flex: 1; min-height: 0; height: auto; }
    .stage { order: -1; flex: 0 0 40%; border-bottom: 1px solid var(--line); }
    .layout[data-tab="preview"] .stage { flex: 1; border-bottom: 0; }
    .panel { flex: 1; min-height: 0; margin-top: 0; border: 0 !important; }
    .layout[data-tab="preview"] .panel { display: none; }
    /* the compact preview above a panel is just the drawing; the Preview tab has the tools */
    .layout:not([data-tab="preview"]) .stage-tools,
    .layout:not([data-tab="preview"]) .statusbar { display: none; }

    .phone-tools { display: flex; gap: 8px; padding: 10px 16px 2px; }
    .phone-tools .seed-box { flex: 1; min-width: 0; }
    .phone-tools .seed-box label { display: block; }
    .phone-tools .seed-box input { flex: 1; min-width: 0; width: auto; }
    .phone-tools #resetParams { width: auto; padding: 0 12px; }
    .phone-tools #resetParams span { display: inline; }

    .stage-tools { top: 8px; max-width: calc(100% - 16px); }
    .statusbar { bottom: 8px; left: 8px; right: 8px; }
    .stage-msg { top: 12px; }
    .layout[data-tab="preview"] .stage-msg { top: 60px; }
    .stage-msg.error { max-width: calc(100% - 24px); }

    .gallery { padding: 0; }
    .gallery-inner { height: 100%; border-radius: 0; border: 0; }
    .gallery-head { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
    .gallery-head h2 { margin-right: auto; }
    .gallery-head input[type="search"] { order: 5; flex: 1 0 100%; max-width: none; }
    .gallery-head .icon-btn:last-child { margin-left: 0; }
    .gallery-body { padding: 0 12px 20px; }
    .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card .card-text { padding: 8px 10px 10px; }
    .keys-inner { max-height: 100%; }
    .keys { grid-template-columns: 1fr; gap: 2px; padding: 14px 18px 20px; overflow-y: auto; }
    .keys dt { text-align: left; margin-top: 10px; }

    .toasts { left: 12px; right: 12px; bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom)); align-items: center; }
}

/* short landscape screens (phones on their side): give the drawing the height */
@media (max-height: 520px) and (min-width: 721px) {
    :root { --topbar-h: 48px; }
    .design-btn { height: 36px; }
    .statusbar { display: none; }
    .design-info { padding-top: 12px; }
}

/* touch: no hover to reveal controls, and fingers need bigger targets */
@media (hover: none) {
    .lock-btn { opacity: 0.55; }
    .lock-btn.locked { opacity: 1; }
    .snap .del { display: grid; }
}
@media (pointer: coarse) {
    .lock-btn { width: 30px; height: 30px; margin: -6px -6px -6px auto; }
    .lock-btn .ic { width: 15px; height: 15px; }
    input[type="range"] { height: 32px; }
    input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9px; }
    input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; }
    .num { height: 32px; }
    select, .text-input { height: 36px; }
    .switch { width: 40px; height: 24px; }
    .switch span { border-radius: 12px; }
    .switch span::after { width: 20px; height: 20px; }
    .switch input:checked + span::after { transform: translateX(16px); }
    .color-input { width: 40px; height: 32px; }
    .seg button { height: 34px; }
    .tool { width: 40px; height: 36px; }
    .menu button { padding: 11px 12px; }
    .pen-row { grid-template-columns: 28px 40px 1fr 66px; }
    .pen-row .eye { width: 28px; height: 28px; }
    .pen-row .num { width: 66px; }
    .image-ctl .btn { height: 34px; }
    .image-ctl .icon-btn { width: 34px; height: 34px; }
    .snap .del { width: 26px; height: 26px; }
}
/* iOS zooms the page into any focused field under 16px */
@supports (-webkit-touch-callout: none) {
    @media (pointer: coarse) {
        input, select, textarea, .num { font-size: 16px; }
        .num, .pen-row .num { width: 76px; }
        .pen-row { grid-template-columns: 28px 40px 1fr 76px; }
    }
}
