:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --bg-soft: #edeee9;
  --panel: #ffffff;
  --panel-2: #f7f7f4;
  --line: rgba(17, 19, 24, 0.1);
  --line-strong: rgba(17, 19, 24, 0.18);
  --text: #111318;
  --muted: #73757c;
  --subtle: #a5a6aa;
  --accent: #2f6bff;
  --accent-2: #101216;
  --accent-3: #d3c8b2;
  --ok: #14784c;
  --warn: #a26a15;
  --danger: #c9364f;
  --shadow: 0 28px 90px rgba(28, 28, 24, 0.11);
  --shadow-soft: 0 16px 42px rgba(28, 28, 24, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 8% -10%, rgba(255, 255, 255, 0.95), transparent 30%),
    radial-gradient(circle at 96% 0%, rgba(47, 107, 255, 0.08), transparent 24%),
    linear-gradient(180deg, #fbfaf7 0%, #f7f6f2 46%, #eeeeea 100%);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Manrope, sans-serif;
  letter-spacing: 0;
  text-rendering: geometricPrecision;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  min-height: 100dvh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 20px;
  max-width: 1620px;
  padding: 14px 16px;
  border: 1px solid rgba(17, 19, 24, 0.08);
  border-radius: 26px;
  background: rgba(247, 246, 242, 0.96);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(26px);
  position: sticky;
  top: 14px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.11), transparent 46%),
    #111318;
  box-shadow: 0 18px 40px rgba(17, 19, 24, 0.2);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 780;
  letter-spacing: -0.02em;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.top-actions,
.source-actions,
.template-row,
.stage-toolbar,
.slide-actions,
.toggle-bar,
.align-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(315px, 390px) minmax(480px, 1fr) minmax(300px, 360px);
  gap: 18px;
  max-width: 1620px;
  margin: 0 auto;
}

.panel,
.stage-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.panel {
  padding: 18px;
}

.source-panel,
.inspector-panel {
  align-self: start;
}

.stage-panel {
  overflow: hidden;
  border-color: rgba(17, 19, 24, 0.9);
  background: #090a0c;
  box-shadow: 0 34px 110px rgba(17, 19, 24, 0.26);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head.compact {
  margin-top: 18px;
}

h2 {
  color: #17191f;
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease,
    transform 180ms ease;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(47, 107, 255, 0.44);
  box-shadow:
    0 0 0 4px rgba(47, 107, 255, 0.09),
    inset 0 1px 0 rgba(255, 255, 255, 0.78);
  background: #ffffff;
}

textarea {
  min-height: 300px;
  padding: 15px;
  resize: vertical;
  line-height: 1.5;
}

#selectedText {
  min-height: 164px;
}

input,
select {
  height: 44px;
  padding: 0 13px;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 16px,
    calc(100% - 12px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0.04em;
}

.form-grid,
.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid label:first-child,
.form-grid label:nth-child(2) {
  grid-column: 1 / -1;
}

.file-row input {
  padding: 10px;
  height: auto;
  min-height: 44px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(247, 247, 244, 0.84);
}

.source-actions {
  margin-top: 10px;
}

.source-actions input {
  flex: 1;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(247, 247, 244, 0.76);
  color: #313642;
  font-size: 13px;
  font-weight: 700;
}

.check-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.check-row span {
  margin: 0;
  color: inherit;
  font-size: inherit;
}

.template-row {
  margin-bottom: 8px;
}

.template-save-row {
  align-items: stretch;
  flex-direction: column;
  margin-top: 8px;
  margin-bottom: 0;
}

.template-save-row .button {
  width: 100%;
}

.template-save-status {
  min-height: 18px;
  margin: 0;
  color: #73767e;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.45;
}

.migration-button {
  border-color: rgba(47, 107, 255, 0.3);
  background: rgba(47, 107, 255, 0.08);
  color: #245bd6;
}

.named-select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 44px 44px;
  gap: 8px;
}

