:root {
  --bg: #0c1020;
  --panel: #151a2e;
  --panel-2: #1d2440;
  --panel-3: #252d4f;
  --text: #f6f7fb;
  --muted: #aab3d2;
  --line: rgba(255, 255, 255, 0.12);
  --cyan: #38d9ff;
  --pink: #ff4fd8;
  --purple: #8d66ff;
  --green: #67f7a4;
  --yellow: #ffd66b;
  --danger: #ff6b7a;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --topbar-height: 72px;
  --frame-strip-height: 308px;
  --stage-size: clamp(380px, 48vw, 560px);
}


* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 10% 0%, rgba(56, 217, 255, 0.16), transparent 34%),
    radial-gradient(circle at 92% 12%, rgba(255, 79, 216, 0.15), transparent 32%),
    linear-gradient(135deg, #080b16, var(--bg));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

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

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 16, 32, 0.82);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--cyan), var(--pink));
  box-shadow: 0 10px 35px rgba(56, 217, 255, 0.22);
  font-size: 27px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.03em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top-actions,
.playback {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  transition: 160ms ease;
  user-select: none;
}

.btn:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.12); }
.btn.primary { border-color: rgba(56, 217, 255, 0.42); background: linear-gradient(135deg, rgba(56, 217, 255, 0.28), rgba(141, 102, 255, 0.24)); }
.btn.pink { border-color: rgba(255, 79, 216, 0.38); background: rgba(255, 79, 216, 0.13); }
.btn.green { border-color: rgba(103, 247, 164, 0.35); background: rgba(103, 247, 164, 0.11); }
.btn.danger { border-color: rgba(255, 107, 122, 0.38); background: rgba(255, 107, 122, 0.12); }
.btn.small { padding: 6px 9px; font-size: 12px; border-radius: 10px; }

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.speed-control input { width: 120px; accent-color: var(--cyan); }

.main-grid {
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  min-height: 0;
}

.panel {
  min-height: 0;
  background: rgba(21, 26, 46, 0.82);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

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

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

.panel-header h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin: 0 0 6px;
  color: var(--cyan);
}

.panel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.panel-body {
  padding: 14px;
  overflow: auto;
  min-height: 0;
}

.tool-section {
  background: rgba(255,255,255,0.045);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.tool-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: #fff;
}

.grid-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid-buttons.one { grid-template-columns: 1fr; }
.full-width { width: 100%; display: inline-flex; justify-content: center; align-items: center; }

.music-card {
  margin-top: 10px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--line);
}
.music-title {
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 9px;
}
.music-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.music-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0;
}
.music-row input { accent-color: var(--green); }
.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 7px;
}
.check-row input { accent-color: var(--cyan); }

.form-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
  color: var(--muted);
  font-size: 12px;
}

.form-row input[type="range"] { width: 100%; accent-color: var(--pink); }
.form-row input[type="color"] { width: 100%; height: 34px; border: 0; background: transparent; }
.form-row input[type="number"],
.form-row input[type="text"],
.form-row select {
  width: 100%;
  color: var(--text);
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.asset-card {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.07) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.07) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.07) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.07) 75%),
    rgba(255,255,255,0.04);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.asset-card img { max-width: 90%; max-height: 90%; object-fit: contain; pointer-events: none; }
.asset-card:hover { outline: 2px solid rgba(56, 217, 255, 0.5); }
.asset-card::after {
  content: attr(title);
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  color: white;
  background: rgba(0,0,0,0.56);
  border-radius: 8px;
  padding: 3px 4px;
  font-size: 9px;
  line-height: 1.1;
  opacity: 0;
  transition: 140ms ease;
}
.asset-card:hover::after { opacity: 1; }

.stage-wrap {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: max-content var(--frame-strip-height);
  overflow-y: auto;
  overflow-x: hidden;
}

.stage-area {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: visible;
}

.stage-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.stage-meta {
  width: var(--stage-size);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.stage-meta strong { color: var(--text); }

.canvas-shell {
  width: var(--stage-size);
  height: var(--stage-size);
  padding: 16px;
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(56,217,255,0.24), rgba(255,79,216,0.22));
  box-shadow: var(--shadow);
  position: relative;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: white;
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
  touch-action: none;
}

.stage.grid-on::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    linear-gradient(rgba(0,0,0,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.07) 1px, transparent 1px),
    linear-gradient(rgba(56,217,255,0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56,217,255,0.16) 1px, transparent 1px);
  background-size: 25% 25%, 25% 25%, 12.5% 12.5%, 12.5% 12.5%;
}

.onion-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.28;
  z-index: 2;
  filter: saturate(0.7);
}

.object {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: center center;
  user-select: none;
  touch-action: none;
  z-index: 4;
}

.object img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.object.text-object {
  display: grid;
  place-items: center;
  padding: 8px;
  color: #12131b;
  font-weight: 800;
  text-align: center;
  line-height: 1.05;
  white-space: pre-wrap;
}
.object.shape-object { border-radius: 18px; }
.object.selected { outline: 2px solid var(--cyan); outline-offset: 3px; }
.object.selected::before {
  content: "";
  position: absolute;
  inset: -9px;
  border: 1px dashed rgba(56,217,255,0.85);
  border-radius: 10px;
  pointer-events: none;
}

.frame-strip {
  height: var(--frame-strip-height);
  min-height: var(--frame-strip-height);
  max-height: var(--frame-strip-height);
  border-top: 1px solid var(--line);
  background: rgba(9, 12, 24, 0.74);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.frame-strip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.frame-strip-header h2 { margin: 0; font-size: 14px; }
.frame-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(84px, 1fr));
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 4px 6px 2px;
  min-height: 0;
}

.frame-thumb {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.06);
  padding: 7px;
  color: var(--muted);
}
.frame-thumb.active { outline: 2px solid var(--pink); background: rgba(255,79,216,0.12); }
.thumb-canvas {
  width: 100%;
  aspect-ratio: 1;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  margin-bottom: 5px;
}
.thumb-canvas .object { pointer-events: none; }
.thumb-label { display: flex; justify-content: space-between; align-items: center; font-size: 11px; }

.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(13, 16, 28, 0.42);
  text-align: center;
  padding: 26px;
  pointer-events: none;
  z-index: 0;
}
.empty-hint strong { display: block; color: rgba(13,16,28,0.58); font-size: 22px; margin-bottom: 8px; }

.hidden { display: none !important; }

.help-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.layer-list { display: flex; flex-direction: column; gap: 7px; }
.layer-item {
  padding: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.055);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.layer-item.active { color: var(--text); border-color: rgba(56,217,255,0.55); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: rgba(8, 10, 20, 0.92);
  border: 1px solid var(--line);
  color: white;
  padding: 11px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: 180ms ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1180px) {
  :root { --stage-size: clamp(340px, 42vw, 500px); }
  .main-grid { grid-template-columns: 250px 1fr 260px; }
  .asset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .frame-list { grid-template-columns: repeat(4, minmax(82px, 1fr)); }
}

@media (max-width: 920px) {
  html, body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; }
  .topbar { height: auto; align-items: flex-start; flex-direction: column; }
  .main-grid { grid-template-columns: 1fr; }
  .panel, .panel.right { border: 0; border-bottom: 1px solid var(--line); max-height: 420px; }
  .stage-wrap { grid-template-rows: max-content var(--frame-strip-height); overflow: visible; }
  .frame-list { grid-template-columns: repeat(3, minmax(82px, 1fr)); }
  :root { --stage-size: min(90vw, 520px); --frame-strip-height: 360px; }
}
