:root {
  color-scheme: dark;
  --bg: #090b10;
  --panel: #121620;
  --panel-2: #181d29;
  --line: #2a3141;
  --text: #f5f7fb;
  --muted: #9da7b8;
  --accent: #7b61ff;
  --accent-2: #9b87ff;
  --danger: #e04f5f;
  --success: #38b67a;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
button:hover { border-color: #48526a; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: transparent; }
button.danger { background: var(--danger); border-color: transparent; }
button.active { outline: 2px solid var(--accent-2); }
button.wide { width: 100%; }

.topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: #0d1017; position: sticky; top: 0; z-index: 20; }
.topbar h1 { margin: 0; font-size: clamp(18px, 3vw, 26px); }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; }

.app-shell { display: grid; grid-template-columns: minmax(260px, 310px) minmax(0, 1fr) minmax(260px, 320px); min-height: calc(100vh - 76px); }
.panel { background: var(--panel); padding: 14px; overflow-y: auto; max-height: calc(100vh - 76px); }
.parts-panel { border-right: 1px solid var(--line); }
.animation-panel { border-left: 1px solid var(--line); }
.panel section { padding: 12px 0 18px; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; }

.piece-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.piece-slot { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px; min-width: 0; }
.piece-preview { width: 42px; height: 42px; border-radius: 8px; background: #0a0c11; object-fit: contain; border: 1px solid #2a3040; }
.piece-slot label { font-size: 11px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.piece-slot input { width: 100%; font-size: 10px; color: transparent; }

.selected-name { background: #0c0f15; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; color: var(--accent-2); font-weight: 700; }
.control-grid { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
input[type="range"] { width: 100%; }
input[type="number"] { width: 100%; background: #0c0f15; border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 8px; }
.button-row { display: flex; gap: 8px; margin-top: 10px; }
.button-row > * { flex: 1; }
.button-row.compact { margin-top: 0; }
.button-row.compact button { padding: 7px 10px; }
.file-button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.file-button input { display: none; }
.file-button.small { padding: 10px 8px; font-size: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }

.workspace-wrap { display: flex; flex-direction: column; min-width: 0; background: #07090d; }
.canvas-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.canvas-stage { flex: 1; min-height: 420px; display: grid; place-items: center; overflow: hidden; padding: 12px; touch-action: none; }
#studioCanvas { width: 100%; height: auto; max-height: calc(100vh - 130px); aspect-ratio: 16 / 9; background: #1d222d; border: 1px solid #30384b; box-shadow: 0 12px 40px rgba(0,0,0,.45); touch-action: none; }

.transport { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 8px; }
.time-readout { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: -2px; }
.keyframe-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; min-height: 28px; }
.keyframe-chip { border: 1px solid var(--line); background: #0d1119; border-radius: 999px; padding: 6px 9px; font-size: 11px; cursor: pointer; }
.keyframe-chip.active { border-color: var(--accent); color: var(--accent-2); }
#waveformCanvas { width: 100%; height: 70px; margin: 8px 0; background: #0b0e14; border: 1px solid var(--line); border-radius: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(30px); opacity: 0; pointer-events: none; background: #f4f6fb; color: #11141a; padding: 10px 14px; border-radius: 999px; font-weight: 700; font-size: 13px; transition: .2s ease; z-index: 50; max-width: calc(100vw - 30px); text-align: center; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: #ffdadf; color: #651522; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .animation-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .animation-panel section { border-bottom: 0; }
}

@media (max-width: 760px) {
  .topbar { position: static; align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .app-shell { display: flex; flex-direction: column; }
  .panel { max-height: none; border: 0; }
  .workspace-wrap { order: -1; }
  .canvas-stage { min-height: auto; padding: 0; }
  #studioCanvas { max-height: none; border-left: 0; border-right: 0; }
  .parts-panel { display: grid; grid-template-columns: 1fr; }
  .animation-panel { display: block; }
  .piece-slots { grid-template-columns: 1fr 1fr; }
}
