/* ============ Town Bus Hits — the art carries the site ============ */

:root {
  --yellow: #d8b62c;
  --ink-cream: #f4efe2;
  /* liquid glass */
  --glass-bg: rgba(22, 22, 26, 0.44);
  --glass-border: rgba(255, 255, 255, 0.13);
  --glass-hi: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  --glass-blur: blur(22px) saturate(1.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans Tamil", sans-serif;
  overflow: hidden;
  background: #1d2430;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ============ STAGE (art + pinned overlays) ============ */

#stage { position: fixed; inset: 0; overflow: hidden; }
#stage img {
  position: absolute;
  user-select: none; -webkit-user-drag: none;
  /* a hair of overscan, so the sway below never shows an edge */
  transform: scale(1.014);
  will-change: transform;
}
/* staggered crossfade: the incoming frame leads, the outgoing one lingers
   a beat — no grey double-exposure midpoint */
#art-day   { transition: opacity 1.75s cubic-bezier(.42, 0, .2, 1) .12s; }
#art-night { transition: opacity 1.45s cubic-bezier(.42, 0, .2, 1); }
#art-night { opacity: 0; }
body.night #art-night { opacity: 1; }
body.night #art-day { opacity: 0; }
/* the bus rolls while a song is playing: an uneven road, not a metronome.
   The sway lives on the paintings, the engine judder on their container, so
   the two motions layer instead of overwriting each other. */
body.rolling #stage img { animation: bus-ride 3.1s ease-in-out infinite; }
@keyframes bus-ride {
  0%   { transform: scale(1.014) translateY(0)      rotate(0); }
  11%  { transform: scale(1.014) translateY(-1.7px) rotate(0.07deg); }
  24%  { transform: scale(1.014) translateY(0.9px)  rotate(-0.05deg); }
  36%  { transform: scale(1.014) translateY(-0.5px) rotate(0.03deg); }
  49%  { transform: scale(1.014) translateY(1.8px)  rotate(-0.08deg); }
  61%  { transform: scale(1.014) translateY(-1.2px) rotate(0.05deg); }
  74%  { transform: scale(1.014) translateY(0.6px)  rotate(-0.02deg); }
  87%  { transform: scale(1.014) translateY(-2px)   rotate(0.08deg); }
  100% { transform: scale(1.014) translateY(0)      rotate(0); }
}
body.engine #stage { animation: judder 0.09s linear infinite; }
@keyframes judder { 0%,100% { transform: translateY(0); } 50% { transform: translateY(0.7px); } }

/* film grain — sits over the painting, under the chrome */
#grain {
  position: fixed; inset: -100px; z-index: 6;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.07;
  mix-blend-mode: overlay;
  animation: grain-drift 0.9s steps(4) infinite;
}
@keyframes grain-drift {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-34px, 22px); }
  50% { transform: translate(18px, -41px); }
  75% { transform: translate(-47px, -14px); }
  100% { transform: translate(0, 0); }
}

/* hotspots — only the whistle advertises itself on hover */
.hotspot {
  position: absolute; z-index: 4; border-radius: 18px;
  -webkit-tap-highlight-color: transparent;
}
#hot-whistle::before {
  content: ""; position: absolute; inset: -6px; border-radius: 24px;
  background: radial-gradient(closest-side, rgba(255, 236, 170, 0.28), transparent 75%);
  opacity: 0; transition: opacity 0.3s;
}
#hot-whistle:hover::before, #hot-whistle:active::before, #hot-whistle:focus-visible::before { opacity: 1; }
.hotspot:focus-visible { outline: 2px solid rgba(255, 236, 170, 0.65); outline-offset: 4px; }
#hot-whistle::after {
  content: attr(data-label);
  position: absolute; left: 50%; bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: var(--glass-bg); color: var(--ink-cream);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  font-size: 12px; font-weight: 600; white-space: nowrap;
  padding: 5px 11px; border-radius: 999px;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
#hot-whistle:hover::after, #hot-whistle:active::after, #hot-whistle:focus-visible::after { opacity: 1; }
#hot-engine.on { box-shadow: inset 0 0 40px rgba(255, 220, 130, 0.25); }

/* debug outlines via #debug in the URL */
#stage.debug .hotspot { outline: 1.5px solid rgba(255, 80, 80, 0.75); }

/* ============ HEADER ============ */

header {
  position: fixed; z-index: 10;
  top: max(14px, env(safe-area-inset-top)); right: 16px;
  display: flex; align-items: flex-start; justify-content: flex-end;
  pointer-events: none;
}
header a, header button { pointer-events: auto; }