.duplicate-template-button,
.rename-button,
.delete-button {
  width: 44px;
  height: 44px;
  font-size: 20px;
  line-height: 1;
}

.delete-button {
  border-color: rgba(180, 35, 24, 0.14);
  color: #b42318;
}

.rename-dialog {
  width: min(420px, calc(100vw - 28px));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(17, 19, 24, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 36px 120px rgba(17, 19, 24, 0.24);
  color: var(--text);
  backdrop-filter: blur(24px);
}

.rename-dialog::backdrop {
  background: rgba(17, 19, 24, 0.34);
  backdrop-filter: blur(5px);
}

.rename-dialog__form {
  padding: 20px;
}

.rename-dialog__head,
.rename-dialog__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rename-dialog__head h2 {
  margin-top: 3px;
  font-size: 22px;
}

.dialog-eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.rename-dialog__close {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  font-size: 24px;
}

.rename-dialog__field {
  display: block;
  margin-top: 20px;
}

.rename-dialog__error {
  margin: 8px 0 0;
  color: #b42318;
  font-size: 12px;
  font-weight: 650;
}

.delete-dialog__text {
  margin: 20px 0 0;
  color: #454952;
  font-size: 14px;
  line-height: 1.55;
}

.rename-dialog__actions {
  justify-content: flex-end;
  margin-top: 18px;
}

@media (max-width: 480px) {
  .rename-dialog {
    width: calc(100vw - 20px);
    border-radius: 18px;
  }

  .rename-dialog__actions .button {
    flex: 1;
  }
}

.button,
.icon-button,
.tool-button {
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--text);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease,
    color 180ms ease;
}

.button {
  height: 44px;
  padding: 0 16px;
  font-weight: 760;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.button.small {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.button.primary {
  border-color: #111318;
  background: #111318;
  box-shadow: 0 18px 36px rgba(17, 19, 24, 0.18);
  color: #ffffff;
}

.button.danger {
  border-color: #b42318;
  background: #b42318;
  box-shadow: 0 18px 36px rgba(180, 35, 24, 0.18);
  color: #ffffff;
}

.button.secondary {
  border-color: rgba(17, 19, 24, 0.16);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 24px rgba(17, 19, 24, 0.06);
  color: #17191f;
}

.button.ghost {
  border-color: rgba(17, 19, 24, 0.1);
  background: rgba(255, 255, 255, 0.46);
  color: #50535b;
}

.button:hover,
.icon-button:hover,
.tool-button:hover {
  transform: translateY(-1px);
  border-color: rgba(17, 19, 24, 0.28);
  box-shadow: 0 18px 38px rgba(17, 19, 24, 0.12);
}

.button:active,
.icon-button:active,
.tool-button:active {
  transform: translateY(0);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  min-width: 124px;
  height: 44px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(237, 238, 233, 0.78);
}

.segmented button {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.segmented button.active {
  background: #ffffff;
  color: #111318;
  box-shadow: 0 8px 20px rgba(17, 19, 24, 0.09);
}

.warning {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(200, 132, 16, 0.24);
  border-radius: 14px;
  background: #fff8e8;
  color: #8a5a00;
  font-size: 13px;
  line-height: 1.4;
}

.export-progress {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  width: min(380px, calc(100vw - 36px));
  padding: 14px;
  border: 1px solid rgba(17, 19, 24, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 28px 90px rgba(17, 19, 24, 0.18);
  backdrop-filter: blur(24px);
}

.export-progress__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.export-progress__top strong {
  font-size: 14px;
  font-weight: 850;
}

.export-progress__top span {
  color: #111318;
  font-size: 13px;
  font-weight: 850;
}

.export-progress__bar {
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef0f4;
}

.export-progress__bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #111318;
  transition: width 180ms ease;
}

.export-progress p {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.export-progress.success {
  border-color: rgba(20, 120, 76, 0.28);
}

.export-progress.error {
  border-color: rgba(201, 54, 79, 0.34);
}

.stage-toolbar {
  justify-content: space-between;
  padding: 15px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025));
  color: #f6f5f1;
}

.slide-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.slide-meta strong {
  font-size: 14px;
  color: #f6f5f1;
  font-weight: 740;
}

.slide-meta span {
  color: rgba(246, 245, 241, 0.52);
  font-size: 12px;
  text-transform: uppercase;
}

.icon-button,
.tool-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-color: rgba(17, 19, 24, 0.1);
  background: rgba(255, 255, 255, 0.72);
  color: #23262e;
  font-weight: 900;
  box-shadow: 0 8px 22px rgba(17, 19, 24, 0.07);
}

.stage-toolbar .icon-button {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.08);
  color: #f6f5f1;
  box-shadow: none;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  margin: 0 2px;
  background: rgba(255, 255, 255, 0.14);
}

