/* ==========================================================
   BASE TIMELINE PLAYER
========================================================== */

.timeline-player-ui {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  color: #f3e7c1;
}

.timeline-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.timeline-group-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Stable group / chapter background */
.timeline-group-container::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;

  background:
    linear-gradient(to bottom,
      rgba(0, 0, 0, .38),
      rgba(0, 0, 0, .68)),
    var(--timeline-group-bg, none);

  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

.timeline-group-container::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;

  background:
    radial-gradient(circle at center,
      transparent 35%,
      rgba(0, 0, 0, .55) 100%);
}

/* ==========================================================
   HEADER / GROUP SELECTOR
========================================================== */

.timeline-header {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;

  display: flex;
  justify-content: center;
  align-items: center;

  color: #8a6f3d;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-shadow: 0 2px 4px rgba(0, 0, 0, .75);
}

.timeline-header span {
  position: relative;
  display: inline-block;
  padding: 0 56px;
}

.timeline-header span::before,
.timeline-header span::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;

  background:
    linear-gradient(to right,
      transparent,
      rgba(212, 175, 55, .95),
      transparent);

  box-shadow: 0 0 6px rgba(212, 175, 55, .35);
}

.timeline-header span::before {
  top: 0;
}

.timeline-header span::after {
  bottom: 0;
}

.timeline-group-control {
  position: absolute;
  top: 18px;
  right: 20px;
  z-index: 4001;

  display: flex;
  flex-direction: row-reverse;
  align-items: flex-start;
  gap: 6px;
}

.timeline-group-panel {
  position: static;

  width: 130px;
  min-width: 130px;
  padding: 6px;

  background: rgba(30, 30, 30, .65);
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, .6);
  backdrop-filter: blur(3px);
}

.timeline-group-row {
  position: relative;

  padding: 8px 6px;
  border-radius: 6px;

  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;

  background: rgba(0, 0, 0, .4);
  text-shadow: 1px 1px 2px black;

  cursor: pointer;
}

.timeline-group-row+.timeline-group-row {
  margin-top: 4px;
}

.timeline-group-row.is-active {
  background: rgba(138, 111, 61, .78);
  color: #f3e7c1;
}

/* ==========================================================
   TRACK STACK / TRACKS
========================================================== */

.timeline-track-stack {
  position: absolute;
  z-index: 3;

  display: flex;
  gap: 0;
}

.timeline-track {
  position: relative;
  overflow: visible;

  background: none !important;
  box-shadow: none;

  opacity: .7;
  transition:
    opacity .16s ease,
    filter .16s ease;
}

.timeline-track::before,
.timeline-track::after {
  display: none;
}

.timeline-track.is-active {
  opacity: 1;
  filter:
    brightness(1.08) saturate(1.08);
}

.timeline-track-title {
  position: absolute;
  z-index: 4;

  color: #f2e6c9;

  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;

  text-shadow:
    0 0 2px #000,
    0 0 8px rgba(0, 0, 0, .9);

  pointer-events: none;
}

/* ==========================================================
   AXIS / EVENT LAYER / DOTS
========================================================== */

