@import url('https://fonts.googleapis.com/css2?family=Archivo+Narrow:ital,wght@0,400;0,600;0,700&display=swap');

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ----- Start screen ----- */

#start-screen {
  align-items: center;
  justify-content: center;
  background: #110F10;
}

#start-btn {
  appearance: none;
  -webkit-appearance: none;

  /* Size — large CTA, как активный ROUND в селекторе, только крупнее */
  width: calc(100% - 40px);
  max-width: 350px;
  height: 96px;

  /* Fill & border — активный ROUND-стиль */
  background: rgba(216, 189, 113, 0.12);
  border: 1px solid #D8BD71;
  border-radius: 8px;

  /* Typography — Archivo Narrow italic caps */
  font-family: 'Archivo Narrow', 'Arial Narrow', sans-serif;
  font-weight: 700;
  font-style: italic;
  font-size: 40px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #D8BD71;

  /* Layout */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;

  cursor: pointer;
  transition: transform 80ms ease-out, background 150ms ease-out;
}

#start-btn:hover {
  background: rgba(216, 189, 113, 0.18);
}

#start-btn:active {
  transform: scale(0.98);
  background: rgba(216, 189, 113, 0.22);
}

/* ----- Player screen ----- */

#player-screen {
  background: #000;
  display: block; /* override .screen flex; controls float as overlay */
}

#video-wrap {
  position: absolute;
  inset: 0;
  background: #000;
}

.player-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
  display: block;
}

#video-b {
  opacity: 0;
  pointer-events: none;
}

#tap-layer {
  position: absolute;
  inset: 0;
  display: flex;
  /* pointer-events passthrough to video for system gestures is not needed;
     we handle taps ourselves. */
}


#moment-label {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 12px));
  left: 50%;
  transform: translateX(-50%);
  color: #22ff66;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  z-index: 4;
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 6px rgba(0, 0, 0, 0.55);
  transition: opacity 200ms ease;
}

#moment-label.hidden {
  opacity: 0;
}

.tap-half {
  flex: 1 1 0;
  height: 100%;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

#loading-overlay {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: #2da04a;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#debug-overlay {
  position: absolute;
  left: 8px;
  top: 8px;
  right: 8px;
  max-height: 60%;
  overflow: auto;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.75);
  color: #ffcc66;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.35;
  border-radius: 6px;
  z-index: 10;
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
}

#debug-overlay .err { color: #ff6b6b; }

/* ----- Controls ----- */

#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(0.3rem, env(safe-area-inset-bottom, 0.3rem));
  padding:
    0.4rem
    max(0.8rem, env(safe-area-inset-right, 0.8rem))
    0.4rem
    max(0.8rem, env(safe-area-inset-left, 0.8rem));
  display: flex;
  align-items: center;
  gap: 0.6rem;
  z-index: 6;
  transition: opacity 200ms ease;
  /* Container itself doesn't block taps — only its visible children do.
     This lets single-taps on empty areas between capsules pass through to
     the tap-layer beneath so controls can be toggled. */
  pointer-events: none;
}

#controls > * {
  pointer-events: auto;
}

#controls.hidden {
  opacity: 0;
  pointer-events: none;
}

#controls.hidden > * {
  pointer-events: none;
}

#play-btn {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  line-height: 1;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#play-btn:active { background: rgba(0, 0, 0, 0.75); }

.slider-group {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 14px 8px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#global-group { flex: 2 1 0; }
#local-group  { flex: 1 1 0; }

/* Heatmap wave (shown only on /heatmap variant via body.heatmap). */
#slider-stack {
  position: relative;
  width: 100%;
}

#heatmap-svg {
  display: none;
}

body.heatmap #heatmap-svg {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 13px; /* sits behind the range thumb's center */
  width: 100%;
  height: 18px;
  pointer-events: none; /* clicks pass through to the slider */
  overflow: visible;
  transition: height 140ms ease;
}

/* While the user is dragging the Entire Video slider, grow the heatmap
   vertically so peaks are easier to target. */
body.heatmap.scrubbing #heatmap-svg {
  height: 48px;
}

#heatmap-svg path {
  stroke-width: 0.4;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

#heatmap-best  { fill: url(#grad-best);  stroke: rgba(34, 255, 102, 0.9); }
#heatmap-learn { fill: url(#grad-learn); stroke: rgba(255, 90, 90, 0.9); }

body.filter-best  #heatmap-learn { display: none; }
body.filter-learn #heatmap-best  { display: none; }

/* Category-colored moment label */
#moment-label.moment-best  { color: #22ff66; }
#moment-label.moment-learn { color: #ff5a5a; }

/* Filter buttons overlay */
#filter-buttons {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 12px));
  right: max(12px, env(safe-area-inset-right, 12px));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  z-index: 7;
  transition: opacity 200ms ease;
}

/* In portrait the screen is too narrow for the top-centered label and the
   top-right buttons to coexist on the same row — push the buttons below
   the label height. */
@media (orientation: portrait) {
  #filter-buttons {
    top: calc(max(12px, env(safe-area-inset-top, 12px)) + 36px);
  }
}

#filter-buttons.hidden {
  opacity: 0;
  pointer-events: none;
}

.filter-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 150ms ease, box-shadow 150ms ease;
}

.filter-best-btn {
  background: rgba(34, 255, 102, 0.22);
  border-color: rgba(34, 255, 102, 0.55);
}
.filter-best-btn.active {
  background: rgba(34, 255, 102, 0.55);
  box-shadow: 0 0 0 2px rgba(34, 255, 102, 0.75);
}

.filter-learn-btn {
  background: rgba(255, 77, 79, 0.22);
  border-color: rgba(255, 77, 79, 0.55);
}
.filter-learn-btn.active {
  background: rgba(255, 77, 79, 0.55);
  box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.75);
}

.filter-full-btn {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.30);
  color: #eee;
}
.filter-full-btn.active {
  background: rgba(255, 255, 255, 0.40);
  color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.65);
}

.slider-group.disabled { opacity: 0.4; }

.slider-label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #ddd;
}

.slider-side {
  font-variant-numeric: tabular-nums;
  color: #ccc;
}

.slider-side:first-child  { text-align: left; }
.slider-side:last-child   { text-align: right; }

.slider-title {
  font-weight: 500;
  color: #eee;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  margin: 0;
  padding: 0.4rem 0;
  cursor: pointer;
  touch-action: manipulation;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #333;
  border-radius: 2px;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: #333;
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #eee;
  margin-top: -7px;
  border: none;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #eee;
  border: none;
}

input[type="range"]:disabled {
  cursor: not-allowed;
}

input[type="range"]:disabled::-webkit-slider-thumb { background: #666; }
input[type="range"]:disabled::-moz-range-thumb { background: #666; }

/* Landscape tweak: slightly slimmer controls */
@media (orientation: landscape) and (max-height: 500px) {
  #controls { padding: 0.4rem 0.6rem 0.5rem; gap: 0.5rem; }
  .slider-label { font-size: 0.7rem; }
  #play-btn { width: 2.5rem; height: 2.2rem; font-size: 1.1rem; }
}
