:root {
  color-scheme: light dark;
  --paper: light-dark(#eef3f2, #06171f);
  --ink: light-dark(#0a2533, #e4efee);
  --buoy: #f2542d;
  --pad: clamp(16px, 4vw, 56px);
  --gap: 16px; /* keep in sync with GAP in app.js */
  --chips: 6px; /* keep in sync with CHIPS in app.js */
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
}

:root[data-theme='light'] {
  color-scheme: light;
}

:root[data-theme='dark'] {
  color-scheme: dark;
}

body {
  margin: 0;
  padding: var(--pad);
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.4;
}

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

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

button {
  cursor: pointer;
}

/* Header */

h1 {
  margin: 0 0 0.3em;
  font-size: clamp(3rem, 11vw, 8.5rem);
  font-weight: 300;
  font-stretch: 78%;
  letter-spacing: -0.02em;
  line-height: 0.9;
  overflow-wrap: anywhere;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 10px;
}

/* A line of its own, so a long search never pushes the controls around. */
#status {
  flex: 1 0 100%;
  margin: 0 0 4px;
}

#status button {
  margin-left: 0.6em;
  padding: 0;
  border: 0;
  background: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}

#search {
  flex: 0 1 240px;
  margin-right: 6px;
}

#query,
#order {
  width: 100%;
  padding: 8px 0;
  border: 0;
  border-bottom: 1.5px solid var(--ink);
  border-radius: 0;
  background: transparent;
}

#query::placeholder {
  color: color-mix(in srgb, var(--ink) 55%, transparent);
}

.bar > button,
.bar > a {
  padding: 8px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  text-decoration: none;
}

#favorites[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}

#favorites[data-count]:not([data-count='0'])::before {
  content: '';
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-right: 0.5em;
  border-radius: 50%;
  background: var(--buoy);
}

/* Chapters (sub-boards) and moods (a custom field) */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  margin-top: 24px;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pills:empty {
  display: none;
}

.pills button {
  padding: 5px 13px;
  border: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
  border-radius: 999px;
  background: transparent;
  font-size: 0.92rem;
}

.pills button[aria-pressed='true'] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* Ready-made questions for the AI search */

.try {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin: 18px 0 0;
  font-size: 0.92rem;
}

.try span {
  opacity: 0.6;
}

.try button {
  padding: 0;
  border: 0;
  background: none;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--ink) 35%, transparent);
  text-underline-offset: 4px;
}

.try button:hover {
  text-decoration-color: var(--buoy);
}

/* The board's colors, drawn as a wave. Each bar is a filter. */

.strip {
  display: flex;
  align-items: flex-end;
  height: clamp(64px, 12vw, 132px);
  margin: 28px calc(-1 * var(--pad)) 40px;
}

.strip button {
  flex: 1 1 0;
  min-width: 0;
  height: var(--h);
  padding: 0;
  border: 0;
  background: var(--c);
  transform-origin: bottom;
  transition: height 0.15s;
}

.strip button:hover,
.strip button:focus-visible,
.strip button[aria-pressed='true'] {
  height: 100%;
}

.strip button:focus-visible,
.strip button[aria-pressed='true'] {
  position: relative;
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

/* Grid. app.js sets the column count, the row unit and each tile's span. */

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  grid-auto-rows: var(--unit, 2px);
  column-gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  margin-bottom: var(--gap);
  overflow: hidden;
  border-radius: 3px;
  transition: opacity 0.15s;
}

.tile.dim {
  opacity: 0.14;
}

.tile a {
  flex: 1;
  min-height: 0;
  background: var(--avg);
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The image's own colors, like a paint chip under it. */
.chips {
  display: flex;
  flex: none;
  height: var(--chips);
}

.chips i {
  flex: 1;
}

.favorite {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: #fff;
  opacity: 0;
}

.favorite svg {
  width: 22px;
  height: 22px;
  /* The shadow keeps the outline readable on pale images. */
  filter: drop-shadow(0 0 2px rgb(0 0 0 / 0.55));
  fill: rgb(0 0 0 / 0.25);
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.favorite[aria-pressed='true'] svg {
  fill: var(--buoy);
}

.tile:hover .favorite,
.favorite:focus-visible,
.favorite[aria-pressed='true'] {
  opacity: 1;
}

.favorite:focus-visible {
  outline-color: #fff;
  outline-offset: -6px;
}

@media (hover: none) {
  .favorite {
    opacity: 1;
  }
}

.notice {
  max-width: 34em;
  margin: 0;
  font-size: 1.25rem;
}

/* One image, on its own colors */

dialog {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--fg);
}

dialog[open] {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
  align-items: center;
}

dialog :focus-visible {
  outline-color: currentColor;
}

figure {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  height: 100dvh;
  margin: 0;
  padding: var(--pad);
}

figure img {
  /* Never more than twice the image's own size. */
  height: min(84dvh, var(--natural));
  max-width: 100%;
  object-fit: contain;
  border-radius: 3px;
}

.panel {
  padding: var(--pad);
  padding-left: 0;
}

.panel h2 {
  margin: 0 0 0.4em;
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.panel p {
  margin: 0 0 1.75em;
  opacity: 0.8;
}

.panel .facts {
  margin-bottom: 1em;
  font-size: 0.92rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 1.75em;
  padding: 0;
  list-style: none;
}

.tags button {
  padding: 3px 11px;
  border: 1px solid color-mix(in srgb, currentColor 40%, transparent);
  border-radius: 999px;
  background: transparent;
  font-size: 0.88rem;
}

.tags button:hover {
  border-color: currentColor;
}

.palette {
  display: grid;
  gap: 4px;
  margin: 0 0 2em;
  padding: 0;
  list-style: none;
}

.palette button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 4px 0;
  border: 0;
  background: none;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.palette button::before {
  content: '';
  flex: none;
  width: 44px;
  height: 28px;
  border-radius: 2px;
  background: var(--c);
  box-shadow: 0 0 0 1px color-mix(in srgb, currentColor 25%, transparent);
}

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

.actions button {
  padding: 8px 16px;
  border: 1.5px solid currentColor;
  border-radius: 999px;
  background: transparent;
}

.actions button[aria-pressed='true'] {
  border-color: var(--buoy);
  background: var(--buoy);
  color: #fff;
}

@media (max-width: 760px) {
  dialog[open] {
    display: block;
    overflow-y: auto;
  }

  figure {
    height: auto;
  }

  figure img {
    height: auto;
    max-height: 70dvh;
  }

  .panel {
    padding: 0 var(--pad) var(--pad);
  }
}

/* Slideshow */

#cinema[open] {
  display: block;
  overflow: hidden;
  transition: background 1.2s;
}

#cinema img {
  position: absolute;
  inset: var(--pad);
  width: calc(100% - 2 * var(--pad));
  height: calc(100% - 2 * var(--pad) - 56px);
  object-fit: contain;
  opacity: 0;
  transition: opacity 1.2s;
}

