:root {
  --bg: #0b0d12;
  --glass: rgba(14, 16, 22, 0.62);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f1ea;
  --muted: rgba(244, 241, 234, 0.62);
  --accent: #e8b04a;   /* warm amber, like city lights */
  --live: #ff5a4e;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
svg { width: 20px; height: 20px; fill: currentColor; display: block; }
a { color: inherit; }

/* ── Ambient blurred thumbnail (fills empty space on tall screens) ── */
.ambient {
  position: fixed; inset: -10%; pointer-events: none;
  background: center / cover no-repeat;
  filter: blur(40px) brightness(.45) saturate(1.2);
  transition: background-image .6s ease;
}

/* ── Background video ──
   .video-box is sized to cover the screen and clips the iframe, which is scaled up
   a little so YouTube's edges (title, logo) fall outside. The box's background is
   the video's thumbnail; the iframe fades in only once the video is truly playing,
   so YouTube's spinner, pause icon and title overlay are never seen. */
.video-wrap { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.video-box {
  position: absolute; top: 50%; left: 50%;
  width: 100vw; height: 56.25vw;            /* 16:9 */
  min-height: 100vh; min-width: 177.78vh;
  /* dvh = the height actually visible (iOS Safari's 100vh is taller than the screen) */
  min-height: 100dvh; min-width: 177.78dvh;
  transform: translate(-50%, -50%);
  overflow: hidden;
  background: #000 center / cover no-repeat;
}
.video-box iframe {
  /* The iframe is 240px taller than the visible box. YouTube fits the video to the
     width, so the picture still fills the box exactly, while YouTube's own chrome
     (title bar on top, logo and buttons at the bottom) lands in the hidden part. */
  position: absolute; left: 0; width: 100%;
  top: -120px; height: calc(100% + 240px);
  opacity: 0; transition: none;            /* hiding is instant, so YouTube's spinner never shows */
}
body.vid-on .video-box iframe { opacity: 1; transition: opacity .6s ease; }  /* only fade in */

.shade {
  position: fixed; inset: 0; pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0,0,0,.55), transparent 22%),
    linear-gradient(to top, rgba(0,0,0,.65), transparent 35%);
}

/* ── Auto-hide UI ── */
.ui { transition: opacity .5s ease, transform .5s ease; }
body.idle .ui { opacity: 0; pointer-events: none; }
body.idle .bar { transform: translateY(12px); }
body.idle { cursor: none; }
body:not(.started) .ui { opacity: 0; pointer-events: none; }

/* ── Top bar ── */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 20px 16px;
}
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .02em; font-size: 18px; }
.logo {
  width: 22px; height: 22px; border-radius: 50%;
  border: 4px solid var(--accent); position: relative;
}
.logo::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--accent); }
.modes { margin-left: auto; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.modes button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 13px; }
.modes svg { width: 16px; height: 16px; }
.ub-now {
  margin-left: auto; display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.ub-now strong { color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; }
.weather { color: var(--text); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip:hover { border-color: rgba(255,255,255,.3); }
.chip svg { width: 16px; height: 16px; }

/* ── Start screen ── */
.start {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(11,13,18,.55), rgba(11,13,18,.88));
  transition: opacity .6s ease;
}
body.started .start { opacity: 0; pointer-events: none; }
.start-card { text-align: center; max-width: 520px; }
.start h1 {
  font-size: clamp(44px, 9vw, 84px); font-weight: 800; letter-spacing: -.03em; line-height: 1;
}
.tagline { margin-top: 18px; font-size: clamp(16px, 2.4vw, 20px); line-height: 1.5; }
.for { margin-top: 8px; color: var(--muted); font-size: 15px; }
.start-btn {
  margin-top: 32px; display: inline-flex; align-items: center; gap: 10px;
  padding: 16px 34px; border-radius: 999px;
  background: var(--accent); color: #17130a; font-weight: 800; font-size: 17px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  transition: transform .15s ease, box-shadow .15s ease;
}
.start-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,.45); }
.start-btn svg { width: 22px; height: 22px; }
.hint { margin-top: 20px; font-size: 13px; color: var(--muted); }
.rotate-hint { display: none; margin-top: 10px; font-size: 13px; color: var(--muted); }

