:root {
  --bg: #07101d;
  --panel: #0d1b2b;
  --panel-2: #12263a;
  --line: #28445d;
  --text: #edf8ff;
  --muted: #91aabd;
  --cyan: #51e7e0;
  --yellow: #ffd166;
  --red: #ff6b78;
  --green: #71f2a5;
  --channel-width: 190px;
  --timeline-width: 1440px;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { background-image: radial-gradient(circle at 15% -10%, #173b52 0, transparent 31%), linear-gradient(160deg, #07101d 0%, #050b14 100%); }
button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); line-height: 1.55; }
.error { min-height: 1.2em; color: var(--red); }
.eyebrow { margin: 0 0 .4rem; color: var(--cyan); font-size: .72rem; font-weight: 800; letter-spacing: .18em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .5rem; font-size: clamp(2rem, 5vw, 3.5rem); line-height: .95; }
h2 { margin-bottom: 0; font-size: clamp(1.6rem, 3vw, 2.5rem); }
h3 { margin-bottom: 1rem; }

.scanlines { position: fixed; inset: 0; z-index: 100; pointer-events: none; opacity: .035; background: repeating-linear-gradient(to bottom, transparent 0, transparent 3px, #9ad9ef 4px); }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }
.auth-card { width: min(470px, 100%); padding: clamp(2rem, 7vw, 4rem); border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(145deg, rgba(19, 45, 65, .95), rgba(8, 19, 32, .96)); box-shadow: 0 30px 100px #000a; }
.brand-mark { width: 72px; height: 72px; display: grid; place-items: center; margin-bottom: 1.5rem; border: 3px solid var(--cyan); border-radius: 18px 6px 18px 6px; color: var(--cyan); font-weight: 950; font-size: 1.65rem; box-shadow: inset 0 0 20px #51e7e028, 0 0 28px #51e7e01f; transform: rotate(-2deg); }
.brand-mark.small { width: 44px; height: 44px; margin: 0; border-width: 2px; border-radius: 12px 4px; font-size: 1rem; }

label { display: grid; gap: .45rem; margin-bottom: 1rem; color: #bad0de; font-size: .82rem; font-weight: 700; }
input, select { width: 100%; min-height: 44px; padding: .7rem .8rem; border: 1px solid #36526a; border-radius: 8px; outline: none; background: #07121f; color: var(--text); }
input:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px #51e7e020; }
button { min-height: 40px; padding: .65rem 1rem; border: 1px solid transparent; border-radius: 8px; background: transparent; font-weight: 800; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.primary { background: var(--cyan); color: #03201f; }
.primary:hover { background: #8af8f3; }
.secondary { border-color: #45647b; background: #142a3c; }
.secondary:hover { border-color: var(--cyan); }
.danger { border-color: #713343; color: #ffc2ca; background: #3a1721; }
.icon-button { padding: .45rem .65rem; min-height: 34px; border-color: var(--line); color: var(--muted); }

.topbar { position: sticky; top: 0; z-index: 20; height: 76px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; padding: 0 clamp(1rem, 3vw, 3rem); border-bottom: 1px solid #29465b; background: #081421ed; backdrop-filter: blur(20px); }
.brand { display: flex; align-items: center; gap: .85rem; padding: 0; text-align: left; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: .12rem; color: var(--muted); font-size: .58rem; letter-spacing: .12em; }
nav { display: flex; gap: .25rem; padding: .3rem; border: 1px solid #223c50; border-radius: 12px; background: #07111c; }
.nav-button { min-height: 34px; padding: .45rem .85rem; color: var(--muted); }
.nav-button.active { background: var(--panel-2); color: var(--cyan); }
.clock { justify-self: end; text-align: right; font-variant-numeric: tabular-nums; }
.clock span, .clock small { display: block; }
.clock span { color: var(--yellow); font-size: 1.25rem; font-weight: 900; letter-spacing: .08em; }
.clock small { color: var(--muted); font-size: .67rem; }

main { padding: clamp(1rem, 3vw, 3rem); }
.view { display: none; animation: rise .2s ease-out; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }
.hero-bar, .section-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.hero-bar, .section-heading { margin-bottom: 1.5rem; }
.hero-actions { display: flex; gap: .6rem; }

.guide-shell { overflow-x: auto; overflow-y: hidden; border: 1px solid var(--line); border-radius: 16px; background: #081523; box-shadow: 0 20px 50px #0006; }
.time-header { position: sticky; top: 0; z-index: 5; width: calc(var(--channel-width) + var(--timeline-width)); min-width: 100%; height: 48px; margin-left: 0; border-bottom: 1px solid var(--line); background: #0b1a29; }
.time-header::before { content: "CHANNEL"; position: sticky; left: 0; z-index: 6; width: var(--channel-width); height: 48px; display: grid; place-items: center start; padding-left: 1rem; border-right: 1px solid var(--line); background: #0b1a29; color: var(--muted); font-size: .65rem; font-weight: 900; letter-spacing: .14em; }
.time-label { position: absolute; top: 0; bottom: 0; padding: .9rem .5rem; border-left: 1px solid #274359; color: #a8c1d1; font-size: .74rem; font-weight: 800; }
.guide-grid { position: relative; width: calc(var(--channel-width) + var(--timeline-width)); min-width: 100%; }
.guide-row { height: 92px; display: grid; grid-template-columns: var(--channel-width) var(--timeline-width); border-bottom: 1px solid #1d374a; }
.channel-cell { position: sticky; left: 0; z-index: 4; display: flex; align-items: center; gap: .75rem; padding: .8rem 1rem; border-right: 1px solid var(--line); background: linear-gradient(90deg, #102538, #0d2032); cursor: pointer; }
.channel-cell:hover { background: #17354c; }
.channel-number { min-width: 34px; color: var(--yellow); font-size: 1.1rem; font-weight: 950; text-align: right; font-variant-numeric: tabular-nums; }
.channel-cell strong { display: block; line-height: 1.15; }
.channel-cell small { display: block; margin-top: .3rem; color: var(--muted); font-size: .66rem; }
.program-track { position: relative; overflow: hidden; background-image: linear-gradient(90deg, transparent 24.9%, #203b4d 25%, transparent 25.1%, transparent 49.9%, #203b4d 50%, transparent 50.1%, transparent 74.9%, #203b4d 75%, transparent 75.1%); }
.program { position: absolute; top: 6px; bottom: 6px; min-width: 2px; overflow: hidden; padding: .72rem .8rem; border: 1px solid #31536a; border-radius: 7px; background: #153149; text-align: left; }
.program:hover, .program.current { border-color: var(--cyan); background: #1a4357; }
.program strong, .program small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.program strong { font-size: .82rem; }
.program small { margin-top: .3rem; color: #a6c4d4; font-size: .68rem; }
.now-line { position: absolute; z-index: 3; top: 0; bottom: 0; width: 2px; margin-left: var(--channel-width); background: var(--red); box-shadow: 0 0 9px #ff6677; pointer-events: none; }
.now-line::before { content: "NOW"; position: absolute; top: -47px; left: -15px; padding: .15rem .3rem; border-radius: 3px; background: var(--red); color: #22030a; font-size: .57rem; font-weight: 950; }
.empty-state { display: grid; place-items: center; max-width: 600px; margin: 8vh auto; padding: 3rem; border: 1px dashed #31536a; border-radius: 18px; text-align: center; }
.empty-state p { max-width: 450px; color: var(--muted); }
.empty-icon { color: var(--cyan); font-size: 4rem; }

.split-layout { display: grid; grid-template-columns: minmax(280px, 390px) 1fr; gap: 1.25rem; align-items: start; }
.panel { padding: 1.35rem; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, #0f2234, #0b1928); box-shadow: 0 15px 35px #0003; }
.form-panel { position: sticky; top: 96px; }
.form-row { display: grid; grid-template-columns: 100px 1fr; gap: .8rem; }
.card-list, .channel-list { display: grid; gap: .8rem; }
.server-card, .channel-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 1rem; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 12px; background: #0d1d2d; }
.server-card p, .channel-card p { margin: .3rem 0 0; color: var(--muted); font-size: .75rem; }
.card-actions { display: flex; gap: .35rem; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: .45rem; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }
#library-panel { margin-top: 1.25rem; }
.library-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .65rem; }
.library-item { display: flex; align-items: center; gap: .7rem; margin: 0; padding: .8rem; border: 1px solid #2a465a; border-radius: 8px; background: #091725; }
.library-item input { width: 18px; min-height: 18px; }
.library-item span { display: block; }
.library-item small { display: block; margin-top: .2rem; color: var(--muted); font-size: .66rem; }
.channel-card { grid-template-columns: 58px 1fr auto; }
.channel-card .large-number { color: var(--yellow); font-size: 1.5rem; font-weight: 950; text-align: center; }
.mode-chip { display: inline-block; margin-top: .4rem; padding: .18rem .4rem; border: 1px solid #34576d; border-radius: 999px; color: var(--cyan); font-size: .6rem; text-transform: uppercase; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.copy-field { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.copy-field button { border-color: var(--line); background: #142b3d; }
.security-note { padding: .75rem; border-left: 3px solid var(--yellow); background: #332b14; color: #ffebb0; font-size: .76rem; line-height: 1.4; }
.backup-list { display: grid; gap: .45rem; }
.backup-item { display: flex; justify-content: space-between; gap: .5rem; padding: .55rem; border-bottom: 1px solid #284359; color: var(--muted); font-size: .75rem; }
.backup-item a { color: var(--cyan); }
.danger-panel { border-color: #512a36; }

.player-dialog { width: min(1180px, 96vw); max-width: none; padding: 0; border: 1px solid #45677e; border-radius: 12px; overflow: hidden; background: #010305; box-shadow: 0 35px 100px #000; }
.player-dialog::backdrop { background: #01050be8; backdrop-filter: blur(12px); }
.player-frame { position: relative; aspect-ratio: 16 / 9; background: #000; }
.player-frame video { width: 100%; height: 100%; object-fit: contain; }
.player-chrome { position: absolute; inset: 0 0 auto; display: flex; justify-content: space-between; align-items: start; padding: 1.2rem; background: linear-gradient(#000c, transparent); pointer-events: none; }
.player-chrome > div { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; align-items: center; text-shadow: 0 2px 8px #000; }
.player-chrome small { grid-column: 2; color: #c1d1da; }
.player-chrome button { pointer-events: auto; min-width: 46px; padding: 0; background: #0008; font-size: 2rem; }
.channel-badge { grid-row: span 2; min-width: 50px; padding: .55rem; border: 2px solid var(--yellow); color: var(--yellow); text-align: center; font-weight: 950; }
.tuning { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; background: radial-gradient(circle, #172b37, #020407); letter-spacing: .15em; }
.tuning span { color: var(--muted); font-size: .7rem; }
.tuning strong { margin-top: .5rem; color: var(--cyan); font-size: 1.4rem; }
.tuning.hidden { display: none; }
.toast { position: fixed; z-index: 200; right: 1.5rem; bottom: 1.5rem; max-width: 360px; padding: .9rem 1.1rem; border: 1px solid var(--cyan); border-radius: 8px; background: #0e2935; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 800px) {
  :root { --channel-width: 140px; --timeline-width: 1080px; }
  .topbar { height: auto; grid-template-columns: 1fr auto; padding: .7rem 1rem; }
  nav { grid-column: 1 / -1; grid-row: 2; justify-content: stretch; overflow-x: auto; }
  .nav-button { flex: 1; }
  .clock { grid-column: 2; grid-row: 1; }
  .brand small { display: none; }
  main { padding: 1rem; }
  .split-layout, .settings-grid { grid-template-columns: 1fr; }
  .form-panel { position: static; }
  .guide-row { height: 80px; }
  .channel-cell { padding: .6rem; gap: .5rem; }
  .channel-number { min-width: 25px; font-size: .9rem; }
  .hero-bar { align-items: end; }
  .hero-actions { flex-direction: column; }
}
