:root {
  color-scheme: light;
  --bg: #f4f1f3;
  --panel: #ffffff;
  --ink: #25232a;
  --muted: #706b75;
  --line: #ded7dd;
  --accent: #a95178;
  --accent-dark: #982760;
  --rose: #c77ba3;
  --shadow: 0 18px 50px rgba(37, 35, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.stage-panel,
.side-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stage-panel {
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto auto;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

h2 {
  font-size: 13px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

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

.file-control,
.topbar-button,
.help-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.help-button {
  width: 38px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  font-size: 16px;
  font-weight: 900;
}

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

.help-popover {
  position: absolute;
  z-index: 10;
  top: 68px;
  right: 20px;
  width: min(340px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.help-popover strong {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
}

.help-popover ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

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

.stage-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(222, 215, 221, 0.45) 1px, transparent 1px),
    linear-gradient(rgba(222, 215, 221, 0.45) 1px, transparent 1px);
  background-size: 28px 28px;
}

.stage {
  display: grid;
  width: min(72vw, 720px);
  min-height: 420px;
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stage-dissolve {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100%;
}

.stage-frame {
  grid-area: 1 / 1;
}

.stage-frame-current {
  opacity: 1;
}

.stage-dissolve.is-dissolving .stage-frame-current {
  animation-name: dissolve-in;
  animation-timing-function: linear;
  animation-fill-mode: both;
}

.stage-dissolve.is-dissolving .stage-frame-previous {
  animation-name: dissolve-out;
  animation-timing-function: linear;
  animation-fill-mode: both;
}

.stage svg {
  display: block;
  width: min(100%, 520px);
  height: auto;
  overflow: visible;
}

@keyframes dissolve-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes dissolve-out {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.icon-button,
.play-button,
.section-title button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
}

.icon-button svg,
.play-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.play-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 96px;
  min-height: 38px;
  justify-content: center;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field {
  display: grid;
  grid-template-columns: auto minmax(120px, 220px) 54px;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.transition-field,
.hold-field {
  margin-left: 0;
}

.field strong {
  color: var(--ink);
  font-size: 12px;
}

input[type="range"] {
  accent-color: var(--accent);
}

.timeline {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}

.frame-thumb {
  display: grid;
  place-items: center;
  flex: 0 0 74px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.frame-thumb.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(169, 81, 120, 0.18);
}

.frame-thumb svg {
  width: 58px;
  height: auto;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}

.side-panel section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.side-panel section:last-child {
  border-bottom: 0;
}

.frame-readout,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

#frameName {
  font-size: 15px;
  font-weight: 800;
}

#frameCounter {
  color: var(--muted);
  font-size: 13px;
}

.frame-slider {
  width: 100%;
  margin-top: 14px;
}

.section-title {
  margin-top: 0;
  margin-bottom: 12px;
}

.section-title button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.layers-list {
  display: grid;
  gap: 8px;
}

.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.layer-row {
  display: grid;
  grid-template-columns: 18px 16px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.fixed-layer-row {
  border-color: rgba(169, 81, 120, 0.42);
  background: rgba(169, 81, 120, 0.06);
}

.layer-row input {
  margin: 0;
  accent-color: var(--accent);
}

.swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(37, 35, 42, 0.2);
  border-radius: 50%;
}

.layer-row span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.stats {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
}

.stats div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee8ed;
}

.stats dt {
  color: var(--muted);
  font-size: 13px;
}

.stats dd {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .stage {
    width: 100%;
    min-height: 320px;
    padding: 24px;
  }

  .transport {
    flex-wrap: wrap;
  }

  .field {
    grid-template-columns: auto minmax(110px, 1fr) 54px;
    width: 100%;
    margin-left: 0;
  }
}

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

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

  .file-control {
    width: 100%;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-button {
    flex: 1;
  }

  .stage-wrap {
    padding: 12px;
  }
}
