/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background: #0d0d0f;
  color: #e8e8ea;
  height: 100vh;
  overflow: hidden;
}
button { cursor: pointer; font-family: inherit; }
input  { font-family: inherit; }

/* ── VARS ── */
:root {
  --bg:    #0d0d0f;
  --bg2:   #121215;
  --bg3:   #1a1a1f;
  --bd:    rgba(255,255,255,0.07);
  --bd2:   rgba(255,255,255,0.14);
  --t1:    #e8e8ea;
  --t2:    #8a8a99;
  --t3:    #48484f;
  --red:   #c0182a;
  --red2:  #e0203a;
  --rail:  80px;
}

/* ── INTRO ── */
#intro {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  animation: introFade 0.5s ease 1.8s forwards;
}
@keyframes introFade { to { opacity: 0; pointer-events: none; } }
.intro-inner { text-align: center; }
.intro-logo {
  font-size: 42px; font-weight: 700; letter-spacing: -2px; color: var(--t1);
}
.intro-logo span { color: var(--red2); }
.intro-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; letter-spacing: 5px; text-transform: uppercase;
  color: var(--t3); margin-top: 8px;
}
.intro-line {
  width: 0; height: 2px; background: var(--red2);
  margin: 18px auto 0;
  animation: lineGrow 1.2s ease 0.4s forwards;
}
@keyframes lineGrow { to { width: 60px; } }
.intro-quote {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: var(--t3); margin-top: 24px;
  min-height: 16px; opacity: 0;
  animation: quoteFade 0.5s ease 1s forwards;
  max-width: 320px; margin-left: auto; margin-right: auto;
}
@keyframes quoteFade { to { opacity: 1; } }

/* ── INTRO OVERLAY ── */
.intro-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
.intro-overlay.hidden { display: none; }
.intro-overlay-inner {
  background: var(--bg2); border: 1px solid var(--bd);
  padding: 32px 40px; max-width: 420px; text-align: center;
}
.intro-overlay-title {
  font-size: 22px; font-weight: 700; color: var(--t1);
  margin-bottom: 20px;
}
.intro-overlay-text {
  font-size: 15px; color: var(--t2); line-height: 1.7;
  margin-bottom: 16px;
}
.intro-overlay-btn {
  margin-top: 24px; padding: 12px 32px;
  background: var(--red); border: none;
  color: #fff; font-size: 15px; font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.intro-overlay-btn:hover { background: var(--red2); }

/* ── LAYOUT ── */
.hidden { display: none !important; }
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── RAIL ── */
#rail {
  width: var(--rail); flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--bd);
  display: flex; flex-direction: column;
  align-items: center;
  padding: 16px 0 12px;
  gap: 4px;
}
.brand {
  font-size: 15px; font-weight: 700; color: var(--t1);
  padding: 0 0 16px; letter-spacing: -0.5px;
}
.brand span { color: var(--red2); }
.rail-nav { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 0 7px; }
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 11px 4px; background: none; border: none;
  color: var(--t3); font-size: 10px; font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase;
  transition: color 0.15s, background 0.15s; width: 100%;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { color: var(--t1); background: rgba(255,255,255,0.04); }
.nav-btn.active { color: var(--red2); background: rgba(192,24,42,0.1); }

/* ── RAIL SOURCE TOGGLE ── */
.rail-source-toggle {
  margin-top: auto; padding: 12px 7px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  border-top: 1px solid var(--bd); width: 100%;
}
.rst-label {
  font-size: 9px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--t3); margin-bottom: 2px;
}
.rst-btn {
  width: 100%; padding: 7px 0; background: none;
  border: 1px solid var(--bd); color: var(--t3);
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  transition: all 0.15s;
}
.rst-btn:hover { color: var(--t1); border-color: var(--bd2); }
.rst-btn.active { background: var(--red); border-color: var(--red); color: #fff; }

/* ── CONTENT ── */
#content { flex: 1; position: relative; overflow: hidden; }

/* ── PANEL ── */
.panel { position: absolute; inset: 0; display: none; flex-direction: column; overflow: hidden; }
.panel.active { display: flex; }

/* ── PANEL BAR ── */
.panel-bar {
  flex-shrink: 0; height: 54px;
  background: var(--bg2); border-bottom: 1px solid var(--bd);
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  overflow-x: auto; overflow-y: hidden;
}
.panel-bar::-webkit-scrollbar { display: none; }
.panel-title {
  font-size: 13px; font-weight: 700; color: var(--t2);
  letter-spacing: 0.8px; text-transform: uppercase; flex-shrink: 0;
}
.bar-controls { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }

.chip {
  padding: 6px 14px; background: none;
  border: 1px solid var(--bd); color: var(--t2);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--bd2); color: var(--t1); }
.chip.active { background: var(--red); border-color: var(--red); color: #fff; }

.search-box input {
  background: var(--bg3); border: 1px solid var(--bd);
  color: var(--t1); font-size: 14px;
  padding: 6px 14px; outline: none; width: 220px;
  transition: border-color 0.15s;
}
.search-box input::placeholder { color: var(--t3); }
.search-box input:focus { border-color: var(--bd2); }

/* ── PANEL BODY ── */
.panel-body {
  flex: 1; min-height: 0; overflow-y: auto; padding: 16px;
}
.panel-body::-webkit-scrollbar { width: 5px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--bg3); }

