/* ==========================================================
   Theme variables
   Declared on <body> because JavaScript overrides the three
   colours there for each era. The derived colours must live on
   the same element so they are recalculated with the new values.
   ========================================================== */
body {
  --bg: #111111;
  --text: #f2f2f2;
  --accent: #e5e5e5;

  /* Derived colours, so each era only needs to set three values */
  --muted: color-mix(in srgb, var(--text) 75%, var(--bg));
  --line: color-mix(in srgb, var(--text) 18%, var(--bg));

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --gap: 1.5rem;
  --tap: 2.75rem; /* minimum size of touch targets (44px) */
  --fade: 0.6s ease; /* speed of the colour change between eras */
}

/* ==========================================================
   Base
   ========================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  transition: background-color var(--fade), color var(--fade);
}

/* Elements with their own theme colours fade along with the body.
   (Elements that just inherit the body's colour fade automatically.) */
.logo span,
.era-button,
.view-toggle,
.favourite-button,
.track-album,
.tracks-header,
.status,
.album-year,
.album-description,
.volume,
.section-title,
.track,
.track-icon,
.track-name,
.track-time,
.site-footer {
  transition: color var(--fade), background-color var(--fade), border-color var(--fade);
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* Visible focus ring for keyboard users */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* Hidden until focused with the keyboard */
.skip-link {
  position: absolute;
  z-index: 1;
  left: 1rem;
  top: -4rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.skip-link:focus {
  top: 1rem;
}

/* Loading and error messages */
.status {
  margin: 0;
  color: var(--muted);
}

.status:not(:empty) {
  padding-block: 0.75rem;
}

/* Shared style for the pill-shaped buttons */
.era-button,
.view-toggle {
  min-height: var(--tap);
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  white-space: nowrap;
}

.era-button:hover,
.view-toggle:hover {
  border-color: var(--accent);
}

.era-button[aria-pressed="true"],
.view-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

/* ==========================================================
   Header
   ========================================================== */
.site-header {
  padding: var(--gap) 1rem 0;
}

.logo {
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.logo span {
  color: var(--accent);
}

.era-list {
  display: flex;
  gap: 0.5rem;
  /* Padding leaves room for the focus ring, which overflow would cut off;
     the negative margin keeps the buttons aligned with the logo */
  margin: 0.5rem -0.5rem 0;
  padding: 0.5rem;
  list-style: none;
  overflow-x: auto; /* horizontal scroll on small screens */
}

/* ==========================================================
   Main layout (mobile first: one column, centred)
   ========================================================== */
.layout {
  display: grid;
  gap: calc(var(--gap) * 2);
  padding: var(--gap) 1rem;
}

.album {
  display: grid;
  gap: var(--gap);
  justify-items: center;
  text-align: center;
}

/* ---------- Vinyl record ---------- */
.cover-wrap {
  position: relative; /* Ned is positioned relative to this box */
  width: min(100%, 20rem);
}

.cover {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--line);
  overflow: hidden;
  box-shadow: 0 1.5rem 3rem rgb(0 0 0 / 0.35);
  /* Always "spinning", but paused until music plays */
  animation: spin 12s linear infinite;
  animation-play-state: paused;
}

/* JavaScript adds .is-spinning while a preview is playing */
.cover.is-spinning {
  animation-play-state: running;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

.cover img {
  transition: opacity 0.4s ease;
}

/* Hidden while the new era's cover downloads, then fades in */
.cover img.is-loading {
  opacity: 0;
}

/* Grooves: thin dark rings over the artwork */
.cover::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0 3px, rgb(0 0 0 / 0.07) 3px 4px);
}

/* Centre hole, in the page colour so it looks cut out */
.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 12%;
  height: 12%;
  margin: auto;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 0 0 0.5rem rgb(0 0 0 / 0.25);
  transition: background-color var(--fade);
}

/* ---------- Ned: peeks out from the corner of the record ---------- */
.ned {
  position: absolute;
  right: -4%;
  bottom: -2%;
  width: 28%;
  padding: 0;
  border: 0;
  border-radius: 1rem;
  background: none;
  /* Gentle floating, so it looks alive and invites a click */
  animation: float 3s ease-in-out infinite;
  transition: transform 0.2s ease;
}

.ned img {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0.5rem 0.75rem rgb(0 0 0 / 0.35));
}

.ned:hover {
  transform: scale(1.08) rotate(-4deg);
}

.ned:disabled {
  cursor: default;
}

/* Hover greeting: a small speech bubble made only with CSS.
   ::before is the bubble with the text, ::after is its little tail. */
.ned::before,
.ned::after {
  position: absolute;
  opacity: 0;
  pointer-events: none; /* the greeting never gets in the way of clicks */
  transition: opacity 0.2s ease;
}

.ned::before {
  /* \A is a line break inside CSS content; white-space: pre keeps it */
  content: "Hello, I'm Ned!\A Click me to learn more about this era.";
  bottom: calc(100% + 0.6rem);
  right: 0;
  padding: 0.4rem 0.75rem;
  border-radius: 0.75rem;
  background: var(--text);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: left;
  white-space: pre;
  box-shadow: 0 0.5rem 1rem rgb(0 0 0 / 0.3);
}

.ned::after {
  content: "";
  bottom: calc(100% + 0.6rem - 0.5rem);
  right: 30%;
  border: 0.5rem solid transparent;
  border-top-color: var(--text);
  border-bottom: 0;
}