#links { display: flex; gap: 14px; align-items: center; }

/* naked brand glyphs — quiet until touched */
#links a {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  color: var(--ink-cream); opacity: 0.72;
  text-decoration: none;
  filter: drop-shadow(0 1px 6px rgba(8, 10, 16, 0.6));
  transition: opacity 0.25s, transform 0.25s, color 0.25s;
}
#links a:hover { opacity: 1; transform: translateY(-1px); }
#link-spotify:hover { color: #1ed760; }
#link-ytmusic:hover { color: #ff6b6b; }
#links a:focus-visible {
  opacity: 1; outline: 2px solid rgba(244, 239, 226, 0.7);
  outline-offset: 3px; border-radius: 50%;
}

/* ---- the day/night medallion: a glass lens holding the sun or moon ---- */
#daynight {
  position: relative; padding: 0;
  width: 46px; height: 46px; border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
#daynight:focus-visible { outline: 2px solid rgba(244, 239, 226, 0.7); outline-offset: 3px; }
.dn-halo {
  position: absolute; inset: -9px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 204, 92, 0.35), transparent 72%);
  opacity: 0.8; transition: opacity 1.4s cubic-bezier(.42, 0, .2, 1), background 1.4s cubic-bezier(.42, 0, .2, 1);
  animation: halo-breathe 5s ease-in-out infinite alternate;
}
body.night .dn-halo {
  background: radial-gradient(closest-side, rgba(146, 168, 255, 0.42), transparent 74%);
  opacity: 1;
}
@keyframes halo-breathe { from { transform: scale(1); } to { transform: scale(1.12); } }
.dn-glass {
  position: absolute; inset: 0; border-radius: 50%; overflow: hidden;
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(5px) saturate(1.2); -webkit-backdrop-filter: blur(5px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.35),
    inset 0 -6px 12px rgba(10, 12, 20, 0.25),
    0 4px 14px rgba(8, 10, 16, 0.35);
  transition: transform 0.9s cubic-bezier(.6,-0.15,.3,1.25);
}
#daynight:active .dn-glass { transform: scale(0.92); }
.dn-sun, .dn-moon {
  position: absolute; left: 50%; top: 50%;
  width: 22px; height: 22px; border-radius: 50%;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
  transition: opacity 1.15s cubic-bezier(.42, 0, .2, 1), transform 1.5s cubic-bezier(.42, 0, .2, 1);
}
.dn-sun {
  background:
    radial-gradient(circle at 34% 32%, #fff3c4 0%, #ffd864 42%, #f2a614 78%, #e08b00 100%);
  box-shadow: 0 0 10px rgba(255, 206, 84, 0.9), 0 0 22px rgba(255, 186, 40, 0.45);
}
.dn-moon {
  background:
    radial-gradient(circle 3.2px at 38% 34%, rgba(148, 140, 112, 0.55) 96%, transparent),
    radial-gradient(circle 2.1px at 62% 56%, rgba(148, 140, 112, 0.5) 96%, transparent),
    radial-gradient(circle 1.4px at 50% 74%, rgba(148, 140, 112, 0.45) 96%, transparent),
    radial-gradient(circle at 38% 32%, #fdf9e8 0%, #ece5c8 55%, #cfc7a5 100%);
  box-shadow: 0 0 10px rgba(240, 238, 214, 0.75), 0 0 24px rgba(178, 190, 255, 0.4);
  opacity: 0; transform: translate(-50%, -50%) rotate(-120deg) scale(0.55);
}
body.night .dn-sun { opacity: 0; transform: translate(-50%, -50%) rotate(120deg) scale(0.55); }
body.night .dn-moon { opacity: 1; transform: translate(-50%, -50%) rotate(0deg) scale(1); }

/* ============ PLAYER DOCK ============ */

#playerdock {
  position: fixed; z-index: 10; left: 0; right: 0;
  bottom: calc(34px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 0 14px; pointer-events: none;
}

/* liquid-glass player */
#dockrow {
  display: grid; align-items: stretch;
  grid-template-columns: 1fr min(680px, 100%) 1fr;
  gap: 14px; width: 100%;
}
#pill { grid-column: 2; }
#riders { grid-column: 3; justify-self: start; }
/* while YouTube is still waking up, the pill sits quietly instead of
   showing dashes and a dead 0:00 */
body.boarding #seekbox { opacity: 0.28; }
body.boarding #song-sub { opacity: 0.4; }
body.boarding #controls { opacity: 0.5; pointer-events: none; }
body.boarding #thumb { animation: thumbwait 1.6s ease-in-out infinite alternate; }
@keyframes thumbwait { from { opacity: 0.5; } to { opacity: 0.85; } }
#pill {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "thumb meta controls" "seek seek seek";
  align-items: center; gap: 6px 16px;
  width: 100%;
  background: var(--glass-bg);
  color: var(--ink-cream);
  border: 1px solid var(--glass-border);
  border-radius: 34px; padding: 16px 24px 15px;
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-hi), 0 18px 50px rgba(4, 6, 12, 0.42);
}
#thumb {
  grid-area: thumb; width: 54px; height: 54px;
  border-radius: 15px; object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.09);
}
#meta { grid-area: meta; display: flex; flex-direction: column; min-width: 0; }
#song-title { font-weight: 650; font-size: 16px; letter-spacing: 0.1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#song-sub { font-size: 12.5px; opacity: 0.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#controls { grid-area: controls; display: flex; gap: 4px; align-items: center; }
#controls button {
  display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  color: var(--ink-cream); opacity: 0.85;
  transition: opacity 0.2s, transform 0.15s, background 0.2s;
}
#controls button:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }
#controls button:active { transform: scale(0.9); }
#controls button:focus-visible { opacity: 1; outline: 2px solid rgba(244, 239, 226, 0.7); outline-offset: 1px; }
#controls svg { width: 22px; height: 22px; }
#btn-play { width: 52px; height: 52px; }
#btn-play svg { width: 29px; height: 29px; }
#btn-play .icon-pause { display: none; }
body.rolling #btn-play .icon-play { display: none; }
body.rolling #btn-play .icon-pause { display: block; }

