:root {
  --bg: #EEEDF2; --panel: #FFFFFF; --ink: #17161C; --muted: #6A6875; --line: #E1DFE8;
  --brand: #E0245E; --brand-ink: #FFFFFF; --soft: #F7F6FA;
  --ui: "Manrope", system-ui, sans-serif; --hand: "Gochi Hand", cursive;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 15px; line-height: 1.45; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { background: var(--soft); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: .9em; }

/* top bar */
.bar { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 800; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--brand); color: #fff; font-size: 15px; }
.tpl-pick select { padding: 8px 32px 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); font-weight: 700; }
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.more { position: relative; }
.more summary { list-style: none; cursor: pointer; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); font-weight: 600; }
.more summary::-webkit-details-marker { display: none; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.14); padding: 6px; min-width: 220px; display: grid; }
.menu button, .menu-file { text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.menu button:hover, .menu-file:hover { background: var(--soft); }
.menu-file input { display: none; }
.primary { border: 0; background: var(--brand); color: var(--brand-ink); padding: 10px 18px; border-radius: 10px; font-weight: 800; cursor: pointer; box-shadow: 0 6px 16px rgba(224,36,94,.28); }
.primary:disabled { opacity: .6; cursor: progress; }
.menu-link { padding: 10px 12px; border-radius: 8px; font-weight: 600; color: var(--ink); text-decoration: none; }
.menu-link:hover { background: var(--soft); }
.cloud-state { font-size: 13px; color: var(--muted); white-space: nowrap; }
.cloud-state.ok::before { content: "● "; color: #1E7F4F; }
.cloud-state.busy::before { content: "● "; color: #C9A04E; }
.cloud-state.bad { color: #B4232C; }
.k-acc { font-weight: 700; color: var(--ink); text-decoration: none; padding: 8px 10px; border-radius: 10px; white-space: nowrap; }
.k-acc:hover { background: var(--soft); }
#cloud-save[hidden] { display: none; }

.tabs { display: none; }

/* work area */
.work { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 440px) 1fr; }
.panel { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; border-right: 1px solid var(--line); }
.stage { min-height: 0; display: grid; place-items: stretch; padding: 16px; }
.frame-wrap { height: 100%; width: 100%; margin: 0 auto; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.12); transition: width .35s ease; }
.frame-wrap[data-view="phone"] { width: 390px; max-width: 100%; border-radius: 32px; border: 10px solid #17161C; }
iframe { width: 100%; height: 100%; border: 0; display: block; }

/* cards & fields */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.f { display: grid; gap: 5px; margin-top: 10px; }
.f:first-child { margin-top: 0; }
.row2 .f { margin-top: 0; }
.f > span { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.f input[type="text"], .f input[type="number"], .f input[type="datetime-local"], .f textarea, .f select {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--soft);
}
.f textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.f input:focus, .f textarea:focus, .f select:focus { background: #fff; border-color: var(--brand); outline: none; }

.sec-card { padding: 0; overflow: hidden; }
.sec-card > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; }
.sec-card > summary::-webkit-details-marker { display: none; }
.sec-card > summary::before { content: "›"; font-size: 20px; line-height: 1; color: var(--muted); transition: transform .2s ease; }
.sec-card[open] > summary::before { transform: rotate(90deg); }
.sec-name { font-weight: 800; flex: 1; }
.sec-card.off .sec-name { color: var(--muted); text-decoration: line-through; }
.sec-tools { display: flex; align-items: center; gap: 4px; }
.icon { border: 0; background: none; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 16px; }
.icon:hover { background: var(--soft); color: var(--ink); }
.icon:disabled { opacity: .3; cursor: default; }
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 auto; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.switch span { position: absolute; inset: 0; border-radius: 22px; background: #CFCBD8; transition: background .2s ease; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s ease; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.sec-body { padding: 0 14px 14px; border-top: 1px solid var(--line); padding-top: 12px; }

.items { display: grid; gap: 10px; margin-top: 10px; }
.item { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; background: var(--soft); position: relative; }
.item-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; font-weight: 800; color: var(--muted); margin-bottom: 4px; }
.item .f input, .item .f textarea { background: #fff; }
.ghost-btn { border: 1px dashed var(--line); background: none; border-radius: 10px; padding: 9px; font-weight: 700; cursor: pointer; color: var(--muted); width: 100%; }
.ghost-btn:hover { border-color: var(--brand); color: var(--brand); }

.img-pick { display: flex; align-items: center; gap: 10px; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: repeating-linear-gradient(45deg, #ECEAF1 0 8px, #F6F5F9 8px 16px); border: 1px solid var(--line); flex: 0 0 auto; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 4px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; margin-top: 4px; }
.thumbs .t { position: relative; }
.thumbs .t img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 9px; display: block; }
.thumbs .t button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1; }
.thumbs .file-btn { justify-content: center; aspect-ratio: 1; border-style: dashed; color: var(--muted); font-size: 12px; text-align: center; padding: 4px; }

.add-row { display: flex; gap: 8px; }
.add-row select { flex: 1; }
.add-row button { border: 0; background: var(--ink); color: #fff; border-radius: 9px; padding: 0 16px; font-weight: 700; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; transition: opacity .3s ease, transform .3s ease; pointer-events: none; z-index: 40; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .bar { gap: 8px; }
  .seg { display: none; }
  .brand-name { display: none; }
  .tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel); border-bottom: 1px solid var(--line); }
  .tabs button { border: 0; background: none; padding: 10px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
  .tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }
  .work { grid-template-columns: 1fr; }
  .work[data-tab="edit"] .stage { display: none; }
  .work[data-tab="preview"] .panel { display: none; }
  .panel { border-right: 0; }
  .stage { padding: 0; }
  .frame-wrap, .frame-wrap[data-view="phone"] { width: 100%; border-radius: 0; border: 0; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition-duration: .01ms !important; } }

.icon.armed { width: auto; padding: 0 8px; background: var(--brand); color: #fff; font-weight: 800; font-size: 12px; }
.menu button.armed { background: var(--brand); color: #fff; }

/* secondary button */
.secondary { border: 1px solid var(--ink); background: var(--panel); color: var(--ink); padding: 9px 16px; border-radius: 10px; font-weight: 800; cursor: pointer; }
.secondary:hover { background: var(--ink); color: #fff; }

/* look panel */
.look > summary { gap: 12px; }
.look-peek { display: inline-flex; }
.look-peek i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--panel); margin-left: -5px; box-shadow: 0 0 0 1px var(--line); }
.pals { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.pal { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 6px; cursor: pointer; display: grid; gap: 5px; text-align: left; }
.pal[aria-checked="true"] { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.pal-sw { height: 38px; border-radius: 8px; display: flex; align-items: flex-end; gap: 3px; padding: 6px; border: 1px solid rgba(0,0,0,.06); }
.pal-sw i { width: 12px; height: 12px; border-radius: 50%; }
.pal-name { font-size: 11.5px; font-weight: 700; color: var(--muted); line-height: 1.2; }
.sub { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--soft); }
.sub > summary { cursor: pointer; font-weight: 700; font-size: 13px; color: var(--muted); }
.clrs { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 10px; }
.clr { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.clr input { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 9px; padding: 2px; background: #fff; cursor: pointer; flex: 0 0 auto; }
.pairs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.pair { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: grid; gap: 2px; text-align: left; }
.pair[aria-checked="true"] { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.pair b { font-size: 19px; font-weight: 400; line-height: 1.15; }
.pair span { font-size: 11.5px; color: var(--muted); }
.pair em { font-style: normal; font-size: 17px; color: var(--brand); line-height: 1.1; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.row3 .f { margin-top: 0; }
.f output { float: right; font-weight: 600; color: var(--ink); }
.f input[type="range"] { width: 100%; accent-color: var(--brand); }
#look-reset { margin-top: 12px; }
@media (max-width: 520px) { .row3 { grid-template-columns: 1fr; } }

/* video dialog */
.vid-dlg { border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 30px 80px rgba(0,0,0,.3); color: var(--ink); background: var(--panel); }
.vid-dlg::backdrop { background: rgba(23,22,28,.6); }
.vid-in { padding: 18px 20px 20px; display: grid; gap: 4px; }
.vid-head { display: flex; justify-content: space-between; align-items: center; }
.vid-head h2 { margin: 0; font-size: 19px; }
.vid-step { display: grid; gap: 12px; }
.seg-wide { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
.seg-wide button { display: grid; gap: 1px; padding: 8px 6px; text-align: center; }
.seg-wide small { font-weight: 500; font-size: 11px; color: var(--muted); }
.primary.wide { width: 100%; padding: 13px; font-size: 15px; }
.vid-canvas-wrap { width: 100%; max-height: 56vh; aspect-ratio: 9 / 16; margin: 0 auto; background: #111; border-radius: 14px; overflow: hidden; display: grid; place-items: center; }
.vid-canvas-wrap canvas, .vid-canvas-wrap video { width: 100%; height: 100%; object-fit: contain; display: block; }
.vid-bar { height: 8px; border-radius: 8px; background: var(--soft); overflow: hidden; }
.vid-bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s linear; }
.vid-actions { display: flex; gap: 10px; }
.vid-actions > * { flex: 1; }
@media (max-width: 860px) { #make-video { padding: 9px 10px; } }
.fonts-row { display: grid; gap: 10px; margin-top: 10px; }
.fonts-row .f { margin-top: 0; grid-template-columns: 96px 1fr; align-items: center; }
.fonts-row select { font-size: 15px; }

/* guest links */
.guestlinks .gl-base, .guestlinks .gl-list { width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font: inherit; }
.gl-out { display: grid; gap: 8px; margin-top: 6px; }
.gl-row { display: grid; gap: 2px; padding: 8px 10px; border-radius: 9px; background: #fff; border: 1px solid var(--line); font-size: 13px; }
.gl-url { color: var(--muted); word-break: break-all; font-size: 12px; }
#who-extra .f { margin-top: 12px; }

/* account bar on small screens */
@media (max-width: 860px) {
  .bar-actions { margin-left: 0; width: 100%; flex-wrap: wrap; gap: 6px; }
  .bar-actions > * { flex: 1 1 auto; }
  .bar-actions .secondary, .bar-actions .primary, .more summary { padding: 8px 10px; font-size: 14px; white-space: nowrap; text-align: center; }
  .cloud-state { flex-basis: 100%; order: 9; }
  .tpl-pick { flex: 1; }
  .tpl-pick select { width: 100%; }
}

.img-off .img-pick { background: var(--soft); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; }
.img-off .hint { flex: 1; margin: 0; }
