:root {
  --bg0: #0b1018;
  --bg1: #111927;
  --line: rgba(212, 185, 130, 0.14);
  --line2: rgba(148, 163, 184, 0.12);
  --text: #e8eef7;
  --muted: #8b9bb2;
  --gold: #d4b982;
  --gold2: #f0d7a0;
  --blue: #5b8cff;
  --blue2: #7aa2ff;
  --ok: #3ecf8e;
  --danger: #ff6b7a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 10% -10%, #1a2740 0%, transparent 55%),
    radial-gradient(900px 600px at 90% 0%, #1b1a14 0%, transparent 50%),
    var(--bg0);
  min-height: 100%;
}

.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
}
.bg-glow {
  position: fixed; width: 420px; height: 420px; right: -80px; top: 120px;
  background: radial-gradient(circle, rgba(212,185,130,0.12), transparent 70%);
  pointer-events: none; z-index: 0;
}

.shell {
  position: relative; z-index: 1;
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
}

.top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo {
  width: 44px; height: 44px; border-radius: 14px;
  background: linear-gradient(145deg, #1b2435, #121a28);
  border: 1px solid var(--line);
  display: grid; place-items: center; gap: 3px;
}
.logo span {
  display: block; width: 18px; height: 3px; border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), var(--gold2));
}
.logo span:nth-child(2) { width: 12px; opacity: 0.8; }
.logo span:nth-child(3) { width: 15px; opacity: 0.55; }

h1 { margin: 0; font-size: 22px; font-weight: 700; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.status-pill {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line2);
  background: rgba(17, 25, 39, 0.8);
  padding: 8px 12px; border-radius: 999px;
  backdrop-filter: blur(8px);
  white-space: nowrap;
}
.status-pill.ok { color: var(--ok); border-color: rgba(62,207,142,0.28); }
.status-pill.bad { color: var(--danger); border-color: rgba(255,107,122,0.28); }

.panel { display: grid; gap: 16px; }
.card {
  background: linear-gradient(180deg, rgba(24,34,51,0.92), rgba(17,25,39,0.92));
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* author `display:` rules must not override HTML hidden attribute */
[hidden] {
  display: none !important;
}

.field-label {
  display: block; font-size: 12px; color: var(--muted);
  margin-bottom: 10px; letter-spacing: 0.4px; text-transform: uppercase;
}
.input-row { display: flex; gap: 10px; }
input#roomInput {
  flex: 1; min-width: 0; height: 48px; border-radius: 12px;
  border: 1px solid rgba(212,185,130,0.18);
  background: rgba(8,12,20,0.72);
  color: var(--text); padding: 0 14px;
  font: 500 14px/1.2 var(--mono); outline: none;
}
input#roomInput::placeholder { color: #5d6d85; font-weight: 400; }
input#roomInput:focus {
  border-color: rgba(212,185,130,0.45);
  box-shadow: 0 0 0 3px rgba(212,185,130,0.12);
}

.btn {
  border: 0; cursor: pointer; border-radius: 12px;
  height: 48px; padding: 0 18px;
  font: 600 14px/1 var(--sans);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s ease, opacity .12s ease, filter .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary {
  min-width: 104px; color: #14110a;
  background: linear-gradient(135deg, var(--gold2), var(--gold));
  box-shadow: 0 8px 24px rgba(212,185,130,0.18);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.04); }
.btn.ghost {
  height: 36px; padding: 0 12px; color: var(--text);
  background: rgba(255,255,255,0.04); border: 1px solid var(--line2);
}
.btn.ghost.is-faved {
  color: #1a1408;
  background: linear-gradient(135deg, var(--gold2), var(--gold));
  border-color: transparent;
}
.btn.small {
  height: 32px; padding: 0 10px; font-size: 12px; border-radius: 9px;
  color: var(--gold2);
  background: rgba(212,185,130,0.08);
  border: 1px solid rgba(212,185,130,0.18);
}
.btn.small.iina {
  color: #0e1420;
  background: linear-gradient(135deg, #8eb6ff, #5b8cff);
  border-color: transparent;
  font-weight: 700;
}
.btn.small:hover { filter: brightness(1.05); }

.btn-spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(20,17,10,0.2);
  border-top-color: #14110a;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hints {
  margin-top: 12px; color: var(--muted); font-size: 12px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.hints .dot { opacity: 0.45; }

/* Favorites */
.fav-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-bottom: 12px;
}
.fav-sub { color: var(--muted); font-size: 12px; }
.fav-head-actions { display: flex; gap: 8px; }
.fav-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.fav-empty {
  color: var(--muted); font-size: 13px; line-height: 1.5;
  padding: 8px 2px 2px;
}
.fav-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: stretch;
  border: 1px solid var(--line2);
  background: rgba(8,12,20,0.45);
  border-radius: 14px;
  padding: 8px;
  transition: border-color .15s, background .15s;
}
.fav-item:hover {
  border-color: rgba(212,185,130,0.28);
  background: rgba(212,185,130,0.06);
}
.fav-main {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; color: inherit;
  cursor: pointer; text-align: left; padding: 4px; min-width: 0;
  border-radius: 10px;
}
.fav-main:disabled { opacity: 0.55; cursor: not-allowed; }
.fav-avatar {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center;
  font: 700 14px/1 var(--sans);
  color: #1a1408;
  background: linear-gradient(145deg, var(--gold2), var(--gold));
}
.fav-meta {
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.fav-name {
  font-size: 13.5px; font-weight: 650; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 160px;
}
.fav-rid {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
}
.fav-del {
  width: 32px; min-width: 32px; padding: 0;
  color: var(--muted) !important;
  background: transparent !important;
  border-color: transparent !important;
  font-size: 18px !important;
  line-height: 1;
}
.fav-del:hover {
  color: var(--danger) !important;
  background: rgba(255,107,122,0.1) !important;
}

.result-head {
  display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;
  margin-bottom: 18px;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.live-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.8px;
  color: #0d1a14; background: var(--ok);
  padding: 3px 8px; border-radius: 999px; margin-bottom: 8px;
}
.live-badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: #0d1a14;
}
.result-head h2 {
  margin: 0; font-size: 18px; font-weight: 650; line-height: 1.35; max-width: 640px;
}
.meta {
  margin-top: 6px; color: var(--muted); font-size: 12px; font-family: var(--mono);
}

