:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1f2430;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --accent: #30d158;
  --accent-dark: #06210e;
  --danger: #ff453a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

/* ---------- Header and footer ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 0.2px;
}

.app-footer {
  padding: 12px 16px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin-top: auto;
}

.app-footer p { margin: 0; }

.app-version {
  margin-top: 4px;
  opacity: 0.7;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid #2c3446;
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: #262d3b; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-dark);
  border-color: var(--accent);
  font-weight: 700;
}

.btn.primary:hover { background: #3de466; }

.btn.ghost {
  background: transparent;
  border-color: #2c3446;
}

.btn.ghost:hover { background: var(--panel2); }

.btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

input[type="range"]:disabled { opacity: 0.5; }

.btn.big {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  font-size: 22px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Start screen ---------- */
.upload-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.drop-zone {
  width: 100%;
  max-width: 560px;
  border: 2px dashed #3a4356;
  border-radius: 20px;
  padding: 44px 24px;
  text-align: center;
  background: var(--panel);
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: #15241a;
}

.drop-zone-icon { font-size: 52px; line-height: 1; }

.drop-zone-title { font-size: 20px; font-weight: 600; margin: 14px 0 6px; }

.drop-zone-hint {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 22px;
  line-height: 1.6;
}

.upload-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.drop-zone-info {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #2c3446;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drop-zone-info p {
  margin: 0;
}

.drop-zone-info strong {
  color: var(--text);
}

/* ---------- Player layout ---------- */
.player-screen {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 4px 16px 24px;
}

.player-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

.player-main { min-width: 0; }

@media (max-width: 900px) {
  .player-grid { grid-template-columns: 1fr; }
}

/* ---------- Stage (video + canvas) ---------- */
.stage {
  position: relative;
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#video,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#overlay {
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: absolute;
  top: 8px;
  left: 8px;
  right: auto;
  width: fit-content;
  max-width: calc(100% - 16px);
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  background: rgba(10, 12, 16, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 10px;
  padding: 5px;
}

.tool-group {
  display: flex;
  gap: 3px;
  align-items: center;
}

.tool-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.22);
  flex: none;
}

.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.tool-btn:hover { background: rgba(255, 255, 255, 0.08); }

.tool-btn.active {
  background: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  padding: 0;
  flex: none;
}

.swatch.active {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.thickness-icon {
  font-size: 15px;
  color: var(--text);
  padding: 0 2px;
}

#thickness-slider {
  width: 64px;
}

#thickness-slider::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
}

#thickness-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
}

.thickness-value {
  font-size: 12px;
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.draw-hint {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 5;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(10, 12, 16, 0.55);
  border-radius: 8px;
  padding: 4px 10px;
  pointer-events: none;
}

@media (max-width: 600px) {
  .draw-hint { display: none; }
}

@media (max-width: 480px) {
  .toolbar { padding: 4px; gap: 3px; }
  .tool-btn { padding: 5px 6px; font-size: 14px; }
  .swatch { width: 20px; height: 20px; }
  .tool-divider { height: 18px; }
}

/* ---------- Transport ---------- */
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 12px;
}

.transport .tool-btn {
  width: 46px;
  height: 46px;
  font-size: 18px;
  padding: 0;
  justify-content: center;
}

.time-display {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 138px;
  text-align: center;
  font-size: 14px;
}

/* ---------- Speed ---------- */
.speed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 14px;
}

.speed-row input[type="range"] {
  flex: 1;
  min-width: 140px;
  max-width: 320px;
}

.speed-value {
  min-width: 56px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.speed-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  background: var(--panel2);
  border: 1px solid #2c3446;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.chip:hover { background: #262d3b; }

.chip.active {
  background: var(--accent);
  color: var(--accent-dark);
  border-color: var(--accent);
  font-weight: 700;
}

/* ---------- Slider (timeline) ---------- */
.scrubber-row {
  margin-top: 8px;
  padding: 0 2px;
}

/* ---------- Trim ---------- */
.trim-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(48, 209, 88, 0.12);
  border: 1px solid rgba(48, 209, 88, 0.35);
  border-radius: 10px;
  font-size: 13px;
}

.trim-banner span {
  flex: 1;
  min-width: 120px;
}

.trim-banner .btn {
  padding: 6px 10px;
  font-size: 12px;
}

.trim-panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
}

.trim-title {
  font-size: 15px;
  font-weight: 600;
}

.trim-hint {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
  margin-top: 2px;
  line-height: 1.5;
}

.trim-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.trim-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.trim-row input {
  width: 70px;
  background: var(--bg);
  border: 1px solid #2c3446;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
}

.trim-row input:focus { outline: 1px solid var(--accent); }

.trim-row .btn {
  padding: 8px 12px;
  font-size: 13px;
}

.trim-length {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.trim-status {
  font-size: 13px;
  color: var(--accent);
  margin: 10px 0 0;
  line-height: 1.5;
}

#scrubber { width: 100%; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: #2c3446;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--accent-dark);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--accent-dark);
  cursor: pointer;
}

/* ---------- Overlay list ---------- */
.overlay-panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
}

.overlay-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.overlay-header .overlay-toggle {
  flex: 1;
  padding: 4px 0;
}

.overlay-header .btn {
  padding: 8px 14px;
  font-size: 13px;
  flex: none;
  white-space: nowrap;
}

.glf-status {
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 6px;
  line-height: 1.5;
}

.overlay-toggle {
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  padding: 4px 0 8px;
  cursor: pointer;
}

.overlay-content.hidden { display: none; }

.overlay-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

#overlay-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
}

.overlay-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel2);
  border-radius: 8px;
  padding: 8px;
  flex-wrap: wrap;
}

.ov-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
}

.ov-name {
  font-size: 13px;
  font-weight: 600;
  flex: none;
  min-width: 44px;
}

.ov-time {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.ov-time input {
  width: 56px;
  background: var(--bg);
  border: 1px solid #2c3446;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}

.ov-time input:focus { outline: 1px solid var(--accent); }

.ov-width {
  font-size: 12px;
  min-width: 30px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.ov-vis,
.ov-del,
.ov-width-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 6px;
  color: var(--text);
}

.ov-vis:hover { background: rgba(255, 255, 255, 0.08); }
.ov-vis.off { opacity: 0.35; }
.ov-del:hover { background: rgba(255, 69, 58, 0.18); }

.overlay-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.overlay-actions .btn { padding: 8px 12px; font-size: 13px; }

/* ---------- Focus styles ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Drawing toolbar on phones (moved below the video) ---------- */
.toolbar.toolbar-flow {
  position: static;
  width: 100%;
  max-width: none;
  margin: 0 0 6px;
  justify-content: center;
  background: var(--panel);
}

.toolbar.toolbar-flow .tool-btn:hover { background: rgba(255, 255, 255, 0.08); }