/* ── MEDIA GRID ── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.media-card {
  cursor: pointer; position: relative; overflow: hidden;
  background: var(--bg3); border: 1px solid var(--bd);
  transition: border-color 0.15s, transform 0.12s;
}
.media-card:hover { border-color: var(--red2); transform: scale(1.025); }
.media-card img {
  width: 100%; aspect-ratio: 2/3;
  object-fit: cover; display: block; background: var(--bg3);
}
.media-card-placeholder {
  width: 100%; aspect-ratio: 2/3;
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; background: var(--bg3); color: var(--t3);
}
.media-card-info { padding: 9px 10px 11px; }
.media-card-name {
  font-size: 14px; font-weight: 600; color: var(--t1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.media-card-year { font-size: 12px; color: var(--t3); margin-top: 3px; }
.media-card-rating {
  position: absolute; top: 7px; right: 7px;
  background: rgba(0,0,0,0.82);
  color: #f5c518; font-size: 11px; font-weight: 700;
  padding: 3px 7px;
}
.media-card-type {
  position: absolute; top: 7px; left: 7px;
  background: rgba(192,24,42,0.85);
  color: #fff; font-size: 10px; font-weight: 700;
  padding: 3px 7px; letter-spacing: 0.5px; text-transform: uppercase;
}
.media-card-src {
  position: absolute; bottom: 44px; left: 7px;
  background: rgba(30,120,200,0.82);
  color: #fff; font-size: 10px; font-weight: 700;
  padding: 3px 7px; letter-spacing: 0.5px; text-transform: uppercase;
}

.fallback-banner {
  display: flex; align-items: flex-start; gap: 16px;
  background: rgba(192,24,42,0.08); border: 1px solid rgba(192,24,42,0.25);
  padding: 22px 24px; margin-bottom: 4px;
}
.fb-icon { font-size: 26px; flex-shrink: 0; line-height: 1; }
.fb-text { font-size: 14px; color: var(--t2); line-height: 1.7; }
.fb-text b { color: var(--t1); font-weight: 600; }

.load-more {
  display: block; margin: 20px auto 0;
  background: none; border: 1px solid var(--bd);
  color: var(--t2); font-size: 14px; padding: 10px 36px;
  transition: all 0.15s;
}
.load-more:hover { border-color: var(--bd2); color: var(--t1); }

/* ── CREDITS ── */
.credits-content {
  max-width: 500px; margin: 40px auto; text-align: center;
}
.credits-main {
  font-size: 16px; color: var(--t2); line-height: 1.8;
  margin-bottom: 24px;
}
.credits-shoutout {
  font-size: 15px; color: var(--t1); line-height: 1.7;
}

/* ── MEDIA MODAL ── */
.modal-bg {
  position: fixed; inset: 0; z-index: 5000;
  background: rgba(0,0,0,0.88);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-bg.open { display: flex; }

.modal-box {
  background: var(--bg2); border: 1px solid var(--bd);
  width: 100%; max-width: 1100px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
}
.modal-head {
  flex-shrink: 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--bd);
}
.modal-title { font-size: 20px; font-weight: 700; color: var(--t1); }
.modal-meta  { font-size: 13px; color: var(--t3); margin-top: 4px; }
.modal-close {
  background: none; border: 1px solid var(--bd);
  color: var(--t2); width: 34px; height: 34px; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s; margin-left: 14px;
}
.modal-close:hover { border-color: var(--bd2); color: var(--t1); }

.tv-controls {
  flex-shrink: 0; display: flex; gap: 20px; align-items: center;
  padding: 10px 18px; border-bottom: 1px solid var(--bd);
  font-size: 14px; color: var(--t2);
}
.tv-controls label { display: flex; align-items: center; gap: 8px; }
.tv-controls input {
  width: 72px; background: var(--bg3); border: 1px solid var(--bd);
  color: var(--t1); font-size: 14px; padding: 5px 10px; outline: none;
  transition: border-color 0.15s;
}
.tv-controls input:focus { border-color: var(--bd2); }

.source-tabs { flex-shrink: 0; display: flex; border-bottom: 1px solid var(--bd); }
.src-btn {
  padding: 10px 18px; background: none; border: none; border-right: 1px solid var(--bd);
  color: var(--t3); font-size: 13px; font-weight: 500; transition: all 0.15s;
}
.src-btn:hover { color: var(--t1); background: rgba(255,255,255,0.03); }
.src-btn.active { color: var(--red2); background: rgba(192,24,42,0.08); }

.embed-wrap { flex: 1; min-height: 0; position: relative; min-height: 500px; }
.embed-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; }

/* ── PROXY PANEL ── */
.proxy-setup {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; padding: 40px 20px; text-align: center;
}
.ps-icon  { font-size: 48px; }
.ps-title { font-size: 20px; font-weight: 700; color: var(--t1); }
.ps-desc  { font-size: 14px; color: var(--t2); max-width: 420px; line-height: 1.6; }
.ps-desc code { background: var(--bg3); padding: 1px 6px; color: var(--red2); font-size: 13px; }
.ps-row {
  display: flex; gap: 0; width: min(480px, 90vw); margin-top: 4px;
}
.ps-row input {
  flex: 1; background: var(--bg3); border: 1px solid var(--bd);
  border-right: none; color: var(--t1); font-size: 14px;
  padding: 10px 14px; outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
.ps-row input:focus { border-color: var(--bd2); }
.ps-row input::placeholder { color: var(--t3); }
.ps-row button {
  padding: 10px 20px; background: var(--red); border: 1px solid var(--red);
  color: #fff; font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background 0.15s; white-space: nowrap;
}
.ps-row button:hover { background: var(--red2); }
.ps-hint { font-size: 12px; color: var(--t3); margin-top: 4px; }

.proxy-frame-wrap {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
}
.proxy-frame-wrap iframe {
  flex: 1; border: none; width: 100%; height: 100%;
}
