/* Tournament timeline: the evening as a row of level cells. */

.tournament-timeline {
  grid-area: timeline;
  display: grid;
  gap: var(--s-2);
  min-width: 0;
}

.setup-structure-timeline {
  margin-top: var(--s-2);
}

.timeline-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
}

.timeline-title {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
}

.timeline-title strong {
  font-size: var(--text-md);
  font-weight: 650;
}

.timeline-title > span,
.timeline-summary {
  color: var(--ink-3);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.setup-structure-timeline .timeline-header {
  display: none;
}

.timeline-track-shell {
  position: relative;
  min-width: 0;
  padding: 36px 0 10px;
}

.setup-structure-timeline .timeline-track-shell:not(:has(.timeline-reentry-window)) {
  padding-top: 12px;
}

/* Setup: a long structure scrolls sideways instead of crushing its cells */
.setup-structure-timeline:not(.mobile-scroll-timeline) .timeline-track-shell {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 14px;
}

/* Firefox has no ::-webkit-scrollbar; elsewhere the custom bar stays visible instead of macOS overlay bars. */
@supports not selector(::-webkit-scrollbar) {
  .setup-structure-timeline .timeline-track-shell {
    scrollbar-width: thin;
    scrollbar-color: var(--rule-strong) transparent;
  }
}

.setup-structure-timeline:not(.mobile-scroll-timeline) .timeline-track {
  min-width: var(--timeline-min-width, 0px);
}

.setup-structure-timeline .timeline-track-shell::-webkit-scrollbar {
  height: 8px;
}

.setup-structure-timeline .timeline-track-shell::-webkit-scrollbar-track {
  border-radius: var(--r-pill);
  background: var(--face-3);
}

.setup-structure-timeline .timeline-track-shell::-webkit-scrollbar-thumb {
  border-radius: var(--r-pill);
  background: var(--rule-strong);
}

.timeline-track {
  --timeline-h: 84px;
  position: relative;
  display: flex;
  height: var(--timeline-h);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--face);
}

.timeline-level {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "label duration"
    "blinds blinds"
    "start start";
  align-items: center;
  column-gap: 6px;
  flex: none;
  min-width: 0;
  padding: 9px 9px 8px 11px;
  overflow: hidden;
  border-left: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
  transition: background-color var(--t-base) var(--ease-out), color var(--t-base) var(--ease-out);
}

.timeline-level:first-of-type,
.timeline-reentry-window + .timeline-level {
  border-left: 0;
  border-radius: var(--r-md) 0 0 var(--r-md);
}

.timeline-level:last-of-type {
  border-radius: 0 var(--r-md) var(--r-md) 0;
}

.timeline-level > strong {
  grid-area: label;
  overflow: hidden;
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.timeline-level > span {
  grid-area: blinds;
  overflow: hidden;
  font-size: 1.1875rem;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.015em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.timeline-level > small,
.timeline-level-start {
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.timeline-level > small {
  grid-area: duration;
}

.timeline-level-start {
  grid-area: start;
}

.timeline-level.break {
  grid-template-areas:
    "label label"
    "blinds blinds"
    "start start";
  padding-left: 7px;
  padding-right: 5px;
  background: var(--face-3);
  color: var(--ink-2);
}

.timeline-level.break > strong .icon {
  display: block;
  width: 15px;
  height: 15px;
}

.timeline-level.break > span {
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 600;
}

.timeline-level.past {
  background: color-mix(in srgb, var(--ground) 55%, var(--face));
}

.timeline-level.past > span {
  color: var(--ink-3);
  text-decoration: line-through;
  text-decoration-color: var(--rule-strong);
}

.timeline-level.current {
  background: var(--accent);
  color: var(--accent-ink);
}

.timeline-level.current > strong,
.timeline-level.current > span,
.timeline-level.current > small,
.timeline-level.current .timeline-level-start {
  color: var(--accent-ink);
}

.timeline-level.current > small,
.timeline-level.current .timeline-level-start {
  opacity: 0.8;
}

.timeline-level.next {
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

.timeline-level.next > strong {
  color: var(--accent);
}

/* Re-entry window: a lane over the levels it covers, closed off by a dashed rule through the strip */
.timeline-reentry-window {
  position: absolute;
  top: -32px;
  left: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  width: var(--reentry-width, 0%);
  min-width: max-content;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--accent-line);
  border-bottom: 0;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: var(--text-xs);
  font-weight: 650;
  white-space: nowrap;
}

.timeline-reentry-window .icon {
  flex: none;
  width: 14px;
  height: 14px;
}

.timeline-reentry-window::after {
  content: "";
  position: absolute;
  top: 0;
  right: -1px;
  height: calc(100% + 6px);
  border-right: 2px dashed var(--accent);
  pointer-events: none;
}

.timeline-reentry-window.closed {
  border-color: var(--rule-strong);
  background:
    repeating-linear-gradient(-45deg, transparent 0 6px, color-mix(in srgb, var(--rule-strong) 45%, transparent) 6px 7px),
    var(--face-2);
  color: var(--ink-3);
}

.timeline-reentry-window.closed::after {
  border-right-color: var(--rule-strong);
}

/* Progress and cursor */
.timeline-progress-fill {
  position: absolute;
  left: 0;
  bottom: -1px;
  width: var(--timeline-progress, 0%);
  height: 3px;
  border-radius: var(--r-pill);
  background: var(--accent);
  pointer-events: none;
}

.timeline-cursor {
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: var(--timeline-progress, 0%);
  z-index: 3;
  width: 24px;
  min-width: 24px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: ew-resize;
  pointer-events: auto;
  touch-action: none;
  transform: translateX(-50%);
}

.timeline-cursor:hover:not(:disabled) {
  background: transparent;
}

.timeline-cursor::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background: var(--ink);
}

.timeline-cursor::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border: 2px solid var(--face);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: var(--lift-1);
  transition: transform var(--t-fast) var(--ease-out);
}

.timeline-cursor:hover::after,
.timeline-cursor.dragging::after,
.timeline-cursor:focus-visible::after {
  transform: scale(1.25);
}

.timeline-seek-tooltip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  display: grid;
  gap: 2px;
  min-width: 150px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--ink-inverse);
  font-size: var(--text-xs);
  text-align: left;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
}

