:root {
  --bg: #ffffff;
  --tile-idle: #f2f2f3;
  --tile-border: rgba(0,0,0,0.06);
  --label: #111111;
  --label-muted: rgba(0,0,0,0.55);
  --label-fade: rgba(0,0,0,0.4);
  --footer-bg: #f2f2f3;
  --shadow-idle: 0 2px 6px rgba(0,0,0,0.04);
  --radius: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --tile-idle: #1c1c1e;
    --tile-border: rgba(255,255,255,0.06);
    --label: #ffffff;
    --label-muted: rgba(255,255,255,0.65);
    --label-fade: rgba(255,255,255,0.4);
    --footer-bg: #1c1c1e;
    --shadow-idle: 0 2px 6px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "SF Pro Text", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(env(safe-area-inset-top), 14px) 16px max(env(safe-area-inset-bottom), 14px);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 16px;
}
.wordmark {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--label-muted);
}
.status {
  font-size: 12px;
  font-weight: 500;
  color: var(--label-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.status .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 1 1 auto;
  align-content: stretch;
}

.tile {
  position: relative;
  border-radius: var(--radius);
  background: var(--tile-idle);
  border: 1px solid var(--tile-border);
  box-shadow: var(--shadow-idle);
  overflow: hidden;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  color: inherit;
  text-align: left;
  padding: 16px 16px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 130px;
  transition: transform 0.18s ease, box-shadow 0.25s ease, background 0.25s ease, color 0.25s ease;
}
.tile:active { transform: scale(0.975); }
.tile::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 4px;
  background: var(--brand);
  transition: width 0.25s ease, opacity 0.2s ease;
}
.tile .preset {
  font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--label-muted);
  letter-spacing: 0.04em;
}
.tile .name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--label);
  word-break: break-word;
}

