:root {
  --app-bg: #1f232b;
  --panel: #343941;
  --panel-soft: #2a2f37;
  --panel-deep: #252a32;
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-border-strong: rgba(245, 161, 40, 0.72);
  --panel-border-soft: rgba(245, 161, 40, 0.22);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.7);
  --muted-soft: rgba(255, 255, 255, 0.48);
  --accent: #f5a128;
  --accent-soft: rgba(245, 161, 40, 0.16);
  --blue: #4b80ff;
  --blue-strong: #6794ff;
  --danger: #f06262;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--app-bg);
  color: var(--text);
  font-family: "Segoe UI", "Aptos", "Helvetica Neue", sans-serif;
}

body {
  overflow-x: hidden;
  overflow-y: auto;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

#app {
  min-height: 100vh;
}

.shell {
  min-height: 100vh;
  padding: 14px;
  box-sizing: border-box;
}

.workspace {
  min-height: calc(100vh - 28px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
  gap: 16px;
}

.hero-panel,
.board-panel,
.panel,
.timeline-rail-card,
.timeline-preview-card,
.waveform-card {
  background: linear-gradient(180deg, rgba(53, 58, 68, 0.98), rgba(42, 47, 56, 0.98));
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.hero-panel {
  border-radius: 30px;
  padding: 22px 24px 18px;
  display: grid;
  gap: 16px;
}

.hero-title-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
}

.hero-copy {
  display: grid;
  gap: 10px;
}

.hero-title {
  margin: 0;
  font-size: clamp(2.1rem, 3.2vw, 3rem);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.hero-subtitle {
  margin: 0;
  max-width: 700px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.45;
}

.auto-save-badge {
  align-self: flex-start;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(37, 42, 50, 0.88);
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
}

.hero-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.control-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.control-label {
  color: var(--muted);
  font-size: 0.95rem;
}

.segmented-group,
.utility-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toolbar-button,
.ghost-button,
.danger-button,
.media-button,
.timeline-button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.toolbar-button:hover,
.ghost-button:hover,
.danger-button:hover,
.media-button:hover,
.timeline-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.toolbar-button.is-active,
.timeline-button.is-active {
  background: rgba(255, 255, 255, 0.92);
  color: #22262d;
  border-color: rgba(255, 255, 255, 0.96);
}

.compact-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.primary-button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--blue-strong), var(--blue));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(75, 128, 255, 0.22);
}

.primary-add-button {
  min-width: 118px;
}

.ghost-button.export-button {
  background: rgba(255, 255, 255, 0.96);
  color: #22262d;
  font-weight: 700;
}

.danger-button {
  background: rgba(240, 98, 98, 0.12);
  color: #ffd6d6;
  border-color: rgba(240, 98, 98, 0.22);
}

.hero-status,
.utility-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.hero-status {
  margin-left: auto;
  max-width: 260px;
  text-align: right;
}

.utility-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.utility-note {
  color: var(--muted-soft);
}

.content-grid {
  min-height: 0;
  display: grid;
  gap: 14px;
}

.content-grid.board {
  grid-template-columns: 1fr;
  align-content: start;
}

.content-grid.timeline {
  grid-template-columns: minmax(0, 1fr) minmax(236px, 272px);
  align-content: start;
  overflow: auto;
  padding-right: 4px;
}

.board-panel,
.panel {
  border-radius: 24px;
  min-height: 0;
}

.board-panel {
  border-color: var(--panel-border-strong);
  box-shadow: 0 0 0 1px var(--panel-border-soft), var(--shadow);
}

.board-panel-body,
.panel-body {
  height: auto;
  min-height: 0;
  padding: 10px 14px 14px;
}

.scene-grid {
  min-height: 0;
  display: grid;
  gap: 14px;
  padding-right: 4px;
}

.scene-grid.vertical {
  grid-template-columns: 1fr;
  align-content: start;
  overflow: visible;
}

.scene-grid.horizontal {
  grid-auto-flow: column;
  grid-auto-columns: minmax(520px, 680px);
  overflow-x: auto;
  overflow-y: hidden;
}

.scene-card {
  border-radius: 18px;
  padding: 12px;
  display: grid;
  gap: 12px;
  background: linear-gradient(180deg, rgba(40, 45, 53, 0.94), rgba(36, 40, 48, 0.96));
  border: 1px solid rgba(245, 161, 40, 0.38);
}

.scene-card.is-selected {
  box-shadow: 0 0 0 1px rgba(245, 161, 40, 0.34), 0 12px 34px rgba(0, 0, 0, 0.2);
}

.scene-card.is-drop-target {
  border-color: rgba(103, 148, 255, 0.92);
  box-shadow: 0 0 0 1px rgba(103, 148, 255, 0.32), 0 12px 34px rgba(0, 0, 0, 0.2);
}

