/* Built for phones first. Colours and the font are set once here, so the look can be changed in one place. */
:root {
  /* A soft sage-mint surround, with the songs on a pale straw mat set into it. */
  --page: #92cfc3;
  --paper: #f4eed9;
  --ink: #1c1a12;
  --muted: #524d31;
  --line: rgba(70, 60, 10, 0.22);
  /* The frame round the heading: a warm brown, like the wooden edge of a mat. */
  --mat-edge: #8a6a3b;
  /* The edge of the floating bar at the bottom. */
  --edge: rgba(28, 26, 18, 0.3);
  /* Our two colours, used only for our initials: seal red for Mads, lapis blue for Sam. */
  --mads: #cf3a24;
  --sam: #1e50a2;
  --font: "ABC Areal", Arial, Helvetica, sans-serif;
}

/* The font file lives in assets/, so the phones get it too and nothing is fetched from another website. */
@font-face {
  font-family: "ABC Areal";
  src: url("assets/abc-areal-regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

/* The slanted cut, used only for the name of the player each song opens in. */
@font-face {
  font-family: "ABC Areal";
  src: url("assets/abc-areal-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* The heavier cut, used only for the title. */
@font-face {
  font-family: "ABC Areal";
  src: url("assets/abc-areal-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  /* The room at the bottom is for the bar pinned there. The side insets only matter with the phone turned sideways. */
  padding: 16px max(20px, env(safe-area-inset-right)) 96px max(20px, env(safe-area-inset-left));
  max-width: 640px;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.35;
  /* Only the regular weight is loaded, so the phone must not fake a bold. */
  font-synthesis: none;
  /* Long song titles wrap instead of pushing the page sideways. */
  overflow-wrap: anywhere;
  /* Stops iPhone Safari enlarging text when the phone is turned sideways. */
  -webkit-text-size-adjust: 100%;
}

/* Every button on the page is plain text with a thin line under it, like a link. Each stays 44px tall, the smallest comfortable size for a thumb. */
button,
.song-link,
.message-link,
.message-undo,
.unlock-link {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

button {
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  color: var(--muted);
  text-decoration: none;
}

.who-mads {
  color: var(--mads);
}

.who-sam {
  color: var(--sam);
}

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

/* ---- Header ---- */

/* Title on top; under it the song count on the left and whose phone this is on the right. */
/* The heading sits on its own rectangular mat with a thin brown frame and the faintest shadow. */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 5px;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--mat-edge);
  border-radius: 2px;
  background: var(--paper) url("assets/mat.svg") 0 0 / 8px 7px;
  box-shadow: 0 1px 4px rgba(28, 26, 18, 0.08);
}

/* Bold white letters with a red outline, sized from the screen's width so it always fits on one line. */
.site-title {
  margin: 0;
  color: #ffffff;
  font-size: min(4.7vw, 27px);
  font-weight: 700;
  line-height: 44px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  /* A fine outline, drawn behind the letters so it doesn't eat into them. */
  -webkit-text-stroke: 1.5px var(--mads);
  paint-order: stroke fill;
}

/* How many songs so far: a small raised number beside the title. */
.song-count {
  align-self: flex-start;
  margin: 8px 0 0;
  font-size: 12px;
}

/* Whose phone this is: their initial in a thin ring, like a name seal. Tap it to switch. */
.listener-badge {
  position: relative;
  width: 28px;
  height: 28px;
  min-height: 28px;
  margin-left: auto;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
}

/* Widens the area that answers a tap to 44px without making the ring bigger. */
.listener-badge::after {
  content: "";
  position: absolute;
  inset: -8px;
}

.listener-mads .listener-badge {
  color: var(--mads);
}

.listener-sam .listener-badge {
  color: var(--sam);
}

/* For visitors: the way in, on its own line under the title. */
.unlock-link {
  display: inline-flex;
  align-items: center;
  flex-basis: 100%;
  min-height: 44px;
  font-size: 14px;
}

/* ---- Who's listening? Asked once, then it shrinks to an initial in the corner. ---- */

.listener {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 0;
  padding: 0;
  border: 0;
}

.listener-title {
  float: left;
  padding: 0;
}

/* The real radio button is hidden; the name beside it is the thing to tap. */
.listener-choice {
  position: absolute;
  opacity: 0;
}

.listener-option span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
}

.listener-choice:checked + span {
  color: var(--ink);
}

.listener-choice:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ---- Add a song ---- */

/* ---- The bar pinned to the bottom of the screen ---- */

/* Holds the player while a song is playing, and always the line for adding a song. */
/* A white rounded box with a thin edge, floating a little above the mat and in from the screen's edges. */
.dock {
  position: fixed;
  /* Keeps clear of the iPhone's home bar. */
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  z-index: 2;
  /* A small box, centred, rather than one the full width of the screen. */
  max-width: 300px;
  margin: 0 auto;
  padding: 2px 14px;
  border: 1px solid var(--edge);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 6px 20px rgba(60, 50, 10, 0.14);
}

/* Visitors have no add box, so with nothing playing there is nothing to show. */
.dock:not(:has(.add-song)):has(.dock-player[hidden]) {
  display: none;
}

.dock-player {
  padding-top: 12px;
  border-bottom: 1px solid var(--line);
}

/* YouTube: a small video on the left, the song's name beside it. */
.dock-now-youtube {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.dock-title {
  min-width: 0;
  margin: 0;
}

.dock-song,
.dock-artist {
  display: block;
}

/* A long name is cut off after three lines. */
.dock-song {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.dock-artist {
  color: var(--muted);
  font-size: 13px;
}

/* Just added a song: the box widens to show it as it looks in the list, with the offer to send it on. */
.dock:has(.dock-share:not([hidden])) {
  max-width: 616px;
}

/* The add line steps aside until Done is tapped. */
.dock-inner:has(.dock-share:not([hidden])) .add-song {
  display: none;
}

.dock-share {
  padding: 4px 0 2px;
}

.dock-share-song .song-row {
  padding: 8px 0 10px;
}

/* "Send Sam?" is the one loud thing in the box: a full-width button in that person's colour. */
.share-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  border-radius: 10px;
  background: var(--ink);
  color: #ffffff;
  text-decoration: none;
}

.share-to-mads {
  background: var(--mads);
}

.share-to-sam {
  background: var(--sam);
}

.share-destination,
.share-status {
  margin: 8px 0 0;
}

/* The line to paste on, with Paste or Add at the end of it. */
.add-song-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* 16px text stops iPhone Safari zooming in when the box is tapped. */
.add-song-input {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  outline: none;
}

/* The hint is a little smaller than what gets typed. (The typed text stays 16px, or iPhones zoom in.) */
.add-song-input::placeholder {
  color: var(--muted);
  font-size: 14px;
  opacity: 1;
}

/* Paste is a small arrow rather than the word. */
.add-song-paste {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
}

.message {
  margin: 12px 0 0;
}

.message-link {
  margin-left: 6px;
}

/* "Removed ... Put it back" */
.message-removed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.message-undo {
  flex: none;
}

.empty {
  margin: 24px 0 0;
  color: var(--muted);
}

/* ---- All / Mads / Sam ---- */

/* Set in a little, in line with the words in the heading above. */
.filter {
  display: flex;
  gap: 20px;
  margin: 8px 0 0;
  padding-left: 16px;
}

/* All is black, Mads red and Sam blue. The one being shown is underlined. */
.filter-option {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-decoration: none;
  text-transform: uppercase;
}

.filter-option[data-sender="Mads"] {
  color: var(--mads);
}

.filter-option[data-sender="Sam"] {
  color: var(--sam);
}

.filter-option[aria-pressed="true"] {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* ---- The playlist: one unbroken list ---- */

/* The list sits in its own frame on the mat, with a thin line between every song. */
.songs {
  margin: 10px 0 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--edge);
  border-radius: 14px;
  /* Soft ribs, like the rush of a mat: one small drawing (assets/mat.svg) repeated down the list. */
  background: var(--paper) url("assets/mat.svg") 0 0 / 8px 7px;
  list-style: none;
}

.song + .song {
  border-top: 1px solid var(--line);
}

/* One song: artwork, title over artist and date, then on the right an M or S (top) and where it plays (bottom). */
.song-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  padding: 8px 12px;
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.song-row::-webkit-details-marker {
  display: none;
}

.song-row:active {
  background: rgba(70, 60, 10, 0.1);
}

.song-row:focus-visible {
  outline-offset: -2px;
}

.song-art {
  display: block;
  width: 44px;
  height: 44px;
  background: var(--line);
  object-fit: cover;
}

/* Long titles are cut short with "…" until the row is opened. */
.song-title,
.song-artist {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.song-details[open] .song-title,
.song-details[open] .song-artist {
  white-space: normal;
}

.song-artist,
.song-meta {
  color: var(--muted);
  font-size: 13px;
}

/* The M or S sits right in the row's top right corner and the player's name in the bottom right, with
   the length and date between them: the margins pull the lines out past the row's padding. */
.song-meta {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-self: stretch;
  margin: -5px -6px -4px 0;
  line-height: 1.2;
  text-align: right;
}

.song-playtime,
.song-sent {
  display: block;
}

/* The player a song opens in, in italics and that service's own colour. */
.song-service {
  font-size: 12px;
  font-style: italic;
}

/* The M or S keeps its place in the top corner even on a song with no sender. */
.song-sent {
  min-height: 1.35em;
}

/* The middle line: how long it runs, then, more quietly, when it was sent. */
.song-when {
  display: block;
}

.song-date {
  margin-left: 6px;
  opacity: 0.7;
}

.song-service-youtube {
  color: #ff0000;
}

.song-service-apple {
  color: #fa243c;
}

.song-service-soundcloud {
  color: #ff5500;
}

/* Spotify's green, a shade deeper so it can be read on the pale sheet. */
.song-service-spotify {
  color: #169c46;
}

/* Read out by screen readers, never shown. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- An opened song: the player, then its links ---- */

.song-more {
  padding: 0 12px;
}

.song-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 20px;
}

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

.song-remove-form {
  margin-left: auto;
}

.song-remove {
  color: var(--muted);
}

/* The "hidden" setting must win over the layout rules above. */
[hidden] {
  display: none !important;
}

/* Each person's own music service comes first. */
.listener-mads .song-link-apple,
.listener-sam .song-link-spotify {
  order: -1;
}

.song-player-frame {
  display: block;
  width: 100%;
  border: 0;
}

/* Kept small so the list stays in view. */
.song-player-youtube {
  flex: none;
  width: 200px;
  height: 113px;
}

/* Previous song / Next song / Close, under the player. */
.song-player-controls {
  display: flex;
  justify-content: space-between;
}

/* ---- The talk window: the question for visitors, and the card that hands over the link ---- */

/* Drawn like the talk window of an old role-playing game: a bold rounded edge, a thinner line just
   inside it, and a small hard shadow. */
.talk-window {
  position: relative;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 5px 0 rgba(28, 26, 18, 0.22);
}

.talk-window::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--ink);
  border-radius: 13px;
  pointer-events: none;
}

/* The "?" in the corner that opens the question. */
.riddle-toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-left: auto;
  border: 1px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  font-size: 14px;
  line-height: 1;
  text-decoration: none;
}

.riddle-toggle::after {
  content: "";
  position: absolute;
  inset: -8px;
}

/* The bubble drops down from the "?", with a little tail pointing back up at it. */
.riddle {
  position: fixed;
  top: 100px;
  right: max(12px, env(safe-area-inset-right));
  left: max(12px, env(safe-area-inset-left));
  z-index: 4;
  max-width: 420px;
  margin: 0 0 0 auto;
  padding: 16px 18px 8px;
  transform-origin: calc(100% - 40px) 0;
  transition: transform 0.26s cubic-bezier(0.2, 1.4, 0.4, 1), opacity 0.16s ease-out, visibility 0s;
}

.riddle::before {
  content: "";
  position: absolute;
  top: -9px;
  right: 30px;
  width: 14px;
  height: 14px;
  border-top: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
  border-top-left-radius: 3px;
  background: #ffffff;
  transform: rotate(45deg);
}

.riddle[data-open="false"] {
  visibility: hidden;
  opacity: 0;
  transform: translateY(-10px) scale(0.9);
  transition: transform 0.2s ease-in, opacity 0.16s ease-in, visibility 0s 0.2s;
}

/* A wrong answer makes the window shake its head. */
.riddle[data-state="wrong"] {
  animation: riddle-no 0.34s;
}

@keyframes riddle-no {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Room for two lines, so the window doesn't grow while the question is being typed out. */
.riddle-question {
  display: block;
  min-height: 2.7em;
  margin: 2px 0 6px;
  font-size: 18px;
  line-height: 1.35;
}

.riddle-reply {
  margin: 0 0 2px;
  color: var(--mads);
  font-size: 14px;
}

.riddle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--ink);
}

.riddle-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.riddle-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* The choices read like a game menu: a small arrow marks the one to pick. */
.riddle-answer,
.riddle-later {
  text-decoration: none;
}

.riddle-answer::before {
  content: "\25B6";
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  vertical-align: 1px;
  animation: talk-blink 1s steps(1) infinite;
}

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

.riddle-later {
  color: var(--muted);
  font-size: 14px;
}

/* Right answer: their own link, shown quietly in the same white bubble the question was in. */
.welcome {
  animation: welcome-in 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes welcome-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.9); }
}

.welcome-title {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* The link itself, on one line; the rest is cut off with "…" but all of it is copied. */
.welcome-link {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.welcome-copy[data-done="true"] {
  color: var(--mads);
}

@media (prefers-reduced-motion: reduce) {
  .riddle,
  .riddle[data-open="false"],
  .riddle[data-state="wrong"],
  .riddle-answer::before,
  .welcome {
    transition: none;
    animation: none;
  }
}
