:root {
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d8d2ff;
  --panel: #ffffff;
  --soft: #f7f4ff;
  --accent: #7c3aed;
  --accent-2: #ff9f2f;
  --dark: #1e1b4b;
  --shadow: 0 18px 44px rgba(76, 29, 149, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f4f1ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: #f4f1ff; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 88px;
  padding: 16px 24px;
  color: #fff;
  background: linear-gradient(110deg, #6d28d9, #a855f7);
  overflow: visible;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: #fff;
  object-fit: contain;
  padding: 5px;
}

.brand span { min-width: 0; }
.brand strong { display: block; font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1.05; white-space: nowrap; }
.brand sup { font-size: .42em; line-height: 0; position: relative; top: -.55em; }
.brand small { display: block; margin-top: 5px; font-size: .95rem; opacity: .9; }
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.quick-actions button,
.toolbar button,
.rail-add,
.menu summary,
.menu-panel button,
.menu-panel a,
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 800;
  text-decoration: none;
}

.quick-actions .primary,
.primary,
.rail-add {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.show-app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: calc(100vh - 88px);
  min-height: 680px;
}

.menu-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  box-shadow: 0 10px 28px rgba(76, 29, 149, .06);
  position: relative;
  z-index: 10;
  overflow: visible;
}

.menu { position: relative; }
.menu summary { list-style: none; min-width: 88px; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "⌄"; margin-left: 4px; color: var(--muted); }
.menu[open] summary { border-color: var(--accent); color: var(--accent); background: #fbfaff; }
.menu-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  min-width: 240px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}
.menu-panel button,
.menu-panel a {
  justify-content: flex-start;
  border: 0;
  border-radius: 7px;
  background: transparent;
  min-height: 34px;
  padding: 7px 9px;
  text-align: left;
}
.menu-panel button:hover,
.menu-panel a:hover { background: var(--soft); color: var(--accent); }
.menu-panel hr { width: 100%; border: 0; border-top: 1px solid #eee8ff; margin: 6px 0; }
.submenu {
  width: 100%;
}
.submenu > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  border-radius: 7px;
  padding: 7px 9px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
  list-style: none;
}
.submenu > summary::-webkit-details-marker { display: none; }
.submenu > summary::after {
  content: ">";
  color: var(--muted);
  font-size: .8rem;
}
.submenu[open] > summary,
.submenu > summary:hover {
  background: var(--soft);
  color: var(--accent);
}
.submenu > div {
  display: grid;
  gap: 2px;
  margin: 2px 0 4px 12px;
  padding-left: 8px;
  border-left: 2px solid #eee8ff;
}
.submenu .submenu-note {
  padding: 4px 9px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 750;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  overflow: visible;
  position: relative;
  z-index: 5;
}
.toolbar button { min-width: 38px; padding: 7px 9px; }
.toolbar select,
.toolbar input[type="number"] {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  background: #fff;
  font-weight: 750;
}
.toolbar input[type="number"] { width: 70px; }
.divider { width: 1px; align-self: stretch; background: #e8e0ff; margin: 0 5px; }
.zoom-tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 900;
  background: #fff;
}
.zoom-tool input[type="range"] {
  width: 118px;
  accent-color: var(--accent);
}
.zoom-tool output {
  min-width: 44px;
  color: var(--ink);
  text-align: right;
}
.color-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 7px;
  font-weight: 900;
}
.color-tool input { width: 28px; height: 26px; border: 0; padding: 0; background: transparent; }

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(460px, 1fr) 280px;
  min-height: 0;
}