.rec-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px;
}
.rec-item {
  border: 1px solid rgba(212,185,130,0.16);
  background: linear-gradient(180deg, rgba(212,185,130,0.07), rgba(255,255,255,0.02));
  border-radius: 14px; padding: 14px;
}
.rec-item .k {
  font-size: 11px; letter-spacing: 0.5px; color: var(--gold);
  text-transform: uppercase; margin-bottom: 6px; font-weight: 600;
}
.rec-item .v {
  font-family: var(--mono); font-size: 12px; color: #c7d2e2;
  word-break: break-all; line-height: 1.45; max-height: 4.2em; overflow: hidden;
}
.rec-item .actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.tabs {
  display: flex; gap: 6px; border-bottom: 1px solid var(--line2);
  margin-bottom: 14px; padding-bottom: 2px;
}
.tab {
  background: transparent; border: 0; color: var(--muted);
  font: 600 13px/1 var(--sans); padding: 10px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -3px;
}
.tab.active { color: var(--gold2); border-bottom-color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stream-list { display: grid; gap: 10px; }
.stream-item {
  display: grid; grid-template-columns: 88px 1fr auto; gap: 12px; align-items: center;
  padding: 12px; border-radius: 12px;
  background: rgba(8,12,20,0.45); border: 1px solid var(--line2);
}
.q-tag {
  height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; font: 700 11px/1 var(--mono); letter-spacing: 0.4px;
  color: var(--blue2); background: rgba(91,140,255,0.12);
  border: 1px solid rgba(91,140,255,0.2); text-transform: uppercase;
}
.q-tag.best {
  color: #1a1408; background: linear-gradient(135deg, var(--gold2), var(--gold));
  border-color: transparent;
}
.url-text {
  font-family: var(--mono); font-size: 11.5px; color: #aebccc;
  word-break: break-all; line-height: 1.4; max-height: 3.2em; overflow: hidden;
}
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.error-card {
  display: flex; gap: 14px; align-items: flex-start;
  border-color: rgba(255,107,122,0.28);
  background: linear-gradient(180deg, rgba(60,24,30,0.55), rgba(17,25,39,0.92));
}
.error-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800;
  color: var(--danger); background: rgba(255,107,122,0.1);
  border: 1px solid rgba(255,107,122,0.22);
  flex: 0 0 auto;
}
.error-card h2 { margin: 0 0 8px; font-size: 16px; color: #ffc0c6; }
.error-card p {
  margin: 0; color: #e8eef7; line-height: 1.55; font-size: 13.5px;
  word-break: break-word; white-space: pre-wrap;
}

.help h3 { margin: 14px 0 8px; font-size: 14px; color: var(--gold2); }
.help h3:first-child { margin-top: 0; }
.help p, .help li { color: var(--muted); font-size: 13px; line-height: 1.55; }
.help ul { padding-left: 18px; margin: 0; }
.help pre {
  margin: 0; padding: 12px 14px; border-radius: 12px;
  background: rgba(8,12,20,0.65); border: 1px solid var(--line2); overflow: auto;
}
.help code { font-family: var(--mono); font-size: 12px; color: #d7e2f0; }

.foot {
  margin-top: 18px; color: #6d7d94; font-size: 12px;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 50; padding: 10px 16px; border-radius: 999px;
  background: rgba(20,28,42,0.95); border: 1px solid rgba(212,185,130,0.25);
  color: var(--gold2); font-size: 13px; font-weight: 600;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 980px); padding-top: 20px; }
  .top { flex-direction: column; }
  .input-row { flex-direction: column; }
  .btn.primary { width: 100%; }
  .rec-grid { grid-template-columns: 1fr; }
  .stream-item { grid-template-columns: 1fr; gap: 8px; }
  .item-actions { justify-content: flex-start; }
  .result-head { flex-direction: column; }
  .head-actions { justify-content: flex-start; }
  .fav-list { grid-template-columns: 1fr; }
}