.tool-button.italic {
  font-style: italic;
}

.tool-button.underline {
  text-decoration: underline;
}

.tool-button.active {
  border-color: rgba(47, 107, 255, 0.34);
  background: rgba(47, 107, 255, 0.1);
  color: var(--accent);
}

.canvas-wrap {
  display: grid;
  min-height: 0;
  padding: 28px;
  place-items: center;
  background:
    radial-gradient(circle at 50% 4%, rgba(255, 255, 255, 0.13), transparent 32%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, #111318 0%, #07080a 100%);
  background-size: auto, 34px 34px, 34px 34px, auto;
}

#stageCanvas {
  display: block;
  width: min(100%, 520px);
  height: auto;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 22px;
  background: #000;
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.52),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  touch-action: none;
}

.thumbs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 76px;
  gap: 10px;
  overflow-x: auto;
  padding: 14px 16px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: #090a0c;
}

.thumb {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.055);
  box-shadow: none;
}

.thumb.active {
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.22);
}

.thumb canvas {
  display: block;
  width: 58px;
  height: auto;
  border-radius: 7px;
  background: #000;
}

.thumb span {
  color: rgba(246, 245, 241, 0.58);
  font-size: 11px;
  font-weight: 800;
}

.toggle-bar,
.align-row {
  margin-top: 12px;
}

.align-row {
  justify-content: stretch;
}

.align-row .tool-button,
.toggle-bar .tool-button {
  flex: 1;
}

input[type="color"] {
  padding: 4px;
}

.topbar,
.source-panel,
.stage-panel,
.inspector-panel {
  animation: studioIn 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.source-panel {
  animation-delay: 40ms;
}

.stage-panel {
  animation-delay: 90ms;
}

.inspector-panel {
  animation-delay: 130ms;
}

@keyframes studioIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(280px, 340px) minmax(360px, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
  }

  .inspector-panel .control-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .workspace {
    display: flex;
    flex-direction: column;
  }

  .topbar {
    align-items: stretch;
    position: static;
    top: auto;
    z-index: auto;
    margin-bottom: 12px;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .button,
  .top-actions .segmented {
    flex: 1 1 auto;
  }

  .stage-panel {
    order: -1;
  }

  .canvas-wrap {
    padding: 10px;
  }

  #stageCanvas {
    width: min(100%, 390px);
  }

  textarea {
    min-height: 220px;
  }

  .inspector-panel .control-grid,
  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .export-progress {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }
}

@media (max-width: 440px) {
  .top-actions {
    gap: 7px;
  }

  .button {
    padding: 0 10px;
    font-size: 13px;
  }

  .source-actions,
  .template-row {
    align-items: stretch;
    flex-direction: column;
  }

  .stage-toolbar {
    gap: 6px;
    padding: 12px;
  }

  .stage-toolbar .slide-actions {
    gap: 5px;
  }

  .stage-toolbar .icon-button {
    width: 34px;
    height: 34px;
  }

  .slide-meta span {
    display: none;
  }
}
