:root {
  --bg0: #07090f;
  --bg1: #0d121c;
  --panel: rgba(18, 24, 36, .88);
  --panel-solid: #121824;
  --line: rgba(255,255,255,.08);
  --line2: rgba(255,255,255,.14);
  --text: #eef3fb;
  --muted: #8b97ad;
  --faint: #667289;
  --pink: #ff4f98;
  --pink2: #ff7ab8;
  --blue: #6ea8fe;
  --green: #3ddc97;
  --amber: #ffb454;
  --red: #ff6b88;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 60px rgba(0,0,0,.45);
  --font: "Segoe UI", ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Noto Sans SC", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 520px at 12% -8%, rgba(255,79,152,.16), transparent 55%),
    radial-gradient(900px 480px at 92% 0%, rgba(110,168,254,.12), transparent 50%),
    radial-gradient(700px 400px at 50% 110%, rgba(61,220,151,.06), transparent 45%),
    linear-gradient(180deg, #0a0d15, var(--bg0) 40%, #080b12);
  min-height: 100%;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app {
  width: min(1280px, calc(100% - 28px));
  margin: 0 auto;
  padding: 16px 0 36px;
  display: grid;
  gap: 14px;
}

/* topbar */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 20px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  position: sticky;
  top: 10px;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 12px;
  background:
    linear-gradient(135deg, var(--pink), #ff8f6b 55%, var(--blue));
  box-shadow: 0 8px 24px rgba(255,79,152,.35);
  position: relative;
}
.logo::after {
  content: "";
  position: absolute; inset: 10px 12px 10px 13px;
  background: #fff;
  clip-path: polygon(0 0, 0 100%, 100% 50%);
  opacity: .92;
}
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: .98rem; letter-spacing: .01em; }
.brand-text span { color: var(--muted); font-size: .75rem; }

.search { display: flex; gap: 10px; min-width: 0; }
.search-box {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 12px;
  border-radius: 14px;
  border: 1px solid var(--line2);
  background: rgba(0,0,0,.28);
}
.search-box:focus-within {
  border-color: color-mix(in srgb, var(--pink) 55%, white 10%);
  box-shadow: 0 0 0 3px rgba(255,79,152,.14);
}
.search-ico { width: 18px; height: 18px; color: var(--faint); }
.search input {
  border: 0; outline: 0; background: transparent;
  padding: 10px 4px; min-width: 0; width: 100%;
  font-size: 1rem;
}
.search select {
  border: 0; outline: 0;
  background: rgba(255,255,255,.05);
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  max-width: 120px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 650;
  letter-spacing: .01em;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--pink), var(--pink2));
  color: #fff;
  box-shadow: 0 10px 24px rgba(255,79,152,.28);
  min-width: 84px;
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--line2);
  color: var(--muted);
}
.btn.soft {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  color: var(--text);
}
.btn.sm { padding: 7px 11px; font-size: .86rem; border-radius: 10px; }

