:root {
  /* Three visible tiers, darkest to lightest: page -> panel -> row. */
  --background: #0d0a1c;
  --panel: #120f22;
  --card: #15121f;
  --card-hover: #1c1830;
  --foreground: #f3f4f8;
  --border: #2a2540;
  --border-strong: #3b3460;
  --muted-foreground: #b4b2c8;

  --accent-blue: #25aae1;
  --accent-purple: #9747ff;
  --accent-lime: #00ff0a;
  --accent-goldenrod: #ff8a00;
  --accent-pink: #ff0084;

  /* Flat tints behind the left block of a row, keyed to the row's bar colour. */
  --tint-blue: #173548;
  --tint-purple: #352254;
  --tint-neutral: #1d1a2e;

  --role-runner: var(--accent-purple);
  --role-host: var(--accent-blue);
  --role-commentator: var(--accent-goldenrod);

  --font-body: 'Maven Pro', system-ui, sans-serif;
  --font-heading: Lexend, system-ui, sans-serif;
  --font-mono: 'Miriam Libre', ui-monospace, monospace;
  /* Readable pixel face for game names; the blockier Press Start 2P is
     reserved for short labels because it becomes illegible when it wraps. */
  --font-title: 'Jersey 10', var(--font-heading);
  --font-pixel: 'Press Start 2P', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-body);
  line-height: 1.4;
}

/* A fixed pseudo-element rather than background-attachment: fixed, which
   iOS Safari ignores (the hills would scroll away with the page there). */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: url('/img/bg-hills.svg'), url('/img/bg-stars.svg');
  background-repeat: repeat-x, repeat;
  background-position: bottom left, top left;
  image-rendering: pixelated;
}

a {
  color: var(--accent-blue);
}

.site-header {
  padding: 2rem 1.5rem 1.25rem;
  margin-bottom: 0.5rem;
}

.site-header__inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* Pixel "dialog box" around the titles. Stepped corners need clip-path, and
   clip-path also cuts away a real border, so the frame is two layers: the
   purple outer box showing through the 4px padding around the clipped panel.
   The panel stays solid so the starfield never sits behind the small text. */
.title-window {
  --step: 6px;
  --stepped-corners: polygon(
    0 calc(var(--step) * 2), var(--step) calc(var(--step) * 2), var(--step) var(--step),
    calc(var(--step) * 2) var(--step), calc(var(--step) * 2) 0,
    calc(100% - var(--step) * 2) 0, calc(100% - var(--step) * 2) var(--step),
    calc(100% - var(--step)) var(--step), calc(100% - var(--step)) calc(var(--step) * 2),
    100% calc(var(--step) * 2), 100% calc(100% - var(--step) * 2),
    calc(100% - var(--step)) calc(100% - var(--step) * 2), calc(100% - var(--step)) calc(100% - var(--step)),
    calc(100% - var(--step) * 2) calc(100% - var(--step)), calc(100% - var(--step) * 2) 100%,
    calc(var(--step) * 2) 100%, calc(var(--step) * 2) calc(100% - var(--step)),
    var(--step) calc(100% - var(--step)), var(--step) calc(100% - var(--step) * 2),
    0 calc(100% - var(--step) * 2)
  );
  flex: 1 1 26rem;
  max-width: 40rem;
  padding: 4px;
  background: var(--accent-purple);
  clip-path: var(--stepped-corners);
}

.site-header__titles {
  position: relative;
  padding: 2.1rem 4.5rem 1.4rem 1.5rem;
  background: var(--panel);
  clip-path: var(--stepped-corners);
  /* Inner bevel plus a darker bottom lip, like an old game's menu window. */
  box-shadow: inset 0 0 0 2px #1f1a3a, inset 0 -6px 0 #0a0816;
}

/* Sits on the frame's top edge like a window title tab. */
.site-header__brand {
  position: absolute;
  top: 0;
  left: 1.5rem;
  margin: 0;
  padding: 0.4rem 0.65rem 0.35rem;
  background: var(--accent-purple);
  color: var(--foreground);
  text-transform: uppercase;
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  line-height: 1.2;
}

.title-window__sprite {
  position: absolute;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 30px;
  height: 21px;
}

.site-header__title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  margin: 0;
  color: var(--foreground);
}

.site-header__subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.95rem;
}

.site-header__updated {
  margin: 0.2rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.8rem;
}

.site-header__actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
  padding-top: 0.3rem;
  /* Keeps this pinned to the right even when it wraps onto its own line
     below the title, where justify-content on the parent alone would not
     have anything to space it against and would default to the left. */
  margin-left: auto;
}

