/* SPDX-License-Identifier: GPL-3.0-or-later */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5c6370;
  --border: #e2e5ec;
  --accent: #6d5efc;
  --accent-2: #38bdf8;
  --badge-source-bg: #e8e6ff;
  --badge-source-fg: #4c3fd6;
  --badge-match-bg: #dcf5e7;
  --badge-match-fg: #157347;
  --badge-search-bg: #eef0f4;
  --badge-search-fg: #5c6370;
  --shadow: 0 1px 2px rgb(20 22 30 / 5%), 0 8px 24px rgb(20 22 30 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #191c22;
    --text: #eceef2;
    --muted: #9aa3b2;
    --border: #2a2e37;
    --accent: #8b7dff;
    --accent-2: #38bdf8;
    --badge-source-bg: #2c2854;
    --badge-source-fg: #b8aeff;
    --badge-match-bg: #123527;
    --badge-match-fg: #5fd39a;
    --badge-search-bg: #23262e;
    --badge-search-fg: #9aa3b2;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
  }
}

* { box-sizing: border-box; }

/* Specific display rules (e.g. #track { display: flex }) must not defeat
   the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  max-width: 44rem;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.55;
}

header { text-align: center; margin-bottom: 2rem; }

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3rem);
  letter-spacing: -0.03em;
  font-weight: 800;
}

.logo-accent {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline { margin: 0.4rem 0 0; color: var(--muted); }

#link-input {
  width: 100%;
  padding: 1rem 3.1rem 1rem 1.2rem;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  outline: none;
  transition: border-color 0.15s;
}

#link-input:focus { border-color: var(--accent); }

.input-wrap { position: relative; }

/* The magnifier inside the main input — the visible commit for a search. */
.input-btn {
  position: absolute;
  top: 50%;
  right: 0.55rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 0.7rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.input-btn:hover {
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.opener {
  margin: 0.55rem 0.2rem 0;
  padding: 0;
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
}

.opener:hover { color: var(--accent); }

@keyframes spin { to { transform: rotate(360deg); } }

/* Status area: three single-owner lines — #status (phase/outcome),
   #note (source caveats), #suggest (artist chips). */
.line {
  margin: 0.8rem 0.2rem 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.line + .line { margin-top: 0.3rem; }

.line[data-tone='warn'] { color: #c07a1c; }

/* Animated ellipsis while a lookup phase is running. Browsers without
   content animation keep the static fallback dots. */
.line[data-busy]::after {
  display: inline-block;
  width: 1.1em;
  text-align: left;
  content: '...';
  animation: dots 1.2s steps(1, end) infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* A turning hourglass while a throttled MusicBrainz call is being retried.
   It marks a real request in flight — there is no countdown behind it,
   because MusicBrainz sends no Retry-After and its window is one second. */
.line[data-busy='retry']::before {
  display: inline-block;
  margin-right: 0.4em;
  content: '⌛';
  animation: hourglass 3s ease-in-out infinite;
}

/* A real hourglass is turned over, not spun: it rests, flips, rests. A
   continuous rotation reads as a generic spinner and sits skewed most of
   the time. Two half-turns per cycle end upright again. */
@keyframes hourglass {
  0%, 40% { transform: rotate(0deg); }
  50%, 90% { transform: rotate(180deg); }
  100% { transform: rotate(360deg); }
}

/* "Try again" next to the throttle warning: a button, not a wait. */
.note-action {
  margin-left: 0.5em;
  padding: 0.1rem 0.5rem;
  font: inherit;
  font-size: 0.86rem;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 999px;
  cursor: pointer;
}

.note-action:hover { background: rgb(192 122 28 / 0.12); }

@media (prefers-reduced-motion: reduce) {
  .line[data-busy]::after { animation: none; }
  /* The hourglass still marks the retry — it just stops turning. */
  .line[data-busy='retry']::before { animation: none; }
}

/* One-click artist suggestions inside the status line */
.chip {
  padding: 0.14rem 0.55rem;
  margin: 0.1rem 0;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text);
  background: var(--badge-search-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

#track {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-top: 1.4rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow);
}

#thumb {
  width: 4.5rem;
  height: 4.5rem;
  object-fit: cover;
  border-radius: 0.6rem;
  flex-shrink: 0;
}

.track-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.75rem;
  align-items: center;
  flex: 1;
}

.track-fields label { font-size: 0.85rem; color: var(--muted); }

.track-fields input {
  width: 100%;
  padding: 0.45rem 0.7rem;
  font-size: 0.98rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  outline: none;
}

.track-fields input:focus { border-color: var(--accent); }

/* Top-track context under the artist field (artist sessions only). */
#topsongs {
  grid-column: 2;
  margin: -0.15rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

#results { margin-top: 1.6rem; }

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.7rem;
}

/* Wrapping, because the three buttons together are wider than a 320px
   screen and pushed the page into horizontal scroll. */
.results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.track-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-self: center;
}

#kind-toggle { display: flex; }

.kind-btn {
  flex: 1;
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.kind-btn:first-child { border-radius: 0.55rem 0 0 0.55rem; }
.kind-btn:last-child { border-radius: 0 0.55rem 0.55rem 0; }
.kind-btn + .kind-btn { border-left: none; }

.kind-btn[aria-pressed='true'] {
  color: var(--badge-source-fg);
  background: var(--badge-source-bg);
  border-color: var(--accent);
}

.btn-go {
  gap: 0.35rem;
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.btn-go:hover { filter: brightness(1.08); }

/* Narrow screens: the action column moves below the fields as a row. */
@media (max-width: 34rem) {
  .track-actions {
    flex-direction: row;
    flex-wrap: wrap;
    flex-basis: 100%;
  }

  .track-actions > * { flex: 1; }

  /* One column here, so cards are as narrow as they ever get. Measured:
     a four-button card (Preview + App + Open + Copy) needs these tighter
     paddings to stay on one line down to a 320px viewport — otherwise
     exactly the cards that have an app link grow a second row and stick
     out of the grid. */
  .card-actions {
    gap: 0.45rem 0.3rem;
  }

  .card-actions .btn {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}

.results-head h2 { margin: 0; font-size: 1.1rem; }

#cards {
  display: grid;
  /* min() so the track can fall below 19rem instead of overflowing the
     page: on a 320px screen the container is ~276px and a bare 19rem
     minimum pushed the whole grid into horizontal scroll. */
  grid-template-columns: repeat(auto-fill, minmax(min(19rem, 100%), 1fr));
  gap: 0.6rem;
}

.card {
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  box-shadow: var(--shadow);
}

.card-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.7rem;
}

.card-row .card-body {
  min-width: 7rem;
}

/* Actions sit on their own line so every card is the same height whether
   or not it has a Preview or App button. Preview is pushed left because it
   loads third-party content; the primary trio stays on the right edge, so
   Open sits in the same place on every card. */
.card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.45rem 0.5rem;
  margin-top: 0.6rem;
}

.card-actions .btn-preview {
  margin-right: auto;
}

.embed-slot {
  margin-top: 0.7rem;
}

.embed-slot iframe {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0.6rem;
}

.icon {
  width: 1.4rem;
  height: 1.4rem;
  flex-shrink: 0;
  color: var(--text);
}

.icon-monogram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.05rem;
  border: 2px solid currentColor;
  border-radius: 0.35rem;
}

