/*
MIT License

Copyright (c) 2025 Chris Funderburg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/* THEME VARIABLES
   - Default: light (no data-theme attr)
   - If system is dark, @media block below applies
   - If user overrides, [data-theme="dark"/"light"] wins
*/
/* THEME VARIABLES */
:root {
  /* Light (default) */
  --bg: #f7f9fc;
  --bg-2: #eef2f7;
  --card: #ffffff;
  --card-hover: #f2f5fa;
  --text: #0b1220;
  --muted: #4b5565;
  --accent: #2563eb;
  --accent-2: #059669;
  --danger: #dc2626;

  --title: #0b1220;
  --player-bg: rgba(250,252,255,.75);
  --player-border: rgba(0,0,0,.08);
}

/* System prefers dark: use dark palette unless user overrides with data-theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --bg-2: #0d121a;
    --card: #111823;
    --card-hover: #162032;
    --text: #e7edf6;
    --muted: #a8b3c6;
    --accent: #5cc8ff;
    --accent-2: #4ade80;
    --danger: #ef4444;

    --title: #ffffff;
    --player-bg: rgba(8,12,18,.85);
    --player-border: rgba(255,255,255,.08);
  }
}

/* Explicit user overrides from your toggle */
:root[data-theme="light"] {
  --bg: #f7f9fc; --bg-2: #eef2f7;
  --card:#fff; --card-hover:#f2f5fa; --text:#0b1220; --muted:#4b5565;
  --accent:#2563eb; --accent-2:#059669; --danger:#dc2626;
  --title:#0b1220; --player-bg: rgba(250,252,255,.75); --player-border: rgba(0,0,0,.08);
}
:root[data-theme="dark"] {
  --bg:#0b0f14; --bg-2:#0d121a;
  --card:#111823; --card-hover:#162032; --text:#e7edf6; --muted:#a8b3c6;
  --accent:#5cc8ff; --accent-2:#4ade80; --danger:#ef4444;
  --title:#ffffff; --player-bg: rgba(8,12,18,.85); --player-border: rgba(255,255,255,.08);
}


*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; font:16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  color:var(--text);
  /* use two colours, not calc() */
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 30%, var(--bg) 100%);
}
.container{max-width:1100px; margin:0 auto; padding:24px 20px 120px}
header{display:flex; align-items:center; gap:12px; margin-bottom:18px}
.logo{
  width:36px;
  height:36px;
  border-radius:10px;
  background-image: url('android-chrome-192x192.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow:0 6px 22px rgba(76, 201, 255, .25)
}
h1{font-size:1.4rem; margin:0}

/* Grid of station cards */
.grid{display:grid; grid-template-columns:repeat(auto-fill, minmax(240px, 1fr)); gap:14px}

.card{
  background:var(--card); border:1px solid rgba(255,255,255,.06); border-radius:16px;
  padding:14px; display:flex; flex-direction:column; gap:8px; cursor:pointer; position:relative;
  transition:transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.card:hover{background:var(--card-hover); transform:translateY(-1px); box-shadow:0 6px 20px rgba(0,0,0,.25)}
.card.active{outline:2px solid var(--accent);}
.badge{font-size:.72rem; color:var(--muted); opacity:.9}
.title{ font-weight:700; color: var(--title); }
.desc{color:var(--muted); font-size:.9rem}

/* Sticky Player uses variables so it flips with theme */
.player{
  position:fixed; left:0; right:0; bottom:0; backdrop-filter:saturate(1.2) blur(8px);
  background: var(--player-bg);
  border-top: 1px solid var(--player-border);
}
.player-inner{max-width:1100px; margin:0 auto; padding:12px 16px; display:flex; align-items:center; gap:14px}

/* Fix: Ensure the now playing section takes available space, pushing controls right */
.np{min-width:0; flex:1; display:flex; flex-direction:column; gap:2px; align-items: flex-start;}

/* Info details beside Now Playing - ensure left alignment */
.np-details {
  margin-left: 6px;
  align-self: flex-start;  /* explicitly left-align within the .np container */
}

/* Fix: Keep player controls grouped on the right */
.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;  /* This pushes the controls to the right */
}

.np .label{font-size:.72rem; color:var(--muted)}
.np .value{white-space:nowrap; overflow:hidden; text-overflow:ellipsis}

button.icon{
  border:0; width:36px; height:36px; border-radius:12px;
  display:grid; place-items:center; cursor:pointer; transition:transform .08s ease, background .15s ease;
}
button.icon:active{transform:scale(.98)}

/* Fix the volume wrapper to keep mute button and slider horizontal */
.vol-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint{margin-top:10px; color:var(--muted); font-size:.9rem}
a{color:var(--accent)}

/* Ensure volume slider doesn't break to new line */
#volume {
  min-width: 80px;  /* or whatever width you prefer */
}

/* Player buttons (play/pause, mute) - separate from theme button */
.player .icon {
  background: #0f1622;  /* dark bg in dark mode */
  color: var(--muted);
  flex-shrink: 0;  /* prevent buttons from shrinking */
}
.player .icon:hover {
  background: #132033;
  color: var(--text);
}

