:root {
  color-scheme: dark;
  --bg: #101216;
  --surface: #181b21;
  --surface-2: #21252d;
  --line: #343946;
  --text: #f4f6fb;
  --muted: #9ca7b8;
  --accent: #56c1ff;
  --accent-2: #f0b44c;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(280px, 1fr) auto;
  min-width: 0;
  overflow: hidden;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 3.2rem);
  line-height: 1;
}

h2 {
  font-size: 0.88rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
}

.upload-button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}

.upload-button {
  padding: 0 16px;
  white-space: nowrap;
}

.upload-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

button:hover,
.upload-button:hover {
  border-color: var(--accent);
  background: #262c36;
}

button:active,
.upload-button:active {
  transform: translateY(1px);
}

.canvas-zone {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-width: 0;
  min-height: 360px;
  padding: 24px;
  background-color: #0c0e12;
  background-image:
    linear-gradient(45deg, #151922 25%, transparent 25%),
    linear-gradient(-45deg, #151922 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #151922 75%),
    linear-gradient(-45deg, transparent 75%, #151922 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.preview-stage {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  overflow: hidden;
}

#previewCanvas {
  image-rendering: pixelated;
  width: auto;
  height: auto;
  max-width: min(100%, 840px);
  max-height: 64vh;
  border: 1px solid var(--line);
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.38);
}

.empty-state {
  position: absolute;
  display: grid;
  gap: 7px;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

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

.empty-state strong {
  color: var(--text);
  font-size: 1.1rem;
}

.timeline {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  padding: 14px 18px 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.frames {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 12px 18px 18px;
  min-height: 110px;
}

.frame-tile {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 74px;
  width: 74px;
  height: 74px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11141a;
}

.frame-tile.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(240, 180, 76, 0.24);
}

.frame-tile canvas {
  image-rendering: pixelated;
  max-width: 62px;
  max-height: 62px;
}

.frame-tile span {
  position: absolute;
  bottom: 3px;
  right: 5px;
  color: var(--muted);
  font-size: 0.68rem;
}

.controls {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}

.panel {
  display: grid;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

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

label {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

input[type="number"],
select {
  width: 100%;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11141a;
  color: var(--text);
}

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

label b {
  min-width: 32px;
  color: var(--text);
  font-size: 0.85rem;
  text-align: right;
}

.check-row {
  grid-template-columns: auto 1fr;
  justify-content: start;
}

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

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

.panel > button {
  width: 100%;
}

.drop-ready .canvas-zone {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

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

  .controls {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

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