:root {
  --bg-0: #070a14;
  --bg-1: #0b1020;
  --bg-2: #141d34;
  --text-0: #f4f7ff;
  --text-1: #b5bfd9;
  --accent: #4f8cff;
  --danger: #ff5f74;
  --border: rgba(255, 255, 255, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-0);
  background: radial-gradient(circle at top right, #1f2f57 0%, var(--bg-1) 35%, var(--bg-0) 100%);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 20px;
}

.topbar {
  padding: 16px;
  border-radius: 18px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 26px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
}

.brand h1 {
  font-size: 1.2rem;
}

.brand p {
  color: var(--text-1);
  font-size: 0.88rem;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: stretch;
}

.scan-status {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-1);
  padding: 0 4px;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 20px;
}

.sidebar {
  border-radius: 18px;
  padding: 14px;
  min-height: 70vh;
}

.sidebar-head {
  padding: 10px;
  margin-bottom: 8px;
}

.sidebar-head h2 {
  font-size: 0.95rem;
  color: var(--text-1);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.group-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-item {
  border: 1px solid transparent;
  padding: 12px;
  border-radius: 12px;
  color: var(--text-0);
  background: transparent;
  text-align: left;
  font-size: 0.95rem;
  cursor: pointer;
}

.group-item:hover,
.group-item:focus-visible {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.group-item.active {
  background: linear-gradient(180deg, rgba(79, 140, 255, 0.28), rgba(79, 140, 255, 0.12));
  border-color: rgba(79, 140, 255, 0.6);
}

.content {
  min-width: 0;
  padding-right: var(--content-mini-inset-right, 0px);
  padding-bottom: var(--content-mini-inset-bottom, 0px);
}

.content-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 4px 0 12px;
}

.content-head h2 {
  font-size: 1.35rem;
}

.count-pill {
  color: var(--text-1);
  font-size: 0.9rem;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.channel-card {
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  min-height: 260px;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.channel-card:hover,
.channel-card:focus-within {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.38);
}

.channel-card.playing {
  border: 1px solid rgba(123, 218, 133, 0.9);
  box-shadow: 0 0 0 1px rgba(123, 218, 133, 0.4) inset, 0 10px 30px rgba(68, 172, 89, 0.28);
}

.card-link {
  color: inherit;
  text-decoration: none;
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 260px;
}

.card-image {
  width: 100%;
  height: 190px;
  object-fit: cover;
  background: linear-gradient(140deg, #1f2f57, #0d1528);
}

.card-info {
  padding: 12px;
  display: grid;
  gap: 4px;
}

.card-title {
  font-size: 1rem;
}

.card-group {
  color: var(--text-1);
  font-size: 0.84rem;
}

.card-edit {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
}

.card-status {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 95, 116, 0.6);
  background: rgba(255, 95, 116, 0.2);
  color: #ffd6dc;
  font-size: 0.7rem;
  font-weight: 600;
}

.card-status.success {
  border-color: rgba(123, 218, 133, 0.65);
  background: rgba(123, 218, 133, 0.2);
  color: #dcffe1;
}

.card-status.warning {
  border-color: rgba(255, 196, 94, 0.68);
  background: rgba(255, 196, 94, 0.2);
  color: #fff2d7;
}

.card-status.error {
  border-color: rgba(255, 95, 116, 0.6);
  background: rgba(255, 95, 116, 0.2);
  color: #ffd6dc;
}

.empty-state {
  margin-top: 20px;
  color: var(--text-1);
}

.now-playing {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 20;
  border-radius: 16px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(360px, calc(100vw - 28px));
}

.now-playing-info h3 {
  font-size: 0.95rem;
}

.now-playing-info p {
  font-size: 0.82rem;
  color: var(--text-1);
}

.now-playing-actions {
  display: flex;
  gap: 8px;
}

.now-playing-actions .btn {
  padding: 7px 10px;
  font-size: 0.8rem;
}

.btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-0);
  border-radius: 11px;
  padding: 10px 13px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn:hover,
.btn:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  outline: none;
}

.btn.primary {
  background: rgba(79, 140, 255, 0.25);
  border-color: rgba(79, 140, 255, 0.65);
}

.btn.danger {
  background: rgba(255, 95, 116, 0.2);
  border-color: rgba(255, 95, 116, 0.5);
}

.btn.tiny {
  padding: 6px 10px;
  font-size: 0.76rem;
}

.file-btn {
  display: inline-flex;
  align-items: center;
}

.dialog {
  width: min(460px, calc(100vw - 30px));
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text-0);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.form-stack {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.form-stack label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-1);
}

.field-feedback {
  font-size: 0.78rem;
  color: var(--text-1);
}

.field-feedback.error {
  color: var(--danger);
}

.field-feedback.success {
  color: #9fdd9f;
}