.status {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
  padding: 0 6px;
  min-height: 1.3em;
}
.status.err { color: #ffb0bf; }
.status.ok { color: #b9f5d4; }

/* workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  align-items: start;
}

.player-panel, .side-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.player-panel {
  padding: 14px;
  display: grid;
  gap: 12px;
  min-height: 520px;
}

.side-panel {
  padding: 14px;
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 110px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  overflow: hidden;
}

.side-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.side-head h2 { margin: 0; font-size: .95rem; color: var(--muted); font-weight: 650; }
.hint { color: var(--faint); font-size: .75rem; text-align: right; max-width: 60%; }

.empty {
  min-height: 420px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  color: var(--muted);
  border: 1px dashed var(--line2);
  border-radius: 16px;
  background: rgba(0,0,0,.18);
  padding: 28px 18px;
}
.empty-icon {
  width: 56px; height: 56px; margin: 0 auto 6px;
  border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(255,79,152,.25), rgba(110,168,254,.2));
  color: #fff;
  font-size: 1.2rem;
}
.empty h2 { margin: 0; color: var(--text); font-size: 1.15rem; }
.empty p { margin: 0; max-width: 360px; line-height: 1.55; font-size: .92rem; }

.wrap-hidden { display: none !important; }
.is-live .empty { display: none; }
.is-live .wrap-hidden { display: revert !important; }
.is-live #stageWrap { display: grid !important; }
.is-live #playerFooter { display: flex !important; }
.is-live #meta { display: grid !important; }

/* stage / deck */
.stage {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: center;
}
.viewport {
  position: relative;
  height: clamp(280px, 48vh, 560px);
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.03);
}
.deck { position: absolute; inset: 0; }

.nav-btn {
  width: 44px; height: 72px;
  border-radius: 14px;
  border: 1px solid var(--line2);
  background: rgba(255,255,255,.04);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  padding: 0;
}
.nav-btn:hover { background: rgba(255,255,255,.08); }
.nav-btn:disabled { opacity: .28; cursor: not-allowed; }

.card {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  overflow: hidden;
  background: #05070c;
  transition: transform .36s cubic-bezier(.2,.8,.2,1), opacity .28s ease, filter .28s ease;
  will-change: transform, opacity;
  box-shadow: 0 18px 50px rgba(0,0,0,.4);
}
.card video {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.card .chrome {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.75), transparent);
  z-index: 2;
  pointer-events: none;
}
.card .chrome-left, .card .chrome-right {
  display: flex; align-items: center; gap: 8px; min-width: 0;
}
.card .code {
  font-weight: 700; font-size: .92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 42vw;
  text-shadow: 0 1px 6px #000;
}
.card .state-pill {
  font-size: .72rem; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.45);
  color: #dce6f5;
}
.card .state-pill.load { color: #ffe0a8; border-color: rgba(255,180,84,.35); }
.card .state-pill.ok { color: #c9ffe0; border-color: rgba(61,220,151,.35); }
.card .state-pill.err { color: #ffc1cd; border-color: rgba(255,107,136,.4); }

.card .fail {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  text-align: center;
  background: rgba(6,8,14,.78);
  color: #ffd0d9;
  line-height: 1.55;
  font-size: .95rem;
  z-index: 3;
}

.card.is-active {
  z-index: 5; opacity: 1; filter: none; pointer-events: auto;
  transform: translateX(0) scale(1);
}
.card.is-next {
  z-index: 4; pointer-events: none;
  transform: translateX(42px) scale(.93);
  opacity: .55; filter: brightness(.7);
}
.card.is-prev {
  z-index: 4; pointer-events: none;
  transform: translateX(-42px) scale(.93);
  opacity: .55; filter: brightness(.7);
}
.card.is-far {
  z-index: 1; pointer-events: none;
  transform: scale(.86);
  opacity: 0; filter: brightness(.4);
}

/* footer tabs */
.player-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.source-tabs {
  display: flex; flex-wrap: wrap; gap: 8px;
  min-height: 36px;
}
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: .8rem;
  font-weight: 650;
}
.tab:hover { background: rgba(255,255,255,.06); color: var(--text); }
.tab.active {
  color: #fff;
  border-color: color-mix(in srgb, var(--pink) 45%, var(--line));
  background: color-mix(in srgb, var(--pink) 18%, transparent);
  box-shadow: 0 0 0 1px rgba(255,79,152,.15);
}
.tab .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #556178;
}
.tab .dot.ok { background: var(--green); box-shadow: 0 0 8px rgba(61,220,151,.5); }
.tab .dot.load { background: var(--amber); animation: pulse 1s infinite; }
.tab .dot.err { background: var(--red); }

@keyframes pulse {
  0%,100% { opacity: .4; }
  50% { opacity: 1; }
}

.footer-actions {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: .82rem;
}
.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  user-select: none; cursor: pointer;
}
.toggle input { accent-color: var(--pink); }
.count {
  color: var(--faint);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.2);
}

