:root {
  --bg-canvas: #f6f5f1;
  --bg-surface: #ffffff;
  --bg-subtle: #efede6;
  --border: #e2e0d8;
  --border-strong: #cfccc2;
  --ink: #18181b;
  --ink-muted: #52525b;
  --ink-faint: #71717a;
  --accent: #1e40af;
  --accent-soft: #eff6ff;
  --accent-border: #bfdbfe;
  --danger: #dc2626;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font-family: inherit;
  font-size: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 52px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--ink);
  display: inline-block;
}

.brand-title {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.preset-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}

.preset-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--ink-muted);
  padding: 6px 11px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.preset-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: var(--bg-canvas);
}

.preset-btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn-ghost {
  background: var(--bg-surface);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--bg-canvas);
  border-color: var(--border-strong);
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.btn-primary:hover {
  background: #27272a;
}

.btn-full {
  width: 100%;
}

/* Workspace */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.viewport-pane {
  position: relative;
  flex: 1;
  min-width: 0;
  background: var(--bg-canvas);
  overflow: hidden;
}

.viewport-3d {
  width: 100%;
  height: 100%;
  display: block;
}

.viewport-3d canvas {
  display: block;
  outline: none;
}

.viewport-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--ink-muted);
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

/* Floating Live Viewfinder */
.viewfinder-wrap {
  position: absolute;
  top: 14px;
  left: 14px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(24, 24, 27, 0.08);
  overflow: hidden;
  z-index: 10;
  backdrop-filter: blur(6px);
  transition: width 180ms ease;
}

.viewfinder-wrap.aspect-9-16 {
  width: 214px;
}

.viewfinder-wrap.aspect-16-9 {
  width: 316px;
}

.vf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.vf-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.vf-rec-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

.vf-guide-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-canvas);
  color: var(--ink-muted);
  padding: 3px 7px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
}

.vf-guide-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.vf-stage {
  position: relative;
  width: 100%;
  background: #18181b;
  overflow: hidden;
}

.viewfinder-wrap.aspect-9-16 .vf-stage {
  aspect-ratio: 9 / 16;
}

.viewfinder-wrap.aspect-16-9 .vf-stage {
  aspect-ratio: 16 / 9;
}

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

.vf-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
}

.vf-overlay.is-visible {
  opacity: 1;
}

/* Rule of Thirds */
.vf-thirds {
  position: absolute;
  inset: 0;
}

.vf-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.42);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.45);
}

.vf-line-v1 {
  top: 0;
  bottom: 0;
  left: 33.333%;
  width: 1px;
}

.vf-line-v2 {
  top: 0;
  bottom: 0;
  left: 66.666%;
  width: 1px;
}

.vf-line-h1 {
  left: 0;
  right: 0;
  top: 33.333%;
  height: 1px;
}

.vf-line-h2 {
  left: 0;
  right: 0;
  top: 66.666%;
  height: 1px;
}

.vf-power-point {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  background: rgba(30, 64, 175, 0.55);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.65);
  transform: translate(-50%, -50%);
}

.vf-pp-tl {
  left: 33.333%;
  top: 33.333%;
}

.vf-pp-tr {
  left: 66.666%;
  top: 33.333%;
}

.vf-pp-bl {
  left: 33.333%;
  top: 66.666%;
}

.vf-pp-br {
  left: 66.666%;
  top: 66.666%;
}

/* Reels UI Safe Zone (visible only in 9:16) */
.vf-reels-safe {
  position: absolute;
  inset: 0;
  display: none;
}

.viewfinder-wrap.aspect-9-16 .vf-reels-safe {
  display: block;
}

.vf-safe-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 11%;
  border-bottom: 1px dashed rgba(251, 191, 36, 0.65);
  background: rgba(251, 191, 36, 0.08);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 3px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.vf-safe-right {
  position: absolute;
  right: 7px;
  bottom: 24%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 6px 4px;
  border: 1px dashed rgba(251, 191, 36, 0.65);
  border-radius: 4px;
  background: rgba(24, 24, 27, 0.28);
}

.vf-ui-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
}

.vf-ui-disc {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.2);
}

.vf-safe-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22%;
  border-top: 1px dashed rgba(251, 191, 36, 0.65);
  background: rgba(251, 191, 36, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 5px;
  padding: 10px 44px 10px 10px;
}

.vf-ui-bar {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.55);
}

.vf-ui-bar-short {
  width: 48%;
}

.vf-ui-bar-long {
  width: 85%;
}

.vf-readout {
  padding: 7px 9px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--ink-muted);
}

/* Right Control Sidebar */
.sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

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

.panel-title {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.control-group {
  margin-bottom: 14px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label,
.control-label-row label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
}

.control-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.mono-val {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}

/* Range Inputs */
input[type='range'] {
  width: 100%;
  margin: 2px 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.range-scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
}

/* Segmented Controls */
.segmented {
  display: grid;
  gap: 4px;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px;
}

.segmented-2 {
  grid-template-columns: repeat(2, 1fr);
}

.segmented-4 {
  grid-template-columns: repeat(4, 1fr);
}

.seg-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
  padding: 6px 6px;
  border-radius: 3px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.is-active {
  background: var(--bg-surface);
  color: var(--ink);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.06);
}

/* Beat Buttons */
.beat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.btn-beat {
  background: var(--bg-canvas);
  color: var(--ink);
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
}

.btn-beat:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-beat.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* Sticker Form */
.sticker-input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#input-sticker-text {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--ink);
  font-size: 12.5px;
  outline: none;
}

#input-sticker-text:focus {
  border-color: var(--ink);
}

@media (max-width: 980px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .workspace {
    flex-direction: column;
  }

  .viewport-pane {
    height: 62vh;
    min-height: 420px;
  }

  .sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