.tile[data-state="connecting"] {
  background: color-mix(in srgb, var(--brand) 12%, var(--tile-idle));
}
.tile[data-state="playing"] {
  background: var(--brand);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 14px 32px -10px color-mix(in srgb, var(--brand) 60%, transparent);
}
.tile[data-state="playing"]::before { width: 0; opacity: 0; }
.tile[data-state="playing"] .preset { color: rgba(255,255,255,0.7); }
.tile[data-state="playing"] .name { color: #fff; }
.tile[data-state="failed"] {
  background: #ef4444;
  color: #fff;
  border-color: transparent;
}
.tile[data-state="failed"] .preset,
.tile[data-state="failed"] .name { color: #fff; }

.live-dot {
  position: absolute;
  top: 14px; right: 14px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff;
  display: none;
}
.tile[data-state="playing"] .live-dot { display: block; }
.live-dot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: rgba(255,255,255,0.5);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0%   { transform: scale(1);   opacity: 0.6; }
  100% { transform: scale(2.5); opacity: 0; }
}

.spinner {
  position: absolute;
  bottom: 14px; right: 14px;
  width: 16px; height: 16px;
  display: none;
}
.tile[data-state="connecting"] .spinner { display: block; }
.spinner::after {
  content: "";
  display: block;
  width: 100%; height: 100%;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.warn {
  position: absolute;
  top: 12px; right: 12px;
  width: 18px; height: 18px;
  display: none;
}
.tile[data-state="failed"] .warn { display: block; }
.warn svg { width: 100%; height: 100%; fill: #fff; }

.footer {
  padding-top: 18px;
  display: flex;
  justify-content: center;
}
.footer-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--label-muted);
  background: var(--footer-bg);
  border-radius: 999px;
}
.footer-card .speaker-icon { display: inline-flex; }

@media (max-width: 360px) {
  .tile { min-height: 116px; padding: 14px; }
  .tile .name { font-size: 19px; }
}
@media (min-height: 800px) {
  .tile { min-height: 158px; }
}

/* ---------- Hannes Music tile ---------- */
.tile-hannes {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--brand) 14%, var(--tile-idle)),
    var(--tile-idle));
}
.tile-hannes .live-dot { display: none; }
.tile-hannes[data-state="playing"] {
  background: linear-gradient(135deg, #7C5CFF, #C13CFF);
}
.tile-action {
  position: absolute;
  top: 12px; right: 12px;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 10px;
  background: rgba(127,92,255,0.12);
  color: var(--brand);
  cursor: pointer;
  -webkit-appearance: none; appearance: none;
  transition: background 0.2s ease, transform 0.15s ease;
}
.tile-action:active { transform: scale(0.9); }
.tile-hannes[data-state="playing"] .tile-action {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

/* ---------- Playlist panel ---------- */
body.panel-locked { overflow: hidden; }

.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 50;
}
.panel-overlay.open { opacity: 1; pointer-events: auto; }

.panel {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.3);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.panel-overlay.open .panel { transform: translateY(0); }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--tile-border);
}
.panel-title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.panel-sub {
  font-size: 12px; color: var(--label-muted);
  display: flex; align-items: center; gap: 8px; margin-top: 2px;
}
.mode {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.mode-author { background: rgba(127,92,255,0.16); color: #7C5CFF; }
.mode-prod   { background: var(--tile-idle); color: var(--label-muted); }

.panel-head-actions { display: flex; align-items: center; gap: 8px; }
.panel-play {
  border: none; border-radius: 999px;
  background: linear-gradient(135deg, #7C5CFF, #C13CFF);
  color: #fff; font: inherit; font-weight: 600; font-size: 13px;
  padding: 8px 14px; cursor: pointer;
}
.panel-play:disabled { opacity: 0.4; cursor: default; }
.panel-close {
  border: none; background: var(--tile-idle); color: var(--label);
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 15px; cursor: pointer; line-height: 1;
}

.panel-list { overflow-y: auto; padding: 8px 10px 16px; -webkit-overflow-scrolling: touch; }

.song {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 14px;
  cursor: default;
}
.song[data-playable="1"] { cursor: pointer; }
.song[data-playable="1"]:active { background: var(--tile-idle); }
.song.is-playing { background: color-mix(in srgb, #7C5CFF 12%, transparent); }

.song-idx {
  width: 26px; flex: none; text-align: center;
  font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; color: var(--label-muted);
}
.song.is-playing .song-idx { color: #7C5CFF; }
.song-meta { flex: 1 1 auto; min-width: 0; }
.song-title {
  font-size: 15px; font-weight: 600; color: var(--label);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.song.is-playing .song-title { color: #7C5CFF; }
.song-artist {
  font-size: 12.5px; color: var(--label-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px;
}
.song-empty .song-title { color: var(--label-muted); }
.song-right { flex: none; display: flex; align-items: center; gap: 8px; }
.song-dur { font-size: 12px; color: var(--label-fade); font-variant-numeric: tabular-nums; }
.song-pending { font-size: 11.5px; color: var(--label-fade); font-style: italic; }
.song-err { font-size: 11.5px; color: #ef4444; max-width: 140px; }

.song-x {
  border: none; background: transparent; color: var(--label-fade);
  font-size: 13px; cursor: pointer; padding: 4px 6px; border-radius: 8px;
}
.song-x:active { background: var(--tile-idle); }
.song-add {
  border: none; border-radius: 999px;
  background: rgba(127,92,255,0.14); color: #7C5CFF;
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.song-add:active { transform: scale(0.95); }

.fld {
  width: 100%; box-sizing: border-box;
  border: 1px solid var(--tile-border); border-radius: 10px;
  background: var(--tile-idle); color: var(--label);
  font: inherit; font-size: 14px; padding: 9px 12px; margin: 4px 0;
}
.fld:focus { outline: 2px solid rgba(127,92,255,0.5); outline-offset: 0; }
.fld-inline { width: 160px; margin: 0; padding: 7px 10px; font-size: 12.5px; }

.converting { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--label-muted); }
.spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  display: inline-block; animation: spin 0.8s linear infinite;
}

.panel-addnew {
  margin: 14px 8px 4px; padding: 14px;
  border: 1px dashed var(--tile-border); border-radius: 16px;
}
.addnew-title { font-size: 13px; font-weight: 600; color: var(--label-muted); margin-bottom: 6px; }
.btn-primary {
  margin-top: 6px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, #7C5CFF, #C13CFF);
  color: #fff; font: inherit; font-weight: 600; font-size: 14px;
  padding: 10px 16px; cursor: pointer; width: 100%;
}
.addnew-msg { font-size: 12px; color: var(--label-muted); margin-top: 8px; min-height: 16px; }

/* now-playing equalizer */
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 13px; }
.eq i {
  width: 3px; background: #7C5CFF; border-radius: 1px;
  animation: eqbar 0.9s ease-in-out infinite;
}
.eq i:nth-child(1) { height: 6px;  animation-delay: -0.2s; }
.eq i:nth-child(2) { height: 12px; animation-delay: -0.5s; }
.eq i:nth-child(3) { height: 8px;  animation-delay: -0.1s; }
@keyframes eqbar { 0%,100% { transform: scaleY(0.4); } 50% { transform: scaleY(1); } }

/* ---------- Hannes Music tile ---------- */
.tile-hannes {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--brand) 14%, var(--tile-idle)),
    var(--tile-idle));
}
.tile-hannes .live-dot { display: none; }
.tile-hannes[data-state="playing"] {
  background: linear-gradient(135deg, #7C5CFF, #C13CFF);
}
.tile-action {
  position: absolute;
  top: 12px; right: 12px;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 10px;
  background: rgba(127,92,255,0.12);
  color: var(--brand);
  cursor: pointer;
  -webkit-appearance: none; appearance: none;
  transition: background 0.2s ease, transform 0.15s ease;
}
.tile-action:active { transform: scale(0.9); }
.tile-hannes[data-state="playing"] .tile-action {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

/* ---------- Playlist panel ---------- */
body.panel-locked { overflow: hidden; }

.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 50;
}
.panel-overlay.open { opacity: 1; pointer-events: auto; }

.panel {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.3);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.panel-overlay.open .panel { transform: translateY(0); }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--tile-border);
}
.panel-title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.panel-sub {
  font-size: 12px; color: var(--label-muted);
  display: flex; align-items: center; gap: 8px; margin-top: 2px;
}
.mode {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.mode-author { background: rgba(127,92,255,0.16); color: #7C5CFF; }
.mode-prod   { background: var(--tile-idle); color: var(--label-muted); }

.panel-head-actions { display: flex; align-items: center; gap: 8px; }
.panel-play {
  border: none; border-radius: 999px;
  background: linear-gradient(135deg, #7C5CFF, #C13CFF);
  color: #fff; font: inherit; font-weight: 600; font-size: 13px;
  padding: 8px 14px; cursor: pointer;
}
.panel-play:disabled { opacity: 0.4; cursor: default; }
.panel-close {
  border: none; background: var(--tile-idle); color: var(--label);
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 15px; cursor: pointer; line-height: 1;
}

.panel-list { overflow-y: auto; padding: 8px 10px 16px; -webkit-overflow-scrolling: touch; }

.song {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 14px;
  cursor: default;
}
.song[data-playable="1"] { cursor: pointer; }
.song[data-playable="1"]:active { background: var(--tile-idle); }
.song.is-playing { background: color-mix(in srgb, #7C5CFF 12%, transparent); }

.song-idx {
  width: 26px; flex: none; text-align: center;
  font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; color: var(--label-muted);
}
.song.is-playing .song-idx { color: #7C5CFF; }
.song-meta { flex: 1 1 auto; min-width: 0; }
.song-title {
  font-size: 15px; font-weight: 600; color: var(--label);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.song.is-playing .song-title { color: #7C5CFF; }
.song-artist {
  font-size: 12.5px; color: var(--label-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px;
}
.song-empty .song-title { color: var(--label-muted); }
.song-right { flex: none; display: flex; align-items: center; gap: 8px; }
.song-dur { font-size: 12px; color: var(--label-fade); font-variant-numeric: tabular-nums; }
.song-pending { font-size: 11.5px; color: var(--label-fade); font-style: italic; }
.song-err { font-size: 11.5px; color: #ef4444; max-width: 140px; }

.song-x {
  border: none; background: transparent; color: var(--label-fade);
  font-size: 13px; cursor: pointer; padding: 4px 6px; border-radius: 8px;
}
.song-x:active { background: var(--tile-idle); }
.song-add {
  border: none; border-radius: 999px;
  background: rgba(127,92,255,0.14); color: #7C5CFF;
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.song-add:active { transform: scale(0.95); }

.fld {
  width: 100%; box-sizing: border-box;
  border: 1px solid var(--tile-border); border-radius: 10px;
  background: var(--tile-idle); color: var(--label);
  font: inherit; font-size: 14px; padding: 9px 12px; margin: 4px 0;
}
.fld:focus { outline: 2px solid rgba(127,92,255,0.5); outline-offset: 0; }
.fld-inline { width: 160px; margin: 0; padding: 7px 10px; font-size: 12.5px; }

.converting { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--label-muted); }
.spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  display: inline-block; animation: spin 0.8s linear infinite;
}

.panel-addnew {
  margin: 14px 8px 4px; padding: 14px;
  border: 1px dashed var(--tile-border); border-radius: 16px;
}
.addnew-title { font-size: 13px; font-weight: 600; color: var(--label-muted); margin-bottom: 6px; }
.btn-primary {
  margin-top: 6px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, #7C5CFF, #C13CFF);
  color: #fff; font: inherit; font-weight: 600; font-size: 14px;
  padding: 10px 16px; cursor: pointer; width: 100%;
}
.addnew-msg { font-size: 12px; color: var(--label-muted); margin-top: 8px; min-height: 16px; }

/* now-playing equalizer */
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 13px; }
.eq i {
  width: 3px; background: #7C5CFF; border-radius: 1px;
  animation: eqbar 0.9s ease-in-out infinite;
}
.eq i:nth-child(1) { height: 6px;  animation-delay: -0.2s; }
.eq i:nth-child(2) { height: 12px; animation-delay: -0.5s; }
.eq i:nth-child(3) { height: 8px;  animation-delay: -0.1s; }
@keyframes eqbar { 0%,100% { transform: scaleY(0.4); } 50% { transform: scaleY(1); } }