/* meta */
.meta {
  display: grid; gap: 6px;
  padding-top: 2px;
}
.meta h3 {
  margin: 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-size: 1.02rem; line-height: 1.35;
}
.meta .title { color: var(--muted); font-weight: 500; font-size: .95rem; }
.meta .row {
  display: flex; flex-wrap: wrap; gap: 8px 14px;
  color: var(--muted); font-size: .88rem;
}
.meta .warn {
  color: #ffd39a;
  background: rgba(213,155,43,.12);
  border: 1px solid rgba(213,155,43,.28);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: .88rem;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: .78rem;
  color: var(--muted);
}

/* results */
.results {
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
  align-content: start;
}
.side-empty {
  color: var(--faint);
  font-size: .88rem;
  padding: 18px 8px;
  text-align: center;
}
.result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px;
  background: rgba(0,0,0,.18);
  transition: border-color .15s ease, background .15s ease;
}
.result:hover { background: rgba(255,255,255,.03); }
.result.active {
  border-color: color-mix(in srgb, var(--pink) 45%, var(--line));
  background: color-mix(in srgb, var(--pink) 10%, transparent);
}
.result h3 {
  margin: 0 0 4px;
  font-size: .9rem;
  line-height: 1.35;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.result .sub { color: var(--muted); font-size: .78rem; line-height: 1.4; }
.result .sub + .sub { margin-top: 2px; color: var(--faint); }

.badge {
  display: inline-flex; align-items: center;
  font-size: .68rem; font-weight: 700;
  letter-spacing: .02em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.badge.exact { background: rgba(154,230,180,.16); color: #d9ffe6; border-color: rgba(154,230,180,.28); }
.badge.live { background: rgba(255,79,152,.18); color: #ffd0e4; border-color: rgba(255,79,152,.35); }
.badge.av01 { background: rgba(110,168,254,.2); color: #d7e7ff; border-color: rgba(110,168,254,.35); }
.badge.jable { background: rgba(255,79,152,.2); color: #ffd0e4; border-color: rgba(255,79,152,.35); }
.badge.javmost { background: rgba(125,122,255,.2); color: #dddfff; border-color: rgba(125,122,255,.35); }
.badge.netflav { background: rgba(61,220,151,.18); color: #d9ffef; border-color: rgba(61,220,151,.32); }
.badge.avgle { background: rgba(255,180,84,.18); color: #ffe9c8; border-color: rgba(255,180,84,.32); }
.badge.supjav { background: rgba(84,210,255,.18); color: #d7f5ff; border-color: rgba(84,210,255,.32); }
.badge.avple { background: rgba(255,107,107,.18); color: #ffd4d4; border-color: rgba(255,107,107,.32); }
.badge.unknown { background: #2a3140; color: #c9d2e3; }

/* auth */
.auth-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(400px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0; font-size: 1.4rem; }
.auth-card label {
  display: grid; gap: 6px;
  font-size: .88rem; color: var(--muted);
}
.auth-card input {
  border: 1px solid var(--line2);
  background: rgba(0,0,0,.28);
  border-radius: 12px;
  padding: 12px 14px;
  outline: 0;
}
.auth-card input:focus {
  border-color: color-mix(in srgb, var(--pink) 55%, white 10%);
  box-shadow: 0 0 0 3px rgba(255,79,152,.14);
}
.auth-card .btn.primary, .auth-card button[type="submit"] {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--pink), var(--pink2));
  color: #fff;
}
.error {
  background: rgba(255,92,122,.14);
  border: 1px solid rgba(255,92,122,.35);
  color: #ffd6d6;
  padding: 10px 12px;
  border-radius: 10px;
}
.muted { color: var(--muted); font-size: .92rem; margin: 0; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .side-panel {
    position: static;
    max-height: none;
  }
  .results { max-height: 420px; }
}

@media (max-width: 720px) {
  .app { width: min(100% - 16px, 1280px); padding-top: 10px; }
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand logout"
      "search search";
    gap: 10px;
  }
  .brand { grid-area: brand; }
  #logout { grid-area: logout; }
  .search { grid-area: search; }
  .search select { max-width: 98px; }
  .stage { grid-template-columns: 1fr; }
  .nav-btn { display: none; }
  .viewport { height: clamp(240px, 42vh, 420px); }
  .player-panel { min-height: 0; }
}
