/* Light theme by default; the dark theme swaps these. The <head> script sets
   data-theme before anything draws, from the saved choice or the device. */
:root {
  --gradient: linear-gradient(135deg, #ffe259, #ffa751);
  --ink: #3b2400;
  --box: rgba(255, 255, 255, 0.82);    /* countdown boxes */
  --panel: rgba(255, 255, 255, 0.88);  /* music player */
  --pop: #fff;                         /* volume pop-up */
  --track: rgba(59, 36, 0, 0.2);       /* empty part of sliders */
  --line: rgba(59, 36, 0, 0.12);
  --hover: rgba(255, 61, 129, 0.12);
  --current: #d6246a;                  /* the playing song in the list */
  --shadow: rgba(59, 36, 0, 0.25);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --gradient: linear-gradient(135deg, #3a3a40, #1f1f23);
  --ink: #f2f2f4;
  --box: rgba(44, 44, 49, 0.88);
  --panel: rgba(40, 40, 45, 0.92);
  --pop: #34343a;
  --track: rgba(255, 255, 255, 0.22);
  --line: rgba(255, 255, 255, 0.12);
  --hover: rgba(255, 255, 255, 0.1);
  --current: #ff7aae;
  --shadow: rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

/* script.js sets --bg-wide / --bg-tall (and the -dark pair) from background/.
   Only the picture for the current theme and screen shape gets downloaded;
   without one, the theme's gradient shows. */
body {
  background: var(--bg-wide, var(--gradient)) center / cover no-repeat;
  color: var(--ink);
  font-family: "Fredoka", system-ui, sans-serif;
  transition: color 0.3s;
  /* tapping for hearts shouldn't select text or pick up pictures */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

img { -webkit-user-drag: none; }

[data-theme="dark"] body { background-image: var(--bg-wide-dark, var(--gradient)); }

@media (max-aspect-ratio: 1/1) {
  body { background-image: var(--bg-tall, var(--gradient)); }
  [data-theme="dark"] body { background-image: var(--bg-tall-dark, var(--gradient)); }
}

/* ---------- theme switch ---------- */

.theme-switch {
  position: fixed;
  top: 14px;
  left: 50%;
  z-index: 4;
  translate: -50% 0;
  width: 64px;
  height: 32px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  background: linear-gradient(135deg, #8fd8ff, #3d9be9);
  box-shadow: 0 4px 14px var(--shadow);
  cursor: pointer;
  transition: background 0.35s;
}

[data-theme="dark"] .theme-switch { background: linear-gradient(135deg, #3b3b6b, #15152a); }

.theme-switch:focus-visible { outline: 3px solid #ff3d81; outline-offset: 3px; }

.theme-switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.35s cubic-bezier(0.5, 1.6, 0.5, 1), background 0.35s;
}

[data-theme="dark"] .theme-switch .knob {
  transform: translateX(32px);
  background: #e9e9f2;
}

.theme-switch svg {
  position: absolute;
  inset: 3px;
  width: 18px;
  height: 18px;
  transition: opacity 0.35s, transform 0.35s;
}

.theme-switch .sun { fill: #f5a300; }
.theme-switch .moon { fill: #5b5b8f; opacity: 0; transform: rotate(-90deg) scale(0.5); }
[data-theme="dark"] .theme-switch .sun { opacity: 0; transform: rotate(90deg) scale(0.5); }
[data-theme="dark"] .theme-switch .moon { opacity: 1; transform: none; }

/* ---------- flying screenshots ---------- */

/* Layers: page content (1) < hearts & flying pictures (2) < play button (3).
   The flyers never take clicks, so the button always works. */
#sky, #hearts {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.flyer {
  position: absolute;
  top: 0;
  left: 0;
  animation: fly var(--dur) linear forwards;
  will-change: transform;
}

@keyframes fly {
  from { transform: translate(var(--x0), var(--y0)) rotate(var(--r0)); }
  to   { transform: translate(var(--x1), var(--y1)) rotate(var(--r1)); }
}

.shot {
  display: block;
  max-width: 300px;
  max-height: 240px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(59, 36, 0, 0.25);
}

/* ---------- hearts ---------- */

.heart {
  position: absolute;
  bottom: -60px;
  left: var(--x);
  font-size: var(--size);
  animation: rise var(--dur) linear forwards;
}

.heart > span {
  display: block;
  animation: sway 2.4s ease-in-out infinite alternate;
}

@keyframes rise {
  0%   { transform: translateY(0); opacity: 0; }
  10%  { opacity: 0.9; }
  85%  { opacity: 0.9; }
  100% { transform: translateY(calc(-100vh - 120px)); opacity: 0; }
}

@keyframes sway {
  from { transform: translateX(-14px) rotate(-10deg); }
  to   { transform: translateX(14px) rotate(10deg); }
}

/* ---------- centre ---------- */

/* no z-index here, so its children can sit above or below the flyers */
main {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 16px 16px; /* room for the theme switch on top */
  pointer-events: none;
}

.pinned {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  transform: rotate(-1.5deg);
}

.pinned img {
  display: block;
  width: 100%;
  border-radius: 12px;
  border: 4px solid #fff;
  box-shadow: 0 12px 32px rgba(59, 36, 0, 0.3);
}

.pin {
  position: absolute;
  top: -16px;
  left: 50%;
  translate: -50% 0;
  font-size: 30px;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.25));
}

.countdown {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.countdown > div {
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--box);
  box-shadow: 0 6px 18px var(--shadow);
  text-align: center;
  transition: background 0.3s;
}

.countdown b {
  display: block;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.countdown span {
  font-size: 13px;
  opacity: 0.7;
}

.daily {
  position: relative;
  z-index: 1;
  max-width: min(460px, 100%);
  margin: 0;
  padding: 8px 16px;
  border-radius: 14px;
  background: var(--box);
  box-shadow: 0 6px 18px var(--shadow);
  font-size: 16px;
  text-align: center;
}

.daily[hidden] { display: none; }

/* hearts from a tap */
.burst {
  position: absolute;
  font-size: 22px;
  pointer-events: none;
}

.frame {
  position: relative;
  z-index: 1;
  /* leave room for the pinned message, countdown, button and footer */
  width: min(900px, 100%, calc((100dvh - 410px) * 16 / 9));
  min-width: 280px;
  aspect-ratio: 16 / 9;
  border-radius: 20px;
  overflow: hidden;
  background: #12002b;
  border: 6px solid #fff;
  box-shadow: 0 20px 60px rgba(59, 36, 0, 0.35);
}

.frame[hidden] { display: none; }

#player-video, #player-bg, #bars {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#player-video, #player-bg { object-fit: cover; }
#player-video[hidden], #player-bg[hidden] { display: none; }

/* soft shade at the bottom so the bars stand out on any gif */
.frame::after {
  content: "";
  position: absolute;
  inset: 50% 0 0 0;
  background: linear-gradient(transparent, rgba(18, 0, 43, 0.55));
  pointer-events: none;
}

#bars { z-index: 1; }

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

.player {
  position: relative;
  z-index: 3;
  width: min(460px, 100%);
  padding: 14px 18px 12px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 12px 32px var(--shadow);
  pointer-events: auto;
  transition: background 0.3s;
}

.player[hidden] { display: none; }

.track-title {
  text-align: center;
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.progress span { flex: none; min-width: 36px; opacity: 0.75; }
.progress span:last-child { text-align: right; }

/* Sliders: a clear 6px track that fills pink up to --fill (set by script.js),
   inside a 24px-tall box so they're easy to grab with a finger. */
.player input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 24px;
  margin: 0;
  background: linear-gradient(to right, #ff3d81 var(--fill, 0%), var(--track) var(--fill, 0%))
    center / 100% 6px no-repeat;
  border-radius: 3px;
  cursor: pointer;
}

.player input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #ff3d81;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.player input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #ff3d81;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.player input[type="range"]::-moz-range-track { background: transparent; }

.player input[type="range"]:focus-visible { outline: 3px solid #ff3d81; outline-offset: 2px; }

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.volume { position: relative; }

.volume-pop {
  position: absolute;
  bottom: calc(100% + 8px);
  left: -8px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 230px;
  padding: 6px 14px 6px 6px;
  border-radius: 16px;
  background: var(--pop);
  box-shadow: 0 8px 24px var(--shadow);
}

.volume-pop[hidden] { display: none; }

/* little arrow pointing at the speaker */
.volume-pop::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 22px;
  border: 8px solid transparent;
  border-top-color: var(--pop);
}

.volume-value {
  flex: none;
  min-width: 26px;
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

/* With a mouse there's room to keep the slider out all the time, so the
   pop-up's contents just sit in the row and the extra speaker button goes. */
@media (hover: hover) and (pointer: fine) {
  #volume-btn { display: none; }
  .volume-pop,
  .volume-pop[hidden] {
    position: static;
    display: flex;
    gap: 2px;
    width: auto;
    padding: 0;
    background: none;
    box-shadow: none;
  }
  .volume-pop::after, .volume-value { display: none; }
  .volume-pop input[type="range"] { flex: none; width: 76px; }
}

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
}

.list-toggle { justify-self: end; }

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover { background: var(--hover); }
.icon-btn:focus-visible { outline: 3px solid #ff3d81; outline-offset: 1px; }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn[aria-expanded="true"] { color: #ff3d81; }

.speaker .icon-muted { display: none; }
.speaker.muted .icon-sound { display: none; }
.speaker.muted .icon-muted { display: block; }

.playlist {
  max-height: min(28vh, 240px);
  margin: 10px 0 0;
  padding: 6px 0 0;
  border-top: 1px solid var(--line);
  list-style: none;
  overflow-y: auto;
}

.playlist[hidden] { display: none; }

.playlist button {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.playlist button:hover { background: var(--hover); }
.playlist .n, .playlist .d { opacity: 0.6; font-variant-numeric: tabular-nums; }
.playlist .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.playlist .current button { color: var(--current); font-weight: 700; }
.playlist .current .n { opacity: 1; }

#toggle {
  position: relative;
  flex: none;
  width: 64px;
  height: 64px;
  border: 4px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ff3d81, #7b2ff7);
  box-shadow: 0 10px 30px rgba(123, 47, 247, 0.45);
}

/* no grow-on-hover: scaling it mid-pulse drew thin lines for a moment */
#toggle:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

#toggle svg { width: 30px; height: 30px; fill: #fff; }
#toggle .icon-pause { display: none; }
#toggle.playing .icon-play { display: none; }
#toggle.playing .icon-pause { display: block; }

/* idle pulse to say "press me" */
#toggle:not(.playing) { animation: pulse 1.8s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 61, 129, 0.55); }
  50% { box-shadow: 0 0 0 14px rgba(255, 61, 129, 0); }
}

/* The YouTube player: real size (browsers may not play from a hidden speck),
   but invisible and out of the way. */
.audio-only {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 320px;
  height: 180px;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

.audio-only iframe {
  width: 100%;
  height: 100%;
  border: 0;
}


.footer {
  margin: 0;
  font-size: 14px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

@media (max-width: 600px) {
  main { gap: 12px; }
  .shot { max-width: 200px; max-height: 170px; }
  .countdown { gap: 6px; }
  main { padding-top: 56px; }
  .countdown > div { min-width: 0; flex: 1 1 28%; padding: 6px; }
  .countdown span { font-size: 11px; }
  .player { padding: 12px 12px 10px; }
  .transport { gap: 4px; }
  .volume-pop { width: min(230px, calc(100vw - 48px)); }
}

/* The theme switch keeps its little slide-and-bounce even here: it's short
   and only happens when someone flips it. */
@media (prefers-reduced-motion: reduce) {
  #toggle:not(.playing), .heart > span { animation: none; }
}