.scene-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.scene-head-main,
.scene-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.scene-index {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f8b34d, var(--accent));
  color: #15110b;
  font-weight: 800;
  flex: 0 0 auto;
}

.scene-title-input {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  font-size: 1.08rem;
  font-weight: 700;
  outline: none;
}

.scene-title-input::placeholder {
  color: rgba(255, 255, 255, 0.56);
}

.scene-media {
  position: relative;
  min-height: clamp(260px, 38vh, 360px);
  border-radius: 14px;
  overflow: hidden;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  background: rgba(31, 35, 43, 0.88);
}

.scene-media.is-editable {
  cursor: zoom-in;
}

.scene-media.is-empty {
  border-color: rgba(255, 255, 255, 0.12);
}

.scene-media.has-media {
  border-style: solid;
}

.media-stage {
  position: absolute;
  inset: 0;
}

.media-stage.is-grok-draggable {
  cursor: grab;
}

.media-stage.is-grok-draggable:active {
  cursor: grabbing;
}

.media-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.media-source {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: rgba(15, 17, 22, 0.6);
  opacity: 0;
  pointer-events: none;
}

.scene-media-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.panel-copy,
.timeline-subtitle,
.muted-note,
.scene-simple-note,
.field-label {
  color: var(--muted);
}

.panel-copy,
.timeline-subtitle,
.scene-simple-note {
  margin: 0;
  line-height: 1.45;
}

.scene-surface-chip {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.8rem;
  font-weight: 600;
}

.motion-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(20, 23, 29, 0.48);
}

.motion-card-head {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.motion-card-title {
  margin: 0;
  font-size: 1rem;
}

.motion-card-body,
.motion-button-row,
.scene-simple-meta {
  display: grid;
  gap: 10px;
}

.motion-select-field {
  max-width: 220px;
}

.field-select {
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(20, 23, 29, 0.82);
  color: var(--text);
}

.motion-button-row {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.motion-button-row > button[disabled] {
  opacity: 0.48;
  transform: none;
}

.motion-badge {
  align-self: flex-start;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.audio-pill {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.58);
  color: var(--text);
}

.audio-pill.is-live {
  background: rgba(245, 161, 40, 0.96);
  color: #20170c;
  border-color: rgba(248, 179, 77, 0.98);
}

.scene-simple-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.scene-actions,
.field-grid,
.timeline-toolbar,
.timeline-secondary-toolbar,
.timeline-rail-actions,
.timeline-preview-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.media-button,
.timeline-button {
  background: rgba(255, 255, 255, 0.04);
}

.timeline-rail-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.timeline-rail-button {
  min-height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.timeline-rail-button:hover,
.timeline-rail-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
}

.timeline-rail-button.is-active {
  background: rgba(255, 255, 255, 0.92);
  color: #22262d;
  border-color: rgba(255, 255, 255, 0.96);
}

.timeline-rail-button.is-accent {
  border-color: rgba(245, 161, 40, 0.18);
  background: rgba(245, 161, 40, 0.08);
  color: #ffd8a1;
}

.timeline-rail-button.is-danger {
  border-color: rgba(240, 98, 98, 0.18);
  background: rgba(240, 98, 98, 0.1);
  color: #ffd7d7;
}

.timeline-rail-button[disabled] {
  opacity: 0.45;
  transform: none;
}

.field-stack {
  display: grid;
  gap: 10px;
}

.field-label {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
}

.field-textarea {
  width: 100%;
  min-height: 90px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(20, 23, 29, 0.82);
  color: var(--text);
  resize: vertical;
}

.timeline-layout {
  height: auto;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 12px;
}

.timeline-controls-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(20, 23, 29, 0.48);
}

.timeline-preview-card,
.timeline-rail-card {
  border-radius: 22px;
  padding: 12px;
  display: grid;
  gap: 10px;
  min-height: 0;
}

.timeline-rail-card {
  grid-template-rows: auto 1fr;
  background:
    linear-gradient(180deg, rgba(49, 54, 64, 0.98), rgba(37, 41, 49, 0.98)),
    linear-gradient(160deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0));
}

.timeline-title,
.timeline-preview-title {
  margin: 0;
  font-size: 1.14rem;
}

.timeline-rail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.timeline-rail-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #ffcf7f;
  font-size: 0.88rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timeline-preview-media {
  position: relative;
  height: clamp(176px, 24vh, 220px);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 17, 22, 0.54);
}

.crop-editor-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 26px;
  background: rgba(6, 8, 12, 0.8);
  backdrop-filter: blur(10px);
}

.crop-editor-modal {
  width: min(1220px, calc(100vw - 40px));
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  padding: 22px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(31, 35, 43, 0.98), rgba(22, 25, 31, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.4);
}

