:root {
  --ui-bg: #efece6;
  --ui-panel: #fbfaf7;
  --ui-ink: #1c1d22;
  --ui-muted: #7a7a80;
  --ui-line: #e3dfd7;
  --ui-accent: #173a6b;
  --ui-accent-soft: #dce8f6;
  --ui-radius: 12px;
  font-family: Inter, system-ui, sans-serif;
  color: var(--ui-ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ui-bg); overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }

/* ---------------------------------------------------------------- panel */
.panel {
  background: var(--ui-panel); border-right: 1px solid var(--ui-line);
  overflow-y: auto; padding: 16px 18px 40px; font-size: 13px;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--ui-accent); color: #fff; display: grid; place-items: center; font-size: 18px; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--ui-muted); font-size: 11.5px; }
.panel section { padding: 14px 0; border-bottom: 1px solid var(--ui-line); }
.panel h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ui-muted); font-weight: 600; }
.panel select, .panel input[type=text] {
  width: 100%; padding: 7px 9px; border: 1px solid var(--ui-line); border-radius: 8px; background: #fff;
}
.row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 8px; margin: 6px 0; }
.hint { color: var(--ui-muted); font-size: 12px; margin: 8px 0 0; line-height: 1.4; }

.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-btn { text-align: left; border: 1px solid var(--ui-line); background: #fff; border-radius: 10px; padding: 8px; cursor: pointer; }
.theme-btn .sw { display: flex; gap: 3px; margin-bottom: 6px; }
.theme-btn .sw i { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.08); }
.theme-btn b { display: block; font-size: 12px; }
.theme-btn small { color: var(--ui-muted); font-size: 10.5px; }
.theme-btn[aria-pressed=true] { border-color: var(--ui-accent); box-shadow: 0 0 0 2px var(--ui-accent-soft); }

