/* MEMORY BOX */

@font-face {
  font-family: "Monument Extended";
  src: url("MonumentExtended-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "COMMITTEE";
  src: url("COMMITTEE-Light.otf") format("opentype");
  font-weight: 300;
  font-display: swap;
}
@font-face {
  font-family: "COMMITTEE";
  src: url("COMMITTEE-Bold.otf") format("opentype");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "COMMITTEE Rough";
  src: url("COMMITTEE-Rough.otf") format("opentype");
  font-display: swap;
}

:root {
  --red: #f00;
  --ink: #000;
  --bg: #feedd8;

  --heading-font: "Monument Extended", sans-serif;
  --body-font: "COMMITTEE", sans-serif;

  --logo-width: min(320px, 60vw);
  --chest-width: min(600px, 100vw - 40px);

  /* Waveform: rounded vertical lines, read by app.js */
  --wave-height: 120px;
  --wave-line-width: 3px;
  --wave-line-gap: 3px;
  --wave-color: #000;
  --wave-played-color: #f00;

  /* Clip list around the current clip, read by app.js. Rows shrink and
     fade evenly from the current clip down to the end values. */
  --queue-row-height: 44px;
  --queue-font-size: 22px;
  --queue-above: 2;
  --queue-below: 6;
  --queue-end-scale: 0.68;
  --queue-end-opacity: 0.36;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body-font);
  font-weight: 300;
}

/* Fill the window; the stage takes up any extra height. */
body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

/* ---------------------------------------------------------- header */

.site-header {
  display: flex;
  justify-content: center;
  padding: 32px 20px 0;
}
.logo {
  display: block;
  width: var(--logo-width);
  height: auto;
}

/* ---------------------------------------------------------- stage */

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.is-closed .stage { justify-content: center; }

.title {
  font-family: var(--heading-font);
  font-weight: 700;
  color: var(--red);
  text-transform: uppercase;
  font-size: clamp(30px, 8vw, 80px);
  letter-spacing: 0.02em;
  margin: 24px 0 0;
  text-align: center;
}
.is-player .title { margin-top: 12px; }

/* Time of the newest clip, shown under MEMORY BOX with the player. */
.updated {
  font-family: var(--body-font);
  font-size: 14px;
  color: #222;
  text-align: center;
  margin: 8px 0 0;
  opacity: 0;
  transition: opacity 0.8s ease 0.3s;
}
.updated.is-visible { opacity: 1; }

/* ---------------------------------------------------------- chest */

.chest {
  display: block;
  width: var(--chest-width);
  transition: opacity 0.5s ease;
}
.chest:focus-visible { outline: 2px solid var(--red); outline-offset: 8px; }
.is-leaving .chest { opacity: 0; }

.chest-float {
  display: block;
  animation: hover-float 3s ease-in-out infinite alternate;
}
@keyframes hover-float {
  from { transform: translateY(6px); }
  to   { transform: translateY(-10px); }
}

/* Both drawings fill the same box. The open SVG has empty canvas around
   its ink (ink spans x 59.19–392.27, y 33.14–296.35 of 423.508 × 429.396,
   the same 333 × 263 as the closed drawing), so it is scaled and shifted
   until the chests line up, and the empty canvas is clipped away. */
.chest-art {
  position: relative;
  display: block;
  aspect-ratio: 333.073 / 263.171;
  overflow: clip;
  overflow-clip-margin: 4px;
}
.chest-art img {
  position: absolute;
  display: block;
  pointer-events: none;
  height: auto;
}
.chest-closed {
  left: 0;
  top: 0;
  width: 100%;
}
.chest-open {
  left: -17.771%;
  top: -12.593%;
  width: 127.152%;
  opacity: 0;
}
.is-open .chest-closed { opacity: 0; }
.is-open .chest-open { opacity: 1; }

/* ---------------------------------------------------------- player */

.player {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: min(1200px, 100% - 40px);
  margin: 40px auto 0;
  opacity: 0;
  transition: opacity 0.8s ease 0.3s;
}
.player.is-visible { opacity: 1; }

.wave-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.play-btn {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  transition: background 0.2s;
}
.play-btn svg { width: 24px; height: 24px; fill: currentColor; }
.play-btn .icon-pause { display: none; }
.is-playing .play-btn { background: var(--red); }
.is-playing .play-btn .icon-play { display: none; }
.is-playing .play-btn .icon-pause { display: block; }
.play-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

.wave {
  flex: 1;
  min-width: 0;
  height: var(--wave-height);
  cursor: pointer;
  touch-action: none;
}
.wave canvas { display: block; width: 100%; height: 100%; }
.wave:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; }

/* ---------------------------------------------------------- transcript */

/* The line being spoken; swapped by app.js as the audio plays. */
.caption {
  font-family: "COMMITTEE Rough", var(--body-font);
  font-size: 18px;
  line-height: 1.4;
  color: #222;
  text-align: center;
  min-height: 2.8em;  /* room for two lines, so the list below doesn't jump */
  margin: 20px 0 0;
}

/* ---------------------------------------------------------- clip list */

.queue-row {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  margin-top: 32px;
}

.queue {
  position: relative;
  height: calc(var(--queue-row-height) * (var(--queue-above) + var(--queue-below) + 1));
  width: 14em;  /* fits the full date shown on hover */
  font-size: var(--queue-font-size);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.queue.is-dragging { cursor: grabbing; }
.queue:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; }

.queue-track { position: absolute; inset: 0 0 auto 0; will-change: transform; }

.queue-item {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--queue-row-height);
  line-height: var(--queue-row-height);
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transform-origin: center;
}
.queue-item.is-current { color: var(--red); font-weight: 700; }

/* Sits level with the current clip. */
.random-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  letter-spacing: 0.06em;
  padding: 12px 22px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  margin-top: calc(var(--queue-row-height) * (var(--queue-above) + 0.5));
  transform: translateY(-50%);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.random-btn svg { width: 24px; height: 24px; fill: currentColor; }
.random-btn:hover { background: var(--red); border-color: var(--red); color: var(--bg); }
.random-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

/* ---------------------------------------------------------- footer */

.site-footer {
  text-align: center;
  font-size: 20px;
  padding: 48px 20px 32px;
  opacity: 0;
  transition: opacity 0.8s ease 0.3s;
}
.site-footer.is-visible { opacity: 1; }
.site-footer p { margin: 0; }
.site-footer a, .site-footer a:hover, .site-footer a:visited { color: var(--red); }

/* ---------------------------------------------------------- mobile */

@media (max-width: 640px) {
  :root {
    --wave-height: 80px;
    --wave-line-width: 2px;
    --wave-line-gap: 2px;
    --queue-row-height: 38px;
    --queue-font-size: 17px;
  }
  .site-header { padding-top: 24px; }
  .title { font-size: 30px; }
  .wave-row { gap: 12px; }
  .play-btn { width: 44px; height: 44px; }
  .play-btn svg { width: 20px; height: 20px; }
  .queue-row { gap: 12px; }
  .queue { width: 10.5em; }
  .random-btn { font-size: 16px; padding: 9px 14px; gap: 7px; }
  .random-btn svg { width: 18px; height: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .chest-float { animation: none; }
}
