/*
 * Oceanaire — drifting player.
 *
 * There is no build step and no framework. This file is served as written.
 */

:root {
  --ink: #f2f0ea;
  --ground: #0d1420;
  --accent: #fad719;
  /* What a search found: the same yellow leaning orange, so it never reads
     as the thing that is playing. */
  --match: #f7b32b;

  /*
   * The scale of a floating phrase: its slashes, type and gaps are all ratios
   * of this. JavaScript overrides it per phrase to give the field depth.
   */
  --icon-size: 54px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--ground);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

/*
 * Sideways clipping belongs to <html> alone, and there is deliberately no
 * overscroll-behavior anywhere. Both of those matter more than they look:
 *
 * Putting `overflow-x: hidden` on <body> as well makes <body> its own scroll
 * container — one with nothing to scroll, since it is exactly as tall as its
 * contents. Add `overscroll-behavior-y: none` and the wheel stops there
 * instead of passing up to the document, so the page only scrolled when the
 * pointer was over the scrollbar, which belongs to <html>. Everywhere else the
 * wheel died on <body>. Tested against the live site: removing
 * overscroll-behavior fixes it, from any point on the page.
 *
 * Icons still drift off both edges by design; <html> clips that.
 */
html {
  overflow-x: hidden;
}

/*
 * No scrollbar. The page is a picture; a grey bar down the side of it is
 * furniture. Only the bar goes — the wheel, trackpad, touch, arrow keys and
 * Page Down all still scroll, which is only true because of the rule above.
 */