.formats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.fmt-btn { border: 1px solid var(--ui-line); background: #fff; border-radius: 10px; padding: 8px 4px 6px; cursor: pointer; display: grid; justify-items: center; gap: 5px; font-size: 11px; }
.fmt-btn .ratio { border: 1.5px solid currentColor; border-radius: 3px; opacity: .7; }
.fmt-btn[aria-pressed=true] { border-color: var(--ui-accent); color: var(--ui-accent); background: var(--ui-accent-soft); }

.toggle { display: flex; align-items: center; gap: 10px; margin: 8px 0; cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle span { width: 32px; height: 18px; border-radius: 99px; background: #d6d2ca; position: relative; flex: none; transition: background .2s; }
.toggle span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + span { background: var(--ui-accent); }
.toggle input:checked + span::after { transform: translateX(14px); }

.btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btns.col { flex-direction: column; }
.btns button, .icon-btn {
  border: 1px solid var(--ui-line); background: #fff; border-radius: 8px; padding: 8px 10px; cursor: pointer; text-align: left;
}
.btns button:hover { border-color: #c9c3b8; }
.btns button.primary { background: var(--ui-accent); color: #fff; border-color: var(--ui-accent); }
button:disabled { opacity: .5; cursor: progress; }

/* ---------------------------------------------------------------- stage */
.stage-wrap { position: relative; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.seg { display: inline-flex; background: #e2ded6; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.seg button[aria-selected=true] { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.counter { margin-left: auto; color: var(--ui-muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: pan-y; }

.toast {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--ui-ink); color: #fff; padding: 10px 16px; border-radius: 99px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 50;
}

/* ---------------------------------------------------------------- slides */
.frame { position: relative; flex: none; border-radius: 6px; overflow: hidden; box-shadow: 0 10px 40px rgba(30,30,40,.14), 0 1px 3px rgba(0,0,0,.08); }
.slide { position: absolute; left: 0; top: 0; transform-origin: 0 0; overflow: hidden; user-select: none; }
.node { position: absolute; will-change: transform; }
.k-text { white-space: pre; }
.k-text > div { white-space: pre; }
.k-image { pointer-events: none; }
.k-image.phys { pointer-events: auto; cursor: grab; touch-action: none; }
.k-image.grabbed { cursor: grabbing; z-index: 999; }
.k-image.has-shadow { filter: drop-shadow(0 calc(8px * var(--u, 1)) calc(9px * var(--u, 1)) var(--shadow, rgba(38,46,70,.2))); }
.k-image.grabbed.has-shadow { filter: drop-shadow(0 calc(26px * var(--u, 1)) calc(22px * var(--u, 1)) var(--shadow, rgba(38,46,70,.28))); }
.txt[data-bind] { cursor: text; }
.txt[contenteditable] { outline: 2px dashed var(--ui-accent); outline-offset: 6px; white-space: pre-wrap; }
.nudge { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 0%,100% { translate: 0 0; } 50% { translate: 14px 0; } }
.bob { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { translate: 0 0; } 50% { translate: 0 -8px; } }
.twinkle { animation: twinkle 2.2s ease-in-out infinite; }
.twinkle.d2 { animation-delay: -1.1s; }
@keyframes twinkle { 0%,100% { scale: 1; rotate: 0deg; opacity: 1; } 50% { scale: .72; rotate: 25deg; opacity: .75; } }
@media (prefers-reduced-motion: reduce) { .nudge, .bob, .twinkle { animation: none; } }

/* carousel */
.carousel { position: absolute; inset: 0; }
.track { position: absolute; top: 0; left: 0; display: flex; align-items: center; gap: 36px; transition: transform .55s cubic-bezier(.2,.8,.2,1); will-change: transform; }
.track.dragging { transition: none; }
.carousel .frame { transition: opacity .4s, transform .55s cubic-bezier(.2,.8,.2,1); }
.carousel .frame:not(.active) { opacity: .45; transform: scale(.94); cursor: pointer; }
.carousel .frame:not(.active) .slide * { pointer-events: none !important; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; border: 0; background: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.12); cursor: pointer; font-size: 18px; z-index: 5; }
.nav.prev { left: 16px; } .nav.next { right: 16px; }
.dots { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: 7px; z-index: 5; }
.dots button { width: 7px; height: 7px; border-radius: 99px; border: 0; background: #c8c2b6; padding: 0; cursor: pointer; transition: width .3s, background .3s; }
.dots button.on { width: 22px; background: var(--ui-accent); }

/* long infographic: fit width (capped), scroll vertically */
.longview { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px 40px; display: flex; justify-content: center; align-items: flex-start; }
.longview .frame { flex: none; }

/* stories */
.stories { position: absolute; inset: 0; display: grid; place-items: center; }
.stories .frame { cursor: pointer; }
.bars { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 4px; z-index: 10; pointer-events: none; }
.bars i { flex: 1; height: 3px; border-radius: 3px; background: rgba(0,0,0,.12); overflow: hidden; }
.bars i b { display: block; height: 100%; width: 0; background: rgba(0,0,0,.55); }

/* grid */
.grid { position: absolute; inset: 0; overflow-y: auto; padding: 8px 20px 40px; display: flex; flex-wrap: wrap; gap: 22px; align-content: flex-start; justify-content: center; }
.grid .cell { display: grid; gap: 8px; justify-items: center; cursor: pointer; }
.grid .cell small { color: var(--ui-muted); font-size: 12px; }
.grid .frame { transition: transform .2s; }
.grid .cell:hover .frame { transform: translateY(-3px); }
.grid .slide * { pointer-events: none !important; }

/* ---------------------------------------------------------------- mobile */
.only-mobile { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .panel { position: fixed; inset: 0 auto 0 0; width: min(340px, 88vw); z-index: 40; transform: translateX(-105%); transition: transform .3s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .panel.open { transform: none; }
  .only-mobile { display: inline-block; }
  .topbar { padding: 10px 12px; }
  .seg button { padding: 6px 10px; }
  .nav { display: none; }
  .track { gap: 16px; }
}

.linkbtn { display: block; border: 1px solid var(--ui-line); background: #fff; border-radius: 8px; padding: 8px 10px; color: var(--ui-accent); text-decoration: none; font-weight: 600; }

/* ---------------------------------------------------------------- viewer */
body[data-mode=viewer] .app { grid-template-columns: 1fr; }
body[data-mode=viewer] .topbar { justify-content: center; padding: 10px 12px 0; }
body[data-mode=viewer] .topbar:not(:has(.seg, .vformats)) { display: none; }
body[data-mode=viewer] .topbar { flex-wrap: wrap; gap: 8px; }
.vformats { display: inline-flex; gap: 2px; background: rgba(0,0,0,.06); border-radius: 10px; padding: 3px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.vformats button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 13px; white-space: nowrap; }
.vformats button i { display: inline-block; border: 1.5px solid currentColor; border-radius: 2px; opacity: .6; }
.vformats button[aria-pressed=true] { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
body[data-mode=viewer] .topbar .seg { background: rgba(0,0,0,.06); }
body[data-mode=viewer] .stage { padding-top: 0; }
body[data-mode=viewer] .carousel .frame:not(.active) { opacity: .35; }

/* Dedicated format pages share a renderer, but navigate as separate documents. */
.format-pages { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.format-pages a { color: var(--ui-muted); text-decoration: none; padding: 7px 10px; border-radius: 7px; font-size: 13px; }
.format-pages a[aria-current=page] { background: #fff; color: var(--ui-accent); box-shadow: 0 1px 4px #0001; }
.page-hint { flex-basis: 100%; text-align: center; color: var(--ui-muted); font-size: 12px; margin: 2px 0 8px; }

.preview-set { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ui-muted); }
.preview-set select { max-width: 230px; padding: 7px 10px; border: 1px solid var(--ui-line); border-radius: 7px; background: #fff; color: var(--ui-accent); font: inherit; }

.all-sets { font-size:13px; color:var(--ui-muted); text-decoration:none; padding:7px; }

/* "Mix per language" switch */
.lang-shuffle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ui-muted); cursor: pointer; user-select: none; }
.lang-shuffle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.lang-shuffle i { position: relative; width: 34px; height: 20px; border-radius: 999px; background: #d6d1c6; transition: background .2s; flex: none; }
.lang-shuffle i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px #0003; transition: transform .2s; }
.lang-shuffle input:checked + i { background: #17233f; }
.lang-shuffle input:checked + i::after { transform: translateX(14px); }
.lang-shuffle input:focus-visible + i { outline: 2px solid #17233f; outline-offset: 2px; }

/* Embedded creator: one large slide with direct object editing. */
body.creator-embed, .creator-embed .stage { background: transparent; }
.creator-embed .topbar { display: none; }
.creator-embed .stage-wrap { height: 100dvh; }
.embedded-slide { position: absolute; inset: 0; display: grid; place-items: center; }
.creator-embed .frame { border-radius: 2px; box-shadow: 0 14px 35px #162b4320; }

html:has(body.creator-embed){background:transparent}

body.creator-embed { background: transparent !important; }