/* ── Bottom bar ── */
.bar {
  position: fixed; left: 16px; right: 16px; z-index: 5;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px 24px;
  padding: 14px 18px; border-radius: var(--radius);
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
}
.station { display: flex; align-items: center; gap: 8px; min-width: 0; }
.icon {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--muted);
}
.icon:hover { color: var(--text); background: rgba(255,255,255,.08); }
.play {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
}
.play .i-pause { display: none; }
body.playing .play .i-play { display: none; }
body.playing .play .i-pause { display: block; }

.st-info { margin-left: 8px; min-width: 0; }
.st-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.live { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.3); }
body.playing .live { background: var(--live); animation: pulse 1.8s infinite; }
body.loading .live { background: var(--accent); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,90,78,.6); }
  70% { box-shadow: 0 0 0 8px rgba(255,90,78,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,90,78,0); }
}
.st-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-sub { font-size: 12px; color: var(--muted); }

.mixer { display: flex; gap: 20px; justify-content: center; }
.slider { display: flex; flex-direction: column; gap: 6px; font-size: 11px; font-weight: 600; color: var(--muted); min-width: 130px; }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px;
  background: rgba(255,255,255,.2); outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--text);
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--text); }
input[type=range]:focus-visible { box-shadow: 0 0 0 3px rgba(232,176,74,.5); }

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.seg {
  display: flex; padding: 3px; border-radius: 999px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
}
.seg button {
  padding: 6px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.seg button:not(:disabled):hover { color: var(--text); }
.seg button.on { background: var(--text); color: var(--bg); }

.credit {
  grid-column: 1 / -1; font-size: 11px; color: var(--muted);
  display: flex; gap: 6px; align-items: center; min-height: 38px;
}
.credit-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.credit a { white-space: nowrap; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--line); }
.credit a:hover { border-color: var(--text); }

