/* celestial — planetarium night-sky UI */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..700;1,9..144,300..700&family=Outfit:wght@300..700&display=swap');

:root {
  --bg: #0b0d1a;
  --bg-raise: #12162b;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(163, 178, 255, 0.14);
  --text: #e8ebf7;
  --text-dim: #98a1c0;
  --text-faint: #626b8a;
  --gold: #f0c168;
  --gold-bright: #ffd98a;
  --gold-deep: #a97f2f;
  --blue: #8fa8ff;
  --danger: #ff7d7d;
  --radius: 18px;
  --radius-sm: 12px;
  --display: 'Fraunces', Georgia, serif;
  --ui: 'Outfit', -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* Night sky: layered glows + a scattering of stars */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(84, 98, 180, 0.28), transparent 65%),
    radial-gradient(ellipse 60% 40% at 85% 100%, rgba(240, 193, 104, 0.07), transparent 60%),
    var(--bg);
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 22%, rgba(255,255,255,0.8), transparent 100%),
    radial-gradient(1px 1px at 78% 8%,  rgba(255,255,255,0.6), transparent 100%),
    radial-gradient(1.5px 1.5px at 34% 64%, rgba(255,255,255,0.45), transparent 100%),
    radial-gradient(1px 1px at 62% 38%, rgba(255,255,255,0.7), transparent 100%),
    radial-gradient(1px 1px at 90% 55%, rgba(255,255,255,0.5), transparent 100%),
    radial-gradient(1.5px 1.5px at 8% 82%,  rgba(255,255,255,0.4), transparent 100%),
    radial-gradient(1px 1px at 45% 12%, rgba(255,255,255,0.55), transparent 100%),
    radial-gradient(1px 1px at 25% 45%, rgba(255,255,255,0.35), transparent 100%),
    radial-gradient(1px 1px at 70% 78%, rgba(255,255,255,0.45), transparent 100%),
    radial-gradient(1.5px 1.5px at 96% 28%, rgba(255,255,255,0.5), transparent 100%);
  animation: twinkle 7s ease-in-out infinite alternate;
}
@keyframes twinkle {
  from { opacity: 0.55; }
  to   { opacity: 1; }
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px calc(40px + env(safe-area-inset-bottom));
}

/* --- header --- */

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 18px;
}

.wordmark {
  font-family: var(--display);
  font-style: italic;
  font-weight: 450;
  font-size: 1.7rem;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
}
.wordmark .star { color: var(--gold); font-style: normal; }

.header-spacer { flex: 1; }

.chip {
  font-size: 0.78rem;
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 5px 11px;
  background: var(--panel);
  white-space: nowrap;
}
button.chip { cursor: pointer; font-family: var(--ui); }
button.chip:active { background: rgba(255,255,255,0.1); }
.chip .dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  margin-right: 6px;
  vertical-align: 1px;
}

/* --- cards --- */

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: rise 0.5s ease both;
}
.card:nth-of-type(2) { animation-delay: 0.06s; }
.card:nth-of-type(3) { animation-delay: 0.12s; }
.card:nth-of-type(4) { animation-delay: 0.18s; }
.card:nth-of-type(5) { animation-delay: 0.24s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

h2 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  margin-bottom: 12px;
}
h2 .count { color: var(--text-faint); font-size: 0.85rem; }

/* --- add bar --- */

.addbar { display: flex; gap: 8px; }
.addbar input {
  flex: 1;
  min-width: 0;
  font-family: var(--ui);
  font-size: 1rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  outline: none;
}
.addbar input::placeholder { color: var(--text-faint); }
.addbar input:focus { border-color: var(--gold-deep); }
.addbar button {
  font-family: var(--ui);
  font-weight: 600;
  font-size: 0.95rem;
  color: #17130a;
  background: linear-gradient(160deg, var(--gold-bright), var(--gold));
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 20px;
  cursor: pointer;
}
.addbar button:active { filter: brightness(0.9); }

.results { margin-top: 10px; display: none; }
.results.open { display: block; }
.result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.result:hover, .result:active { background: rgba(255,255,255,0.06); }
.result img {
  width: 58px; height: 33px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-raise);
  flex-shrink: 0;
}
.result .meta { flex: 1; min-width: 0; }
.result .title {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result .sub { font-size: 0.78rem; color: var(--text-dim); }
.result .next-btn {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--blue);
  background: none;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
  font-family: var(--ui);
}
.searching { color: var(--text-faint); font-size: 0.85rem; padding: 10px 4px 2px; }

