:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b93a5;
  --accent: #5b8cff;
  --accent2: #3b6fe0;
  --danger: #ff6b6b;
  --r: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.primary { background: var(--accent); border: 0; color: #fff; border-radius: 8px; padding: 8px 14px; font-weight: 600; }
.primary:hover { background: var(--accent2); }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; }
.ghost:hover { background: var(--panel2); }
.ghost.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sm { padding: 4px 9px; font-size: 12px; }
.icon { padding: 6px 10px; }
.row { display: flex; gap: 6px; align-items: center; }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle, #fff 30%, var(--accent) 34%); }
.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

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

/* left panel */
.panel { width: 440px; max-width: 100%; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 12px 6px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.panel-body { flex: 1; overflow-y: auto; padding: 14px; }
.panel-foot { padding: 6px 14px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }
.tabhead { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; border: 1px dashed var(--line); border-radius: var(--r); }
.intro { color: var(--muted); margin: 0 0 12px; font-size: 13px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }

/* block cards */
.blocks { display: flex; flex-direction: column; gap: 8px; }
.block { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--r); }
.block.open { border-color: #3b4458; }
.block.is-hidden .bhead { opacity: .5; }
.block.drop { outline: 2px dashed var(--accent); }
.bhead { display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer; user-select: none; }
.grip { cursor: grab; color: var(--muted); padding: 0 2px; }
.bicon { font-size: 18px; }
.btitle { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.btitle b { font-size: 13px; }
.bsum { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 12px; }
.tools { display: flex; gap: 2px; }
.tools button { background: none; border: 0; padding: 4px 6px; border-radius: 6px; color: var(--muted); font-size: 13px; }
.tools button:hover:not(:disabled) { background: var(--line); color: var(--text); }
.tools button.danger:hover { color: var(--danger); }
.bbody { padding: 4px 12px 14px; border-top: 1px solid var(--line); }
.add-bottom { width: 100%; margin-top: 10px; padding: 12px; border: 1px dashed var(--line); background: none; border-radius: var(--r); color: var(--muted); }
.add-bottom:hover { color: var(--text); border-color: var(--accent); }

/* forms */
.form { display: flex; flex-direction: column; gap: 12px; padding-top: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.fl { font-size: 12px; font-weight: 600; color: var(--muted); }
.hint { font-size: 11.5px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.range { display: flex; align-items: center; gap: 10px; }
.range input { padding: 0; border: 0; accent-color: var(--accent); background: none; }
.rv { min-width: 52px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.group { border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; }
.group > summary { padding: 9px 0; cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--muted); }
.group[open] > summary { color: var(--text); }
.group > .form { padding: 0 0 12px; }
.color { display: flex; align-items: center; gap: 6px; }
.chip { position: relative; width: 34px; height: 34px; flex-shrink: 0; border-radius: 8px; border: 1px solid var(--line); overflow: hidden;
  background-image: linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%), linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%);
  background-size: 10px 10px; background-position: 0 0, 5px 5px; }
.chip input { position: absolute; inset: -6px; width: 50px; height: 50px; opacity: 0; cursor: pointer; padding: 0; }
.ctext { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.day { padding: 5px 9px; border: 1px solid var(--line); border-radius: 99px; cursor: pointer; font-size: 12px; user-select: none; }
.day.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.day input { display: none; }
.emoji { position: relative; display: flex; gap: 6px; }
.emoji-in { width: 80px; font-size: 18px; text-align: center; padding: 4px; }
.emoji-pop { display: none; position: absolute; top: 100%; left: 0; z-index: 20; margin-top: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; width: 290px; flex-wrap: wrap; gap: 2px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.emoji-pop.open { display: flex; }
.emoji-pop button { background: none; border: 0; font-size: 20px; padding: 3px; border-radius: 6px; width: 34px; }
.emoji-pop button:hover { background: var(--panel2); }
.imgf { display: flex; gap: 10px; align-items: flex-start; }
.thumb { width: 64px; height: 64px; flex-shrink: 0; border-radius: 8px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 22px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.imgf-r { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.uploaded { font-size: 12px; color: var(--muted); padding: 8px 0 2px; }
.imgs { display: flex; flex-direction: column; gap: 8px; }
.imgs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.imgs-grid:empty { display: none; }
.imgs-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg); }
.imgs-item img { width: 100%; height: 100%; object-fit: cover; }
.imgs-tools { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 2px; padding: 3px; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.imgs-tools button { background: rgba(0,0,0,.5); border: 0; color: #fff; border-radius: 5px; padding: 1px 7px; font-size: 12px; }
.action { display: flex; flex-direction: column; gap: 10px; padding: 10px; background: rgba(91,140,255,.06); border: 1px solid rgba(91,140,255,.25); border-radius: 8px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.li { border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.02); }
.li-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; cursor: pointer; user-select: none; }
.caret { color: var(--muted); transition: transform .15s; font-size: 11px; }
.li.open .caret { transform: rotate(90deg); }
.li-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.li-body { padding: 0 10px 12px; border-top: 1px solid var(--line); }
.add-item { background: none; border: 1px dashed var(--line); border-radius: 8px; padding: 8px; color: var(--muted); }
.add-item:hover { color: var(--text); border-color: var(--accent); }
.palettes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pal { display: flex; flex-direction: column; align-items: center; gap: 5px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; font-size: 11.5px; }
.pal:hover { border-color: var(--accent); }
.pal-sw { width: 100%; height: 26px; border-radius: 6px; display: flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid rgba(128,128,128,.3); }
.pal-sw i { width: 14px; height: 14px; border-radius: 50%; }
.size { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.warn { margin-top: 6px; padding: 8px 10px; border-radius: 8px; background: rgba(255,180,60,.12); color: #ffcf85; }
.code { width: 100%; white-space: pre; }

/* preview stage */
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; background:
  radial-gradient(circle at 1px 1px, rgba(255,255,255,.06) 1px, transparent 0) 0 0 / 18px 18px, var(--bg); }
.stage-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 6px 12px; font-size: 12.5px; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); }
.sched { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.sched select { width: auto; padding: 5px 8px; font-size: 12.5px; }
.stage-scroll { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 10px 16px 16px; }
.device { background: #000; border-radius: 44px; padding: 12px; box-shadow: 0 30px 80px rgba(0,0,0,.5), inset 0 0 0 2px #2c2c2e; transition: width .25s; height: min(844px, calc(100vh - 150px)); flex-shrink: 0; }
.device[data-dev="phone"] { width: 414px; }
.device[data-dev="tablet"] { width: 792px; border-radius: 28px; }
.device[data-dev="desktop"] { width: 100%; max-width: 1280px; border-radius: 12px; padding: 0; height: calc(100vh - 150px); }
.device iframe { width: 100%; height: 100%; border: 0; border-radius: 32px; background: #fff; display: block; }
.device[data-dev="tablet"] iframe { border-radius: 18px; }
.device[data-dev="desktop"] iframe { border-radius: 12px; }
.stage-hint { text-align: center; color: var(--muted); font-size: 12px; margin: 0 0 10px; }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: 86vh; }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.dlg-head h2 { font-size: 16px; margin: 0; }
.dlg-head form { margin: 0; }
.addgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; padding: 14px; }
.addgrid.one { grid-template-columns: 1fr; }
.addopt { text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 3px; }
.addopt:hover { border-color: var(--accent); }
.addopt .ai { font-size: 22px; }
.addopt small { color: var(--muted); font-size: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #fff; color: #111; padding: 10px 18px; border-radius: 99px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.view-toggle { display: none; }

/* narrow screens: one pane at a time */
@media (max-width: 900px) {
  .panel { width: 100%; border-right: 0; }
  .stage { display: none; }
  body.show-preview .panel { display: none; }
  body.show-preview .stage { display: flex; }
  .device[data-dev] { width: 100%; max-width: 430px; height: calc(100vh - 170px); padding: 0; border-radius: 16px; box-shadow: none; }
  .device iframe { border-radius: 16px; }
  .stage-hint { display: none; }
  .view-toggle { display: block; position: fixed; right: 16px; bottom: 16px; z-index: 50; background: var(--accent); color: #fff; border: 0; border-radius: 99px; padding: 12px 18px; font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
  .view-toggle .to-edit { display: none; }
  body.show-preview .view-toggle .to-edit { display: inline; }
  body.show-preview .view-toggle .to-prev { display: none; }
  .top .sep { display: none; }
  .panel-body { padding-bottom: 80px; }
}

/* time tabs */
.ttwrap { margin: -2px 0 14px; }
.ttabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.ttab { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; max-width: 200px; }
.ttab b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ttab small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ttab:hover { border-color: #3b4458; }
.ttab.on { border-color: var(--accent); background: rgba(91,140,255,.12); }
.ttab.add { border-style: dashed; color: var(--muted); }
.tinfo { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.tinfo.special { padding: 10px 12px 0; border: 1px solid rgba(91,140,255,.35); background: rgba(91,140,255,.07); border-radius: 10px; color: var(--text); }
.tinfo.special p { margin: 0 0 10px; }
.tinfo .group { background: var(--panel); margin-bottom: 10px; }
.danger-t { color: var(--danger); border-color: rgba(255,107,107,.4); }
.chip-t { align-self: flex-start; margin-top: 3px; font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: rgba(91,140,255,.15); color: #a9c0ff; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-t.off { background: rgba(255,107,107,.15); color: #ffb3b3; }
.tools .eye.off { opacity: 1; }
.check.small { font-size: 12px; color: var(--muted); }

/* formatting toolbar */
.rich { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.rich > input, .rich > textarea { border: 0; border-radius: 0; }
.richbar { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; padding: 4px 6px; background: var(--panel); border-bottom: 1px solid var(--line); }
.rb { background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 7px; font-size: 12px; color: var(--muted); line-height: 18px; min-width: 24px; }
.rb:hover { background: var(--panel2); color: var(--text); border-color: var(--line); }
.rb-accent { color: var(--accent); font-weight: 700; }
.rb-sw { width: 18px; height: 18px; min-width: 0; padding: 0; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); }
.rb-sw:hover { transform: scale(1.15); border-color: #fff; }
.rb-pick { position: relative; cursor: pointer; overflow: hidden; }
.rb-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; padding: 0; border: 0; }
.rb-sep { width: 1px; height: 16px; background: var(--line); margin: 0 3px; }
.rich-ed { padding: 8px 10px; min-height: 36px; background: var(--bg); outline: none; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.rich-ed.multi { min-height: 90px; }
.rich-ed:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.rich-ed a { color: #8fb0ff; text-decoration: underline; }
.rich-ed ::selection { background: rgba(91,140,255,.45); }

/* typed values next to sliders and colors */
.rbox { display: flex; align-items: center; flex-shrink: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding-right: 8px; }
.rbox input { border: 0; background: none; width: 58px; padding: 6px 4px 6px 8px; text-align: right; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.rbox input::-webkit-inner-spin-button, .rbox input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.rbox:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.rbox input:focus { outline: none; }
.rbox .unit { font-size: 12px; color: var(--muted); }
.rbox .cop { width: 40px; }
.range input[type=range] { flex: 1; min-width: 0; }
.ctext { text-transform: lowercase; }

/* hex color picker */
button.chip { padding: 0; cursor: pointer; }
.cpick { position: fixed; z-index: 200; width: 244px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 10px; }
.cp-sv { position: relative; height: 150px; border-radius: 8px; cursor: crosshair; touch-action: none; }
.cp-dot { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.5); pointer-events: none; }
.cp-hue { position: relative; height: 14px; border-radius: 99px; cursor: pointer; touch-action: none; background: linear-gradient(to right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00); }
.cp-hdot { position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.5); pointer-events: none; }
.cp-row { display: flex; align-items: center; gap: 8px; }
.cp-prev { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; border: 1px solid var(--line); }
.cp-lab { font-size: 12px; color: var(--muted); }
.cp-hex { font-family: ui-monospace, Menlo, monospace; font-size: 13px; padding: 6px 8px; text-transform: lowercase; }
.cp-recent { display: flex; gap: 5px; flex-wrap: wrap; }
.cp-recent button { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); padding: 0; }
.icon-thumb { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-thumb img { width: 26px; height: 26px; object-fit: contain; }
.emoji { flex-wrap: wrap; align-items: center; }

/* version history */
.verlist { padding: 0 16px 16px; overflow: auto; }
.verlist .pad { margin: 10px 0 6px; }
.vernew { display: flex; gap: 8px; margin-top: 14px; }
.vernew input { flex: 1; min-width: 0; }
.verrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.verrow:last-child { border-bottom: 0; }
.vermeta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.vermeta span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.veracts { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
