:root {
  --fg: #d9ffe2;
  --dim: #7fae8c;
  --accent: #7dffb3;
  --panel: rgba(0, 12, 6, 0.82);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--fg); font-family: var(--mono); overflow: hidden; -webkit-tap-highlight-color: transparent; }
#tv { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: manipulation; cursor: none; }
#tv.show-ui { cursor: default; }

video, canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
video { object-fit: contain; background: #000; opacity: 0; pointer-events: none; }
video.is-live { opacity: 1; }
#pattern { display: none; object-fit: contain; }
#static { display: none; image-rendering: pixelated; }
.scanlines { position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.12) 3px); mix-blend-mode: multiply; }
.hidden { display: none !important; }
.dim { color: var(--dim); }

/* No signal card */
.card { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 8px; background: #05080a; }
.card .big { font-size: clamp(28px, 8vw, 72px); letter-spacing: .2em; margin: 0; color: var(--accent); }
.card p { margin: 0; color: var(--dim); }

/* On screen display */
#osd { position: absolute; left: max(20px, env(safe-area-inset-left)); top: max(20px, env(safe-area-inset-top)); display: flex; gap: 18px; align-items: flex-start; padding: 14px 20px; background: var(--panel); border: 1px solid rgba(125,255,179,.35); border-radius: 6px; max-width: min(92vw, 640px); animation: osdin .15s ease-out; text-shadow: 0 0 6px rgba(125,255,179,.5); }
.osd-num { font-size: clamp(40px, 9vw, 76px); line-height: 1; color: var(--accent); letter-spacing: .05em; }
.osd-name { font-size: clamp(16px, 3.4vw, 24px); letter-spacing: .08em; text-transform: uppercase; }
.osd-line { font-size: clamp(12px, 2.4vw, 15px); margin-top: 6px; }
.osd-link { display: inline-block; margin-top: 8px; color: var(--accent); font-size: 13px; text-decoration: underline; pointer-events: auto; }
@keyframes osdin { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

#numbuf { position: absolute; right: 28px; top: 20px; font-size: clamp(48px, 10vw, 96px); color: var(--accent); text-shadow: 0 0 10px rgba(125,255,179,.6); }
#toast { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); padding: 8px 14px; background: var(--panel); border: 1px solid rgba(125,255,179,.35); border-radius: 4px; font-size: 13px; }

/* Overlays */
.overlay { position: absolute; inset: 4vh 4vw 12vh; padding: 16px 20px; background: rgba(0, 10, 24, 0.9); border: 1px solid rgba(125,255,179,.35); border-radius: 6px; overflow: auto; }
.overlay header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.overlay h2 { margin: 0; font-size: 18px; letter-spacing: .25em; color: var(--accent); }
.hint { font-size: 12px; margin: 12px 0 0; }
#help ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 14px; }
kbd { font-family: var(--mono); border: 1px solid rgba(125,255,179,.5); border-radius: 3px; padding: 1px 6px; font-size: 12px; }

/* Guide grid */
#guide-grid { display: grid; gap: 4px; }
.g-row { display: grid; grid-template-columns: 132px 1fr; gap: 8px; align-items: stretch; cursor: pointer; }
.g-row:hover .g-label, .g-row.current .g-label { border-color: var(--accent); }
.g-label { padding: 8px; background: rgba(125,255,179,.08); border: 1px solid transparent; font-size: 12px; line-height: 1.25; }
.g-label b { color: var(--accent); margin-right: 6px; }
.g-track { position: relative; height: 38px; background: rgba(255,255,255,.03); overflow: hidden; }
.g-slot { position: absolute; top: 0; bottom: 0; padding: 4px 6px; font-size: 11px; line-height: 1.2; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; background: rgba(60, 120, 255, .22); border-left: 1px solid rgba(0,0,0,.6); }
.g-slot.ad { background: rgba(255, 200, 80, .2); }
.g-slot.now { background: rgba(125, 255, 179, .28); }
.g-off { padding: 12px 8px; font-size: 11px; color: var(--dim); }
.g-ticks { display: grid; grid-template-columns: 132px 1fr; gap: 8px; font-size: 11px; color: var(--dim); }
.g-ticks .g-t { position: relative; height: 16px; }
.g-ticks .g-t span { position: absolute; transform: translateX(-50%); }
.g-nowline { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); z-index: 2; }

/* Remote */
#remote { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 8px; padding: 8px; background: var(--panel); border: 1px solid rgba(125,255,179,.3); border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .25s; }
#tv.show-ui #remote { opacity: 1; pointer-events: auto; }
#remote button { font: inherit; font-size: 12px; letter-spacing: .08em; color: var(--fg); background: transparent; border: 1px solid rgba(125,255,179,.35); border-radius: 999px; min-width: 44px; height: 40px; padding: 0 14px; cursor: pointer; }
#remote button:hover, #remote button:focus-visible { background: rgba(125,255,179,.18); outline: none; }
#remote button.on { background: rgba(125,255,179,.28); }

/* Power-on screen */
#power { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 16px; background: #020403; z-index: 20; cursor: default; }
#power .logo { width: min(70vw, 420px); height: auto; margin-bottom: 18px; opacity: .92; }
#power p { margin: 0; letter-spacing: .4em; color: var(--dim); font-size: 13px; }
#power-btn { width: 108px; height: 108px; border-radius: 50%; border: 2px solid rgba(125,255,179,.55); background: radial-gradient(circle at 50% 40%, rgba(125,255,179,.18), transparent 70%); color: var(--accent); cursor: pointer; display: grid; place-items: center; box-shadow: 0 0 30px rgba(125,255,179,.15); animation: pulse 2.4s ease-in-out infinite; }
#power-btn:hover, #power-btn:focus-visible { box-shadow: 0 0 50px rgba(125,255,179,.4); outline: none; }
@keyframes pulse { 50% { box-shadow: 0 0 46px rgba(125,255,179,.32); } }
@media (prefers-reduced-motion: reduce) { #power-btn { animation: none; } #osd { animation: none; } }
@media (max-width: 560px) { #remote { gap: 5px; padding: 6px; } #remote button { min-width: 40px; padding: 0 10px; } .g-row, .g-ticks { grid-template-columns: 96px 1fr; } }

/* Ambience mixer: a glass drawer on desktop, a bottom sheet on phones */
#mixer { position: absolute; z-index: 15; top: 16px; right: 16px; bottom: 84px; width: min(392px, calc(100vw - 32px)); padding: 18px; display: flex; flex-direction: column; gap: 14px; overflow: auto;
  background: linear-gradient(180deg, rgba(14, 22, 20, .78), rgba(6, 10, 10, .86)); -webkit-backdrop-filter: blur(22px) saturate(1.3); backdrop-filter: blur(22px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, .12); border-radius: 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .06); animation: mxin .22s ease-out; cursor: default; }
@keyframes mxin { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.mx-head { display: flex; justify-content: space-between; align-items: flex-start; }
.mx-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .02em; color: #fff; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.mx-sub { margin: 3px 0 0; font-size: 12px; color: rgba(255, 255, 255, .55); font-family: system-ui, sans-serif; }
.mx-x { width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .08); color: #fff; cursor: pointer; font-size: 13px; }
.mx-x:hover, .mx-x:focus-visible { background: rgba(255, 255, 255, .18); outline: none; }
.mx-master { display: flex; align-items: center; gap: 12px; font: 12px system-ui, sans-serif; color: rgba(255, 255, 255, .65); }
.mx-master input { flex: 1; accent-color: var(--accent); }
.mx-moods { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.mx-moods::-webkit-scrollbar { display: none; }
.mx-mood { flex: 0 0 auto; font: 500 12px system-ui, sans-serif; color: rgba(255, 255, 255, .85); background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1); border-radius: 999px; padding: 7px 13px; cursor: pointer; }
.mx-mood:hover, .mx-mood:focus-visible { background: rgba(255, 255, 255, .15); outline: none; }
.mx-mood.on { background: rgba(125, 255, 179, .2); border-color: rgba(125, 255, 179, .6); color: #fff; }
.mx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mx-tile { position: relative; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; height: 56px; padding: 0 12px; overflow: hidden; border-radius: 14px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .09); color: rgba(255, 255, 255, .8); font: 500 13px system-ui, sans-serif; cursor: pointer; touch-action: pan-y; user-select: none; -webkit-user-select: none; transition: border-color .15s, color .15s; }
.mx-tile:hover { border-color: rgba(255, 255, 255, .22); }
.mx-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mx-fill { position: absolute; inset: 0 auto 0 0; width: var(--lvl, 0%); background: linear-gradient(90deg, rgba(125, 255, 179, .16), rgba(125, 255, 179, .34)); transition: width .08s linear; pointer-events: none; }
.mx-tile > span { position: relative; }
.mx-tile.on { color: #fff; border-color: rgba(125, 255, 179, .55); box-shadow: 0 0 18px rgba(125, 255, 179, .12); }
.mx-tile.on .mx-ic { color: var(--accent); }
.mx-ic { display: grid; place-items: center; }
.mx-pct { font-size: 11px; color: rgba(255, 255, 255, .6); font-variant-numeric: tabular-nums; }
.mx-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: auto; }
.mx-foot button { font: 500 12px system-ui, sans-serif; color: rgba(255, 255, 255, .8); background: transparent; border: 1px solid rgba(255, 255, 255, .18); border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.mx-foot button:hover, .mx-foot button:focus-visible { background: rgba(255, 255, 255, .12); outline: none; }
#b-amb[data-count]:not([data-count=""])::after { content: attr(data-count); margin-left: 6px; font-size: 10px; background: var(--accent); color: #031; border-radius: 999px; padding: 1px 6px; }
@media (max-width: 640px) {
  #mixer { top: auto; right: 8px; left: 8px; bottom: 76px; width: auto; max-height: 66vh; border-radius: 22px 22px 18px 18px; animation-name: mxup; }
  @keyframes mxup { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) { #mixer { animation: none; } .mx-fill { transition: none; } }