/* --- now playing --- */

.now { text-align: center; padding: 22px 16px 18px; }

.art-wrap { position: relative; display: inline-block; margin-bottom: 16px; }
.art {
  width: min(64vw, 300px);
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 14px;
  background: var(--bg-raise);
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.55);
  display: block;
}
.art-wrap.playing::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 17px;
  z-index: -1;
  background: radial-gradient(ellipse at center, rgba(240,193,104,0.35), transparent 70%);
  filter: blur(18px);
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

.now .track-title {
  font-family: var(--display);
  font-weight: 550;
  font-size: 1.3rem;
  line-height: 1.25;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}
.now .track-artist { color: var(--text-dim); font-size: 0.95rem; }
.now .track-req { color: var(--text-faint); font-size: 0.78rem; margin-top: 6px; }

.idle-hint {
  color: var(--text-dim);
  font-size: 0.95rem;
  padding: 26px 10px;
}
.idle-hint .big {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.35rem;
  display: block;
  color: var(--text);
  margin-bottom: 8px;
}

/* progress */
.progress { margin: 18px 6px 6px; }
.bar {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.bar .fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold-bright));
  transition: width 0.5s linear;
}
.times {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* transport */
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 14px;
}
.tbtn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 10px;
  border-radius: 50%;
  display: flex;
  line-height: 0;
}
.tbtn:active { background: rgba(255,255,255,0.1); }
.tbtn svg { width: 26px; height: 26px; fill: currentColor; }
.tbtn.small svg { width: 20px; height: 20px; }
.tbtn.play {
  background: linear-gradient(160deg, var(--gold-bright), var(--gold));
  color: #17130a;
  padding: 18px;
  box-shadow: 0 6px 30px rgba(240, 193, 104, 0.35);
}
.tbtn.play:active { filter: brightness(0.9); }
.tbtn.play svg { width: 30px; height: 30px; }