.image-preview {
  width: 100%;
  max-width: 220px;
  height: 124px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(140deg, #1f2f57, #0d1528);
}

.player-dialog {
  width: min(980px, calc(100vw - 30px));
  resize: both;
  overflow: auto;
  min-width: min(520px, calc(100vw - 30px));
  min-height: 360px;
}

.m3u-dialog {
  width: min(980px, calc(100vw - 30px));
}

.player-shell {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.player-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.player-head h3 {
  font-size: 1.1rem;
}

.player-head p {
  color: var(--text-1);
  font-size: 0.86rem;
}

.player-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #000;
}

.player-shell .dialog-actions {
  flex-wrap: wrap;
}

.m3u-list {
  display: grid;
  gap: 10px;
  max-height: min(58vh, 620px);
  overflow: auto;
}

.m3u-list-actions {
  display: flex;
  justify-content: center;
}

.m3u-search-wrap {
  display: grid;
  gap: 8px;
}

.m3u-search-wrap input {
  width: 100%;
}

.m3u-search-wrap select {
  width: 100%;
}

.network-stream-form {
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.network-stream-form h4 {
  font-size: 0.95rem;
}

.network-import-row {
  display: flex;
  justify-content: flex-start;
}

.network-stream-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.m3u-item {
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.m3u-item.last-previewed {
  border: 1px solid rgba(79, 140, 255, 0.75);
  box-shadow: 0 0 0 1px rgba(79, 140, 255, 0.35) inset;
}

.m3u-item-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
}

.m3u-item-image {
  width: 70px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  background: linear-gradient(140deg, #1f2f57, #0d1528);
}

.m3u-item-title {
  font-size: 0.92rem;
}

.m3u-item-subtitle {
  font-size: 0.8rem;
  color: var(--text-1);
  word-break: break-word;
}

.m3u-item-status {
  margin-top: 4px;
  font-size: 0.76rem;
  font-weight: 600;
}

.m3u-item-status.success {
  color: #b8ffca;
}

.m3u-item-status.warning {
  color: #ffe7ba;
}

.m3u-item-status.error {
  color: #ffd1d8;
}

.m3u-item-actions {
  display: flex;
  gap: 8px;
  width: 100%;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
}

.m3u-group-select {
  min-width: 150px;
  max-width: 220px;
  width: min(220px, 100%);
  font-size: 0.8rem;
  padding: 7px 8px;
  border-radius: 8px;
}

.m3u-dialog .dialog-actions {
  justify-content: space-between;
}

@media (max-width: 720px) {
  .m3u-item-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .m3u-group-select {
    width: 100%;
    max-width: none;
  }

  .network-stream-grid {
    grid-template-columns: 1fr;
  }
}

.player-video-host,
.mini-player-video-host {
  width: 100%;
}

.player-video-host.aspect-fit .player-video {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.player-video-host.aspect-contain .player-video {
  aspect-ratio: auto;
  width: 100%;
  max-height: min(62vh, 68vw);
  object-fit: contain;
  background: #000;
}

.player-video-host.aspect-cover .player-video {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.player-video-host.aspect-fill .player-video {
  aspect-ratio: 16 / 9;
  object-fit: fill;
}

.player-video-host.aspect-tab-max .player-video {
  aspect-ratio: auto;
  width: 100%;
  height: min(76vh, 74vw);
  object-fit: contain;
  background: #000;
}

.m3u-item.already-added {
  border: 1px solid rgba(123, 218, 133, 0.65);
}

.mini-player {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 2147483647;
  isolation: isolate;
  width: min(360px, calc(100vw - 28px));
  border-radius: 14px;
  padding: 10px;
  display: grid;
  gap: 10px;
  background: linear-gradient(180deg, rgba(100, 100, 100, 0.30), rgba(70, 70, 70, 0.20));
  -webkit-backdrop-filter: blur(48px) saturate(140%);
  backdrop-filter: blur(48px) saturate(140%);
}

#miniPlayer {
  background: linear-gradient(180deg, rgba(100, 100, 100, 0.30), rgba(70, 70, 70, 0.20));
  -webkit-backdrop-filter: blur(58px) saturate(145%);
  backdrop-filter: blur(58px) saturate(145%);
}

.mini-player.dragging {
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.mini-player .player-video {
  border-radius: 10px;
}

.mini-player-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

input,
select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  color: var(--text-0);
  background: rgba(255, 255, 255, 0.05);
}

input:focus,
select:focus {
  outline: 2px solid rgba(79, 140, 255, 0.6);
  outline-offset: 1px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.glass {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.05));
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
    gap: 14px;
  }

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

  .sidebar {
    min-height: 0;
  }

  .group-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
  }

  .group-item {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .topbar {
    align-items: stretch;
  }

  .topbar-actions {
    width: 100%;
  }

  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }

  .content-head {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 640px) {
  .topbar-actions .btn,
  .topbar-actions .file-btn {
    flex: 1 1 calc(50% - 10px);
    justify-content: center;
    text-align: center;
    min-width: 0;
  }

  .dialog,
  .player-dialog,
  .m3u-dialog {
    width: calc(100vw - 16px);
    border-radius: 14px;
  }

  .player-shell,
  .form-stack {
    padding: 12px;
  }

  .channel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .card-link,
  .channel-card {
    min-height: 220px;
  }

  .card-image {
    height: 150px;
  }

  .now-playing {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 10px;
    flex-direction: column;
    align-items: flex-start;
  }

  .now-playing-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .now-playing-actions .btn {
    flex: 1 1 calc(50% - 8px);
  }

  .mini-player {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 10px;
  }
}

@media (max-width: 420px) {
  .topbar-actions .btn,
  .topbar-actions .file-btn,
  .now-playing-actions .btn {
    flex-basis: 100%;
  }
}
