:root {
  --bg: #0f1722;
  --bg-soft: #131f2e;
  --ink: #e8f4ff;
  --ink-dim: #9cb3c9;
  --card: rgba(10, 18, 30, 0.8);
  --line: rgba(157, 193, 224, 0.25);
  --accent: #f5a524;
  --accent-2: #00c7a8;
  --danger: #f05454;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(245, 165, 36, 0.22), transparent 26%),
    radial-gradient(circle at 88% 80%, rgba(0, 199, 168, 0.17), transparent 28%),
    linear-gradient(140deg, #070d16 0%, #0f1722 55%, #101f2f 100%);
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 85%);
  pointer-events: none;
}

.topbar,
main {
  position: relative;
  z-index: 1;
  width: min(1400px, 96vw);
  margin: 0 auto;
}

.topbar {
  padding: 1.4rem 0 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

h1 {
  margin: 0;
  letter-spacing: 0.03em;
  font-size: clamp(1.45rem, 2.8vw, 2.2rem);
}

p {
  margin: 0.3rem 0 0;
  color: var(--ink-dim);
}

.device-select {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.device-select label {
  font-size: 0.8rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

select,
button {
  border: 1px solid var(--line);
  background: rgba(15, 26, 39, 0.9);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  font-family: 'IBM Plex Mono', monospace;
}

button {
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
}

main {
  padding-bottom: 2rem;
}

.status-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}

.badge {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
}

.muted {
  color: var(--ink-dim);
}

.hidden {
  display: none !important;
}

.watch-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ghost-btn {
  background: rgba(245, 165, 36, 0.16);
}

.danger-btn {
  background: rgba(240, 84, 84, 0.2);
  border-color: rgba(240, 84, 84, 0.45);
}

.dashboard-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.runtime-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.watching-ips {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 18, 30, 0.72);
  padding: 0.5rem 0.6rem;
}

.watching-ips-title {
  font-size: 0.75rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.watching-ips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.watching-ip-item {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  background: rgba(15, 26, 39, 0.82);
  color: var(--ink);
  font-size: 0.76rem;
  font-family: 'IBM Plex Mono', monospace;
}

.watching-ips-empty {
  color: var(--ink-dim);
  font-size: 0.8rem;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  background: rgba(10, 18, 30, 0.82);
  font-size: 0.76rem;
  color: var(--ink);
}

.tuner-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 0.45rem;
}

.tuner-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 18, 30, 0.72);
  padding: 0.45rem 0.55rem;
}

.tuner-card.mine {
  border-color: rgba(0, 199, 168, 0.7);
}

.tuner-title {
  font-size: 0.75rem;
  color: var(--ink-dim);
  margin-bottom: 0.2rem;
}

.tuner-status {
  font-size: 0.82rem;
  color: var(--ink);
  font-family: 'IBM Plex Mono', monospace;
}

.guide-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  backdrop-filter: blur(8px);
  padding: 0.8rem;
  margin-bottom: 1rem;
}

.guide-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.guide-head h2 {
  margin: 0;
  font-size: 1rem;
}

.guide-head-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.guide-panel.collapsed .guide-body {
  display: none;
}

.guide-controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 0.65rem;
}

.guide-controls label {
  font-size: 0.8rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.guide-list {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.guide-window {
  margin-bottom: 0.7rem;
}

.guide-window-head {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
}

.guide-block-labels {
  display: grid;
  grid-template-columns: 7.8rem repeat(var(--guide-block-count, 4), minmax(6.2rem, 1fr)) 4.2rem;
  gap: 0.45rem;
  margin-bottom: 0.4rem;
  align-items: center;
}

.guide-block-label {
  font-size: 0.72rem;
  color: var(--ink-dim);
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
}

.guide-block-label.channel {
  text-align: left;
}

.guide-block-label.tune {
  text-align: right;
}

.guide-row {
  display: grid;
  grid-template-columns: 7.8rem 1fr 4.2rem;
  gap: 0.45rem;
  align-items: stretch;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid rgba(157, 193, 224, 0.18);
}

.guide-row:last-child {
  border-bottom: 0;
}

.guide-row.active {
  background: rgba(0, 199, 168, 0.12);
}

.guide-channel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.18rem;
}

.guide-num {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--accent);
}

.guide-name {
  color: var(--ink);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.guide-timeline {
  position: relative;
  min-height: 3.2rem;
  border: 1px solid rgba(157, 193, 224, 0.2);
  border-radius: 10px;
  background:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent calc((100% / var(--guide-block-count, 4)) - 1px),
      rgba(157, 193, 224, 0.12) calc((100% / var(--guide-block-count, 4)) - 1px),
      rgba(157, 193, 224, 0.12) calc(100% / var(--guide-block-count, 4))
    ),
    rgba(15, 26, 39, 0.72);
  overflow: hidden;
}

.guide-program {
  position: absolute;
  top: 0.25rem;
  bottom: 0.25rem;
  border: 1px solid rgba(157, 193, 224, 0.3);
  border-radius: 8px;
  background: rgba(18, 36, 58, 0.86);
  padding: 0.22rem 0.32rem;
  overflow: hidden;
}

.guide-program.current {
  border-color: rgba(245, 165, 36, 0.7);
}

.guide-program-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(245, 165, 36, 0.3), rgba(0, 199, 168, 0.25));
}

.guide-program-title {
  position: relative;
  font-size: 0.74rem;
  line-height: 1.15;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.guide-program-time {
  position: relative;
  margin-top: 0.12rem;
  font-size: 0.67rem;
  color: var(--ink-dim);
}

.guide-program-progress {
  position: relative;
  margin-top: 0.05rem;
  font-size: 0.64rem;
  color: var(--accent);
}

.watcher-info {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--ink-dim);
  font-size: 0.82rem;
}

.guide-row .ghost-btn {
  align-self: center;
  justify-self: end;
}

.guide-tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
  font-size: 0.72rem;
  color: var(--ink-dim);
}

.guide-empty {
  padding: 0.75rem;
  color: var(--ink-dim);
}

.viewer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.9rem;
}

.viewer-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  backdrop-filter: blur(8px);
  padding: 0.8rem;
  animation: slideIn 0.4s ease both;
}

.viewer-card:nth-child(2) {
  animation-delay: 0.05s;
}

.viewer-card:nth-child(3) {
  animation-delay: 0.1s;
}

.viewer-card:nth-child(4) {
  animation-delay: 0.15s;
}

.viewer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
}

.viewer-head h2 {
  margin: 0;
  font-size: 1rem;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.viewer-controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.video-shell {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(157, 193, 224, 0.35);
  background: #000;
}

video {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #d8e8f8;
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.35);
}

.error-text {
  margin: 0.55rem 0 0;
  min-height: 1.2rem;
  color: #ffb4b4;
  font-size: 0.82rem;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1024px) {
  .viewer-grid {
    grid-template-columns: 1fr;
  }

  .guide-controls {
    grid-template-columns: 1fr;
  }

  .tuner-cards {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .guide-block-labels {
    grid-template-columns: 6.4rem repeat(var(--guide-block-count, 4), minmax(5rem, 1fr)) 3.6rem;
  }

  .guide-row {
    grid-template-columns: 6.4rem 1fr 3.6rem;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }
}