.modes {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.mode {
  font-family: var(--ui);
  font-size: 0.78rem;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 13px;
  cursor: pointer;
}
.mode.on {
  color: var(--gold-bright);
  border-color: var(--gold-deep);
  background: rgba(240, 193, 104, 0.09);
}

/* --- listen row --- */

.listen-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.listen-row .grow { flex: 1; }
.lbtn {
  font-family: var(--ui);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.lbtn svg { width: 16px; height: 16px; fill: currentColor; }
.lbtn:active { background: rgba(255,255,255,0.12); }
.lbtn.listening {
  color: var(--gold-bright);
  border-color: var(--gold-deep);
  background: rgba(240, 193, 104, 0.1);
}

/* --- queue --- */

.qhead {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.qhead h2 { flex: 1; }
.qtool {
  font-family: var(--ui);
  font-size: 0.78rem;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
}
.qtool:hover { color: var(--text); }
.qtool.danger:hover { color: var(--danger); }

.qrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.qrow:first-of-type { border-top: none; }
.qrow .idx {
  color: var(--text-faint);
  font-size: 0.78rem;
  width: 20px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.qrow .meta { flex: 1; min-width: 0; }
.qrow .title {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qrow .sub { font-size: 0.75rem; color: var(--text-faint); }
.qrow .act {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 7px;
  line-height: 0;
  flex-shrink: 0;
}
.qrow .act svg { width: 16px; height: 16px; fill: currentColor; }
.qrow .act:hover { color: var(--text); }
.qrow .act.rm:hover { color: var(--danger); }
.empty { color: var(--text-faint); font-size: 0.88rem; padding: 6px 4px; }

/* --- saved playlists --- */

.savebar { display: flex; gap: 8px; margin-bottom: 10px; }
.savebar input {
  flex: 1;
  min-width: 0;
  font-family: var(--ui);
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
}
.savebar button {
  font-family: var(--ui);
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  cursor: pointer;
}
.plrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.plrow:first-of-type { border-top: none; }
.plrow .name { flex: 1; font-size: 0.92rem; }
.plrow .n { color: var(--text-faint); font-size: 0.78rem; }
.plrow button {
  font-family: var(--ui);
  font-size: 0.78rem;
  background: none;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text-dim);
  padding: 5px 12px;
  cursor: pointer;
}
.plrow button:hover { color: var(--text); }
.plrow button.del { border: none; color: var(--text-faint); }
.plrow button.del:hover { color: var(--danger); }

/* --- speakers panel --- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 14, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  z-index: 50;
}
.overlay.open { display: block; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg-raise);
  border: 1px solid var(--panel-border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  z-index: 51;
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 75vh;
  overflow-y: auto;
}
.sheet.open { transform: none; }
.sheet h2 { margin-bottom: 4px; color: var(--text); font-size: 1.2rem; }
.sheet .hint { color: var(--text-faint); font-size: 0.8rem; margin-bottom: 14px; }
.spk {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 2px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.spk .meta { flex: 1; min-width: 0; }
.spk .name { font-size: 0.95rem; }
.spk .type { font-size: 0.72rem; color: var(--text-faint); text-transform: capitalize; }
.spk input[type="range"] { width: 90px; accent-color: var(--gold); }

.switch {
  position: relative;
  width: 46px; height: 27px;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.14);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}
.switch:checked { background: var(--gold-deep); }
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch:checked::after { transform: translateX(19px); }

/* speaker pairing (AirPlay verification code) */
.pinrow {
  padding: 4px 2px 12px;
}
.pinrow .pinlabel {
  font-size: 0.82rem;
  color: var(--gold-bright);
  margin-bottom: 8px;
}
.pinrow .pincontrols { display: flex; gap: 8px; }
.pinrow input {
  width: 110px;
  font-family: var(--ui);
  font-size: 1.05rem;
  letter-spacing: 0.2em;
  text-align: center;
  color: var(--text);
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--gold-deep);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  outline: none;
}
.pinrow button {
  font-family: var(--ui);
  font-weight: 600;
  font-size: 0.88rem;
  color: #17130a;
  background: linear-gradient(160deg, var(--gold-bright), var(--gold));
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  cursor: pointer;
}
.pinrow button:disabled { opacity: 0.5; }
.pinrow button.ghost {
  background: none;
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  font-weight: 400;
}

/* speakers advanced (per-speaker delay) */
.adv-toggle {
  font-family: var(--ui);
  font-size: 0.8rem;
  color: var(--text-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 14px 2px 6px;
}
.adv-toggle::before { content: '▸ '; }
.adv-toggle.open::before { content: '▾ '; }
.adv-toggle:hover { color: var(--text-dim); }
.advanced .hint { margin-bottom: 10px; }
.delayrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.delayrow .name {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.delayrow .step {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-family: var(--ui);
  font-size: 1.05rem;
  line-height: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.delayrow .step:active { background: rgba(255,255,255,0.14); }
.delayrow .step:disabled { opacity: 0.3; cursor: default; }
.delay-val {
  min-width: 74px;
  text-align: center;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}
.delay-val.nonzero { color: var(--gold-bright); border-color: var(--gold-deep); }

/* --- toasts --- */

.toasts {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}
.toast {
  background: var(--bg-raise);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 0.85rem;
  border-radius: 999px;
  padding: 10px 18px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  animation: toast-in 0.25s ease both;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.toast.out { transition: opacity 0.3s; opacity: 0; }

/* --- login --- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 38px 28px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: rise 0.6s ease both;
}
.login-card .wordmark { font-size: 2.2rem; }
.login-card .tag {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 8px 0 26px;
}
.login-card input {
  width: 100%;
  font-family: var(--ui);
  font-size: 1.05rem;
  text-align: center;
  color: var(--text);
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 13px;
  outline: none;
  margin-bottom: 12px;
}
.login-card input:focus { border-color: var(--gold-deep); }
.login-card button {
  width: 100%;
  font-family: var(--ui);
  font-weight: 600;
  font-size: 1rem;
  color: #17130a;
  background: linear-gradient(160deg, var(--gold-bright), var(--gold));
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px;
  cursor: pointer;
}
.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 14px;
  display: none;
}

@media (min-width: 700px) {
  .wrap { padding-top: 34px; }
  .now .track-title { font-size: 1.6rem; }
}