.slide-rail,
.inspector {
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #faf8ff;
}
.inspector { border-right: 0; border-left: 1px solid var(--line); padding: 12px; }
.rail-title {
  padding: 12px 14px 4px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.thumbnail-list { display: grid; gap: 10px; padding: 10px 12px; }
.thumb {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  width: 100%;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  text-align: left;
  box-shadow: 0 8px 18px rgba(31,41,55,.06);
  margin-left: calc(var(--indent, 0) * 16px);
  width: calc(100% - (var(--indent, 0) * 16px));
}
.thumb.active { border-color: var(--accent); }
.thumb.selected-slide,
.sorter-card.selected-slide { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,159,47,.55), 0 8px 18px rgba(31,41,55,.06); }
.thumb.dragging,
.sorter-card.dragging { opacity: .48; }
.thumb.drop-target,
.sorter-card.drop-target { outline: 3px solid var(--accent-2); outline-offset: 3px; }
.hidden-slide { opacity: .58; }
.collapsed-slide .thumb-preview,
.sorter-card.collapsed-slide .thumb-preview { box-shadow: inset 0 0 0 2px rgba(124,58,237,.35); }
.slide-badges { grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px; margin-top: -2px; }
.slide-badge { border: 1px solid #d8ccff; border-radius: 999px; background: #f6f1ff; color: #5b21b6; padding: 1px 5px; font-size: 9px; font-weight: 950; text-transform: uppercase; }
.thumb-num { color: var(--accent); font-weight: 950; }
.thumb-preview {
  position: relative;
  aspect-ratio: 16/9;
  border: 1px solid #eadfff;
  border-radius: 6px;
  background: linear-gradient(135deg, #fff, #f2edff);
  overflow: hidden;
  padding: 6px;
  font-size: .58rem;
  font-weight: 850;
  color: var(--dark);
}
.mini-slide.section,
.mini-slide.dark { background: linear-gradient(135deg, var(--dark), var(--accent)); color: #fff; }
.mini-obj {
  position: absolute;
  display: block;
  overflow: hidden;
  padding: 1px 2px;
  border-radius: 2px;
  font-size: 5px;
  line-height: 1.1;
  transform-origin: center center;
  white-space: pre-wrap;
}
.mini-obj.shape { border: 1px dashed #c4b5fd; }
.mini-obj img { width: 100%; height: 100%; display: block; border: 0; }
.mini-obj.video,
.mini-obj.youtube,
.mini-obj.table {
  display: grid;
  place-items: center;
  border: 1px solid #d8d2ff;
  background: #fff;
  color: #5b21b6;
  font-size: 6px;
}
.mini-obj.html {
  border: 0;
  background: #fff;
  color: inherit;
  font-size: 5px;
  padding: 0;
}
.mini-obj.html img,
.mini-obj.html video,
.mini-obj.html iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  object-fit: contain;
}
.mini-html-content {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.mini-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 7px;
  background: rgba(31,27,75,.9);
  color: #fff;
  text-align: right;
  padding-right: 4px;
  font-size: 5px;
  line-height: 7px;
}
.rail-add { margin: 8px 12px 16px; width: calc(100% - 24px); }
.rail-splitter { display: none; }

.stage-wrap {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: .92rem;
  font-weight: 800;
}
.deck-title-input {
  flex: 1;
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  background: #fff;
}

.stage {
  display: grid;
  place-items: start center;
  min-height: 0;
  padding: 14px;
  overflow: auto;
  --canvas-zoom: 1;
  background:
    linear-gradient(90deg, rgba(124,58,237,.08) 1px, transparent 1px),
    linear-gradient(rgba(124,58,237,.08) 1px, transparent 1px);
  background-size: 24px 24px;
}
.slide-canvas {
  position: relative;
  width: calc(960px * var(--canvas-zoom));
  max-width: none;
  aspect-ratio: 16 / 9;
  flex: none;
  border: 1px solid #cfc3ff;
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.slide-canvas.dark { background: var(--dark); color: #fff; }
.slide-canvas.section { background: linear-gradient(135deg, var(--dark), var(--accent)); color: #fff; }
.slide-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 34px;
  padding: 0 22px;
  background: rgba(31,27,75,.9);
  color: #fff;
  font-size: 13px;
  font-weight: 850;
  pointer-events: auto;
  cursor: text;
  z-index: 20;
}
.slide-footer.selected {
  outline: 3px solid rgba(255,159,47,.8);
  outline-offset: -3px;
}
.slide-footer .footer-text {
  min-width: 120px;
  max-width: calc(100% - 90px);
  border-radius: 4px;
  padding: 2px 4px;
}
.slide-footer .footer-text:focus {
  outline: 2px solid rgba(255,255,255,.86);
  outline-offset: 1px;
  background: rgba(255,255,255,.12);
}
.slide-footer .footer-count {
  flex: none;
}

.slide-object {
  position: absolute;
  min-width: 42px;
  min-height: 28px;
  border: 2px solid transparent;
  outline: none;
  overflow: visible;
}
.slide-object.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255,159,47,.7);
}
.slide-object:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255,159,47,.42);
}
.object-content {
  width: 100%;
  height: 100%;
  padding: 8px;
  overflow: hidden;
}
.object-content[contenteditable="true"]:focus,
.object-content [contenteditable="true"]:focus {
  outline: 2px solid rgba(255,159,47,.72);
  outline-offset: -2px;
}
.slide-object.text .object-content,
.slide-object.list .object-content,
.slide-object.link .object-content,
.slide-object.shape .object-content {
  line-height: 1.25;
  overflow: visible;
}
.slide-object.list ul { margin: 0; padding-left: 1.2em; }
.slide-object.html .object-content {
  background: #fff;
  line-height: 1.2;
  padding: 0;
}
.imported-webdeck-slide {
  background: #fff;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.imported-webdeck-slide:focus { outline: none; }
.imported-webdeck-slide img,
.imported-webdeck-slide video,
.imported-webdeck-slide iframe {
  max-width: 100%;
}
.imported-webdeck-slide h1,
.imported-webdeck-slide h2,
.imported-webdeck-slide h3,
.imported-webdeck-slide p { margin-top: 0; }
.slide-object.image img,
.slide-object.video video,
.slide-object.youtube iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: contain;
}
.slide-object.crop-mode .object-content {
  outline: 2px dashed var(--accent-2);
  outline-offset: -8px;
  cursor: move;
}
.slide-object.audio audio { width: 100%; }
.slide-object.table table { width: 100%; height: 100%; border-collapse: collapse; table-layout: fixed; }
.slide-object.table td {
  border: 1px solid #c7d2fe;
  padding: 6px;
  vertical-align: top;
  cursor: text;
  min-width: 40px;
}
.slide-object.table td:focus {
  outline: 3px solid rgba(255,159,47,.74);
  outline-offset: -3px;
  background: rgba(255,251,235,.92);
}
.slide-object .move-handle {
  position: absolute;
  left: 50%;
  top: -24px;
  width: 46px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(31,41,55,.25);
  cursor: grab;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity .14s ease;
}
.slide-object .move-handle::before {
  content: "";
  position: absolute;
  left: 11px;
  right: 11px;
  top: 4px;
  height: 2px;
  border-top: 2px solid rgba(255,255,255,.9);
  border-bottom: 2px solid rgba(255,255,255,.9);
}
.slide-object .resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 99px;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(31,41,55,.25);
  opacity: 0;
  transition: opacity .14s ease;
}
.resize-handle.nw { left: -8px; top: -8px; cursor: nwse-resize; }
.resize-handle.ne { right: -8px; top: -8px; cursor: nesw-resize; }
.resize-handle.se { right: -8px; bottom: -8px; cursor: nwse-resize; }
.resize-handle.sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.rotate-handle {
  position: absolute;
  left: 50%;
  top: -38px;
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 99px;
  background: var(--accent-2);
  box-shadow: 0 2px 8px rgba(31,41,55,.25);
  cursor: grab;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity .14s ease;
}
.rotate-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 16px;
  width: 2px;
  height: 20px;
  background: var(--accent-2);
  transform: translateX(-50%);
}
.slide-object:hover .move-handle,
.slide-object:hover .resize-handle,
.slide-object:hover .rotate-handle,
.slide-object.selected .move-handle,
.slide-object.selected .resize-handle,
.slide-object.selected .rotate-handle,
.slide-object:focus-within .move-handle,
.slide-object:focus-within .resize-handle,
.slide-object:focus-within .rotate-handle {
  opacity: 1;
}
.slide-audio-bar {
  position: absolute;
  right: 16px;
  bottom: 48px;
  display: grid;
  gap: 4px;
  max-width: 320px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  background: rgba(31,27,75,.76);
  color: #fff;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 800;
  pointer-events: none;
}

