/* ===== Channel Navigator (glitch CRT) — responsive rewrite (with search fix) ===== */

/* Tunables */
:root{
  --ch-bg: rgba(6, 8, 10, 0.96);
  --ch-h-pad: 12px;
  --ch-head-h: 48px;
  --ch-search-h: 52px; /* 16px input avoids iOS zoom */
}

/* Fullscreen sheet on mobile */
.ch-nav{
  position: fixed;
  inset: 0;
  z-index: 1250;
  display: flex;
  flex-direction: column;
  background: var(--ch-bg);
  backdrop-filter: blur(2px);
  border: 1px solid rgba(120,210,255,.35);
  box-shadow: 0 0 18px rgba(120,210,255,.15), inset 0 0 10px rgba(0,0,0,.6);
  border-radius: 14px;
  color: #cfefff;
  font-family: "Roboto Mono", ui-monospace, monospace;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.ch-nav.hidden{ display:none; }

/* Header (sticky) */
.ch-head{
  position: sticky; top: 0; z-index: 2;
  height: var(--ch-head-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--ch-h-pad);
  background: var(--ch-bg);
  border-bottom: 1px solid rgba(120,210,255,.25);

  font-family: "Orbitron", ui-sans-serif;
  letter-spacing: .12em; font-size: 13px;
  color: rgba(190,240,255,.95);
  text-shadow: 0 0 2px rgba(180,230,255,.8),
               1px 0 0 rgba(255,0,90,.35),
              -1px 0 0 rgba(0,180,255,.35);
}
.ch-head .meta{ opacity:.8; font-size:11px; }

/* Search row (sticky under header) */
.ch-search{
  position: sticky; top: var(--ch-head-h); z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto; /* <-- prevents overlap */
  gap: 8px;
  align-items: center;
  padding: 8px var(--ch-h-pad);
  height: var(--ch-search-h);
  background: var(--ch-bg);
  border-bottom: 1px solid rgba(120,210,255,.18);
}
.ch-search input{
  min-width: 0;                 /* <-- allow shrinking inside grid */
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size:16px;               /* prevents iOS zoom */
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid rgba(120,210,255,.35);
  background: rgba(10,14,18,.9);
  color: #e6fbff;
  box-shadow: inset 0 0 6px rgba(0,0,0,.45);
}
.ch-search button{
  height: 36px;
  white-space: nowrap;          /* keep labels intact */
  min-width: 82px;              /* optional: keeps buttons readable */
  font-family: "Orbitron", ui-sans-serif;
  letter-spacing: .12em;
  font-size: 12px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(120,210,255,.5);
  background: rgba(10,14,22,.85);
  color: rgba(190,240,255,.95);
  cursor: pointer;
}
#ch-fav.is-on, #ch-locked.is-on{ border-color: rgba(120,210,255,.85); }

/* Scrollable list fills the rest */
.ch-list{
  flex:1;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;        /* Firefox hide */
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(120,210,255,.18);
  background: rgba(8,10,12,.55);
  position: relative;
}
.ch-list::-webkit-scrollbar{ display: none; } /* Chrome/Safari hide */

/* Rows: larger tap targets for mobile */
.ch-item{
  display:grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px; align-items:center;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  margin: 6px 2px;
  cursor: pointer;
  background: transparent;
}
.ch-item:hover,
.ch-item[aria-selected="true"]{
  border-color: rgba(120,210,255,.35);
  background: rgba(12,16,20,.6);
  box-shadow: inset 0 0 10px rgba(0,0,0,.4);
}

.ch-num{
  font-family: "Orbitron", ui-sans-serif;
  font-size: 14px; letter-spacing: .12em;
  color: #bfe9ff; text-align:center;
}
.ch-main{ min-width:0; }
.ch-title{ font-weight:600; color:#e4f9ff; font-size:13px; }
.ch-desc{
  font-size:12px; opacity:.85; color:#b8e6ff;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

.ch-badges{ display:flex; gap:6px; align-items:center; justify-content:flex-end; }
.badge{
  font-size: 10px; padding: 4px 8px;
  border: 1px solid rgba(180,230,255,.35);
  border-radius: 999px; opacity: .9; white-space: nowrap;
}
.badge.locked{ color:#ffd9d9; border-color: rgba(255,168,168,.4); }
.badge.unlocked{ color:#ceffd9; border-color: rgba(184,255,184,.35); }
.badge.long{ color:#ffe9bd; border-color: rgba(255,222,173,.35); }
.badge.tag{ color:#cfefff; border-color: rgba(120,210,255,.25); }

/* CRT scanlines */
.ch-list::after{
  content:""; position:absolute; inset:0; pointer-events:none;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.03) 0 1px,
    rgba(0,0,0,0) 2px 3px
  );
  mix-blend-mode: overlay;
}

/* Lock page scroll when open (add/remove .ch-open on <body> in JS) */
body.ch-open{
  overflow: hidden; touch-action: none; overscroll-behavior: contain;
}

/* === Floating CHANNELS button (sample: bottom-right, lifted above AI LINK) === */
.ch-btn{
  position: fixed;
  bottom: 4.5rem;  /* lift if AI LINK is at 1.5rem */
  right: 1.5rem;
  background: rgba(8,12,16,0.88);
  color: #cfefff;
  border: 1px solid rgba(120,210,255,.5);
  border-radius: 10px;
  font-family: "Orbitron", ui-sans-serif;
  letter-spacing: .12em;
  font-size: 12px;
  padding: 10px 14px;
  cursor: pointer;
  z-index: 1200;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
  box-shadow: 0 0 10px rgba(120,210,255,.15), inset 0 0 8px rgba(0,0,0,.5);
  overflow: hidden;
}
.ch-btn::before{
  content:""; position:absolute; inset:0; pointer-events:none;
  background-image: repeating-linear-gradient(
    to bottom, rgba(255,255,255,0.06) 0 1px, rgba(0,0,0,0) 2px 3px
  );
  mix-blend-mode: overlay; opacity:.4;
}
.ch-btn::after{
  content:"▤ CHANNELS";
  position:absolute; left:50%; top:50%;
  transform: translate(-50%, -50%);
  color:#cfefff; pointer-events:none; opacity:0;
  text-shadow: 1px 0 0 rgba(255,0,128,.45), -1px 0 0 rgba(0,200,255,.45);
}
@keyframes btn-glitch{
  0%,100%{ transform: translate(-50%, -50%) }
  25%{ transform: translate(calc(-50% + 1px), calc(-50% - 1px)) }
  50%{ transform: translate(calc(-50% - 1px), calc(-50% + 1px)) }
  75%{ transform: translate(calc(-50% + 1px), calc(-50% + 1px)) }
}
.ch-btn:hover,
.ch-btn:focus-visible{
  border-color: rgba(120,210,255,.9);
  box-shadow: 0 0 14px rgba(120,210,255,.35);
  transform: translateY(-1px);
  outline: none;
}
.ch-btn:hover::after,
.ch-btn:focus-visible::after{
  opacity:.9; animation: btn-glitch .5s steps(2) infinite;
}
.ch-btn:focus-visible{
  box-shadow: 0 0 0 2px rgba(10,20,26,1), 0 0 0 4px rgba(120,210,255,.7);
}

/* ===== Tablet & Desktop modal sizing ===== */
@media (min-width: 640px){
  .ch-nav{
    width: min(720px, 96vw);
    height: min(90dvh, 720px);
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 14px;
  }
  .ch-list{ padding: 14px; }
  .ch-item{ padding: 12px 14px; }
}

/* Stack buttons under input on very small phones */
@media (max-width: 390px){
  .ch-search{
    grid-template-columns: 1fr;  /* input on its own row */
    grid-auto-rows: auto;
  }
  .ch-search button{
    width: 100%;
  }
}

@media (min-width: 1024px){
  .ch-nav{
    width: 840px;
    height: 80dvh;
  }
}
