:root {
  --page: #f3f0ea;
  --panel: #ffffff;
  --panel-strong: #fcfaf6;
  --ink: #1f2230;
  --muted: #6f6f7a;
  --accent: #bb4d2d;
  --accent-deep: #8f341a;
  --line: rgba(31, 34, 48, 0.12);
  --panel-gap: 14px;
  --status-error: #b42318;
  --toast-shadow: 0 18px 40px rgba(31, 34, 48, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "SUIT", sans-serif;
  color: var(--ink);
  background: var(--page);
}

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

.page-shell {
  width: min(1680px, calc(100% - 20px));
  margin: 0 auto;
  padding: 12px 0 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  position: relative;
  overflow: visible;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.92fr) minmax(720px, 1.45fr);
  grid-template-areas: "controls settings";
  gap: var(--panel-gap);
  align-items: stretch;
}

.panel::before {
  content: none;
}

.controls {
  grid-area: controls;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  align-content: start;
  min-height: 0;
}

.settings {
  grid-area: settings;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
  align-content: start;
  height: auto;
  max-height: none;
  overflow: visible;
}

.settings .panel-header,
.settings .mockup-box,
.settings .field-grid {
  grid-column: 1 / -1;
}

.panel-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.title-with-info {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.info-tooltip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(31, 34, 48, 0.12);
  background: var(--panel-strong);
  color: var(--accent-deep);
  overflow: visible;
  line-height: 1;
}

.info-tooltip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1;
}

.tooltip-content {
  display: none;
}

.floating-tooltip {
  position: fixed;
  width: min(360px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  padding: 10px 12px;
  border-radius: 10px;
  background: #1f2230;
  border: 1px solid #1f2230;
  color: #fffaf4;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.6;
  text-align: left;
  isolation: isolate;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 160ms ease, transform 160ms ease, visibility 160ms ease;
  pointer-events: none;
  z-index: 9999;
}

.floating-tooltip.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.startup-loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(243, 240, 234, 0.78);
  backdrop-filter: blur(6px);
  z-index: 10001;
}

.startup-loading[hidden] {
  display: none;
}

.startup-loading-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: var(--toast-shadow);
}

.startup-loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(31, 34, 48, 0.16);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

.startup-loading-text {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
}

.status-toast {
  position: fixed;
  top: 24px;
  right: 24px;
  width: auto;
  max-width: calc(100vw - 32px);
  display: grid;
  gap: 8px;
  justify-items: end;
  pointer-events: none;
  z-index: 10000;
}

.status-toast[hidden] {
  display: none;
}

.status-toast-item {
  width: auto;
  max-width: min(480px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(31, 34, 48, 0.96);
  box-shadow: var(--toast-shadow);
  color: #fffaf4;
  line-height: 1.5;
  white-space: normal;
  overflow-wrap: anywhere;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-12px);
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

.status-toast-item.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.status-toast-item.is-error {
  background: rgba(180, 35, 24, 0.96);
  border-color: rgba(255, 255, 255, 0.2);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.controls .field-grid {
  align-items: stretch;
}

.settings .field-grid {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field:has(> .field-item) {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.field-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field span {
  font-size: 0.92rem;
  font-weight: 700;
}

.field input:not([type="color"]),
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 8px;
  background: var(--panel-strong);
  color: var(--ink);
}

.field select {
  appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent-deep) 50%),
    linear-gradient(135deg, var(--accent-deep) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% - 1px),
    calc(100% - 11px) calc(50% - 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.font-field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(187, 77, 45, 0.08);
  color: var(--accent-deep);
  border: 1px solid rgba(187, 77, 45, 0.14);
  font-size: 1.2rem;
}

.icon-button-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transform-origin: center;
}

.icon-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.icon-button.is-loading .icon-button-glyph {
  animation: spin 0.9s linear infinite;
}

.field textarea {
  resize: vertical;
  line-height: 1.55;
}

#sourceText {
  height: 100%;
  resize: none;
}

.controls > .field {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.controls > .field textarea {
  flex: 1;
  min-height: 0;
}

.file-field {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-strong);
  cursor: pointer;
}

.upload-field {
  gap: 6px;
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-name {
  width: 100%;
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.color-field {
  display: flex;
  flex-direction: row;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-strong);
  cursor: pointer;
}

.color-field input[type="color"] {
  width: 0;
  height: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  position: absolute;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(31, 34, 48, 0.12);
}

.color-value {
  font-weight: 700;
  color: var(--accent-deep);
  letter-spacing: 0.02em;
}

.range-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.range-field input[type="range"] {
  flex: 1;
}

.range-field output {
  min-width: 54px;
  font-weight: 700;
  color: var(--accent-deep);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.controls .action-row {
  justify-content: start;
}

button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

button:hover {
  transform: none;
}

.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.secondary {
  background: var(--panel-strong);
  color: var(--accent-deep);
  border-color: rgba(187, 77, 45, 0.18);
}

.mockup-box {
  padding: 8px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.mockup-header {
  display: flex;
  justify-content: start;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.mockup-header h3 {
  font-size: 0.92rem;
  font-weight: 800;
  margin: 0;
}

.slide-mockup {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 4px;
  background: #141822;
  border: 1px solid rgba(16, 19, 26, 0.16);
}

.slide-mockup.has-image {
  background-size: cover;
  background-position: center;
}

.slide-safe-zone {
  position: absolute;
  inset: 60px 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.24);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.24);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.slide-mockup-text {
  position: relative;
  width: 100%;
  display: block;
  white-space: pre-wrap;
  text-align: center;
  cursor: grab;
  user-select: none;
  touch-action: none;
  line-height: 1.2;
  padding: 0;
}

.slide-mockup-text.is-placeholder {
  opacity: 0.64;
}

.slide-mockup-text.dragging {
  cursor: grabbing;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .field-grid {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .mockup-header {
    align-items: start;
    flex-direction: column;
  }

  .floating-tooltip {
    width: min(320px, calc(100vw - 20px));
    max-width: calc(100vw - 20px);
  }

  .field:has(> .field-item) {
    grid-template-columns: 1fr;
  }

  .font-field-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "settings";
    grid-template-rows: auto auto;
  }

  .controls,
  .settings {
    grid-column: auto;
    grid-row: auto;
  }

  .controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: auto;
    max-height: none;
  }

  .settings {
    display: block;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .settings > * + * {
    margin-top: 10px;
  }

  .settings .field-grid {
    padding: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls .field-grid {
    grid-template-columns: 1fr;
  }

  #sourceText {
    display: block;
    width: 100%;
    height: 280px;
    min-height: 280px;
    max-height: 280px;
  }

  .controls .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .controls .action-row > * {
    width: 100%;
  }
}
