:root {
  --bg: #141210;
  --bg2: #1c1916;
  --line: #2c2723;
  --text: #ede6dc;
  --muted: #8f857a;
  --amber: #e0a33a;
  --wood: #6b4226;
  --wood-dark: #4a2c18;
  --wood-light: #8a5733;
  --metal: #c9c2b6;
  --phosphor: #7dffa8;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[data-lucide] { width: 18px; height: 18px; }
.hidden { display: none !important; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--amber); color: #1a1209;
  display: grid; place-items: center;
}
.brand-name { font-family: 'VT323', monospace; font-size: 28px; line-height: 1; letter-spacing: 1px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.user-label { font-size: 13px; color: var(--muted); }

.btn-ghost, .btn-primary {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; transition: .15s;
}
.btn-ghost { border: 1px solid var(--line); background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--bg2); border-color: #3a342e; }
.btn-primary { background: var(--amber); color: #1a1209; border: 0; justify-content: center; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost [data-lucide], .btn-primary [data-lucide] { width: 16px; height: 16px; }

/* Layout */
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 0; min-height: 0;
}
.tv-area { padding: 28px 28px 20px; display: flex; flex-direction: column; align-items: center; gap: 16px; min-width: 0; }
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .guide { border-left: 0 !important; border-top: 1px solid var(--line); max-height: none !important; height: 70vh; }
}

/* ===== The TV ===== */
.tv { width: 100%; max-width: 980px; position: relative; padding-top: 70px; }
.tv-antenna { position: absolute; top: 0; left: 50%; width: 260px; height: 80px; transform: translateX(-50%); pointer-events: none; }
.ant { position: absolute; bottom: 8px; width: 4px; height: 92px; background: var(--metal); border-radius: 2px; transform-origin: bottom center; }
.ant::after { content: ''; position: absolute; top: -6px; left: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--metal); }
.ant-l { left: 50%; transform: rotate(-38deg); }
.ant-r { left: 50%; transform: rotate(32deg); }
.ant-base { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 70px; height: 20px; background: #2a2622; border-radius: 40px 40px 0 0; }

.cabinet {
  position: relative; display: flex; gap: 22px; padding: 26px;
  background-color: var(--wood);
  background-image:
    repeating-linear-gradient(92deg, rgba(0,0,0,.08) 0 3px, transparent 3px 11px, rgba(255,255,255,.03) 11px 13px, transparent 13px 27px);
  border-radius: 28px;
  border: 3px solid var(--wood-dark);
  outline: 2px solid var(--wood-light);
  outline-offset: -9px;
}
.bezel {
  flex: 1; min-width: 0; padding: 22px; background: #1d1a17; border-radius: 26px;
  border: 2px solid #0e0c0b;
}
.screen {
  position: relative; width: 100%; aspect-ratio: 4 / 3; overflow: hidden;
  background: #0b0d0c; border-radius: 9% / 11%;
  isolation: isolate;
}
.screen video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000;
  filter: saturate(1.15) contrast(1.08) brightness(1.02);
  transform: scale(1.02);
}
.screen #static { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; opacity: 0; transition: opacity .15s; z-index: 2; }
.screen.tuning #static { opacity: 1; }

.fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.scanlines { background: repeating-linear-gradient(0deg, rgba(0,0,0,.28) 0 1px, transparent 1px 3px); mix-blend-mode: multiply; }
.vignette { background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.65) 100%); }
.glare { background: radial-gradient(ellipse 60% 40% at 30% 18%, rgba(255,255,255,.07), transparent 70%); }
.flicker { background: rgba(255,255,255,.015); animation: flicker .12s infinite steps(2); }
@keyframes flicker { 0% { opacity: .4 } 100% { opacity: 1 } }
.screen.nofx .fx.scanlines, .screen.nofx .fx.flicker { display: none; }
.screen.nofx video { filter: none; transform: none; }

