/* Share the public site's theme preference and palette. */
:root {
    --bg: var(--site-bg); --panel: var(--site-surface); --panel-2: var(--site-bg);
    --border: var(--site-line); --text: var(--site-text); --muted: var(--site-muted);
    --accent: var(--site-accent); --accent-text: var(--site-on-button);
    --radius: 14px; --thumb-bg: #1a1d24; color-scheme: light;
}
:root.dark-mode { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chip { display: inline-block; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; margin: 0 6px 6px 0; font-size: 14px; color: var(--text); }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ---------- gallery ---------- */
.hero { padding: 36px 20px 8px; max-width: 1400px; margin: 0 auto; }
.hero h1 { margin: 0 0 6px; font-size: clamp(32px, 4vw, 48px); letter-spacing: -.04em; line-height: 1.15; }
.hero p { margin: 0; color: var(--muted); max-width: 760px; }
.filters { max-width: 1400px; margin: 0 auto; padding: 16px 20px 4px; }
.chips { display: flex; flex-wrap: wrap; }
.chips.vibes .chip { font-size: 13px; padding: 3px 10px; }
.vibe-filters summary { width: max-content; cursor: pointer; color: var(--muted); font-size: 14px; padding: 3px 0 8px; }
.vibe-filters summary:focus { outline: 2px solid var(--accent); outline-offset: 3px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.toolbar > * { margin: 0 12px 8px 0; }
.toolbar .search { flex: 1 1 240px; max-width: 440px; min-width: 220px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); }
.tool { color: var(--muted); font-size: 14px; display: flex; align-items: center; }
.tool select { margin-left: 6px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.count { color: var(--muted); font-size: 14px; margin-left: auto !important; }
.pager { max-width: 1400px; margin: 0 auto; padding: 4px 20px; display: flex; flex-wrap: wrap; align-items: center; }
.pg { min-width: 36px; padding: 6px 10px; margin: 0 6px 6px 0; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; }
.pg.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.pg:disabled { opacity: .4; cursor: default; }
.pg-gap { color: var(--muted); margin: 0 8px 6px 2px; }
.obs-chip { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); color: var(--text); vertical-align: 1px; }
.grid { max-width: 1400px; margin: 0 auto; padding: 12px 20px 30px; display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); grid-gap: 18px; }
body[data-cols="2"] .thumb { height: 340px; }
body[data-cols="3"] .thumb { height: 250px; }
body[data-cols="4"] .thumb { height: 190px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; text-decoration: none; color: var(--text); }
.card:hover { border-color: var(--muted); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb { position: relative; height: 220px; overflow: hidden; background: var(--thumb-bg); }
/* color-scheme must match the overlay page (normal) or Chrome paints an opaque backdrop behind the iframe. */
.thumb iframe, .stage iframe { color-scheme: normal; }
.thumb iframe { position: absolute; left: 50%; top: 50%; border: 0; pointer-events: none; transform-origin: 0 0; background: transparent; }
.card .meta { padding: 14px 16px; display: flex; align-items: center; }
.card .meta div { flex: 1; min-width: 0; }
.card .name { font-weight: 600; }
.card .sub { color: var(--muted); font-size: 13px; }
.section-title { max-width: 1400px; margin: 0 auto; padding: 8px 20px 0; font-size: 18px; }
.live-list { max-width: 1400px; margin: 0 auto; padding: 8px 20px 50px; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); grid-gap: 12px; }
.live-list a { display: block; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); text-decoration: none; color: var(--text); }
.live-list a:hover { border-color: var(--muted); }
.live-list b { display: block; }
.live-list span { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 30px 0; }