.timeline-axis {
  position: absolute;
  z-index: 2;
  overflow: hidden;

  background: transparent;

  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/* Fixed full-length rail on the visible axis */
.timeline-axis::before {
  content: "";
  position: absolute;

  background: var(--timeline-color, #8a6f3d);
  box-shadow:
    0 0 8px color-mix(
      in srgb,
      var(--timeline-color, #8a6f3d) 55%,
      transparent
    );

  pointer-events: none;
}

/* Virtual layer only carries dots, not the rail */
.timeline-event-layer::before {
  display: none;
}

.timeline-event-layer {
  position: absolute;
  inset: 0;
  z-index: 3;

  overflow: hidden;

  will-change: transform;
  transition: transform .35s ease-out;
}

.timeline-group-container.is-measuring .timeline-event-layer,
.timeline-group-container.is-jumping .timeline-event-layer {
  transition: none !important;
}

.timeline-group-container.is-playing .timeline-event-layer {
  transition: none;
}

.timeline-group-container.is-step-travel .timeline-event-layer {
  transition: transform 180ms cubic-bezier(.22, .8, .25, 1);
}

.timeline-event-dot {
  position: absolute;
  z-index: 3;

  width: 15px;
  height: 15px;

  padding: 0;
  border: 2px solid #f3e7c1;
  border-radius: 50%;

  background: var(--timeline-color, #8a6f3d);

  box-shadow:
    0 0 0 3px rgba(0, 0, 0, .45),
    0 0 8px rgba(212, 175, 55, .55);

  cursor: pointer;
}

.timeline-event-dot.is-active {
  transform: scale(1.45);

  border-color: #fff;

  box-shadow:
    0 0 0 4px rgba(255, 255, 255, .18),
    0 0 12px rgba(255, 215, 0, .95),
    0 0 24px rgba(255, 215, 0, .65);

  z-index: 10;
}

/* ==========================================================
   PLAYHEAD / TIME LABEL
========================================================== */

.timeline-playhead {
  position: absolute;
  z-index: 20;

  pointer-events: none;

  background: rgba(255, 255, 255, .9);

  box-shadow:
    0 0 8px rgba(255, 255, 255, .5),
    0 0 20px rgba(255, 255, 255, .35);
}

.timeline-playhead-time {
  position: absolute;

  padding: 4px 8px;

  color: #f3e7c1;
  background: rgba(0, 0, 0, .68);

  border: 1px solid rgba(212, 175, 55, .45);
  border-radius: 6px;

  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;

  text-shadow: 1px 1px 2px black;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}

/* ==========================================================
   EVENT INFO CARD
========================================================== */

.timeline-event-info {
  --info-ratio-w: 250;
  --info-ratio-h: 167;
  --info-max-width: 360px;
  --info-max-height: 240px;

  position: absolute;
  z-index: 30;

  width: min(var(--info-max-width),
      calc(100% - 32px),
      calc(var(--info-max-height) * var(--info-ratio-w) / var(--info-ratio-h)));

  aspect-ratio: var(--info-ratio-w) / var(--info-ratio-h);

  height: auto;

  box-sizing: border-box;

  display: flex;
  flex-direction: column;
  justify-content: center;

  padding: 16px 20px;

  color: #f3e7c1;

  background:
    linear-gradient(rgba(0, 0, 0, .48),
      rgba(0, 0, 0, .58)),
    var(--event-bg, none);

  background-size: cover;
  background-position: center center;

  border: 1px solid rgba(212, 175, 55, .45);
  border-radius: 10px;

  border-color: color-mix(in srgb,
      var(--active-timeline-color, #8a6f3d) 55%,
      rgba(212, 175, 55, .45));

  box-shadow:
    0 8px 26px rgba(0, 0, 0, .55),
    inset 0 0 18px color-mix(in srgb,
      var(--active-timeline-color, #8a6f3d) 18%,
      transparent);

  text-shadow: 1px 1px 2px black;
  backdrop-filter: blur(3px);

  overflow: hidden;
}

.timeline-event-info-date {
  margin-bottom: 5px;

  color: #8a6f3d;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.timeline-event-info-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .5px;
}

.timeline-event-info-description {
  margin-top: 7px;

  font-size: 13px;
  line-height: 1.35;
  opacity: .9;
}

/* ==========================================================
   LANDSCAPE MODE
   tracks = stacked rows
   time = left → right
========================================================== */

.timeline-group-container.is-landscape {
  --landscape-track-bottom: 120px;
  --landscape-track-height: 20px;
  --landscape-track-gap: 0px;

  --landscape-info-gap: 15px;
  --landscape-info-top-safe: 24px;

  --landscape-title-left: 76px;
  --landscape-axis-left: 230px;
  --landscape-axis-right: 4%;

  --landscape-time-bottom: 78px;

  --landscape-info-offset-y: 230px;

  --timeline-track-count: 1;
}

.timeline-track-stack.is-landscape {
  left: 0;
  right: 0;
  bottom: var(--landscape-track-bottom);

  display: flex;
  flex-direction: column-reverse;
  gap: var(--landscape-track-gap);
}

.timeline-group-container.is-landscape .timeline-track {
  height: var(--landscape-track-height);
  min-height: var(--landscape-track-height);
  flex: 0 0 var(--landscape-track-height);
}

.timeline-group-container.is-landscape .timeline-track-title {
  left: var(--landscape-title-left);
  top: 50%;

  transform: translateY(-50%);

  white-space: nowrap;
}

.timeline-group-container.is-landscape .timeline-axis {
  left: var(--landscape-axis-left);
  right: var(--landscape-axis-right);
  top: 50%;

  height: 52px;

  transform: translateY(-50%);

  -webkit-mask-image:
    linear-gradient(to right,
      transparent 0%,
      black 10%,
      black 90%,
      transparent 100%);

  mask-image:
    linear-gradient(to right,
      transparent 0%,
      black 10%,
      black 90%,
      transparent 100%);
}

.timeline-group-container.is-landscape .timeline-axis::before {
  left: 0;
  right: 0;
  top: 50%;

  height: 5px;

  transform: translateY(-50%);
}

.timeline-group-container.is-landscape .timeline-event-dot {
  left: calc((var(--event-pos) * 1px) - 7.5px);
  top: calc(50% - 7.5px);
}

.timeline-group-container.is-landscape .timeline-playhead {
  top: 0;
  bottom: 0;
  left: calc(var(--playhead-pos, .5) * 100%);

  width: 3px;

  transform: translateX(-50%);
}

.timeline-group-container.is-landscape .timeline-playhead-time {
  left: 50%;
  bottom: var(--landscape-time-bottom);

  transform: translateX(-50%);
}

.timeline-group-container.is-landscape .timeline-event-info {
  --info-ratio-w: 250;
  --info-ratio-h: 167;

  --available-info-height: calc(100% - var(--landscape-track-bottom) - (var(--timeline-track-count) * var(--landscape-track-height)) - ((var(--timeline-track-count) - 1) * var(--landscape-track-gap)) - var(--landscape-info-gap) - var(--landscape-info-top-safe));

  left: 50%;

  bottom: calc(var(--landscape-track-bottom) + (var(--timeline-track-count) * var(--landscape-track-height)) + ((var(--timeline-track-count) - 1) * var(--landscape-track-gap)) + var(--landscape-info-gap));

  width: min(360px,
      calc(100% - 32px),
      calc(58vh * 1.497),
      calc(var(--available-info-height) * 1.497));

  aspect-ratio: var(--info-ratio-w) / var(--info-ratio-h);
  height: auto;

  transform: translateX(-50%);
  text-align: center;
}

/* ==========================================================
   PORTRAIT MODE
   tracks = stacked columns
   time = top → bottom
========================================================== */

.timeline-group-container.is-portrait {
  --portrait-time-width: 96px;
  --portrait-gap: 14px;
  --portrait-track-width: 15px;
  --portrait-track-gap: 0px;
  --timeline-track-count: 1;
}

.timeline-track-stack.is-portrait {
  position: absolute;

  left: calc(var(--portrait-time-width) + var(--portrait-gap));
  top: 90px;
  bottom: 90px;

  right: auto;

  display: flex;
  flex-direction: row;
  align-items: stretch;

  gap: var(--portrait-track-gap);
}

.timeline-group-container.is-portrait .timeline-track {
  width: var(--portrait-track-width);
  min-height: 0;
  min-width: var(--portrait-track-width);
  height: auto;
  flex: 0 0 var(--portrait-track-width);
}

.timeline-group-container.is-portrait .timeline-track-title {
  left: 50%;
  top: auto;
  bottom: 100%;

  transform:
    translateX(-50%) rotate(90deg);

  transform-origin: center center;

  width: max-content;
  max-width: none;

  font-size: 11px;
  letter-spacing: .14em;

  white-space: nowrap;
  text-align: center;
}

.timeline-group-container.is-portrait .timeline-axis {
  top: 58px;
  bottom: 22px;
  left: 50%;

  width: 52px;

  transform: translateX(-50%);

  -webkit-mask-image:
    linear-gradient(to bottom,
      transparent 0%,
      black 10%,
      black 90%,
      transparent 100%);

  mask-image:
    linear-gradient(to bottom,
      transparent 0%,
      black 10%,
      black 90%,
      transparent 100%);
}

.timeline-group-container.is-portrait .timeline-axis::before {
  top: 0;
  bottom: 0;
  left: 50%;

  width: 5px;

  transform: translateX(-50%);
}

.timeline-group-container.is-portrait .timeline-event-dot {
  left: calc(50% - 7.5px);
  top: calc((var(--event-pos) * 1px) - 7.5px);
}

.timeline-group-container.is-portrait .timeline-playhead {
  left: 0;
  right: 0;
  top: calc(var(--playhead-pos, .5) * 100%);

  height: 3px;

  transform: translateY(-50%);
}

.timeline-group-container.is-portrait .timeline-playhead-time {
  left: 5px;
  top: calc(var(--playhead-pos, .5) * 100% - 15px);
  transform: none;
}

.timeline-group-container.is-portrait .timeline-event-info {
  --info-ratio-w: 250;
  --info-ratio-h: 167;

  --portrait-info-top-safe: 70px;
  --portrait-info-bottom-safe: 92px;

  --portrait-info-left: calc(var(--portrait-time-width) + var(--portrait-gap) + (var(--timeline-track-count) * var(--portrait-track-width)) + ((var(--timeline-track-count) - 1) * var(--portrait-track-gap)) + var(--portrait-gap));

  --portrait-available-width: calc(100% - var(--portrait-info-left) - 16px);

  --portrait-available-height: calc(100% - var(--portrait-info-top-safe) - var(--portrait-info-bottom-safe));

  left: var(--portrait-info-left);

  top: calc(var(--playhead-pos, .5) * 100%);

  width: min(250px,
      var(--portrait-available-width),
      calc(var(--portrait-available-height) * 1.497));

  aspect-ratio: var(--info-ratio-w) / var(--info-ratio-h);
  height: auto;

  transform: translateY(-50%);

  text-align: center;
}

.timeline-group-container.is-portrait .timeline-playhead-time.has-stacked-time {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  top: calc(50% - 19px);
  line-height: 1.15;
  text-align: center;
}

.timeline-playhead-date-part {
  display: block;
}

.timeline-playhead-clock-part {
  display: block;

  color: #8a6f3d;
  font-size: 10px;
  letter-spacing: .08em;
}

/* ==========================================================
   TOOLBAR
========================================================== */

.timeline-toolbar {
  position: fixed;
  left: 50%;
  bottom: 68px;
  z-index: 5000;

  display: flex;
  gap: 5px;

  transform: translateX(-50%);
}

/* ==========================================================
   RESPONSIVE
========================================================== */

@media (max-width: 1024px) {
  .timeline-group-container.is-portrait .timeline-track-title {
    width: 72px;
    font-size: 9px;
  }

  .timeline-header {
    top: 16px;
    font-size: 11px;
    letter-spacing: 2px;
  }

  .timeline-header span {
    padding: 0 34px;
  }

  .timeline-group-control {
    top: 14px;
    right: 12px;
  }

  .timeline-toolbar {
    gap: 7px;
  }
}

@media (max-width: 500px) {
  .timeline-player-ui {
    padding: 1rem;
  }

  .timeline-header span {
    padding: 0 26px;
  }

  .timeline-group-panel {
    width: 120px;
    min-width: 120px;
  }

  .timeline-toolbar {
    bottom: 70px;
    gap: 5px;
  }
}

/* ==========================================================
   VIRTUAL EVENT LAYER
   Fixed-pixel event cadence. The axis is a viewport; the
   event layer is a longer virtual strip translated behind it.
========================================================== */

.timeline-group-container.is-landscape .timeline-event-layer {
  inset: auto;
  top: 0;
  left: 0;
  width: calc(var(--virtual-track-length, 1000) * 1px);
  height: 100%;
}

.timeline-group-container.is-portrait .timeline-event-layer {
  inset: auto;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(var(--virtual-track-length, 1000) * 1px);
}