.header-action {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
}

.header-actions__row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.help-btn {
  color: var(--accent-goldenrod);
  border-color: var(--accent-goldenrod);
}

.help-btn:hover {
  background: var(--accent-goldenrod);
  color: var(--background);
}

.time-format-switch {
  display: inline-flex;
  border: 2px solid var(--border-strong);
  background: var(--background);
}

.time-format-switch__option {
  background: transparent;
  color: var(--muted-foreground);
  border: none;
  padding: 0.4rem 0.7rem;
  font-size: 0.65rem;
}

.time-format-switch__option + .time-format-switch__option {
  border-left: 2px solid var(--border-strong);
}

.time-format-switch__option:hover {
  filter: none;
  background: var(--card-hover);
}

.time-format-switch__option--active,
.time-format-switch__option--active:hover {
  background: var(--accent-purple);
  color: var(--foreground);
}

.layout {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.site-footer {
  width: calc(100% - 3rem);
  max-width: 960px;
  /* Extra bottom room so the panel clears the hills behind it. */
  margin: 0 auto 9rem;
  padding: 1.25rem;
  background: var(--panel);
  border: 2px solid var(--border-strong);
}

.site-footer p {
  margin: 0;
  color: #cbc9db;
  font-size: 0.8rem;
  line-height: 1.6;
  text-align: center;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

.site-footer p + p {
  margin-top: 0.6rem;
}

.panel {
  background: transparent;
}

.panel__heading {
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--accent-blue);
  margin: 0 0 0.75rem;
}

.panel__empty {
  color: var(--muted-foreground);
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
  padding: 1rem;
  border: 2px dashed var(--border-strong);
  background: var(--panel);
}

.next-up-panel {
  text-align: center;
  padding: 1.25rem;
  border: 3px solid var(--accent-purple);
  background: var(--panel);
}

.next-up-panel--hidden {
  display: none;
}

.next-up-panel__label {
  margin: 0 0 0.6rem;
  text-transform: uppercase;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--accent-goldenrod);
}

.next-up-panel__label::before {
  content: '▶ ';
}

.next-up-panel__label::after {
  content: ' ◀';
}

.next-up-panel__name {
  margin: 0 0 0.75rem;
  font-family: var(--font-title);
  font-size: 1.9rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.next-up-panel__countdown {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: clamp(1.4rem, 6vw, 2.5rem);
  color: var(--foreground);
  line-height: 1.2;
}

.settings-panel {
  padding: 0.75rem 1rem;
  border: 2px solid var(--accent-goldenrod);
  background: var(--panel);
}

.settings-panel--hidden {
  display: none;
}

/* Padding lives on the inner body, not the <dialog>, so a click that targets
   the <dialog> element itself is always a backdrop click (see initHelpUi). */
.help-dialog {
  width: calc(100% - 2rem);
  max-width: 38rem;
  max-height: 85vh;
  padding: 0;
  border: 4px solid var(--accent-purple);
  background: var(--panel);
  color: var(--foreground);
  box-shadow: 6px 6px 0 #000;
}

.help-dialog::backdrop {
  background: rgba(5, 3, 15, 0.8);
}

.help-dialog__body {
  padding: 1.5rem 1.5rem 1.25rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

.help-dialog__title {
  margin: 0 0 1rem;
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--accent-blue);
}

.help-dialog h3 {
  margin: 1.4rem 0 0.4rem;
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 0.65rem;
  color: var(--accent-goldenrod);
}

.help-dialog p,
.help-dialog ul {
  margin: 0;
}

.help-dialog ul {
  padding-left: 1.2rem;
}

.help-dialog li + li {
  margin-top: 0.4rem;
}

.help-dialog strong {
  color: #fff;
}

.help-dialog code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-lime);
}

.help-dialog__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.header-popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card);
  border: 2px solid var(--border-strong);
  padding: 0.6rem;
  box-shadow: 4px 4px 0 #000;
  max-width: 90vw;
  z-index: 20;
}

.header-popover--hidden {
  display: none;
}

.header-popover__text {
  max-width: 16rem;
  font-size: 0.85rem;
  color: var(--foreground);
  margin: 0;
}

input[type='text'] {
  background: var(--background);
  border: 2px solid var(--border-strong);
  color: var(--foreground);
  padding: 0.45rem 0.6rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
}

#sync-link-input {
  width: 16rem;
  max-width: 60vw;
}

