:root {
  --bg: #fff;
  --fg: #111;
  --muted: #666;
  --border: #ddd;
  --border-strong: #111;
  --hover: #f6f6f6;
  --active: #fffbe6;
  --dot: #d22;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --line: 1.35;

  --gap: 2px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --fg: #f0f0f0;
    --muted: #999;
    --border: #222;
    --border-strong: #f0f0f0;
    --hover: #141414;
    --active: #1a1605;
    --dot: #f55;
  }
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  line-height: var(--line);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
* { box-sizing: border-box; }

main {
  height: 100dvh;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  grid-template-rows: repeat(var(--rows, 1), 1fr);
  gap: var(--gap);
  padding: var(--gap);
  padding-bottom: calc(var(--gap) + env(safe-area-inset-bottom));
}

.empty {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  margin: 0;
  font-size: 1rem;
}

.station {
  position: relative;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  text-align: left;
  padding: clamp(1rem, 3vmin, 2rem);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.station:hover { background: var(--hover); }
.station:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: -4px;
}
.station.active {
  background: var(--active);
  border-color: var(--border-strong);
}

.station .head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.station .dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--dot);
  flex-shrink: 0;
}
.station.playing .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}
.station .name {
  font-weight: 700;
  font-size: clamp(1.1rem, 3.5vmin, 2.2rem);
  letter-spacing: -0.01em;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

/* Centered now-playing block — fills the middle grid row. */
.station .now {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.3em;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(0.95rem, 2.2vmin, 1.2rem);
}
.station .now .title {
  color: var(--fg);
  font-weight: 600;
  font-size: clamp(1rem, 2.6vmin, 1.5rem);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-width: 100%;
}
.station .now .artist {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.station .now .status {
  color: var(--muted);
  font-style: italic;
}
.station.loading .now .status {
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.station .icon {
  width: clamp(2.2rem, 5vmin, 3.5rem);
  height: clamp(2.2rem, 5vmin, 3.5rem);
  flex-shrink: 0;
  color: var(--fg);
  opacity: 0.85;
}

/* Icon visibility — exactly one of play / pause / loading shows at a time.
   Default state (inactive): play only.
   Active + playing: pause only.
   Active + loading: loading spinner only.
   Active + paused (loaded): play only. */
.station .icon--pause,
.station .icon--loading { display: none; }
.station.playing .icon--play { display: none; }
.station.playing .icon--pause { display: inline-block; }
.station.loading .icon--play,
.station.loading .icon--pause { display: none; }
.station.loading .icon--loading { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.station .foot {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 1rem;
}

/* force 1-col layout on narrow viewports regardless of station count */
@media (max-width: 560px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(var(--count, 1), minmax(8rem, 1fr));
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }
  html, body { overflow: auto; height: auto; }
}