html,
body {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

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

/*
 * The stage is the whole video, at its own shape, however tall that makes the
 * page. Scrolling walks down the footage; the icons live inside the stage, so
 * they travel with it and stay where they were left relative to the water.
 *
 * min-height keeps a tall narrow window — a phone held upright — filled: there
 * the frame is already taller than it is wide, so the stage stops at one
 * screen and the sides are cropped instead. Nothing to scroll, because there
 * is nothing further down to see.
 */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.backdrop,
.backdrop-veil {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.backdrop {
  object-fit: cover;
  object-position: center;
  /* Sits behind everything, and is never a tab stop. */
  z-index: 0;
  pointer-events: none;
}

/* A slight darkening so pale icons stay legible over bright footage. */
.backdrop-veil {
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    rgba(6, 10, 18, 0.15) 0%,
    rgba(6, 10, 18, 0.45) 100%
  );
}

/*
 * Exactly the stage, so JavaScript can read one element to know how tall the
 * world is and let the fish swim all of it.
 *
 * No z-index, on purpose. With one, the field would be a single layer and
 * everything in it would sit on the same side of the windows. Without it,
 * each piece is layered on its own: most at 2, behind the windows at 10, and
 * the nearest at 11, in front of them (.koi-layer.is-front, .koi.is-near).
 */
.field {
  position: absolute;
  inset: 0;
}

/* ------------------------------------------------------------- colophon --- */

/*
 * At the foot of the video, so it arrives when you reach the bottom rather
 * than sitting over the picture the whole time. pointer-events: none keeps it
 * from swallowing a click on an icon drifting underneath.
 */
.colophon {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1.4rem;
  z-index: 3;
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(242, 240, 234, 0.62);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}

/* ------------------------------------------------------------- wordmark --- */

/*
 * Fixed to the middle of the window, so it holds still while the footage and
 * the icons scroll past it. A third of the window wide, matching the design. The clamp keeps it from
 * becoming unreadable on a phone or absurd on an ultrawide monitor.
 *
 * pointer-events: none matters: without it the wordmark would swallow clicks
 * on any icon drifting underneath it.
 */
.wordmark {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  width: clamp(220px, 33.3vw, 720px);
  /* Below the icons, so they still drift across the front of it. */
  z-index: 1;
  pointer-events: none;
}

.wordmark img {
  display: block;
  width: 100%;
  height: auto;
}

/* ------------------------------------------------------------------ koi --- */

/*
 * The fish are drawn by js/fish.js on two canvases the size of the browser
 * window, fixed to it: one under the windows and one over them, so the
 * nearest third of the fish swim in front of any open window and the rest
 * behind. Neither ever takes the pointer; js/fish.js matches the pointer against
 * the drawn bodies itself.
 *
 * The field has no z-index of its own, so these z-indexes are weighed
 * against the windows' 10 rather than shut inside the field.
 */
.koi-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.koi-layer.is-front {
  z-index: 11;
}

/*
 * Each fish's button: invisible, the size of a fingertip, centred on the
 * head and moved there every frame. It is for the keyboard and screen
 * readers, and holds the name that appears beside the head; the pointer
 * passes straight through it.
 */
.koi {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  pointer-events: none;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}

.koi[hidden] {
  display: none;
}

.koi.is-near {
  z-index: 11;
}

/* The pointer is over a fish, wherever it is: a hand, even above a window. */
html.is-over-koi,
html.is-over-koi * {
  cursor: pointer !important;
}

.koi:focus {
  outline: none;
}

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

/*
 * The name, beside the head on the side the fish is heading, so it is not
 * written over the body. Shown while the fish is pointed at, focused or
 * playing. js/fish.js sets --koi-name from the fish's depth.
 */
.koi-name {
  position: absolute;
  top: 50%;
  left: 100%;
  margin-left: 4px;
  transform: translateY(-50%);
  font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  font-size: var(--koi-name, 22px);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0;
  text-transform: lowercase;
  white-space: nowrap;
  color: #ffffff;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}

.koi.is-left .koi-name {
  left: auto;
  right: 100%;
  margin: 0 4px 0 0;
}

.koi.is-named .koi-name {
  opacity: 1;
}

/* The name takes the fish's colour when it has one: playing, or found by a
   search. Playing wins, since it is the more urgent news. */
.koi.is-match .koi-name {
  color: var(--match);
}

.koi.is-playing .koi-name {
  color: var(--accent);
}

/* -------------------------------------------------------------- phrases --- */

/*
 * A floating phrase is words, not a fish, and it is always readable: nothing
 * opens on hover because there is nothing hidden. It is set lighter and in
 * sentence case so it reads as a voice passing by rather than another title.
 * The slashes in front are from the mark, small. Positioned by its right
 * edge (see the translateX(-100%) in js/words.js).
 */
.phrase {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: calc(var(--icon-size) * 0.16);
  white-space: nowrap;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 2px 7px rgba(0, 0, 0, 0.6));
}

.phrase.is-near {
  z-index: 11;
}

.phrase svg {
  display: block;
  fill: currentColor;
}

.phrase:focus {
  outline: none;
}

.phrase:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.phrase-slashes svg {
  height: calc(var(--icon-size) * 0.3);
  width: calc(var(--icon-size) * 0.3744);
}

.phrase-text {
  font-family: "Arial Narrow", "Helvetica Neue", "TeX Gyre Heros Cn",
    "Liberation Sans Narrow", Helvetica, Arial, sans-serif;
  font-stretch: condensed;
  /* Capped by the window, so a whole question still fits across a phone. */
  font-size: min(calc(var(--icon-size) * 0.46), 5.4vw);
  font-style: italic;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.03em;
  /* An underline that draws itself in on hover, from the slashes outwards. */
  background: linear-gradient(currentColor, currentColor) left bottom / 0 1px no-repeat;
  padding-bottom: 0.18em;
  transition: background-size 320ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

.phrase:hover,
.phrase:focus-visible {
  color: var(--accent);
}

.phrase:hover .phrase-text,
.phrase:focus-visible .phrase-text {
  background-size: 100% 1px;
}

/*
 * The phrase anchored under the title. Its starting place is the wordmark's
 * centre (half the window down, since the wordmark is fixed there) plus half
 * the wordmark's height plus a gap. The wordmark's width is the same clamp as
 * .wordmark, and 0.0777 is half the logo's height-to-width ratio (234/1505/2).
 * It is absolute inside the stage, so it scrolls away with the footage.
 *
 * The loop is 29 seconds: fade in over 4, hold for 15, fade out over 4, stay
 * gone for 6. As percentages of 29 s: 4 s = 13.79%, 19 s = 65.52%,
 * 23 s = 79.31%. visibility goes with opacity so an invisible button cannot
 * be clicked or tabbed to.
 *
 * Set in DM Mono, with a block cursor blinking after it as if someone has
 * just typed the question. Text and cursor sit at 75% and come up to full on
 * hover; that lives on the inner span so it never fights the fade, which is
 * on the button itself.
 */
.phrase-anchored {
  position: absolute;
  left: 50%;
  /* Until js/words.js measures it, assume a typical width so the first frame is
     close to centred. */
  --rest-width: 21em;
  top: calc(50vh + clamp(220px, 33.3vw, 720px) * 0.0777 + 1.4rem);
  top: calc(50dvh + clamp(220px, 33.3vw, 720px) * 0.0777 + 1.4rem);
  /*
   * Pinned by the right edge, so the cursor holds still as typing makes the
   * line longer: -100% puts the right edge on `left`, and half the resting
   * width brings it back to centred when nothing is typed.
   */
  transform: translateX(calc(-100% + var(--rest-width) / 2));
  z-index: 3;
  padding: 0.4rem 0.6rem;
  border: 0;
  background: none;
  color: #ffffff;
  font-family: "DM Mono", ui-monospace, Menlo, Consolas, monospace;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(15px, 1.35vw, 22px);
  letter-spacing: 0;
  text-transform: lowercase;
  white-space: nowrap;
  cursor: pointer;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
  -webkit-tap-highlight-color: transparent;
  animation: phrase-breath 29s linear infinite;
}

/* Holds where it is while it is pointed at, so it never fades out from under
   someone who is about to click it. */
.phrase-anchored:hover,
.phrase-anchored:focus-visible {
  animation-play-state: paused;
}

.phrase-anchored-inner {
  opacity: 0.75;
  transition: opacity 200ms ease;
}

.phrase-anchored:hover .phrase-anchored-inner,
.phrase-anchored:focus-visible .phrase-anchored-inner {
  opacity: 1;
}

/*
 * While someone is typing the question stays fully visible: the breathing
 * loop stops, and starts again from nothing once the line is sent or cleared.
 */
.phrase-anchored.is-typing {
  animation: none;
  opacity: 1;
  visibility: visible;
}

.phrase-anchored.is-typing .phrase-anchored-inner {
  opacity: 1;
}

/* What they typed: upright, so it reads as their voice next to the
   question's italic. */
.phrase-typed {
  display: inline-block;
  font-style: normal;
}

.phrase-typed:not(:empty) {
  margin-left: 0.6em;
}

/* The quiet answer when a search finds nothing. */
.phrase-anchored.is-empty .phrase-typed {
  opacity: 0.6;
  font-style: italic;
}

.phrase-anchored.is-sent .phrase-typed {
  opacity: 0;
  transform: translateY(-0.6em);
  transition: opacity 1.2s ease, transform 1.2s ease;
}

/* The field that actually receives the keys. Present for the keyboard and
   screen readers, invisible on screen. */
.phrase-input {
  position: absolute;
  left: 50%;
  top: 50vh;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.phrase-caret {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 0.2em;
  vertical-align: -0.2em;
  background: currentColor;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
  animation: caret-blink 1.1s steps(1) infinite;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.phrase-anchored:focus {
  outline: none;
}

.phrase-anchored:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 4px;
}

@keyframes phrase-breath {
  0% {
    opacity: 0;
    visibility: visible;
  }
  13.79% {
    opacity: 1;
  }
  65.52% {
    opacity: 1;
  }
  79.31% {
    opacity: 0;
    visibility: visible;
  }
  79.32%,
  100% {
    opacity: 0;
    visibility: hidden;
  }
}

/* -------------------------------------------------------------- windows --- */

/*
 * Windows from someone else's computer: paper, a hairline of near-black, a
 * title bar ruled in the album's blue, and a close box in the corner. Only
 * the window in front has its stripes; the ones behind go plain, which is how
 * an old desktop tells you which window is listening.
 *
 * The layer covers the whole stage, so windows scroll with the footage like
 * the icons do. It lets the pointer through, so the icons drifting underneath
 * it stay clickable everywhere a window is not.
 */
.windows {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.win {
  --win-ink: #242424;
  --win-paper: #f9fbf8;
  --win-blue: #3b5683;
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  min-height: 120px;
  background: var(--win-paper);
  color: var(--win-ink);
  border: 1px solid var(--win-ink);
  box-shadow: 2px 2px 0 rgba(36, 36, 36, 0.85), 0 18px 40px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  /* Opacity is set by js/windows.js from the window's place in the stack. */
  transition: opacity 300ms ease;
  animation: win-in 180ms ease-out;
}

/* Gone means gone: no pointer, no keyboard, from the moment it starts to go. */
.win.is-gone {
  pointer-events: none;
  visibility: hidden;
  transition: opacity 300ms ease, visibility 0s linear 300ms;
}

@keyframes win-in {
  from {
    transform: translateY(6px) scale(0.97);
  }
}

.win-bar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  height: 22px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--win-ink);
  cursor: grab;
  /* The bar is a drag handle, so a finger on it must not scroll the page. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.win.is-front .win-bar {
  background-image: repeating-linear-gradient(
    to bottom,
    var(--win-blue) 0 1px,
    transparent 1px 3px
  );
  background-clip: content-box;
  background-origin: content-box;
}

.win.is-dragging .win-bar {
  cursor: grabbing;
}

.win-close {
  position: relative;
  z-index: 1;
  flex: none;
  width: 13px;
  height: 13px;
  padding: 0;
  border: 1px solid var(--win-ink);
  background: var(--win-paper);
  /* A gap of paper around the box, cut out of the stripes. */
  box-shadow: 0 0 0 3px var(--win-paper);
  cursor: pointer;
}

/* The box is drawn small, as it was, but a finger gets a fair-sized target. */
.win-close::after {
  content: "";
  position: absolute;
  inset: -12px;
}

.win-close:hover,
.win.is-front .win-close:focus-visible {
  background: var(--accent);
  outline: none;
}

.win-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 60px);
  padding: 0 8px;
  background: var(--win-paper);
  font-family: "DM Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  text-transform: lowercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.win:not(.is-front) .win-title {
  color: rgba(36, 36, 36, 0.55);
}

