:root {
  color-scheme: light;
  --ink: #17191f;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --paper: #f6f3ec;
  --teal: #087f7a;
  --teal-dark: #055f5b;
  --coral: #e85d4f;
  --yellow: #efb93f;
  --blue: #3d6fd8;
  --shadow: 0 22px 70px rgba(24, 31, 44, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(8, 127, 122, 0.16), transparent 34%),
    linear-gradient(315deg, rgba(232, 93, 79, 0.14), transparent 30%),
    var(--paper);
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.workspace,
.scenes-panel,
.history-panel {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(216, 222, 232, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.workspace {
  min-height: calc(100vh - 56px);
  padding: 22px;
  border-radius: 8px;
}

.topbar,
.section-heading,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  min-height: 70px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 4.25rem);
  line-height: 0.95;
}

h2 {
  font-size: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
  gap: 22px;
}

.controls-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-content: start;
}

.field {
  display: grid;
  gap: 8px;
}

.field.wide {
  grid-column: 1 / -1;
}

.save-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.save-row.wide {
  grid-column: 1 / -1;
}

.save-row .secondary-button {
  flex: 0 0 auto;
}

#saveStatus {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.field span {
  color: #333844;
  font-size: 0.84rem;
  font-weight: 750;
}

input,
select,
textarea,
.output-box {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

input,
select {
  min-height: 46px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 122, 0.16);
}

.result-panel {
  display: grid;
  gap: 16px;
  align-content: start;
}

.visual-preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid #cfd8e6;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(61, 111, 216, 0.22), transparent 42%),
    linear-gradient(45deg, rgba(239, 185, 63, 0.28), transparent 45%),
    #eef4f1;
}

.preview-strip {
  position: absolute;
  inset: 18px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  opacity: 0.76;
}

.preview-strip span {
  display: grid;
  min-width: 0;
  place-items: start end;
  padding: 8px;
  border: 1px solid rgba(23, 25, 31, 0.18);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.36);
  color: rgba(23, 25, 31, 0.68);
  font-size: 0.72rem;
  font-weight: 900;
}

.preview-frame {
  position: relative;
  display: grid;
  width: min(78%, 360px);
  min-height: 158px;
  align-content: end;
  gap: 10px;
  padding: 18px;
  border: 1px solid rgba(23, 25, 31, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.46)),
    rgba(255, 255, 255, 0.78);
  box-shadow: 0 18px 42px rgba(24, 31, 44, 0.12);
}

.preview-frame span {
  width: fit-content;
  max-width: 100%;
  padding: 6px 9px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.preview-frame strong {
  font-size: 1.35rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.output-group {
  display: grid;
  gap: 8px;
}

.output-box {
  min-height: 360px;
  padding: 14px;
  background: #10131a;
  color: #f9fbff;
  line-height: 1.55;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 800;
  transition: transform 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.primary-button {
  padding: 0 22px;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 12px 24px rgba(8, 127, 122, 0.22);
}

.secondary-button,
.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-button {
  flex: 1;
  padding: 0 14px;
}

.ghost-button {
  min-height: 34px;
  padding: 0 12px;
}

.icon-button {
  display: grid;
  width: 42px;
  place-items: center;
  background: var(--ink);
  color: #fff;
}

button:hover {
  transform: translateY(-1px);
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

button:active {
  transform: translateY(0);
}

.scenes-panel,
.history-panel {
  margin-top: 18px;
  padding: 18px;
  border-radius: 8px;
}

#sceneCount,
#historyCount {
  display: grid;
  min-width: 34px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: #eaf6f4;
  color: var(--teal-dark);
  font-weight: 850;
}

.scene-list,
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.scene-card,
.history-card {
  display: grid;
  gap: 10px;
  min-height: 128px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
}

.scene-card h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.scene-card p,
.history-card p {
  margin: 0;
  color: #2a2f3a;
  line-height: 1.42;
}

.history-card p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.scene-index {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eaf6f4;
  color: var(--teal-dark);
  font-size: 0.72rem;
  font-weight: 900;
}

.scene-card button,
.history-card button {
  justify-self: start;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafc;
  font-weight: 800;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 48px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 18px 36px rgba(24, 31, 44, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

  .workspace {
    min-height: auto;
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout-grid,
  .controls-panel {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .save-row,
  .action-row {
    width: 100%;
  }

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

  .primary-button {
    flex: 1;
  }
}

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

  h1 {
    font-size: 2.45rem;
  }

  .visual-preview {
    min-height: 220px;
  }

  .preview-frame {
    width: 86%;
  }
}