/* preview backgrounds */
.bg-checker { background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Crect width='10' height='10' fill='%23d9d9d9'/%3E%3Crect x='10' y='10' width='10' height='10' fill='%23d9d9d9'/%3E%3C/svg%3E") !important; }
.bg-dark { background: #121212 !important; }
.bg-light { background: #f3f3f3 !important; }
.bg-game { background: linear-gradient(180deg, #4a7fbf 0%, #89b8e6 45%, #4f7a3a 46%, #375a27 70%, #2b4720 100%) !important; }

/* ---------- editor ---------- */
.ed { display: flex; height: calc(100vh - 122px); }
.ed-side { min-width: 0; width: 380px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--panel); overflow-y: auto; padding: 14px 16px 40px; }
.ed-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ed-side h1 { margin: 0 0 4px; font-size: 20px; }
.ed-side .desc { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.ed-side select.tpl { width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); margin-bottom: 10px; }
.presets { margin-bottom: 4px; }
.presets-box { margin-top: 4px; }
.presets-box .presets { padding-top: 8px; }
fieldset { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 12px; padding: 4px 12px 10px; }
legend { padding: 0 6px; font-weight: 600; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.fld { margin-top: 10px; }
.fld > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.fld input[type=text], .fld input[type=number], .fld select, .fld textarea { width: 100%; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel-2); }
.fld textarea { min-height: 76px; resize: vertical; }
.fld .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.fld .row { display: flex; align-items: center; }
.fld .row > * + * { margin-left: 8px; }
.fld input[type=range] { flex: 1; min-width: 0; }
.fld .row input.val { width: 70px; flex-shrink: 0; }
.fld input[type=color] { width: 40px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel-2); flex-shrink: 0; }
.fld.bool label { display: flex; align-items: center; color: var(--text); font-size: 14px; cursor: pointer; margin: 0; }
.fld.bool input { flex-shrink: 0; margin: 0 8px 0 0; width: 16px; height: 16px; }
.soc-row { display: flex; align-items: center; margin-bottom: 6px; }
.soc-row select { width: 120px !important; flex-shrink: 0; }
.soc-row input { flex: 1; min-width: 0; margin-left: 6px; }
.soc-row button { margin-left: 6px; padding: 6px 9px; }

.ed-tools { display: flex; align-items: center; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); font-size: 14px; }
.ed-tools label { color: var(--muted); margin-right: 6px; }
.ed-tools input[type=number] { width: 76px; padding: 5px 7px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2); }
.ed-tools select { padding: 5px 7px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2); }
.ed-tools .grp { display: flex; align-items: center; margin-right: 18px; }
.ed-tools .x { margin: 0 4px; color: var(--muted); }
.ed-tools .obs-test .btn { margin-left: 4px; margin-bottom: 4px; }
.ed-tools .grp { margin-bottom: 4px; }
.stage { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.stage .frame-box { position: relative; box-shadow: 0 0 0 1px var(--border); }
.stage iframe { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: transparent; }
.out { border-top: 1px solid var(--border); background: var(--panel); padding: 12px 16px; }
.out .row { display: flex; align-items: center; }
.out .row > * + * { margin-left: 8px; }
.out input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.out .hint { color: var(--muted); font-size: 13px; margin-top: 6px; }
.toast { max-width: calc(100% - 24px); width: max-content; position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--accent); color: var(--accent-text); padding: 8px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 2100; }
.toast.on { opacity: 1; }

@media (max-width: 860px) {
	.ed { flex-direction: column; height: auto; }
	.ed-side { width: auto; border-right: 0; border-bottom: 1px solid var(--border); max-height: none; }
	.ed-main { order: -1; }
	.stage { height: 320px; min-height: 320px; flex: none; }
	.ed-tools .grp { max-width: 100%; }
	.toolbar .search { width: 100%; }
	.grid { grid-template-columns: 1fr; }
	body[data-cols] .thumb { height: 220px; }
	.hero, .filters, .grid, .live-list, .section-title, .pager { padding-left: 16px; padding-right: 16px; }
}

.studio-skip { position: fixed; top: -100px; left: 12px; z-index: 3000; padding: 12px; background: var(--panel); }
.studio-skip:focus { top: 8px; }
.studio-breadcrumb { display: flex; flex-wrap: wrap; align-items: center; min-height: 46px; padding: 8px 20px; border-bottom: 1px solid var(--border); font-size: 14px; }
.studio-breadcrumb span { margin-left: 20px; color: var(--muted); }
.hero p.eyebrow { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .15em; margin-bottom: 8px; }
.hero > p:not(.eyebrow) { font-size: 17px; max-width: 880px; margin-top: 12px; }
.studio-links { display: flex; flex-wrap: wrap; margin-top: 12px; }
.studio-links a { margin-right: 20px; padding: 6px 0; font-size: 14px; }
.chip:hover, .pg:hover:not(:disabled), .card:hover { border-color: var(--accent); }
.chip, .pg, .seg button { min-height: 36px; }
.card .meta > div { margin-right: 10px; }
.card .btn { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.card .name { overflow-wrap: break-word; overflow-wrap: anywhere; }
.ed-tools .obs-test { flex-wrap: wrap; }
button:focus, a:focus, input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 420px) {
    .out .row { flex-wrap: wrap; }
    .out input { flex-basis: 100%; margin-bottom: 8px; }
    .out .row > #copy { margin-left: 0; }
    .card .meta { flex-wrap: wrap; }
    .card .meta > div { flex-basis: 100%; margin-bottom: 8px; }
    .soc-row { flex-wrap: wrap; }
    .soc-row select { width: 100% !important; margin-bottom: 6px; }
    .soc-row input { margin-left: 0; }
}