#cinema img.on {
  opacity: 1;
}

.caption {
  position: absolute;
  bottom: var(--pad);
  left: var(--pad);
  margin: 0;
  font-size: 1.25rem;
}

.cinema-actions {
  position: absolute;
  right: var(--pad);
  bottom: calc(var(--pad) - 6px);
  display: flex;
  gap: 8px;
}

.cinema-actions button {
  padding: 8px 16px;
  border: 1.5px solid currentColor;
  border-radius: 999px;
  background: transparent;
}

@media (prefers-reduced-motion: no-preference) {
  #cinema img.on {
    animation: drift 6s ease-out both;
  }

  @keyframes drift {
    from {
      scale: 1.04;
    }
  }
}

/* Tiles glide to their new places when the filter changes. */
::view-transition-group(*) {
  animation-duration: 0.45s;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* How it's built: a panel from the right */

#hood[open] {
  display: block;
  left: auto;
  width: min(560px, 100vw);
  overflow-y: auto;
  box-sizing: border-box;
  padding: 28px 32px 40px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: -24px 0 60px rgb(0 0 0 / 0.25);
}

#hood::backdrop {
  background: rgb(0 0 0 / 0.35);
}

.hood-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.hood h2 {
  margin: 0 0 0.6em;
  font-size: 1.6rem;
  font-weight: 500;
}

.hood h3 {
  margin: 2em 0 0.5em;
  font-size: 1.05rem;
  font-weight: 600;
}

.hood p {
  margin: 0 0 0.75em;
}

.hood-summary {
  opacity: 0.7;
  font-size: 0.92rem;
}

.hood button,
.hood-actions a {
  padding: 6px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  text-decoration: none;
}

.hood-requests,
.hood-files {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hood-requests li {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  font-size: 0.88rem;
}

.hood-requests code {
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.hood-requests span,
.hood-files span {
  opacity: 0.65;
}

.hood-files li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.92rem;
}

.hood-files button {
  min-width: 108px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.85rem;
}

.hood-files button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}

.hood-source {
  max-height: 360px;
  margin: 12px 0 0;
  padding: 12px;
  overflow: auto;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre;
}

.hood-prompt {
  margin: 0 0 1em;
  padding: 12px 16px;
  border-left: 3px solid var(--buoy);
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  font-size: 0.95rem;
}

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

#hood-remix {
  border-color: var(--buoy);
  background: var(--buoy);
  color: #fff;
}

/* About this app, in the header's empty top-right corner: it covers nothing,
   and scrolls away with the header. */

.top {
  position: relative;
}

.about {
  display: grid;
  justify-items: end;
  gap: 4px;
  font-size: 0.88rem;
  text-align: right;
}

.about a {
  color: inherit;
  text-decoration: none;
}

.about a:hover strong {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.about p {
  margin: 0;
  opacity: 0.65;
}

.about button {
  margin-top: 6px;
  padding: 7px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--buoy);
  color: #fff;
  font-weight: 600;
}

.about button:hover {
  filter: brightness(1.08);
}

@media (min-width: 761px) {
  .about {
    position: absolute;
    top: 0;
    right: 0;
    max-width: 320px;
  }

  /* A long board title stops short of the corner. */
  h1 {
    max-width: calc(100% - 340px);
  }
}

/* On a narrow screen it sits above the title instead. */
@media (max-width: 760px) {
  .about {
    justify-items: start;
    margin-bottom: 24px;
    text-align: left;
  }
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 10;
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  opacity: 0;
  pointer-events: none;
  translate: -50% 0;
  transition: opacity 0.2s;
}

.toast.on {
  opacity: 1;
}

/* The one moment of motion: the wave rises once when the board loads. */
@media (prefers-reduced-motion: no-preference) {
  .strip.rise button {
    animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
    animation-delay: calc(var(--i) * 7ms);
  }

  @keyframes rise {
    from {
      transform: scaleY(0);
    }
  }
}

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