/* Clip gallery. Tokens, type scale, radii and spacing follow docs/design-system.md:
   monochrome, hairlines instead of shadows, sizes 12/13/14/16/24, weights 400/500/600,
   radius 6 for controls and 8 for cards and media, spacing 4/8/12/16/24/32. */

@font-face {
  font-family: 'Geist';
  src: url('fonts/Geist.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --background: #fafafa;
  --card: #ffffff;
  --surface: #f2f2f2;
  --surface-hover: #ebebeb;
  --text: #171717;
  --text-secondary: #666666;
  --text-muted: #8f8f8f;
  --border: #e6e6e6;
  --border-strong: #d4d4d4;
  --primary: #171717;
  --primary-foreground: #ffffff;
  --focus: #0070f3;
  --mark: rgba(0, 0, 0, 0.09);
  --media-outline: rgba(0, 0, 0, 0.08);
  --font: 'Geist', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --page: 1152px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --background: #000000;
    --card: #0a0a0a;
    --surface: #1a1a1a;
    --surface-hover: #1f1f1f;
    --text: #ededed;
    --text-secondary: #a1a1a1;
    --text-muted: #7d7d7d;
    --border: #2e2e2e;
    --border-strong: #454545;
    --primary: #ededed;
    --primary-foreground: #0a0a0a;
    --focus: #3291ff;
    --mark: rgba(255, 255, 255, 0.16);
    --media-outline: rgba(255, 255, 255, 0.1);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --background: #000000;
  --card: #0a0a0a;
  --surface: #1a1a1a;
  --surface-hover: #1f1f1f;
  --text: #ededed;
  --text-secondary: #a1a1a1;
  --text-muted: #7d7d7d;
  --border: #2e2e2e;
  --border-strong: #454545;
  --primary: #ededed;
  --primary-foreground: #0a0a0a;
  --focus: #3291ff;
  --mark: rgba(255, 255, 255, 0.16);
  --media-outline: rgba(255, 255, 255, 0.1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 88px;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--background);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: var(--gutter);
  top: 8px;
  z-index: 20;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Top ---- */

.top,
.search-bar,
.page,
.foot {
  width: 100%;
  max-width: calc(var(--page) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 16px;
}

.brand {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.top-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.link {
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  transition: color 150ms ease-out;
}

.link:hover {
  color: var(--text);
}

.top-links .link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: 12px;
  font-weight: 500;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  transition: color 150ms ease-out;
}

.icon-button:hover {
  color: var(--text);
}

.icon-button:active {
  transform: scale(0.96);
}

.moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .sun {
    display: none;
  }
  :root:not([data-theme='light']) .moon {
    display: block;
  }
}

:root[data-theme='dark'] .sun {
  display: none;
}

:root[data-theme='dark'] .moon {
  display: block;
}

/* ---- Search ---- */

.search-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: 8px;
  padding-bottom: 12px;
  background: var(--background);
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  transition: border-color 150ms ease-out;
}

.search:hover {
  border-color: var(--border-strong);
}

.search:focus-within {
  border-color: var(--text);
}

.search-icon {
  position: absolute;
  left: 16px;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 8px 0 46px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 16px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.search-input::placeholder {
  color: var(--text-muted);
  text-overflow: ellipsis;
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.kbd {
  display: none;
  flex: none;
  min-width: 24px;
  height: 24px;
  margin-right: 14px;
  padding-inline: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 22px;
  text-align: center;
}

.clear {
  flex: none;
  margin-right: 4px;
}

@media (hover: hover) and (pointer: fine) {
  .kbd {
    display: block;
  }
  .search:focus-within .kbd,
  .search.has-value .kbd {
    display: none;
  }
}

/* ---- Page ---- */

.page {
  flex: 1;
  padding-bottom: 32px;
}

/* ---- Filters ---- */

.filters {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.facet {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.facet-label {
  flex: none;
  width: 56px;
  color: var(--text-muted);
  font-size: 12px;
}

.chips {
  display: flex;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 2px 0;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
  /* Let the row scroll under the page gutter on phones. */
  margin-right: calc(-1 * var(--gutter));
  padding-right: var(--gutter);
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition:
    border-color 150ms ease-out,
    color 150ms ease-out,
    background-color 150ms ease-out;
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip:active {
  transform: scale(0.96);
}

.chip[aria-pressed='true'] {
  border-color: var(--text);
  background: var(--surface);
  color: var(--text);
}

.chip:disabled {
  opacity: 0.45;
  cursor: default;
}

.chip-count {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.chip.more-chip {
  border-style: dashed;
}

@media (min-width: 720px) {
  .chips {
    flex-wrap: wrap;
    overflow: visible;
    margin-right: 0;
    padding-right: 0;
  }
  .facet {
    align-items: flex-start;
  }
  .facet-label {
    line-height: 36px;
  }
}

/* ---- Status line ---- */

.status {
  margin: 16px 0 12px;
  color: var(--text-secondary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.status strong {
  color: var(--text);
  font-weight: 500;
}

/* ---- Grid ---- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-flow: dense;
  gap: 24px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 720px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 32px 16px;
  }
}

@media (min-width: 1080px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.tile {
  min-width: 0;
  scroll-margin-top: 88px;
}

.tile-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--media-outline);
}

.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 150ms ease-out;
}

.thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px var(--media-outline);
  pointer-events: none;
}

.tile-button:hover .thumb img {
  opacity: 0.88;
}

.tile-button:active .thumb {
  transform: scale(0.99);
}

.duration {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 1;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 18px;
}

.tile-text {
  display: block;
  padding-top: 8px;
}

.tile-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  text-wrap: pretty;
}

.tile-meta {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snippet {
  display: none;
  margin-top: 6px;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

mark {
  padding: 0 1px;
  border-radius: 3px;
  background: var(--mark);
  color: var(--text);
  font-weight: 500;
}

/* Search results: rows, so the matching words can be read. */

.grid.results {
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

.grid.results .tile {
  border-top: 1px solid var(--border);
}

.grid.results .tile:first-child {
  border-top: 0;
}

.grid.results .tile-button {
  display: grid;
  grid-template-columns: 136px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 16px 0;
  border-radius: 0;
}

.grid.results .tile:first-child .tile-button {
  padding-top: 4px;
}

.grid.results .tile-text {
  padding-top: 0;
}

.grid.results .tile-title {
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.grid.results .snippet:not(:empty) {
  display: -webkit-box;
}

@media (min-width: 720px) {
  .grid.results {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 32px;
  }
  .grid.results .tile:nth-child(2) {
    border-top: 0;
  }
  .grid.results .tile:nth-child(2) .tile-button {
    padding-top: 4px;
  }
  .grid.results .tile-button {
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 16px;
  }
}

/* ---- A clip opened in place ---- */

.tile.open,
.grid.results .tile.open {
  grid-column: 1 / -1;
  border-top: 0;
}

.tile.open > .tile-button {
  display: none;
}

.grid.results .tile.open + .tile {
  border-top: 0;
}

.player {
  position: relative;
  display: grid;
  gap: 16px;
  margin-inline: calc(-1 * var(--gutter));
  padding: 0 0 16px;
  border-block: 1px solid var(--border);
  background: var(--card);
}

.player-video {
  display: block;
  width: 100%;
  max-height: min(72vh, 640px);
  background: #000;
}

.player-body {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding-inline: var(--gutter);
}

.player-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.player-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
  text-wrap: pretty;
}

.player-close {
  flex: none;
  margin: -10px -12px 0 0;
}

.player-meta {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.player-meta .mono {
  font-family: var(--mono);
  font-size: 12px;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition:
    border-color 150ms ease-out,
    background-color 150ms ease-out;
}

.button:active {
  transform: scale(0.96);
}

.button.outline {
  border-color: var(--border);
  background: var(--card);
}

.button.outline:hover {
  border-color: var(--border-strong);
}

.button.ghost {
  color: var(--text-secondary);
}

.button.ghost:hover {
  background: var(--surface);
  color: var(--text);
}

.player-text {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.fold {
  border-top: 1px solid var(--border);
}

.fold summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.fold summary::-webkit-details-marker {
  display: none;
}

.fold summary .icon {
  color: var(--text-muted);
  transition: transform 150ms ease-out;
}

.fold[open] summary .icon {
  transform: rotate(180deg);
}

.fold .player-text {
  padding-bottom: 12px;
}

.post-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0 0 8px;
  list-style: none;
}

.post-list a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding-block: 8px;
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
}

.post-list a:hover .post-name {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.post-date {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 720px) {
  .player {
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 24px;
    margin-inline: 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    align-items: start;
  }
  .player.vertical {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.4fr);
  }
  .player-video {
    position: sticky;
    top: 88px;
    border-radius: 4px;
  }
  .player-body {
    padding-inline: 0;
  }
}

/* ---- More, empty, footer ---- */

.more {
  display: flex;
  justify-content: center;
  padding-top: 32px;
}

.empty {
  display: grid;
  justify-items: start;
  gap: 8px;
  padding: 32px 0;
}

.empty-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.empty-hint {
  margin: 0 0 8px;
  max-width: 44ch;
  color: var(--text-secondary);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding-top: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
}

.foot .link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
