:root {
  color-scheme: dark;
  --app-height: 100dvh;
  --shell-bottom-space: max(8px, env(safe-area-inset-bottom));
  --bg: #050607;
  --ink: #f3f1e8;
  --muted: #8b918f;
  --rail: #0d0f10;
  --rail-2: #15191b;
  --line: #2a3032;
  --line-hot: #e7ff4f;
  --cyan: #20d6d2;
  --coral: #ff5f6d;
  --steel: #7d8b96;
  --radius: 8px;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: var(--bg);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  touch-action: pan-x pan-y;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, #080a0b 0, #050607 42%, #070707 100%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.04) 0 1px,
      transparent 1px 12px
    );
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

svg.filled-icon {
  fill: currentColor;
  stroke: none;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) 178px auto;
  min-height: var(--app-height);
  height: var(--app-height);
  padding: max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right)) var(--shell-bottom-space)
    max(8px, env(safe-area-inset-left));
  gap: 8px;
}

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

.brand-block {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: var(--radius);
}

.brand-block h1,
.brand-block p {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-block h1 {
  font-size: 14px;
  line-height: 1.15;
}

.brand-block p {
  max-width: 58vw;
  color: var(--muted);
  font-size: 11px;
}

.top-actions,
.transport-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.viewer-section {
  min-width: 0;
  min-height: 0;
}

.viewer-panel {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #15191a;
  border-radius: var(--radius);
  background: #020303;
}

.video-stage {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0, rgba(231, 255, 79, 0.08), transparent 38%),
    #020303;
}

.video-fit {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.media-engine {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain !important;
  object-position: center center;
  background: #020303;
}

.chrono-overlay {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  min-width: 196px;
  height: 48px;
  border: 1px solid rgba(231, 255, 79, 0.34);
  border-radius: var(--radius);
  background: rgba(3, 4, 4, 0.72);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.6),
    0 12px 32px rgba(0, 0, 0, 0.44);
  backdrop-filter: blur(10px);
  color: var(--line-hot);
  pointer-events: none;
}