.panel {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 12px;
}
.panel h2 { margin: 0; font-size: 1rem; color: var(--dark); }
.panel textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
}
.panel label { display: grid; gap: 4px; font-size: .84rem; font-weight: 850; color: var(--muted); }
.panel input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--ink);
}
.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.selection-info { color: var(--muted); font-weight: 800; }
.advanced-position {
  border: 1px solid #eee8ff;
  border-radius: 8px;
  padding: 8px;
  background: #fbfaff;
}
.advanced-position summary {
  color: var(--muted);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 900;
}
.advanced-position .grid-two { margin-top: 8px; }

.slide-sorter {
  padding: 18px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.slide-sorter[hidden],
.stage[hidden] { display: none !important; }
.sorter-card {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  box-shadow: 0 8px 18px rgba(31,41,55,.06);
  margin-left: calc(var(--indent, 0) * 18px);
}
.sorter-card.active { border-color: var(--accent); }
.sorter-card .thumb-preview { width: 100%; }

.studio-dialog {
  width: min(900px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0;
}
.studio-dialog::backdrop { background: rgba(31, 27, 75, .35); }
.studio-dialog form { display: grid; gap: 12px; padding: 16px; }
.studio-dialog header,
.studio-dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.studio-dialog h2 { margin: 0; color: var(--dark); }
.studio-dialog textarea {
  width: 100%;
  min-height: 420px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-family: "Courier New", monospace;
}
.studio-dialog button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 11px;
  font-weight: 850;
}
.studio-dialog button:hover { border-color: var(--accent); color: var(--accent); }
.small-dialog { width: min(520px, calc(100vw - 32px)); }
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.dialog-subhead { margin: 14px 0 8px; font-size: 1rem; color: var(--ink); }
.slide-palette {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.slide-palette button {
  min-height: 44px;
  border-width: 2px;
  color: #1f2937;
}
.slide-palette [data-slide-palette="paper"] { background: linear-gradient(90deg,#fff 0 45%,#312e5f 45% 62%,#1f2937 62%); }
.slide-palette [data-slide-palette="lavender"] { background: linear-gradient(90deg,#f4f1ff 0 45%,#5b21b6 45% 62%,#241047 62%); color: #241047; }
.slide-palette [data-slide-palette="mint"] { background: linear-gradient(90deg,#ecfdf5 0 45%,#047857 45% 62%,#12372a 62%); color: #12372a; }
.slide-palette [data-slide-palette="sky"] { background: linear-gradient(90deg,#eff6ff 0 45%,#1d4ed8 45% 62%,#172554 62%); color: #172554; }
.slide-palette [data-slide-palette="peach"] { background: linear-gradient(90deg,#fff7ed 0 45%,#c2410c 45% 62%,#431407 62%); color: #431407; }
.slide-palette [data-slide-palette="charcoal"] { background: linear-gradient(90deg,#111827 0 45%,#7c3aed 45% 62%,#fff 62%); color: #fff; }
.color-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.color-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
}
.color-grid input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  background: #fff;
}

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 190px minmax(360px, 1fr); }
  .inspector { display: none; }
  .workspace.show-inspector { grid-template-columns: 190px minmax(360px, 1fr) 280px; }
  .workspace.show-inspector .inspector { display: block; }
}

@media (max-width: 760px) {
  .app-header { align-items: flex-start; flex-direction: column; min-height: auto; }
  .show-app { height: auto; min-height: 100vh; }
  .workspace { grid-template-columns: 1fr; }
  .slide-rail { order: 1; border-right: 0; border-top: 1px solid var(--line); height: var(--rail-height, 220px); max-height: none; }
  .rail-splitter {
    order: 2;
    display: block;
    height: 14px;
    border-top: 1px solid #d8ccff;
    border-bottom: 1px solid #d8ccff;
    background: linear-gradient(#fbfaff,#efe8ff);
    cursor: row-resize;
    position: relative;
  }
  .rail-splitter::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 72px;
    height: 4px;
    border-radius: 999px;
    background: #9b7cff;
    transform: translate(-50%, -50%);
  }
  .rail-splitter.dragging,
  .rail-splitter:focus-visible { outline: 3px solid rgba(255,159,47,.7); outline-offset: -3px; }
  .stage-wrap { order: 3; min-height: 70vh; }
  .thumbnail-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .stage { padding: 10px; }
  .slide-canvas { width: min(100%, 92vw); }
}