.timeline-seek-tooltip span {
  opacity: 0.75;
}

.timeline-cursor.dragging .timeline-seek-tooltip,
.timeline-cursor:focus-visible .timeline-seek-tooltip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.timeline-cursor.tooltip-left .timeline-seek-tooltip {
  left: 0;
  transform: none;
}

.timeline-cursor.tooltip-right .timeline-seek-tooltip {
  left: auto;
  right: 0;
  transform: none;
}

/* Events: small marks on the top edge */
.timeline-event {
  position: absolute;
  top: -5px;
  left: var(--event-position, 0%);
  z-index: 2;
  width: 10px;
  height: 10px;
  border: 2px solid var(--face);
  border-radius: 50%;
  background: var(--red);
  transform: translateX(-50%);
}

.timeline-event.reentry {
  background: var(--accent);
}

.timeline-event.late-entry {
  background: var(--green);
}

.timeline-event.cluster-event {
  width: 14px;
  height: 14px;
  top: -7px;
}

.timeline-event-label {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  display: grid;
  gap: 2px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--ink-inverse);
  font-size: var(--text-xs);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity var(--t-fast) var(--ease-out);
}

.timeline-event.edge-event .timeline-event-label {
  left: auto;
  right: -6px;
  transform: none;
}

.timeline-event:hover .timeline-event-label {
  opacity: 1;
}

.timeline-event-kind {
  opacity: 0.7;
}

.timeline-event-names {
  display: flex;
  flex-wrap: wrap;
  gap: 2px var(--s-2);
}

.timeline-event-names em {
  margin-left: 4px;
  font-style: normal;
  opacity: 0.7;
}

.timeline-footer {
  display: none;
}

.timeline-seeking .timeline-level {
  transition: none;
}

/* Display: the strip reads from across the room */
.control-grid .timeline-track {
  --timeline-h: 88px;
}

.control-grid .timeline-level > span {
  font-size: 1.3125rem;
}

.control-grid .timeline-level > strong,
.control-grid .timeline-level > small,
.control-grid .timeline-level-start {
  font-size: var(--text-sm);
}

.control-grid .timeline-level.break > span {
  font-size: var(--text-sm);
}

.control-grid .timeline-title strong {
  font-size: var(--text-lg);
}

.control-grid .timeline-track-shell {
  padding-bottom: 6px;
}

/* Scrolling timeline on phones */
.mobile-scroll-timeline .timeline-track-shell {
  overflow-x: auto;
  overflow-y: visible;
  overscroll-behavior-x: contain;
  /* The wide start inset keeps the opening cursor out of the iOS back-swipe edge. */
  padding: 32px var(--s-3) 14px var(--s-8);
  margin: 0 calc(var(--s-3) * -1);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

/* The scroller clips vertically, so while seeking it grows upward over the header to fit the tooltip. */
.mobile-scroll-timeline.timeline-seeking .timeline-track-shell {
  margin-top: -32px;
  padding-top: 64px;
}

.mobile-scroll-timeline .timeline-track-shell::-webkit-scrollbar {
  display: none;
}

.mobile-scroll-timeline .timeline-track {
  --timeline-h: 76px;
  width: var(--timeline-mobile-width, 720px);
}

.mobile-scroll-timeline .timeline-reentry-window {
  top: -30px;
}

.mobile-scroll-timeline .timeline-cursor {
  top: -4px;
  bottom: -4px;
}

/* A thumb-sized grab area and knob on touch screens */
@media (pointer: coarse) {
  .timeline-cursor {
    width: 56px;
    min-width: 56px;
  }

  .timeline-cursor::after {
    width: 22px;
    height: 22px;
    margin-left: -11px;
    bottom: -8px;
  }
}

.mobile-scroll-timeline .timeline-level.break > span {
  display: none;
}