.win-body {
  position: relative;
  /* Grows and shrinks with the window. The basis is auto, not 0, so that the
     height js/windows.js gives it while measuring the opening size is honoured. */
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Contain, not cover: a picture someone left on their computer is shown
   whole, however the window is pulled about. */
.win-body img,
.win-body video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.win-body video {
  background: var(--win-ink);
}

/* Spotify's and Bandcamp's players, and Instagram posts. */
.win-body iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Several posts, one under another, scrolled inside the window. */
.win-body-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.win-body-scroll iframe {
  height: 560px;
}

.win-body-scroll iframe + iframe {
  border-top: 1px solid var(--win-ink);
}

.win-status a {
  color: inherit;
  text-underline-offset: 2px;
}

.win-status a:hover,
.win-status a:focus-visible {
  background: var(--accent);
  outline: none;
}

/* While a window is being dragged, a video inside must not catch the pointer. */
.win.is-dragging .win-body {
  pointer-events: none;
}

.win-flip {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.win-flip:focus {
  outline: none;
}

.win-flip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -4px;
}

.win-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 18px;
  padding-left: 8px;
  border-top: 1px solid var(--win-ink);
  font-family: "DM Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.02em;
  user-select: none;
  -webkit-user-select: none;
}

/* Three diagonal rules in the corner: the grip you drag to resize. */
.win-grip {
  align-self: stretch;
  width: 18px;
  cursor: nwse-resize;
  touch-action: none;
  background: linear-gradient(
    135deg,
    transparent 0 52%,
    var(--win-ink) 52% 58%,
    transparent 58% 68%,
    var(--win-ink) 68% 74%,
    transparent 74% 84%,
    var(--win-ink) 84% 90%,
    transparent 90%
  );
}