/* Power on/off */
.screen.off video, .screen.off #static, .screen.off .osd, .screen.off .nosignal { visibility: hidden; }
.off-msg {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 5;
  font-family: 'VT323', monospace; font-size: 22px; color: #2c3a33; letter-spacing: 3px;
}
.screen:not(.off) .off-msg { display: none; }
.power-flash { position: absolute; inset: 0; z-index: 8; pointer-events: none; background: #fff; opacity: 0; }
.screen.powering-on .power-flash { animation: pon .55s ease-out forwards; }
.screen.powering-off .power-flash { animation: poff .45s ease-in forwards; }
@keyframes pon {
  0% { opacity: 1; clip-path: inset(49.5% 50% 49.5% 50%); }
  35% { opacity: 1; clip-path: inset(49.5% 0 49.5% 0); }
  100% { opacity: 0; clip-path: inset(0 0 0 0); }
}
@keyframes poff {
  0% { opacity: 0; clip-path: inset(0 0 0 0); }
  20% { opacity: 1; clip-path: inset(0 0 0 0); }
  60% { opacity: 1; clip-path: inset(49.5% 0 49.5% 0); }
  90% { opacity: 1; clip-path: inset(49.6% 49% 49.6% 49%); }
  100% { opacity: 0; clip-path: inset(50% 50% 50% 50%); }
}

/* OSD */
.osd {
  position: absolute; z-index: 7; font-family: 'VT323', monospace; color: var(--phosphor);
  text-shadow: 0 0 6px rgba(125,255,168,.7), 2px 2px 0 rgba(0,0,0,.6);
  opacity: 0; transition: opacity .25s; pointer-events: none; white-space: nowrap;
}
.osd.show { opacity: 1; }
.osd-num { top: 7%; right: 8%; font-size: clamp(32px, 6vw, 64px); line-height: 1; }
.osd-name { top: 7%; left: 8%; font-size: clamp(18px, 2.4vw, 28px); max-width: 60%; overflow: hidden; text-overflow: ellipsis; }
.osd-vol { bottom: 9%; left: 8%; right: 8%; font-size: clamp(18px, 2.2vw, 26px); }
.osd-msg { bottom: 9%; left: 8%; font-size: clamp(16px, 2vw, 24px); }
.vol-bar { display: inline-block; letter-spacing: 1px; }

/* No signal */
.nosignal { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #000; }
.nosignal .bars { position: absolute; inset: 0; display: flex; opacity: .9; }
.nosignal .bars span { flex: 1; }
.nosignal .bars span:nth-child(1){background:#c0c0c0}
.nosignal .bars span:nth-child(2){background:#c0c000}
.nosignal .bars span:nth-child(3){background:#00c0c0}
.nosignal .bars span:nth-child(4){background:#00c000}
.nosignal .bars span:nth-child(5){background:#c000c0}
.nosignal .bars span:nth-child(6){background:#c00000}
.nosignal .bars span:nth-child(7){background:#0000c0}
.nosignal-text, .nosignal-sub { position: relative; font-family: 'VT323', monospace; background: #000; color: #fff; padding: 2px 16px; }
.nosignal-text { font-size: clamp(28px, 5vw, 54px); letter-spacing: 4px; }
.nosignal-sub { font-size: clamp(14px, 1.8vw, 20px); color: #bbb; margin-top: 6px; }

/* Control panel */
.panel {
  width: 150px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 16px 12px; background: #2a2521; border-radius: 16px; border: 2px solid #171412;
}
.plate { width: 100%; text-align: center; padding: 6px 4px; background: var(--metal); border-radius: 4px; color: #2a2521; }
.plate-brand { font-family: 'VT323', monospace; font-size: 24px; line-height: 1; letter-spacing: 2px; }
.plate-brand span { color: #a8231b; }
.plate-model { font-size: 8px; font-weight: 700; letter-spacing: 1.5px; }

.knob-group { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.knob-label { font-size: 9px; font-weight: 700; letter-spacing: 2px; color: #b9ad9e; }
.knob { position: relative; width: 84px; height: 84px; cursor: grab; user-select: none; touch-action: none; }
.knob-sm { width: 66px; height: 66px; }
.knob-ticks { position: absolute; inset: 0; border-radius: 50%;
  background: repeating-conic-gradient(from -6deg, #d6cbbb 0 3deg, transparent 3deg 30deg);
  -webkit-mask: radial-gradient(circle, transparent 62%, #000 63%, #000 70%, transparent 71%);
          mask: radial-gradient(circle, transparent 62%, #000 63%, #000 70%, transparent 71%);
}
.knob-face {
  position: absolute; inset: 16%; border-radius: 50%; background: #121010;
  border: 3px solid #3d3631; transition: transform .25s cubic-bezier(.3,1.6,.5,1);
  background-image: repeating-conic-gradient(#191616 0 6deg, #0d0b0b 6deg 12deg);
}
.knob-mark { position: absolute; top: 6%; left: 50%; width: 4px; height: 30%; margin-left: -2px; background: var(--amber); border-radius: 2px; }
.knob-btns { display: flex; gap: 6px; }
.mini {
  width: 34px; height: 26px; border-radius: 6px; background: #3a332d; color: #d8cec1; border: 1px solid #1a1715;
  display: grid; place-items: center; cursor: pointer;
}
.mini:hover { background: #4a423a; }
.mini [data-lucide] { width: 16px; height: 16px; }

.grille { width: 100%; flex: 1; min-height: 50px; border-radius: 8px;
  background: repeating-linear-gradient(0deg, #1a1715 0 3px, #3a332d 3px 6px); }

.switches { display: flex; gap: 6px; }
.switch {
  position: relative; width: 38px; height: 38px; border-radius: 8px; background: #3a332d; color: #d8cec1;
  border: 1px solid #1a1715; display: grid; place-items: center; cursor: pointer; transition: .12s;
}
.switch:hover { background: #4a423a; }
.switch:active { transform: translateY(1px); }
.switch.power { background: #5a1f1a; color: #ffd9d3; }
.switch.power:hover { background: #6e2620; }
.led { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: #3a1210; }
.led.on { background: #ff3b2f; box-shadow: 0 0 6px #ff3b2f; }

.feet { display: flex; justify-content: space-between; padding: 0 70px; }
.feet span { width: 70px; height: 14px; background: #1e1a17; border-radius: 0 0 8px 8px; }

/* Responsive TV */
@media (max-width: 720px) {
  .tv-area { padding: 18px 12px; }
  .cabinet { flex-direction: column; padding: 14px; gap: 14px; border-radius: 20px; }
  .bezel { padding: 12px; border-radius: 18px; }
  .panel { width: 100%; flex-direction: row; flex-wrap: wrap; justify-content: space-between; padding: 12px; gap: 12px; }
  .plate { width: auto; }
  .grille { display: none; }
  .knob { width: 64px; height: 64px; }
  .knob-sm { width: 54px; height: 54px; }
  .tv-antenna { display: none; }
  .tv { padding-top: 0; }
}

/* Fullscreen */
.screen:fullscreen, .screen.pseudo-fs { border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; background: #000; }
.screen.pseudo-fs { position: fixed; inset: 0; z-index: 1000; }
.fs-exit { display: none; position: absolute; top: 16px; right: 16px; z-index: 9; width: 40px; height: 40px; border-radius: 10px;
  background: rgba(0,0,0,.55); color: #fff; border: 1px solid rgba(255,255,255,.2); place-items: center; cursor: pointer; opacity: 0; transition: opacity .2s; }
.screen:fullscreen .fs-exit, .screen.pseudo-fs .fs-exit { display: grid; }
.screen:fullscreen:hover .fs-exit, .screen.pseudo-fs:hover .fs-exit { opacity: 1; }
.screen:fullscreen .vignette { background: radial-gradient(ellipse at center, transparent 65%, rgba(0,0,0,.6) 100%); }

/* Now bar */
.nowbar {
  width: 100%; max-width: 980px; display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
}
.now-logo { width: 44px; height: 44px; border-radius: 8px; background: #26221e; display: grid; place-items: center; overflow: hidden; flex-shrink: 0; color: var(--muted); }
.now-logo img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.now-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); background: transparent; border: 0; cursor: pointer; flex-shrink: 0; transition: .15s; }
.icon-btn:hover { background: #27231f; color: var(--text); }
.icon-btn.boxed { border: 1px solid var(--line); height: 38px; width: 38px; }
.icon-btn.fav { color: var(--amber); }
.icon-btn.fav svg { fill: var(--amber); }
.hints { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; font-size: 12px; color: var(--muted); }
kbd { font-family: inherit; font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); background: var(--bg2); margin-right: 2px; color: var(--text); }

/* Guide */
.guide {
  border-left: 1px solid var(--line); background: #171512; padding: 18px; display: flex; flex-direction: column; gap: 12px;
  height: calc(100vh - 65px); position: sticky; top: 0; min-height: 0;
}
.guide-head { display: flex; align-items: center; justify-content: space-between; }
.guide-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.guide-title [data-lucide] { color: var(--amber); }
.field label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input {
  height: 38px; width: 100%; padding: 0 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-size: 13px; outline: none; font-family: inherit;
}
.input:focus { border-color: #5a4a35; }
select.input { appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238f857a' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.group-sel { width: 130px; }
.search { position: relative; }
.search [data-lucide] { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search .input { padding-left: 34px; }
.custom { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.settings { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; }
.toggle input { display: none; }
.toggle span { width: 32px; height: 18px; border-radius: 10px; background: #3a342e; position: relative; transition: .15s; flex-shrink: 0; }
.toggle span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #cfc5b8; transition: .15s; }
.toggle input:checked + span { background: var(--amber); }
.toggle input:checked + span::after { left: 16px; background: #1a1209; }

.guide-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.src-status { display: inline-flex; align-items: center; gap: 6px; }
.src-status .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.list { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -8px; padding: 0 8px; }
.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-thumb { background: #2f2a25; border-radius: 4px; }
.ch {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; transition: background .1s;
}
.ch:hover { background: #221f1b; }
.ch.active { background: #2b2419; }
.ch.active .ch-name { color: var(--amber); }
.ch.dead { opacity: .4; }
.ch-num { font-family: 'VT323', monospace; font-size: 20px; color: var(--muted); width: 40px; text-align: right; flex-shrink: 0; }
.ch-logo { width: 34px; height: 34px; border-radius: 6px; background: #221f1b; flex-shrink: 0; display: grid; place-items: center; overflow: hidden; color: #4d453d; }
.ch-logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.ch-logo [data-lucide] { width: 16px; height: 16px; }
.ch-info { flex: 1; min-width: 0; }
.ch-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-group { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-star { color: #4d453d; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; background: none; border: 0; cursor: pointer; flex-shrink: 0; }
.ch-star:hover { color: var(--text); }
.ch-star.on { color: var(--amber); }
.ch-star.on svg { fill: var(--amber); }
.ch-star [data-lucide] { width: 15px; height: 15px; }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 10px; }
.empty [data-lucide] { width: 28px; height: 28px; margin: 0 auto 10px; display: block; color: #4d453d; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #2a2521; color: var(--text); border: 1px solid #3a332d; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  transition: .25s; pointer-events: none; z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
