:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f3f4f6;
  color: #172033;
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --danger: #dc2626;
  --stage: #0f172a;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.is-exporting .app-shell {
  pointer-events: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: calc(18px + env(safe-area-inset-top)) 22px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 10px;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

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

.controls-panel,
.output-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px;
}

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

.output-panel section {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(110px, 0.5fr) minmax(160px, 0.8fr) minmax(260px, 1.2fr) auto;
  align-items: end;
  gap: 12px;
}

.output-panel h2 {
  grid-column: 1 / -1;
}

.output-panel .status-text {
  align-self: center;
}

.export-progress {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.export-progress[hidden] {
  display: none;
}

progress {
  width: 100%;
  height: 10px;
  accent-color: var(--accent);
}

.export-progress span,
.export-modal span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--danger);
  font-size: 22px;
  line-height: 1;
}

.file-drop {
  display: grid;
  gap: 8px;
  border: 1px dashed #aeb8c8;
  border-radius: 8px;
  padding: 13px;
  color: var(--muted);
  background: #f8fafc;
  cursor: pointer;
}

.file-drop span {
  color: var(--ink);
  font-weight: 700;
}

.file-drop input {
  width: 100%;
  font-size: 13px;
}

.file-drop input::file-selector-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  margin-right: 8px;
  padding: 0 10px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.status-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.layer-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.layer-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 52px;
  padding: 7px;
  text-align: left;
}

.layer-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.layer-thumb {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 6px;
  background:
    linear-gradient(45deg, #d5dbe6 25%, transparent 25%),
    linear-gradient(-45deg, #d5dbe6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d5dbe6 75%),
    linear-gradient(-45deg, transparent 75%, #d5dbe6 75%);
  background-position:
    0 0,
    0 6px,
    6px -6px,
    -6px 0;
  background-size: 12px 12px;
}

.layer-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-meta {
  color: var(--muted);
  font-size: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  min-height: 36px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

input[type="range"] {
  padding: 0;
}

.range-stack {
  display: grid;
  gap: 12px;
}

.stage-column {
  display: grid;
  grid-template-rows: minmax(320px, 1fr) auto;
  gap: 12px;
  min-width: 0;
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 320px;
  overflow: hidden;
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 10%, rgba(37, 99, 235, 0.18), transparent 30%),
    var(--stage);
}

#stageCanvas {
  max-width: 100%;
  max-height: calc(100vh - 190px);
  width: auto;
  height: auto;
  touch-action: none;
  background:
    linear-gradient(45deg, #243047 25%, transparent 25%),
    linear-gradient(-45deg, #243047 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #243047 75%),
    linear-gradient(-45deg, transparent 75%, #243047 75%),
    #101827;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.empty-state {
  position: absolute;
  display: grid;
  gap: 7px;
  place-items: center;
  min-width: min(86%, 320px);
  min-height: 118px;
  border: 1px solid rgba(229, 231, 235, 0.34);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #e5e7eb;
  padding: 18px;
  text-align: center;
  cursor: pointer;
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  font-size: 22px;
}

.empty-state span {
  color: #b8c0cf;
}

.stage-action {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
}

.stage-action[hidden] {
  display: none;
}

.export-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
}

.export-overlay[hidden] {
  display: none;
}

.export-modal {
  display: grid;
  width: min(360px, 100%);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.24);
}

.export-modal strong {
  font-size: 18px;
}

.timeline {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.timeline button {
  min-height: 36px;
  white-space: nowrap;
}

.frame-number {
  display: grid;
  grid-template-columns: auto 58px;
  align-items: center;
  gap: 6px;
}

.frame-number input {
  min-height: 36px;
  padding: 0 6px;
  text-align: center;
}

#frameReadout {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.output-panel label {
  margin-bottom: 2px;
}

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

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

  .output-panel section {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .output-panel h2,
  .output-panel .status-text,
  .output-panel .export-progress,
  .output-panel .export-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  body {
    background: var(--stage);
  }

  .topbar,
  .workspace {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 20px;
  }

  .export-actions {
    width: 100%;
    gap: 8px;
  }

  .export-actions button {
    flex: 1 1 150px;
    min-height: 44px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
  }

  .stage-column {
    grid-row: 1;
    gap: 8px;
  }

  .canvas-wrap {
    min-height: min(62vh, 520px);
    border-radius: 0;
    margin: 0 -10px;
  }

  .controls-panel {
    grid-row: 2;
  }

  .controls-panel,
  .output-panel,
  .timeline {
    border-radius: 8px;
  }

  .controls-panel,
  .output-panel {
    gap: 14px;
    padding: 12px;
  }

  .output-panel {
    grid-template-columns: 1fr;
  }

  .output-panel section {
    grid-template-columns: 1fr;
  }

  button,
  input,
  select {
    min-height: 44px;
  }

  .file-drop {
    padding: 12px;
  }

  .stage-action {
    top: 8px;
    right: 8px;
    min-height: 38px;
    padding: 0 10px;
    font-size: 13px;
  }

  .timeline {
    grid-template-columns: auto minmax(80px, 1fr) auto;
    gap: 8px;
    padding: 8px;
  }

  .timeline button {
    min-height: 40px;
    padding: 0 12px;
  }

  .frame-number {
    display: none;
  }

  .transform-panel {
    display: none;
  }

  .control-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .control-grid input {
    padding: 0 6px;
    text-align: center;
  }

  #stageCanvas {
    max-height: min(62vh, 520px);
    max-width: calc(100vw - 20px);
  }
}

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