button {
  background: transparent;
  color: var(--accent-blue);
  border: 2px solid var(--accent-blue);
  border-radius: 0;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  line-height: 1.3;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

button:hover {
  background: var(--accent-blue);
  color: var(--background);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:disabled:hover {
  background: transparent;
  color: var(--accent-blue);
}

.btn--success,
.btn--success:hover,
.btn--success:disabled:hover {
  background: var(--accent-lime);
  border-color: var(--accent-lime);
  color: var(--background);
}

.hint-text {
  color: var(--muted-foreground);
  font-size: 0.8rem;
  margin: 0;
}

.settings-panel__status {
  color: var(--accent-goldenrod);
  font-size: 0.85rem;
  min-height: 1.1em;
  margin: 0;
}

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  background: var(--card);
}

.card-list:empty {
  display: none;
}

.day-divider {
  padding: 0.75rem 1rem;
  background: #000;
  border-bottom: 1px solid var(--border);
  color: var(--foreground);
  font-family: var(--font-pixel);
  font-size: 0.65rem;
}

.day-divider:not(:first-child) {
  border-top: 1px solid var(--border);
}

.schedule-card {
  display: grid;
  grid-template-columns: minmax(170px, 28%) 1fr auto;
  align-items: stretch;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s ease;
}

.schedule-card:last-child {
  border-bottom: none;
}

.schedule-card:hover {
  background: var(--card-hover);
}

.schedule-card--orphaned {
  opacity: 0.6;
}

.schedule-card__left {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.85rem 1rem;
  text-align: center;
  border-left: 10px solid var(--border-strong);
  background: var(--tint-neutral);
}

.schedule-card--speedrun .schedule-card__left {
  border-left-color: var(--accent-blue);
  background: var(--tint-blue);
}

.schedule-card--interview .schedule-card__left {
  border-left-color: var(--accent-purple);
  background: var(--tint-purple);
}

/* Declared after the type variants so a picked run's bar always wins. */
.schedule-card--selected .schedule-card__left {
  border-left-color: var(--accent-lime);
}

.schedule-card__name {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 1.5rem;
  line-height: 1.05;
  margin: 0;
  overflow-wrap: anywhere;
}

.schedule-card__time {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #cfd6e6;
  white-space: nowrap;
}

.schedule-card__time--tbd {
  font-style: italic;
}

.schedule-card__right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.85rem 1rem;
}

.schedule-card__info-row {
  display: grid;
  grid-template-columns: 5.5rem 3px 1fr;
  align-items: center;
  gap: 0.75rem;
}

.schedule-card__row-label {
  color: #cfd0dc;
  font-size: 0.8rem;
  text-align: right;
  white-space: nowrap;
}

.schedule-card__row-divider {
  width: 3px;
  align-self: stretch;
  min-height: 1.3rem;
  background: var(--accent-blue);
}

.schedule-card__cast-row .schedule-card__row-divider,
.schedule-card--interview .schedule-card__row-divider {
  background: var(--accent-purple);
}

.schedule-card__row-content {
  min-width: 0;
  font-size: 0.85rem;
  color: var(--foreground);
  overflow-wrap: anywhere;
}

.schedule-card__meta strong {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
}

.schedule-card__meta .muted {
  color: var(--muted-foreground);
}

.schedule-card__people {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.role {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.1rem 0.6rem;
  border: 2px solid currentColor;
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.role svg {
  flex-shrink: 0;
}

.role--runner {
  color: var(--role-runner);
}

.role--host {
  color: var(--role-host);
}

.role--commentator {
  color: var(--role-commentator);
}

.role span {
  color: var(--foreground);
}

.schedule-card__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
}

.pick-btn {
  min-width: 5.5rem;
}

.pick-btn--active,
.pick-btn--active:hover {
  background: var(--accent-lime);
  border-color: var(--accent-lime);
  color: var(--background);
}

.countdown {
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  white-space: nowrap;
}

.countdown--live {
  color: var(--accent-lime);
}

.countdown--soon {
  color: var(--accent-goldenrod);
}

.countdown--finished {
  color: var(--muted-foreground);
}

@media (max-width: 640px) {
  .site-header,
  .layout {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .site-footer {
    width: calc(100% - 2rem);
  }

  .site-header__titles {
    padding: 2rem 3.25rem 1.25rem 1rem;
  }

  .site-header__brand {
    left: 1rem;
  }

  .title-window__sprite {
    right: 0.9rem;
    bottom: 1rem;
  }

  .schedule-card {
    grid-template-columns: 1fr;
  }

  .schedule-card__left {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    text-align: left;
  }

  .schedule-card__info-row {
    grid-template-columns: 4.5rem 3px 1fr;
  }

  .schedule-card__actions {
    flex-direction: row;
    justify-content: space-between;
    padding-top: 0;
  }
}