/* Theme button - separate styling */
.theme-toggle {
  width: 36px; height: 36px; border-radius: 10px;
  display:grid; place-items:center; margin-left:auto;
  border: 0; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
  box-shadow: 0 6px 22px rgba(76, 201, 255, .25);
  opacity: 0.8;
}
.theme-toggle:active { transform: scale(.98); }

/* Light mode overrides */
:root[data-theme="light"] .player .icon,
:root:not([data-theme]) .player .icon {
  background: #e2e8f0;  /* slightly darker light background for better visibility */
  color: #1e293b;       /* dark glyphs */
}
:root[data-theme="light"] .player .icon:hover,
:root:not([data-theme]) .player .icon:hover {
  background: #cbd5e1;  /* even darker on hover */
  color: #0f172a;       /* darker glyphs on hover */
}

/* Theme button in light mode */
:root[data-theme="light"] .theme-toggle,
:root:not([data-theme]) .theme-toggle {
  background: #2e3f5b;  /* darker background to make yellow sun pop */
  color: #ffffda;       /* yellow sun icon */
}
:root[data-theme="light"] .theme-toggle:hover,
:root:not([data-theme]) .theme-toggle:hover {
  background: #0f172a;  /* even darker on hover */
  color: #ffff00;       /* slightly darker yellow on hover */
}

/* Theme button in dark mode */
:root[data-theme="dark"] .theme-toggle {
  background: #587cab;  /* light bg in dark mode (matches the new player button color) */
  color: #fffb7f;       /* bright yellow sun */
}
:root[data-theme="dark"] .theme-toggle:hover {
  background: #1151a5;  /* slightly darker light bg on hover */
  color: #ffff00;       /* darker yellow on hover */
}

/* Player buttons in dark mode (explicit for clarity) */
:root[data-theme="dark"] .player .icon {
  background: #172234;  /* dark bg */
  color: var(--muted);
}
:root[data-theme="dark"] .player .icon:hover {
  background: #202f47;
  color: var(--text);
}

/* Info details beside Now Playing */
.np-details {
  margin-left: 6px;
}
.np-details > summary {
  list-style: none;
  cursor: pointer;
  font-size: .9rem;
  color: var(--muted);
  border: 1px solid var(--player-border);
  border-radius: 8px;
  padding: 6px 8px;
  user-select: none;
}
.np-details[open] > summary {
  color: var(--text);
}
.np-details > div {
  margin-top: 8px;
  max-width: 420px;
  font-size: .9rem;
  color: var(--text);
}
@media (max-width: 720px) {
  .np-details > div { max-width: 60vw; }
}

/* Player artwork thumbnail */
.np-art{
  width: 44px; height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: #0f1622;          /* subtle placeholder */
  border: 1px solid var(--player-border);
}
.player-inner{ gap: 12px; }      /* a touch more breathing room */

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(3px);
  z-index: 1000;
}
.modal-content {
  background: var(--card);
  color: var(--text);
  max-width: 500px;
  margin: 10% auto;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.modal-content h2 {
  margin-top: 0;
  font-size: 1.2rem;
}
.modal-content button {
  margin-top: 12px;
  border: none;
  background: var(--accent);
  color: #000;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.modal-content button:hover {
  background: var(--accent-2);
}

.disclaimer-link {
  margin-left: 12px;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  opacity: 0.7;
  align-self: center;
}
.disclaimer-link:hover {
  opacity: 1;
  color: var(--accent);
}

.ticker{margin:18px auto 10px}
.ticker-inner{display:flex;align-items:center;gap:12px;padding:10px 12px;border-radius:12px;background:var(--card);color:var(--text);box-shadow:0 4px 14px rgba(0,0,0,.12)}
.ticker-msg{
  flex:1;
  min-width:0;
  /* remove white-space:nowrap and add: */
  overflow-wrap: break-word;
  word-wrap: break-word;
  line-height: 1.3;
  /* remove text-overflow:ellipsis since we want wrapping */
}
.ticker-msg.fade{opacity:.15}
.ticker-controls{margin-left:auto;display:flex;flex-direction:column;gap:6px}
.ticker-controls .icon{width:32px;height:32px;border-radius:10px}

/* Base ticker button styles (dark mode) */
.ticker-controls .icon:not(.theme-toggle) {
  background: #172234;
  color: var(--muted);
}
.ticker-controls .icon:not(.theme-toggle):hover {
  background: #202f47;
  color: var(--text);
}

/* Light mode ticker buttons */
:root[data-theme="light"] .ticker-controls .icon:not(.theme-toggle),
:root:not([data-theme]) .ticker-controls .icon:not(.theme-toggle) {
  background: #e2e8f0;
  color: #1e293b;
}
:root[data-theme="light"] .ticker-controls .icon:not(.theme-toggle):hover,
:root:not([data-theme]) .ticker-controls .icon:not(.theme-toggle):hover {
  background: #cbd5e1;
  color: #0f172a;
}