.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.card-name { font-weight: 600; font-size: 0.95rem; }

/* Per-card activity: spins while a pipeline stage could still upgrade
   this card to an exact match. */
.card[data-pending] .card-name::after {
  content: '';
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: 0.4rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: middle;
  animation: spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .card[data-pending] .card-name::after {
    animation: none;
    border-color: var(--accent);
    opacity: 0.5;
  }
}

.badge {
  align-self: flex-start;
  padding: 0.05rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 99px;
}

.badge-source { background: var(--badge-source-bg); color: var(--badge-source-fg); }
.badge-match { background: var(--badge-match-bg); color: var(--badge-match-fg); }
.badge-search { background: var(--badge-search-bg); color: var(--badge-search-fg); }

/* inline-flex with an explicit line-height, because these are a mix of
   <a> and <button>: left to their defaults the anchors inherit the body
   line-height and end up several pixels taller than the buttons sitting
   right next to them. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.42rem 0.8rem;
  font-size: 0.85rem;
  line-height: 1.25;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover { border-color: var(--accent); }

/* Transparent border, not none — a missing border would make this button
   2px shorter than its neighbours. */
.btn-open {
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.btn-open:hover { filter: brightness(1.08); }

/* A real alternative to Open, not an afterthought: accent outline so it
   reads as a peer, filled Open stays the primary. */
.btn-app {
  color: var(--accent);
  border-color: var(--accent);
}

.btn-app:hover { background: var(--badge-source-bg); }

/* The reset action must be findable at a glance: accent outline, calm fill. */
.btn-next {
  gap: 0.35rem;
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}

.btn-next:hover { background: var(--badge-source-bg); }

.legend {
  margin-top: 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.about {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.about h2 { font-size: 1rem; margin-bottom: 0.4rem; }
.about p { font-size: 0.92rem; color: var(--muted); margin: 0; }

footer {
  margin-top: 3rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