/* உடன் பயணிகள் — the live count riding beside the player */
#riders {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 0 22px; border-radius: 999px;
  background: var(--glass-bg); color: var(--ink-cream);
  border: 1px solid var(--glass-border);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-hi), 0 18px 50px rgba(4, 6, 12, 0.42);
  flex: none;
}
#riders-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80; flex: none;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55);
  animation: livepulse 2.6s ease-out infinite;
}
@keyframes livepulse {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
  70%  { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
#riders-label {
  font-size: 14px; font-weight: 600; letter-spacing: 0.2px;
  white-space: nowrap; opacity: 0.85;
}
#riders-n {
  font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums;
  transition: opacity 0.35s;
}
#riders.shifting #riders-n { opacity: 0.25; }

#seekbox {
  grid-area: seek; display: flex; align-items: center; gap: 10px;
  font-size: 11px; font-variant-numeric: tabular-nums; opacity: 0.6;
}
#seek {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 3px; border-radius: 2px;
  background: rgba(255, 255, 255, 0.22); outline: none;
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 11px; height: 11px; border-radius: 50%;
  background: var(--ink-cream); border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
#seek::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--ink-cream); border: none;
}

#credit {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 5px;
  text-align: center; font-size: 9.5px; color: #efe8d4; opacity: 0.5;
  text-shadow: 0 1px 4px rgba(6, 8, 14, 0.8);
}
#credit a { color: inherit; font-weight: 700; }

/* hidden YouTube iframe: must stay technically visible */
#yt-hide {
  position: fixed; bottom: 0; right: 0;
  width: 2px; height: 2px; opacity: 0.01; pointer-events: none; overflow: hidden;
}

@media (max-width: 640px) {
  #credit { font-size: 8.5px; }
  #pill { border-radius: 26px; padding: 11px 15px 10px; gap: 5px 12px; }
  #thumb { width: 46px; height: 46px; border-radius: 13px; }
  #song-title { font-size: 14.5px; }
  #controls button { width: 38px; height: 38px; }
  #btn-play { width: 46px; height: 46px; }
  #btn-play svg { width: 26px; height: 26px; }
  #links { gap: 10px; }
  /* phones: player on top, the count centred under it */
  #dockrow { grid-template-columns: 1fr; gap: 9px; }
  #pill { grid-column: 1; width: 100%; }
  #riders { grid-column: 1; justify-self: center; }
  #riders { align-self: center; padding: 11px 18px; gap: 9px; }
  #riders-label { font-size: 13px; }
  #riders-n { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  #grain, .dn-halo { animation: none; }
  body.rolling #stage img, body.engine #stage { animation: none; }
  #stage img, .dn-sun, .dn-moon, .dn-glass { transition-duration: 0.01s; }
}
