:root {
  color-scheme: dark;
  --bg: #0c0e15;
  --panel: #151822;
  --panel-2: #1c202d;
  --panel-3: #252a3a;
  --border: #30364a;
  --border-soft: #252a38;
  --text: #f6f7fb;
  --muted: #9da5bd;
  --accent: #8b6cff;
  --accent-2: #25d0b1;
  --danger: #ff5e73;
  --warning: #ffbe55;
  --shadow: 0 18px 60px rgba(0, 0, 0, .38);
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-size: 13px; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.app-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 52px minmax(240px, 1fr) 230px 24px;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1a1d29, #141722);
  z-index: 5;
}

.brand { display: flex; align-items: center; min-width: 220px; gap: 10px; }
.brand-logo { width: 32px; height: 32px; filter: drop-shadow(0 4px 14px rgba(139, 108, 255, .35)); }
.brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.project-status { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; white-space: nowrap; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

.top-actions, .timeline-actions, .transport-controls, .tool-options, .view-options, .script-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.button, .icon-button, .tool, .mini-button, .zoom-readout, .tab, .export-card {
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .1s ease;
}
.button:hover, .icon-button:hover, .tool:hover, .mini-button:hover, .zoom-readout:hover, .tab:hover { background: var(--panel-3); }
.button:active, .icon-button:active, .tool:active, .mini-button:active, .export-card:active { transform: translateY(1px); }
.button { min-height: 32px; padding: 6px 11px; border-radius: 7px; white-space: nowrap; }
.button.small { min-height: 28px; padding: 4px 8px; font-size: 12px; }
.button.subtle { border-color: var(--border); background: var(--panel-2); }
.button.primary { background: var(--accent); border-color: #9b82ff; color: white; font-weight: 650; }
.button.primary:hover { background: #7655f4; }
.button.accent { background: var(--accent-2); border-color: #39e1c3; color: #071410; font-weight: 750; }
.button.danger { border-color: rgba(255, 94, 115, .42); color: #ff98a6; background: rgba(255, 94, 115, .08); }
.button.toggle[aria-pressed="true"] { background: rgba(139, 108, 255, .22); border-color: var(--accent); color: #d8d0ff; }
.button:disabled, .icon-button:disabled { opacity: .4; cursor: default; }
.icon-button { width: 32px; height: 32px; border-radius: 7px; border-color: var(--border); background: var(--panel-2); display: inline-grid; place-items: center; font-size: 15px; }

.workspace { min-height: 0; display: grid; grid-template-columns: 48px minmax(300px, 1fr) 300px; }
.toolbar {
  min-height: 0;
  padding: 7px 5px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}
.toolbar-spacer { flex: 1; }
.tool { width: 36px; height: 36px; border-radius: 8px; border-color: transparent; font-size: 17px; display: grid; place-items: center; color: #d9dcef; }
.tool.active { background: rgba(139, 108, 255, .22); border-color: var(--accent); color: white; box-shadow: inset 0 0 0 1px rgba(255,255,255,.05); }

.stage-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: 42px minmax(0, 1fr); }
.stage-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 0 10px; background: #11141e; border-bottom: 1px solid var(--border); color: var(--muted); }
.tool-options label, .compact-label { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.tool-options input[type="color"] { width: 28px; height: 25px; border: 0; padding: 0; border-radius: 5px; background: none; }
.tool-options input[type="number"] { width: 56px; }
input, select, textarea {
  color: var(--text);
  background: #0f121b;
  border: 1px solid var(--border);
  border-radius: 6px;
}
input, select { min-height: 28px; padding: 4px 7px; }
input[type="color"] { cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); }
.mini-button { width: 26px; height: 26px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); }
.zoom-readout { min-width: 54px; height: 26px; border-radius: 6px; color: var(--muted); }

.canvas-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: #262b38;
  background-image:
    linear-gradient(45deg, #2d3240 25%, transparent 25%),
    linear-gradient(-45deg, #2d3240 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2d3240 75%),
    linear-gradient(-45deg, transparent 75%, #2d3240 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  touch-action: none;
}
#stageCanvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.empty-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none; flex-direction: column; gap: 7px; text-align: center; color: var(--muted); pointer-events: none; max-width: 330px; padding: 18px; border-radius: 12px; background: rgba(14, 16, 24, .82); border: 1px solid rgba(255,255,255,.08); backdrop-filter: blur(8px); }
.empty-hint strong { color: var(--text); font-size: 16px; }
.empty-hint.visible { display: flex; }

.inspector { min-width: 0; min-height: 0; border-left: 1px solid var(--border); background: var(--panel); display: grid; grid-template-rows: 39px minmax(0, 1fr); }
.tab-strip { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--border); background: #11141e; }
.tab { min-width: 0; padding: 0 5px; border-radius: 0; color: var(--muted); font-size: 11px; border-bottom: 2px solid transparent; }
.tab.active { color: white; border-bottom-color: var(--accent); background: rgba(139, 108, 255, .08); }
.panel { display: none; min-height: 0; overflow: auto; padding: 12px; }
.panel.active { display: block; }
.panel h2 { margin: 0 0 4px; font-size: 15px; }
.panel p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }

.property-section { border: 1px solid var(--border-soft); border-radius: 9px; margin-bottom: 10px; overflow: hidden; }
.property-section h3 { margin: 0; padding: 8px 10px; font-size: 12px; background: var(--panel-2); border-bottom: 1px solid var(--border-soft); }
.property-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 10px; }
.property-grid label { display: flex; flex-direction: column; gap: 4px; min-width: 0; color: var(--muted); font-size: 11px; }
.property-grid label.full { grid-column: 1 / -1; }
.property-grid input, .property-grid select { width: 100%; }
.property-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 10px 10px; }
.info-card { padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); color: var(--muted); line-height: 1.5; }

.asset-list { display: flex; flex-direction: column; gap: 8px; }
.asset-item { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 9px; padding: 7px; background: var(--panel-2); }
.asset-thumb { width: 42px; height: 42px; border-radius: 6px; object-fit: contain; background: #0b0d13; border: 1px solid var(--border-soft); }
.asset-audio { display: grid; place-items: center; font-size: 19px; }
.asset-meta { min-width: 0; }
.asset-meta strong, .asset-meta span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-meta span { color: var(--muted); font-size: 10px; margin-top: 3px; }
.asset-buttons { display: flex; flex-direction: column; gap: 4px; }

.script-editor { width: 100%; min-height: 220px; padding: 10px; resize: vertical; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 2; }
.script-actions { margin-top: 8px; }
.api-help { margin-top: 14px; color: var(--muted); }
.api-help summary { cursor: pointer; color: var(--text); }
.api-help pre { overflow: auto; padding: 9px; border-radius: 7px; background: #0d1018; border: 1px solid var(--border); font-size: 11px; }
.security-note { margin-top: 12px !important; padding: 9px; border-radius: 7px; background: rgba(37,208,177,.07); border: 1px solid rgba(37,208,177,.22); }
.console-output { font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.console-entry { border-bottom: 1px solid var(--border-soft); padding: 6px 2px; color: #d7dbea; }
.console-entry.error { color: #ff93a2; }
.console-entry.warn { color: #ffd184; }
.console-time { color: #747d96; margin-right: 6px; }

.timeline-shell { min-height: 0; border-top: 1px solid var(--border); background: #11141d; display: grid; grid-template-rows: 42px minmax(0, 1fr); }
.timeline-actions { padding: 0 9px; border-bottom: 1px solid var(--border); background: var(--panel); overflow-x: auto; }
.timeline-grow { flex: 1; }
.compact-label { color: var(--muted); font-size: 11px; }
.compact-label input { width: 58px; }
.timeline-scroller { min-height: 0; overflow: auto; position: relative; }
.timeline { display: grid; width: max-content; min-width: 100%; --cell: 24px; --layer-name: 180px; user-select: none; }
.timeline-ruler, .timeline-row { display: grid; grid-template-columns: var(--layer-name) repeat(var(--frames), var(--cell)); min-height: 31px; }
.timeline-ruler { position: sticky; top: 0; z-index: 4; background: #161a25; border-bottom: 1px solid var(--border); }
.ruler-corner { position: sticky; left: 0; z-index: 6; background: #161a25; border-right: 1px solid var(--border); display: flex; align-items: center; padding: 0 8px; color: var(--muted); font-size: 10px; }
.ruler-cell { border-right: 1px solid #292e3d; display: flex; align-items: center; justify-content: center; color: #7d859e; font-size: 9px; }
.ruler-cell.major { color: #c6cada; background: rgba(255,255,255,.025); }
.layer-header { position: sticky; left: 0; z-index: 3; display: grid; grid-template-columns: 24px 24px minmax(0, 1fr); align-items: center; gap: 3px; padding: 0 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border-soft); background: #191d29; }
.layer-header.active { background: rgba(139,108,255,.16); }
.layer-toggle { width: 22px; height: 22px; padding: 0; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.layer-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; cursor: default; }
.frame-cell { position: relative; width: var(--cell); height: 31px; border-right: 1px solid #252a38; border-bottom: 1px solid #252a38; background: #11141d; cursor: pointer; }
.frame-cell.exposed { background: #1c2130; }
.frame-cell.keyframe { background: #262d41; }
.frame-cell.blank-keyframe { background: #1c2230; }
.frame-cell::before { content: ""; position: absolute; inset: 0; pointer-events: none; }
.frame-cell.keyframe::after { content: ""; position: absolute; width: 7px; height: 7px; border-radius: 50%; left: 7px; top: 11px; background: #f7f8fc; box-shadow: 0 0 0 1px #090b10; }
.frame-cell.blank-keyframe::after { background: transparent; border: 1px solid #e8ebf5; width: 6px; height: 6px; }
.frame-cell.tween::before { background: linear-gradient(135deg, transparent 45%, rgba(37,208,177,.4) 46%, rgba(37,208,177,.4) 54%, transparent 55%); }
.frame-cell.active { box-shadow: inset 0 0 0 2px var(--accent); z-index: 2; }
.frame-cell.playhead::before { border-left: 2px solid #ff5e73; left: -1px; }
.frame-cell:hover { background: #30374c; }

.statusbar { display: flex; align-items: center; gap: 16px; padding: 0 8px; border-top: 1px solid var(--border); background: #0e1119; color: #788199; font-size: 10px; }
.status-spacer { flex: 1; }

.modal { border: 0; padding: 0; background: transparent; color: var(--text); max-width: calc(100vw - 30px); max-height: calc(100vh - 30px); }
.modal::backdrop { background: rgba(5, 7, 12, .78); backdrop-filter: blur(5px); }
.modal-card { width: min(780px, calc(100vw - 30px)); max-height: calc(100vh - 30px); overflow: auto; border: 1px solid var(--border); border-radius: 14px; background: #151925; box-shadow: var(--shadow); }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; background: #1b1f2c; }
.modal-header { border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-header h1 { margin: 0 0 3px; font-size: 18px; }
.modal-header p { margin: 0; color: var(--muted); font-size: 11px; }
.export-settings { padding: 14px 16px 4px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.export-settings label, .form-grid label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 11px; }
.export-settings .checkbox-label { flex-direction: row; align-items: center; margin-top: 20px; }
.export-grid { padding: 12px 16px 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.export-card { min-height: 78px; text-align: left; padding: 12px; border-color: var(--border); border-radius: 10px; background: var(--panel-2); }
.export-card:hover { border-color: var(--accent); background: rgba(139,108,255,.12); }
.export-card strong, .export-card span { display: block; }
.export-card span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.progress-wrap { margin: 0 16px 16px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: #10131c; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 8px; }
progress { width: 100%; height: 10px; accent-color: var(--accent-2); }
.progress-wrap .button { margin-top: 8px; }
.projects-list { padding: 14px; display: flex; flex-direction: column; gap: 9px; min-height: 120px; }
.project-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.project-card h3 { margin: 0 0 4px; font-size: 13px; }
.project-card p { margin: 0; color: var(--muted); font-size: 10px; }
.project-card-actions { display: flex; gap: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; padding: 16px; }
.form-grid label:first-child { grid-column: 1 / -1; }

.toast-region { position: fixed; right: 14px; bottom: 42px; z-index: 30; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { min-width: 240px; max-width: 360px; padding: 10px 12px; border-radius: 9px; background: #222838; border: 1px solid var(--border); box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { border-color: rgba(255,94,115,.55); }
.toast.success { border-color: rgba(37,208,177,.55); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.script-sandbox { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 48px minmax(280px, 1fr) 260px; }
  .top-actions .button.subtle { padding-left: 7px; padding-right: 7px; }
  .project-status { max-width: 140px; }
  .timeline-actions { gap: 4px; }
}

@media (max-width: 780px) {
  html, body { overflow: auto; }
  .app-shell { min-width: 760px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.about-modal a { color: #a998ff; }
.about-modal code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.audio-track-list { display:flex; flex-direction:column; gap:7px; margin-top:14px; }
.audio-track-item { border:1px solid var(--border); border-radius:9px; padding:8px; background:var(--panel-2); }
.audio-track-item strong { display:block; margin-bottom:7px; }
.audio-track-controls { display:grid; grid-template-columns:1fr 1fr auto; gap:6px; align-items:end; }
.audio-track-controls label { display:flex; flex-direction:column; gap:4px; color:var(--muted); font-size:10px; }
