:root {
  --bg: #8f1c07;                /* deep festive maroon (fallback) */
  --panel: #5e1109;            /* maroon panels (topbar, pager, drawer) */
  --panel-2: #7a1a0c;          /* inputs / list rows */
  --border: #c9822f;           /* warm gold border */
  --text: #fff3df;             /* warm cream */
  --muted: #f6d9ac;            /* soft marigold, secondary text */
  --accent: #ffc233;           /* marigold gold */
  --accent-2: #ffd76a;         /* lighter gold */
  --danger: #ff6b5d;
  --gap: 10px;
}

* { box-sizing: border-box; }

/* hidden attribute must win over display:flex on .settings/.pager/.backdrop */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Festive marigold -> saffron -> maroon backdrop */
body {
  background:
    radial-gradient(1200px 600px at 100% 0%, rgba(255, 214, 106, .35), transparent 60%),
    linear-gradient(160deg, #ffab33 0%, #f26418 42%, #8f1c07 100%);
  background-attachment: fixed;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 22px; flex: 0 0 auto; }
.brand h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls { display: flex; gap: 8px; flex: 0 0 auto; }

/* Mute button's descriptive text — capped, and hidden on small screens */
#muteToggle .lbl {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #7a1a0c; border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-icon { padding: 6px 10px; }

/* Support / donate button */
.btn-support {
  background: var(--accent);
  color: #2a0f04;
  border-color: var(--accent-2);
  font-weight: 700;
}
.btn-support:hover { background: var(--accent-2); border-color: var(--accent-2); }

/* ---------- Grid ---------- */
.grid {
  flex: 1 1 auto;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
}

/* Layout adapts to how many tiles are on the current page */
.grid[data-count="1"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.grid[data-count="2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.grid[data-count="3"],
.grid[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.tile {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-height: 0;
}
.tile iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
/* Click-shield: blocks click-through to YouTube (title / center / branding);
   leaves the bottom strip (live seek bar + mute) usable. Label/audio button
   sit above it (z-index 2). */
.tile .tile-shield {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 54px; /* expose YouTube's control bar: live seek + mute */
  z-index: 1;
  background: transparent;
}
.tile .tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 6px;
  pointer-events: none;
  max-width: calc(100% - 56px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Per-tile audio (solo) button */
.tile .tile-audio {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, transform .1s;
  z-index: 2;
}
.tile .tile-audio:hover { background: rgba(0, 0, 0, .75); }
.tile .tile-audio:active { transform: scale(.92); }
.tile .tile-audio.on {
  background: var(--accent);
  border-color: var(--accent-2);
  color: #2a0f04;
  box-shadow: 0 0 0 3px rgba(255, 194, 51, .3);
}

.empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  text-align: center;
  padding: 40px;
  font-size: 15px;
  line-height: 1.6;
  text-shadow: 0 1px 3px rgba(90, 17, 9, .55);
}

/* ---------- Pager ---------- */
.pager {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.page-info { color: var(--muted); font-size: 13px; min-width: 90px; text-align: center; }

/* ---------- Support (UPI) modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 8, 3, .72);
  backdrop-filter: blur(3px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  position: relative;
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 22px 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.modal h2 { margin: 0 0 4px; font-size: 19px; color: var(--text); }
.modal-sub { margin: 0 0 16px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.modal-close:hover { background: #7a1a0c; border-color: var(--accent); }
.upi-qr {
  width: 220px;
  height: 220px;
  max-width: 100%;
  background: #fff;
  padding: 10px;
  border-radius: 12px;
  display: block;
  margin: 0 auto 16px;
}
.upi-id {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}
.upi-id code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--accent-2);
  font-weight: 600;
}
.upi-pay { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.modal-note { margin: 12px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  /* Stack tiles at a real 16:9 height and let the grid scroll vertically,
     rather than squeezing every stream into one screen. */
  .grid {
    display: block;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tile {
    aspect-ratio: 16 / 9;
    width: 100%;
    margin-bottom: var(--gap);
  }
  .tile:last-child { margin-bottom: 0; }
  .empty { min-height: 60vh; }

  .brand h1 { font-size: 15px; }
  .btn { padding: 7px 10px; font-size: 12px; }
  .topbar { padding: 10px 12px; }
  .controls { gap: 6px; }
  #muteToggle .lbl { display: none; } /* icon-only mute on phones */
}
