:root {
  --bg: #f4f6fa; --panel: #fff; --text: #172033; --muted: #66718a; --line: #e2e6ef;
  --accent: #2457d6; --accent-ink: #fff; --danger: #c62f3b; --ok: #1d9a5b; --warn: #c98a0b;
  --side: #121a2c; --side-text: #c6cede; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1320; --panel: #171e2f; --text: #e6eaf3; --muted: #8e98ae; --line: #273046; --side: #0a0f1a; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }
.hidden { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 1.25rem .75rem; display: flex; flex-direction: column; gap: .25rem; }
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; padding: 0 .75rem 1rem; display: flex; gap: .5rem; align-items: center; }
.brand img { width: 28px; }
.side a { color: var(--side-text); text-decoration: none; padding: .55rem .75rem; border-radius: 8px; }
.side a:hover { background: #ffffff12; }
.side a.active { background: var(--accent); color: #fff; }
.side .who { margin-top: auto; padding: .75rem; font-size: .8rem; opacity: .8; word-break: break-all; }
.main { padding: 1.75rem 2rem; max-width: 1200px; width: 100%; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; padding: .5rem; }
  .side .who, .brand { display: none; }
  .main { padding: 1rem; }
}

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: .5rem .9rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: .25rem .55rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.narrow { width: 5.5rem; }
label.field { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; }
label.check { display: inline-flex; align-items: center; gap: .4rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.err { color: var(--danger); min-height: 1.2em; }

/* auth */
.auth { max-width: 380px; margin: 10vh auto; }
.auth h1 { text-align: center; }
.auth form > * { width: 100%; }
.qr { display: block; margin: 0 auto; width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }
.codes { font-family: ui-monospace, monospace; columns: 2; background: var(--bg); padding: .75rem; border-radius: 8px; }
code { font-family: ui-monospace, monospace; background: var(--bg); padding: .1rem .35rem; border-radius: 4px; word-break: break-all; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card.click { cursor: pointer; }
.card.click:hover { border-color: var(--accent); }
.thumb { aspect-ratio: 16/9; background: #0b0f18; display: flex; align-items: center; justify-content: center; color: #8e98ae; overflow: hidden; position: relative; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb .badge { position: absolute; left: .4rem; top: .4rem; }
.card .body { padding: .65rem .75rem; display: flex; flex-direction: column; gap: .35rem; }
.card .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: .72rem; padding: .12rem .45rem; border-radius: 999px; background: var(--line); color: var(--text); text-transform: uppercase; letter-spacing: .03em; }
.badge.ok { background: #1d9a5b22; color: var(--ok); }
.badge.bad { background: #c62f3b22; color: var(--danger); }
.badge.warn { background: #c98a0b22; color: var(--warn); }
.dot { width: .65rem; height: .65rem; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px #1d9a5b33; }
.dot.off { background: var(--danger); }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* editor */
.editor { display: grid; grid-template-columns: 1fr 340px; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } }
.items { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: 28px 96px 1fr auto; gap: .75rem; align-items: center; padding: .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); margin-bottom: .5rem; }
.item.dragging { opacity: .4; }
.item.over { border-color: var(--accent); border-style: dashed; }
.item .handle { cursor: grab; color: var(--muted); text-align: center; user-select: none; }
.item .mini { width: 96px; aspect-ratio: 16/9; background: #0b0f18; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: #8e98ae; font-size: .75rem; }
.item .mini img { width: 100%; height: 100%; object-fit: cover; }
.item .meta { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.item .meta input.title { width: 100%; }
.library { max-height: 60vh; overflow-y: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.library .pick { aspect-ratio: 16/9; border-radius: 6px; overflow: hidden; background: #0b0f18; cursor: pointer; border: 2px solid transparent; position: relative; color: #8e98ae; font-size: .7rem; display: flex; align-items: center; justify-content: center; text-align: center; }
.library .pick:hover { border-color: var(--accent); }
.library .pick img { width: 100%; height: 100%; object-fit: cover; }
.library .pick .badge { position: absolute; right: .2rem; bottom: .2rem; }

.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.5rem; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); color: var(--accent); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* modal + preview */
.modal-bg { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 1.25rem; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.player { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; align-items: center; justify-content: center; }
.player > img, .player > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transition: opacity .6s; }
.player .fit-cover { object-fit: cover; }
.player .fit-stretch { object-fit: fill; }
.player .stream-note { color: #fff; font-size: 1.4rem; text-align: center; }
.player .close { position: absolute; top: 1rem; right: 1rem; z-index: 2; background: #0008; color: #fff; border-color: #fff4; }
.player .caption { position: absolute; bottom: 1rem; left: 1rem; color: #fff; background: #0008; padding: .3rem .6rem; border-radius: 6px; z-index: 2; font-size: .85rem; }

#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast { background: var(--side); color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: 0 6px 20px #0004; max-width: 360px; }
.toast.error { background: var(--danger); }
.empty { padding: 2.5rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* rendered slides (shared by thumbnails, preview and the designer) */
.mini { position: relative; }
.mini-slide, .dz-thumb-inner { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.preview-slide-wrap { position: relative; overflow: hidden; transition: opacity .6s; }
.preview-slide { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

/* slide designer */
.main.wide { max-width: none; padding: 1rem 1.25rem; }
.designer { display: grid; grid-template-rows: auto 1fr; gap: .75rem; height: calc(100vh - 2rem); min-height: 560px; }
.dz-toolbar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.dz-name { font-weight: 600; min-width: 220px; }
.dz-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 .25rem; }
.dz-body { display: grid; grid-template-columns: 210px minmax(0, 1fr) 300px; gap: .75rem; min-height: 0; }
.dz-strip { overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .25rem; }
.dz-strip-row { display: flex; gap: .4rem; align-items: flex-start; cursor: pointer; }
.dz-strip-row .num { width: 1.4rem; text-align: right; font-size: .8rem; color: var(--muted); padding-top: .2rem; }
.dz-strip-row.over .dz-thumb { border-color: var(--accent); border-style: dashed; }
.dz-thumb { position: relative; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; flex: none; }
.dz-strip-row.active .dz-thumb { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.dz-thumb-img { position: relative; overflow: hidden; background: #0b0f18; display: flex; align-items: center; justify-content: center; color: #c6cede; font-size: .75rem; text-align: center; }
.dz-thumb-img > img { width: 100%; height: 100%; object-fit: cover; }
.dz-thumb-label small { opacity: .7; }
.dz-kind { position: absolute; right: .25rem; bottom: .25rem; }
.dz-strip-actions { display: flex; flex-direction: column; gap: .4rem; padding-left: 1.8rem; }
.dz-stage-area { position: relative; background: #262d3d; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; overflow: hidden; min-height: 280px; }
.dz-stage-box { position: relative; box-shadow: 0 10px 40px #0008; touch-action: none; }
.dz-stage, .dz-overlay { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0; }
.dz-stage { overflow: hidden; background: #000; user-select: none; -webkit-user-select: none; }
.dz-stage [data-id] { cursor: move; }
.dz-overlay { pointer-events: none; }
.dz-sel { position: absolute; outline: 2px solid #4f8bff; transform-origin: 50% 50%; }
.dz-handle { position: absolute; background: #fff; border: 1px solid #2457d6; border-radius: 2px; pointer-events: auto; box-sizing: border-box; }
.h-nw, .h-se { cursor: nwse-resize; } .h-ne, .h-sw { cursor: nesw-resize; }
.h-n, .h-s { cursor: ns-resize; } .h-e, .h-w { cursor: ew-resize; }
.dz-rot { border-radius: 50%; cursor: grab; }
.dz-guide { position: absolute; background: #ff3d7f; }
.dz-editing { outline: none; cursor: text; user-select: text; -webkit-user-select: text; min-height: 1em; }
.dz-empty { color: #8e98ae; font-size: 48px; display: flex; align-items: center; justify-content: center; height: 100%; }
.dz-media { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.dz-media img, .dz-media video { width: 100%; height: 100%; object-fit: contain; }
.dz-media.fit-cover img, .dz-media.fit-cover video { object-fit: cover; }
.dz-media.fit-stretch img, .dz-media.fit-stretch video { object-fit: fill; }
.dz-props { overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; }
.dz-section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; display: flex; flex-direction: column; gap: .55rem; }
.dz-section-title { font-weight: 600; font-size: .9rem; }
.dz-section textarea { width: 100%; resize: vertical; font: inherit; }
.dz-section input[type=number], .dz-section select { width: 100%; min-width: 0; }
.dz-section input[type=color] { width: 44px; height: 34px; padding: 2px; }
.dz-section input.narrow { width: 5rem; }
.dz-subtle { display: flex; flex-direction: column; gap: .25rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; padding: .35rem .6rem; margin-left: -1px; }
.seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); position: relative; }
.dz-swatches { display: flex; flex-wrap: wrap; gap: .35rem; }
.dz-swatch { width: 34px; height: 24px; padding: 0; border-radius: 6px; border: 1px solid var(--line); }
.dz-menu { position: absolute; z-index: 45; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px #0005; padding: .6rem; }
.dz-layouts { display: grid; grid-template-columns: repeat(3, auto); gap: .5rem; }
.dz-layout { flex-direction: column; padding: .35rem; gap: .3rem; font-size: .8rem; }
.dz-shape-btn { font-size: 1.3rem; width: 2.6rem; justify-content: center; }
.modal.wide { width: min(860px, 100%); }
.dz-picker { max-height: 55vh; grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) {
  .designer { height: auto; }
  .dz-body { grid-template-columns: 1fr; }
  .dz-strip { flex-direction: row; overflow-x: auto; }
  .dz-stage-area { height: 56vw; }
}

textarea.mono { font-family: ui-monospace, monospace; font-size: .8rem; width: 100%; resize: vertical; }
.ok-text { color: var(--ok); }
.setup-steps { padding-left: 1.2rem; margin: .75rem 0 0; }
details.panel summary { cursor: pointer; }