.crop-editor-header,
.crop-editor-actions {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.crop-editor-title {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

.crop-editor-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}

.crop-editor-stage-shell,
.crop-editor-sidebar {
  min-height: 0;
}

.crop-editor-sidebar {
  display: grid;
  gap: 14px;
  align-content: start;
}

.crop-editor-stage {
  position: relative;
  min-height: 0;
  height: 100%;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #080a0d;
  touch-action: none;
  user-select: none;
}

.crop-editor-source {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: rgba(0, 0, 0, 0.34);
}

.crop-editor-preview {
  position: relative;
  min-height: 248px;
  height: 248px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 17, 22, 0.8);
}

.crop-editor-preview .media-stage {
  position: absolute;
}

.crop-editor-viewport {
  position: absolute;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.24);
  touch-action: none;
  pointer-events: auto;
  cursor: move;
  z-index: 2;
}

.crop-editor-viewport[data-pan-viewport="crop"] {
  border-color: rgba(245, 161, 40, 0.98);
  background: rgba(245, 161, 40, 0.08);
  box-shadow:
    0 0 0 999px rgba(0, 0, 0, 0.52),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16),
    0 0 0 1px rgba(245, 161, 40, 0.18);
}

.crop-editor-viewport[data-pan-viewport="start"] {
  border-color: rgba(245, 161, 40, 0.98);
  background: rgba(245, 161, 40, 0.12);
}

.crop-editor-viewport[data-pan-viewport="end"] {
  border-color: rgba(94, 170, 255, 0.98);
  background: rgba(94, 170, 255, 0.1);
}

.crop-editor-viewport.is-active {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.crop-editor-viewport[data-pan-viewport="crop"].is-active {
  box-shadow:
    0 0 0 999px rgba(0, 0, 0, 0.58),
    inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    0 0 0 2px rgba(245, 161, 40, 0.22),
    0 18px 42px rgba(0, 0, 0, 0.34);
}

.crop-editor-viewport-label {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(8, 10, 13, 0.8);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.crop-editor-viewport[data-pan-viewport="crop"] .crop-editor-viewport-label {
  background: rgba(245, 161, 40, 0.9);
  color: #181109;
}

.crop-editor-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid rgba(8, 10, 13, 0.9);
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.24);
  z-index: 3;
}

.crop-editor-handle[data-pan-handle="topLeft"] {
  left: -11px;
  top: -11px;
  cursor: nwse-resize;
}

.crop-editor-handle[data-pan-handle="topRight"] {
  right: -11px;
  top: -11px;
  cursor: nesw-resize;
}

.crop-editor-handle[data-pan-handle="bottomLeft"] {
  left: -11px;
  bottom: -11px;
  cursor: nesw-resize;
}

.crop-editor-handle[data-pan-handle="bottomRight"] {
  right: -11px;
  bottom: -11px;
  cursor: nwse-resize;
}

.waveform-card {
  border-radius: 24px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  overflow: hidden;
}

.waveform-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.waveform-shell {
  position: relative;
  min-height: clamp(220px, 30vh, 290px);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.24);
  overflow: hidden;
}

#waveformCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.placeholder-overlay {
  position: absolute;
  inset: auto 24px 24px 24px;
  padding: 16px 18px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.56);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.timeline-rail-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.timeline-rail-item {
  position: relative;
  border-radius: 14px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.025);
  display: grid;
  gap: 8px;
}

.timeline-rail-item.is-selected {
  border-color: rgba(245, 161, 40, 0.72);
  background:
    linear-gradient(180deg, rgba(245, 161, 40, 0.1), rgba(245, 161, 40, 0.04)),
    rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 0 0 1px rgba(245, 161, 40, 0.08);
}

.timeline-rail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.timeline-rail-scene {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.timeline-rail-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(245, 161, 40, 0.14);
  color: #ffd28e;
  font-size: 0.78rem;
  font-weight: 800;
  flex: 0 0 auto;
}

.timeline-rail-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

.timeline-rail-summary {
  min-width: 0;
  color: rgba(214, 219, 227, 0.68);
  font-size: 0.79rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.timeline-time {
  color: #ffcf7f;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
}

.start-shell,
.start-panel,
.start-card,
.statusbar,
.brand-stack,
.project-title-input {
  display: none;
}

@media (max-width: 1320px) {
  .content-grid.timeline {
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
  }

  .hero-title-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-status {
    margin-left: 0;
  }

  .timeline-rail-card {
    max-height: none;
  }

  .crop-editor-layout {
    grid-template-columns: 1fr;
  }

  .crop-editor-sidebar {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 900px) {
  .shell {
    padding: 10px;
  }

  .hero-panel {
    padding: 18px;
  }

  .hero-controls,
  .utility-row {
    align-items: flex-start;
  }

  .scene-grid.horizontal {
    grid-auto-columns: minmax(320px, 86vw);
  }

  .scene-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .crop-editor-backdrop {
    padding: 12px;
  }

  .crop-editor-modal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 16px;
  }
}
