:root {
  --bg: #07080c;
  --panel: #10131a;
  --panel-2: #161a23;
  --panel-3: #1e2430;
  --line: #2b3242;
  --text: #f3f6fb;
  --muted: #9aa6b8;
  --soft: #c9d1de;
  --accent: #18c5a7;
  --accent-dark: #0f8a78;
  --gold: #f2b84b;
  --danger: #f45b69;
  --blue: #68a7ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.tv-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  background: #0d1016;
  border-right: 1px solid var(--line);
  padding: 20px;
  position: sticky;
  top: 0;
  align-self: start;
}

.brand-row,
.topbar,
.panel-title,
.settings-head,
.control-strip,
.form-actions,
.field-row {
  display: flex;
  align-items: center;
}

.brand-row,
.topbar,
.panel-title,
.settings-head {
  justify-content: space-between;
  gap: 16px;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.mobile-close,
#open-sidebar {
  display: none !important;
}

.source-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 9px 11px;
  margin: 18px 0;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.84rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--danger);
  flex: 0 0 auto;
}

.source-status.is-live .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(24, 197, 167, 0.16);
}

.search-box {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
}

.quick-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 16px 0 18px;
}

.tab,
.group-button,
.tool-button,
.source-option,
.icon-button {
  border: 1px solid var(--line);
  color: var(--soft);
  background: var(--panel-2);
  border-radius: 8px;
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.tab {
  height: 34px;
  font-size: 0.78rem;
  font-weight: 700;
}

.tab.is-active,
.group-button.is-active,
.source-option.is-selected {
  color: #06110f;
  background: var(--accent);
  border-color: var(--accent);
}

.section-label {
  margin: 20px 0 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.group-list {
  display: grid;
  gap: 7px;
  max-height: calc(100vh - 230px);
  overflow: auto;
  padding-right: 4px;
}

.group-button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  text-align: left;
  font-size: 0.86rem;
}

.group-button span:last-child {
  color: inherit;
  opacity: 0.74;
  font-size: 0.74rem;
}

.watch-area {
  min-width: 0;
  padding: 24px;
}

.topbar {
  min-height: 54px;
  margin-bottom: 18px;
}

.now-heading {
  min-width: 0;
}

.now-heading span,
.settings-head span {
  display: block;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.now-heading h1,
.settings-head h2 {
  margin: 2px 0 0;
  max-width: 56vw;
  overflow: hidden;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions,
.control-strip,
.form-actions {
  gap: 10px;
}

.tool-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  font-weight: 800;
  font-size: 0.85rem;
}

.tool-button.primary {
  color: #06110f;
  background: var(--accent);
  border-color: var(--accent);
}

.tool-button:hover,
.icon-button:hover,
.group-button:hover,
.tab:hover,
.source-option:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tool-button.primary:hover,
.tab.is-active:hover,
.group-button.is-active:hover,
.source-option.is-selected:hover {
  color: #06110f;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex: 0 0 auto;
}

.icon-button.small {
  width: 32px;
  height: 32px;
}

.icon-button.is-on {
  color: #201400;
  background: var(--gold);
  border-color: var(--gold);
}

.player-zone {
  display: grid;
  gap: 12px;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(24, 197, 167, 0.14), transparent 32%),
    radial-gradient(circle at 82% 18%, rgba(104, 167, 255, 0.12), transparent 30%),
    #020306;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

.video-frame.is-empty video {
  opacity: 0;
}

video.is-cover {
  object-fit: cover;
}

.player-empty,
.loading-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--soft);
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

.player-empty svg {
  width: 56px;
  height: 56px;
  color: var(--accent);
}

.player-empty strong {
  font-size: clamp(1rem, 2vw, 1.28rem);
}

.player-empty span {
  color: var(--muted);
  max-width: 360px;
}

.loading-layer {
  background: rgba(3, 5, 8, 0.78);
  font-weight: 800;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.control-strip {
  flex-wrap: wrap;
  min-height: 50px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.switch-control,
.check-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.switch-control {
  margin-left: auto;
  min-height: 34px;
  padding: 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.switch-control input,
.check-control input {
  accent-color: var(--accent);
}

select,
input,
textarea {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

select {
  height: 34px;
  padding: 0 10px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 16px;
  margin-top: 18px;
}

.channel-panel,
.guide-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.panel-title {
  min-height: 52px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-title h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.channel-list {
  display: grid;
  max-height: 430px;
  overflow: auto;
}

.channel-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 10px 14px;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(43, 50, 66, 0.72);
  text-align: left;
}

.channel-row:hover,
.channel-row.is-active {
  background: var(--panel-2);
}

.channel-row.is-active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.channel-logo {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--accent);
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 900;
}

.channel-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.channel-meta {
  min-width: 0;
}

.channel-meta strong,
.guide-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-meta span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-badge {
  max-width: 110px;
  overflow: hidden;
  padding: 4px 8px;
  color: var(--soft);
  background: rgba(104, 167, 255, 0.13);
  border: 1px solid rgba(104, 167, 255, 0.28);
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-list,
.guide-empty {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.guide-now {
  padding: 14px;
  background: linear-gradient(135deg, rgba(24, 197, 167, 0.16), rgba(104, 167, 255, 0.1));
  border-bottom: 1px solid var(--line);
}

.guide-now:empty {
  display: none;
}

.guide-now h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.guide-now p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.progress-line {
  height: 7px;
  overflow: hidden;
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.13);
  border-radius: 99px;
}

.progress-line span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.guide-list {
  max-height: 378px;
  overflow: auto;
}

.guide-item {
  padding: 13px 14px;
  border-bottom: 1px solid rgba(43, 50, 66, 0.72);
}

.guide-item time {
  display: block;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.guide-item p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(1, 3, 7, 0.72);
  backdrop-filter: blur(10px);
}

.settings-panel {
  width: min(720px, 100%);
  max-height: min(820px, calc(100vh - 40px));
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-head {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.settings-head h2 {
  max-width: none;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 16px 18px 0;
}

.source-option {
  min-height: 78px;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 10px;
  font-weight: 800;
}

.source-option svg {
  width: 22px;
  height: 22px;
}

.source-form {
  padding: 18px;
}

.field-group {
  margin-bottom: 15px;
}

.field-group.is-hidden {
  display: none;
}

.field-group label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field-group input,
.field-group textarea {
  width: 100%;
  padding: 11px 12px;
  outline: 0;
}

.field-group textarea {
  resize: vertical;
  min-height: 150px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.field-group input:focus,
.field-group textarea:focus,
select:focus {
  border-color: var(--accent);
}

.server-readout {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.field-row {
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.form-actions {
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

@media (max-width: 1080px) {
  .tv-shell {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .guide-list,
  .channel-list {
    max-height: 360px;
  }
}

@media (max-width: 760px) {
  .tv-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 15;
    width: min(320px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .mobile-close,
  #open-sidebar {
    display: inline-flex !important;
  }

  .watch-area {
    padding: 14px;
  }

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

  .now-heading h1 {
    max-width: calc(100vw - 150px);
    font-size: 1.04rem;
  }

  .top-actions .tool-button span {
    display: none;
  }

  .top-actions .tool-button {
    width: 38px;
    padding: 0;
  }

  .switch-control {
    margin-left: 0;
  }

  .setup-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .channel-row {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .channel-badge {
    display: none;
  }
}
