﻿:root {
  color-scheme: light;
  --bg: #eeeeec;
  --panel: #f8f8f6;
  --panel-2: #ffffff;
  --ink: #252a25;
  --muted: #667067;
  --line: #d9d4c8;
  --accent: #c6a13a;
  --accent-2: #4e8c7c;
  --accent-3: #c95e55;
  --canvas: #f6f6f3;
  --canvas-line: rgba(45, 49, 43, 0.1);
  --shadow: 0 18px 54px rgba(67, 59, 40, 0.14);
  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;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-width: 320px;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 432px;
  gap: 14px;
  height: 100vh;
  padding: 14px;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(45, 49, 43, 0.14);
  border-radius: 8px;
  background: var(--canvas);
  box-shadow: var(--shadow);
}

.stage-header {
  position: absolute;
  z-index: 4;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
  font-size: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--canvas) 0 34%, transparent 35%),
    conic-gradient(from 20deg, var(--accent), var(--accent-2), var(--accent));
  border: 2px solid rgba(29, 33, 30, 0.16);
  box-shadow: 0 6px 18px rgba(29, 33, 30, 0.16);
  flex: 0 0 auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(29, 33, 30, 0.12);
  border-radius: 8px;
  background: rgba(243, 240, 232, 0.72);
  backdrop-filter: blur(16px);
  pointer-events: auto;
  box-shadow: 0 10px 34px rgba(29, 33, 30, 0.12);
}

.tool-btn,
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(29, 33, 30, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.tool-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  background: #fffaf0;
  border-color: rgba(29, 33, 30, 0.28);
}

.tool-btn[aria-pressed="true"] {
  background: var(--ink);
  color: #fffdf7;
  border-color: var(--ink);
}

.tool-btn svg,
.icon-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stage-footer {
  position: absolute;
  z-index: 4;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.status-pill {
  max-width: 62ch;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.82);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: auto;
  box-shadow: 0 12px 38px rgba(29, 33, 30, 0.2);
}

.mini-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.mini-controls .icon-btn {
  background: rgba(255, 253, 247, 0.84);
  color: var(--ink);
  border-color: rgba(45, 49, 43, 0.16);
}

#growthCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.side {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid rgba(45, 49, 43, 0.12);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 12px;
  overflow: hidden;
}

.counter {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.preview-panel,
.timeline-panel,
.control-panel,
.stack-panel {
  border: 1px solid rgba(45, 49, 43, 0.12);
  border-radius: 8px;
  background: var(--panel-2);
  min-width: 0;
  flex: 0 0 auto;
  overflow: hidden;
}

.side-scroll {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 2px;
  order: 2;
}

.preview-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 320px;
  flex-basis: 320px;
  flex-shrink: 0;
  order: 1;
}

.panel-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 10px 11px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid rgba(45, 49, 43, 0.1);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-icon-btn {
  width: 32px;
  height: 32px;
}

#stackViewport {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-height: 280px;
  overflow: hidden;
  background: #f4f4f1;
  cursor: grab;
}

#stackViewport:active {
  cursor: grabbing;
}

#stackViewport canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.stack-fallback {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  color: rgba(37, 42, 37, 0.58);
  font-size: 12px;
  text-align: center;
}

.control-panel,
.stack-panel {
  padding: 10px;
}

.control-panel {
  order: 5;
  overflow: visible;
}

.stack-panel {
  order: 4;
  overflow: visible;
}

.control-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
}

.control-row + .control-row {
  margin-top: 5px;
}

.value {
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

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

.scale-mapper {
  margin-top: 8px;
  border: 1px solid rgba(45, 49, 43, 0.12);
  border-radius: 8px;
  background: #fbfbf8;
  overflow: hidden;
}

.mapper-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(45, 49, 43, 0.1);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#scaleMapperCanvas {
  display: block;
  width: 100%;
  height: 108px;
  cursor: crosshair;
  touch-action: none;
}

.circle-toggle {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(45, 49, 43, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
}

.circle-toggle[aria-pressed="true"] {
  background: var(--ink);
  color: #fffdf7;
  border-color: var(--ink);
}

.circle-toggle svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.timeline-panel {
  position: relative;
  min-height: 0;
  padding: 10px;
  display: grid;
  grid-template-rows: auto minmax(52px, 84px) auto;
  gap: 8px;
  order: 3;
}

.preview-panel.is-focus {
  position: fixed;
  inset: 14px;
  z-index: 40;
  min-height: calc(100vh - 28px);
  box-shadow: 0 22px 58px rgba(29, 33, 30, 0.22);
}

body.stack-focus {
  overflow: hidden;
}

.preview-panel.is-focus #stackViewport {
  min-height: 0;
}

.transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.transport .icon-btn {
  width: 34px;
  height: 34px;
  color: var(--ink);
  border-color: rgba(45, 49, 43, 0.12);
  background: rgba(255, 255, 255, 0.76);
}

.transport-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timeline-wrap {
  position: relative;
  border: 1px solid rgba(45, 49, 43, 0.12);
  border-radius: 8px;
  overflow: hidden;
  min-height: 52px;
  background: #f4f4f1;
  touch-action: none;
}

#timelineCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.trim-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  background: rgba(217, 182, 80, 0.18);
  pointer-events: none;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-1px);
  background: var(--accent-3);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.trim-handle {
  position: absolute;
  top: 5px;
  bottom: 5px;
  width: 22px;
  margin-left: -11px;
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 8px;
  background: var(--accent);
  cursor: ew-resize;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  touch-action: none;
}

.trim-handle::before,
.trim-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 2px;
  height: 24px;
  border-radius: 999px;
  background: rgba(29, 33, 30, 0.48);
  transform: translateY(-50%);
}

.trim-handle::before {
  left: 7px;
}

.trim-handle::after {
  right: 7px;
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.empty-note {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(37, 42, 37, 0.48);
  font-size: 12px;
  pointer-events: none;
}

.kbd {
  min-width: 28px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(45, 49, 43, 0.12);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(520px, 68vh) minmax(560px, auto);
  }

  .side {
    display: flex;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 8px;
    gap: 8px;
    grid-template-rows: minmax(470px, 64vh) minmax(540px, auto);
  }

  .stage-header {
    align-items: flex-start;
  }

  .brand {
    width: 34px;
    overflow: hidden;
  }

  .toolbar {
    gap: 5px;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100% - 52px);
    padding: 5px;
  }

  .tool-btn,
  .icon-btn {
    width: 34px;
    height: 34px;
  }

  .tool-btn svg,
  .icon-btn svg {
    width: 18px;
    height: 18px;
  }

  .status-pill {
    max-width: 100%;
  }

  .control-row {
    grid-template-columns: 64px minmax(0, 1fr) 34px;
  }
}