.chrono-overlay span {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(28px, 8vw, 44px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.chrono-overlay.muted {
  border-color: rgba(125, 139, 150, 0.28);
  color: #687173;
}

.empty-video {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid #3f4545;
  border-radius: var(--radius);
  background: #161a1c;
  color: var(--ink);
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.empty-video[hidden] {
  display: none;
}

.timeline-section {
  position: relative;
  min-height: 0;
  border: 1px solid #171c1e;
  border-radius: var(--radius);
  background: var(--rail);
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.timeline-section * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-bottom: 1px solid #1e2426;
  gap: 10px;
}

.track-title {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 8px;
}

.track-title span {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.track-title strong,
.timeline-status,
.start-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.timeline-status {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  white-space: nowrap;
}

.timeline-body {
  position: relative;
  height: 140px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #101314 0 24px, #080909 24px 100%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.06) 0 1px,
      transparent 1px 18px
    );
}

.timeline-viewport {
  position: absolute;
  inset: 0;
  z-index: 2;
  height: 140px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  touch-action: pan-x;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: grab;
}

.timeline-viewport:active {
  cursor: grabbing;
}

.timeline-viewport::-webkit-scrollbar {
  display: none;
}

.timeline-scroll-space {
  height: 100%;
  min-height: 1px;
}

.timeline-strip {
  position: absolute;
  inset: 0;
  z-index: 1;
  height: 140px;
  overflow: visible;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.timeline-content {
  position: absolute;
  top: 0;
  left: 0;
  height: 140px;
  will-change: transform;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.ruler-canvas,
.video-track-canvas,
.waveform-canvas,
.marker-canvas {
  position: absolute;
  left: 0;
  width: 100%;
  -webkit-user-select: none;
  user-select: none;
}

.ruler-canvas {
  top: 0;
  height: 24px;
}

.video-track-canvas {
  top: 28px;
  height: 48px;
}

.waveform-canvas {
  top: 82px;
  height: 50px;
}

.marker-canvas {
  top: 0;
  height: 140px;
  pointer-events: none;
}

.playhead-fixed {
  position: absolute;
  top: 38px;
  bottom: 0;
  left: 50%;
  z-index: 3;
  width: 0;
  pointer-events: none;
}

.playhead-fixed::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-1px);
  background: var(--line-hot);
  box-shadow: 0 0 18px rgba(231, 255, 79, 0.56);
}

.playhead-fixed span {
  position: absolute;
  top: 0;
  left: -8px;
  width: 16px;
  height: 16px;
  border-radius: 0 0 8px 8px;
  background: var(--line-hot);
}

.tool-dock {
  display: grid;
  grid-template-rows: auto auto;
  min-height: 0;
  padding: 8px 0 0;
  border-top: 1px solid #1c2224;
  gap: 7px;
}

.transport-row {
  display: grid;
  grid-template-columns: 40px 52px 40px minmax(72px, 1fr) minmax(72px, 1fr);
  gap: 7px;
}

.icon-button,
.play-button,
.start-button,
.mark-button,
.tool-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--rail-2);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover,
.play-button:hover,
.start-button:hover,
.mark-button:hover,
.tool-button:hover {
  border-color: #465052;
  background: #1c2224;
}

.icon-button:disabled,
.play-button:disabled,
.start-button:disabled,
.mark-button:disabled,
.tool-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.icon-button,
.play-button {
  display: grid;
  place-items: center;
  height: 42px;
  padding: 0;
}

.icon-button.ghost {
  width: 36px;
  height: 34px;
  border-color: #202627;
  background: #0b0d0e;
  color: var(--steel);
}

.icon-button.ghost.update-ready {
  border-color: #4f5c31;
  background: #111509;
  color: var(--line-hot);
}

.icon-button.ghost.update-ready:hover {
  border-color: #697a41;
  background: #181e0e;
}

.play-button {
  color: var(--cyan);
}

.start-button,
.mark-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 12px;
  background: #20220b;
  color: var(--line-hot);
  gap: 8px;
  font-size: 13px;
  font-weight: 900;
}

.mark-button {
  border-color: #3c2a30;
  background: #1a1114;
  color: #ffd8dc;
}

.start-meta {
  min-height: 14px;
  padding: 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.marks-panel {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.marks-list {
  display: flex;
  min-width: 0;
  margin: 0;
  padding: 0 2px;
  overflow-x: auto;
  list-style: none;
  gap: 6px;
  scrollbar-width: none;
}

.marks-list::-webkit-scrollbar {
  display: none;
}

.mark-chip {
  display: inline-grid;
  grid-template-columns: auto 28px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid #2e3436;
  border-radius: var(--radius);
  background: #0f1314;
}

.start-chip {
  grid-template-columns: auto;
  border-color: #4b4425;
  background: #18170c;
}

.mark-jump,
.mark-delete {
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.mark-jump {
  min-width: 74px;
  height: 28px;
  padding: 0 8px;
  color: #ffd8dc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.start-jump {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  color: #f9d65c;
  gap: 6px;
}

.mark-label {
  color: #fff3ba;
  font-family: system-ui, sans-serif;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.mark-delete {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-left: 1px solid #2e3436;
  color: var(--steel);
}

.mark-delete svg {
  width: 14px;
  height: 14px;
}

.mark-jump:hover,
.mark-delete:hover {
  background: #171d1f;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 10px;
  gap: 7px;
  font-size: 12px;
  font-weight: 800;
}

.tool-button.install {
  border-color: #3f4646;
  color: var(--cyan);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 860px) {
  .app-shell {
    width: min(100vw, 1180px);
    margin: 0 auto;
    grid-template-rows: auto minmax(360px, 1fr) 198px auto;
    padding-top: 14px;
    padding-bottom: max(14px, var(--shell-bottom-space));
    gap: 10px;
  }

  .brand-block h1 {
    font-size: 16px;
  }

  .viewer-panel {
    border-radius: var(--radius);
  }

  .chrono-overlay {
    bottom: 18px;
    min-width: 250px;
    height: 60px;
  }

  .timeline-section {
    min-height: 198px;
  }

  .timeline-viewport,
  .timeline-body,
  .timeline-strip,
  .timeline-content {
    height: 158px;
  }

  .video-track-canvas {
    height: 58px;
  }

  .waveform-canvas {
    top: 94px;
    height: 56px;
  }

  .marker-canvas {
    height: 158px;
  }

  .tool-dock {
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 16px;
  }

  .transport-row {
    grid-row: 1 / 3;
  }

  .start-meta {
    text-align: left;
  }

  .marks-panel {
    align-self: stretch;
    align-content: center;
  }
}

@media (max-height: 690px) {
  .app-shell {
    grid-template-rows: auto minmax(190px, 1fr) 154px auto;
    gap: 6px;
  }

  .timeline-header {
    height: 32px;
  }

  .playhead-fixed {
    top: 32px;
  }

  .timeline-viewport,
  .timeline-body,
  .timeline-strip,
  .timeline-content {
    height: 122px;
  }

  .video-track-canvas {
    height: 42px;
  }

  .waveform-canvas {
    top: 76px;
    height: 40px;
  }

  .marker-canvas {
    height: 122px;
  }

  .tool-dock {
    gap: 5px;
  }
}