.credit .coffee-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 800; color: #17130a; text-decoration: none;
  padding: 9px 16px; border-radius: 999px; white-space: nowrap;
  background: var(--accent); border: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  transition: transform .15s ease, filter .15s ease;
}
.credit .coffee-link:hover { color: #17130a; transform: translateY(-1px); filter: brightness(1.08); }
.coffee-link[hidden] { display: none; }

/* ── Support pop-up ── */
.modal {
  position: fixed; inset: 0; z-index: 30; padding: 16px;
  display: grid; place-items: center;
  background: rgba(5,6,9,.45);
  animation: fadeIn .4s ease;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative; width: min(400px, 100%); text-align: center;
  padding: 32px 24px 18px; border-radius: 22px;
  background: rgba(18,20,27,.92); border: 1px solid var(--line);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  animation: rise .45s cubic-bezier(.2,.8,.2,1);
}
.modal-close { position: absolute; top: 10px; right: 10px; }
.cup { display: block; width: 120px; height: 120px; margin: -8px auto 0; overflow: visible; }
.cup-saucer { fill: rgba(244,241,234,.14); }
.cup-mug { fill: var(--text); }
.cup-handle { fill: none; stroke: var(--text); stroke-width: 6; }
.cup-band { fill: var(--accent); }
.cup-coffee { fill: #6e4224; }
.cup-body { transform-origin: 58px 100px; animation: cupRock 3.2s ease-in-out infinite; }
.cup-steam path {
  fill: none; stroke: rgba(244,241,234,.7); stroke-width: 4; stroke-linecap: round;
  opacity: 0; animation: steam 2.6s ease-in-out infinite;
}
.cup-steam path:nth-child(2) { animation-delay: .8s; }
.cup-steam path:nth-child(3) { animation-delay: 1.6s; }
.cup-heart { fill: var(--live); opacity: 0; transform-origin: 57px 26px; animation: heart 3.6s ease-in-out 1.2s infinite; }
@keyframes cupRock { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes steam {
  0% { opacity: 0; transform: translateY(8px); }
  35% { opacity: .9; }
  100% { opacity: 0; transform: translateY(-14px); }
}
@keyframes heart {
  0% { opacity: 0; transform: translateY(14px) scale(.4); }
  25% { opacity: 1; transform: translateY(0) scale(1); }
  70% { opacity: 1; transform: translateY(-10px) scale(1); }
  100% { opacity: 0; transform: translateY(-22px) scale(.8); }
}
.modal:not([hidden]) .modal-coffee { animation: nudge .6s ease 1.4s 2; }
@keyframes nudge { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg) scale(1.03); } 75% { transform: rotate(3deg) scale(1.03); } }
.modal-card h2 { margin-top: 6px; font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.modal-card p { margin-top: 10px; font-size: 14.5px; line-height: 1.55; color: var(--muted); }
.modal-actions { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.modal-coffee { margin-top: 0; justify-content: center; text-decoration: none; padding: 14px 24px; font-size: 16px; }
.modal-share { justify-content: center; padding: 12px; font-size: 14px; }
.modal-later { margin-top: 10px; padding: 8px 14px; font-size: 13px; color: var(--muted); }
.modal-later:hover { color: var(--text); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.98); } }

/* ── Toast ── */
.toast {
  position: fixed; left: 50%; top: 76px; z-index: 20; max-width: calc(100vw - 32px);
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 999px; font-size: 13px; text-align: center;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: opacity .3s ease, transform .3s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
body.no-fs #fsBtn, body.no-vol .slider.radio-vol { display: none; }

/* ── Medium widths: actions get their own row ── */
@media (max-width: 1100px) {
  .bar { grid-template-columns: auto 1fr; }
  .actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ── Portrait phones: show the whole 16:9 frame instead of a zoomed-in slice ── */
@media (orientation: portrait) {
  .video-box {
    width: 100vw; height: 56.25vw; min-width: 0; min-height: 0;
    top: var(--video-y, 46%);   /* set by app.js to sit between the top bar and controls */
    transition: top .4s ease;
  }
  .shade { background: linear-gradient(to bottom, rgba(0,0,0,.35), transparent 18%); }
  .start .rotate-hint { display: block; }
}

/* ── Phones held sideways: show the whole frame (no cropping), blurred thumbnail on the sides ── */
@media (orientation: landscape) and (max-height: 540px) {
  .video-box {
    height: 100vh; width: 177.78vh;
    height: 100dvh; width: 177.78dvh;
    max-width: 100vw; max-height: 56.25vw;
    min-width: 0; min-height: 0;
  }
}


/* ── Phone / narrow layout ── */
@media (max-width: 860px) {
  .top { flex-wrap: wrap; row-gap: 10px; }
  .modes { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
  .modes button { flex: 1; justify-content: center; }
  .ub-now span[data-i18n] { display: none; }
  .bar { grid-template-columns: 1fr; padding: 14px 16px; gap: 14px; }
  .mixer { justify-content: stretch; }
  .slider { flex: 1; min-width: 0; }
  .actions { flex-wrap: nowrap; gap: 8px; }
  .actions .seg { flex: 1; }
  .actions .seg button { flex: 1; padding: 6px 4px; }
}
@media (max-width: 420px) {
  .top { gap: 10px; padding-left: 16px; padding-right: 16px; }
  .bar { left: 12px; right: 12px; gap: 12px; grid-template-columns: minmax(0, 1fr); }
  .credit { min-width: 0; }
  .credit a#credit { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .credit-actions { flex: none; }
  .credit-actions #nextVid { padding: 9px 11px; }
  .credit-actions #nextVid span { display: none; }   /* icon only on small phones */
}

/* Compact controls for short landscape screens (must come after the narrow-layout rules) */
@media (orientation: landscape) and (max-height: 540px) {
  .top {
    flex-wrap: nowrap; padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  }
  .top .modes { order: 0; width: auto; margin-left: auto; }
  .top .modes button { flex: none; padding: 6px 12px; }
  .bar {
    left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    grid-template-columns: auto 1fr; grid-template-areas: "station mixer" "actions credit";
    padding: 8px 14px; gap: 6px 18px;
  }
  .station { grid-area: station; }
  .mixer { grid-area: mixer; }
  .actions { grid-area: actions; grid-column: auto; }
  .credit { grid-area: credit; grid-column: auto; min-height: 0; justify-content: flex-end; }
  .play { width: 40px; height: 40px; }
  .icon { width: 34px; height: 34px; }
  .st-sub { display: none; }
  .actions .seg button { padding: 5px 8px; }
}

/* Wide screens: put the mode switch in the true center of the page */
@media (min-width: 1024px) and (min-height: 541px) {
  .top .modes { position: absolute; left: 50%; transform: translateX(-50%); margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