::selection {
  background: var(--accent);
  color: #242424;
}

/* Fingers need more to hold on to than a mouse does. */
@media (pointer: coarse) {
  .win-bar {
    height: 30px;
  }
  .win-foot {
    height: 26px;
  }
  .win-grip {
    width: 26px;
  }
}

/* --------------------------------------------------------- other states --- */

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

.noscript {
  position: relative;
  z-index: 3;
  max-width: 32rem;
  margin: 18vh auto;
  padding: 0 1.5rem;
  text-align: center;
  line-height: 1.7;
}

.noscript a {
  color: var(--accent);
}

.noscript img {
  max-width: 100%;
  height: auto;
}

.noscript ul,
.noscript ol {
  padding: 0;
  list-style-position: inside;
}

@media (max-width: 640px) {
  :root {
    --icon-size: 42px;
  }
}

/*
 * Anyone who has asked their system to reduce motion gets slower fish that
 * do not breathe (js/fish.js), and windows and a question that do not animate.
 */
@media (prefers-reduced-motion: reduce) {
  /* The wordmark sits low, out of the way, as it always has in this mode;
     the question below is placed to match. */
  .wordmark {
    top: auto;
    bottom: 8vh;
    transform: translateX(-50%);
  }
  .koi-name {
    transition: none;
  }
  .win,
  .win.is-gone {
    animation: none;
    transition: none;
  }
  /* No fading for anyone who asked for less motion: the question simply
     stays, just above the wordmark, which this mode moves to the bottom. */
  .phrase-caret {
    animation: none;
  }
  .phrase-anchored {
    animation: none;
    top: calc(92vh - clamp(220px, 33.3vw, 720px) * 0.1555 - 2.6rem);
  }
}