/* Shown on mouse hover and keyboard focus... */
.ned:hover::before,
.ned:hover::after,
.ned:focus-visible::before,
.ned:focus-visible::after {
  opacity: 1;
}

/* ...but not while Ned is telling the story, or before the eras load */
.ned[aria-expanded="true"]::before,
.ned[aria-expanded="true"]::after,
.ned:disabled::before,
.ned:disabled::after {
  display: none;
}

@keyframes float {
  50% {
    translate: 0 -0.4rem;
  }
}

/* ---------- Album text ---------- */
.album-year {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.15em;
}

.album-title {
  font-size: clamp(2.25rem, 10vw, 4.5rem);
  font-weight: 900;
  text-transform: uppercase;
}

.album-description {
  max-width: 40ch;
  margin-inline: auto;
  color: var(--muted);
}

/* ---------- Volume slider ---------- */
.volume {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.volume input {
  width: 9rem;
  accent-color: var(--accent); /* colours the native slider with the era accent */
  cursor: pointer;
}

.volume output {
  min-width: 4ch; /* keeps the width steady from 0% to 100% */
  font-variant-numeric: tabular-nums;
}

/* ==========================================================
   Track list
   ========================================================== */
.tracks-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.section-title {
  font-size: 0.875rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-title small {
  margin-left: 0.5rem;
  font-size: inherit;
  letter-spacing: normal;
  text-transform: none;
}

.view-toggle {
  font-size: 0.875rem;
}

.track-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.track {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--line);
  /* New rows slide in one after another; --i is the row index, set by JavaScript */
  animation: slide-in 0.4s ease both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

/* Progress bar: --progress goes from 0 to 1, set by JavaScript */
.track::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  transform: scaleX(var(--progress, 0));
  transform-origin: left;
  transition: transform 0.25s linear, background-color var(--fade);
}

.track-button {
  flex: 1;
  min-width: 0; /* lets long names wrap instead of pushing the row wider */
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 0;
  border: 0;
  background: none;
  text-align: left;
}

.track-icon {
  flex-shrink: 0;
  width: 2.5ch;
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.track-button:hover .track-name {
  color: var(--accent);
}

.track.is-current .track-icon,
.track.is-current .track-name {
  color: var(--accent);
  font-weight: 700;
}

/* Album name under the track name, only in the favourites list */
.track-album {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.track-time {
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.favourite-button {
  flex-shrink: 0;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
}

.favourite-button:hover {
  color: var(--text);
}

.favourite-button[aria-pressed="true"] {
  color: var(--accent);
}

/* ==========================================================
   Ned's speech bubble
   ========================================================== */
.bubble {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: 36%; /* just above Ned's head */
  width: min(100%, 22rem);
  padding: 1rem 1.25rem 0.5rem;
  border-radius: 1rem;
  /* Inverted theme colours: always readable and stands out from the page */
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 0.75rem 2rem rgb(0 0 0 / 0.35);
  text-align: left;
  cursor: pointer;
  transform-origin: bottom right;
  animation: pop-in 0.2s ease;
}

/* The little tail pointing down at Ned */
.bubble::after {
  content: "";
  position: absolute;
  right: 12%;
  bottom: -0.7rem;
  border: 0.75rem solid transparent;
  border-top-color: var(--text);
  border-bottom: 0;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
}

/* Both layers sit in the same grid cell, one on top of the other */
.bubble-text {
  display: grid;
  margin: 0;
  font-weight: 600;
  line-height: 1.5;
}

.bubble-text > span {
  grid-area: 1 / 1;
}

.bubble-full {
  visibility: hidden; /* takes up space, but isn't seen */
}

.bubble-actions {
  display: flex;
  justify-content: space-between;
}

.bubble-button {
  width: var(--tap);
  height: var(--tap);
  border: 0;
  background: none;
  color: inherit;
  font-size: 0.9rem;
}

/* The ▼ blinks when a line is complete, like in games */
.bubble.is-done .bubble-next {
  animation: blink 1s steps(2) infinite;
}

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

/* Hidden on screen but still read by screen readers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ==========================================================
   Footer
   ========================================================== */
.site-footer {
  padding: var(--gap) 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* ==========================================================
   Larger screens: cover on the left, tracks on the right
   ========================================================== */
@media (min-width: 50rem) {
  /* Full width: the side margins grow with the screen (4% of its width) */
  .site-header,
  .layout {
    padding-inline: clamp(2rem, 4vw, 5rem);
  }

  .layout {
    /* Left column as wide as the cover (50% of the window height),
       the track list takes all the remaining width */
    grid-template-columns: minmax(0, 50vh) minmax(0, 1fr);
    align-items: start;
    gap: clamp(3rem, 5vw, 6rem);
  }

  /* The album stays in view while the track list scrolls */
  .album {
    position: sticky;
    top: var(--gap);
    justify-items: start;
    text-align: left;
  }

  /* Fills its column, which is sized by the window height
     so the sticky column always fits on screen */
  .cover-wrap {
    width: 100%;
  }

  .album-title {
    font-size: clamp(2.25rem, 5vw, 6rem);
  }

  .album-description {
    margin-inline: 0;
  }
}

/* ==========================================================
   Reduced motion: no spinning, sliding or fading
   for people who asked their system for less movement
   ========================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
