:root {
  --bg: #0b0f14;
  --bg-2: #121821;
  --bg-3: #1a2330;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef3f8;
  --muted: #8b9aab;
  --accent: #2dd4a8;
  --accent-2: #f0b429;
  --danger: #ff6b6b;
  --sidebar: 360px;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Bebas Neue", Impact, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(45, 212, 168, 0.12), transparent 55%),
    radial-gradient(900px 500px at -10% 100%, rgba(240, 180, 41, 0.08), transparent 50%),
    var(--bg);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100%;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: rgba(10, 14, 20, 0.85);
  backdrop-filter: blur(12px);
  min-height: 0;
}

.brand {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background:
    linear-gradient(135deg, var(--accent), #1aa884 40%, var(--accent-2));
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 10px 30px rgba(45,212,168,0.25);
}
.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: 28px;
  letter-spacing: 0.04em;
  line-height: 1;
}
.brand-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.icon-btn, .pager button {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}
.icon-btn:hover, .pager button:hover:not(:disabled) {
  border-color: rgba(45, 212, 168, 0.45);
}
.pager button:disabled { opacity: 0.35; cursor: default; }

.search-wrap input,
.settings input[type="url"],
.settings input[type="file"] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  outline: none;
}
.search-wrap input:focus,
.settings input[type="url"]:focus {
  border-color: rgba(45, 212, 168, 0.55);
  box-shadow: 0 0 0 3px rgba(45, 212, 168, 0.12);
}

.groups {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active {
  color: #04110c;
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

.channels {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.channel {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  font: inherit;
}
.channel:hover { background: var(--bg-2); }
.channel.active {
  background: var(--bg-3);
  border-color: rgba(45, 212, 168, 0.35);
}
.channel img, .logo-fallback {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg-3);
}
.logo-fallback {
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 18px;
  color: var(--accent);
}
.channel-name {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}
.channel-group {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.pager {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}
#pageInfo {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.stage {
  display: grid;
  grid-template-rows: 1fr auto;
  min-width: 0;
  min-height: 0;
  padding: 18px;
  gap: 14px;
}

.player-shell {
  position: relative;
  min-height: 0;
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
}
#video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(11,15,20,0.2), rgba(11,15,20,0.75)),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255,255,255,0.015) 3px
    );
  pointer-events: none;
}
.overlay.hidden { display: none; }
.overlay-title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(40px, 8vw, 72px);
  letter-spacing: 0.04em;
}
.overlay-sub {
  margin: 6px 0 0;
  color: var(--muted);
}

.now {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: rgba(18, 24, 33, 0.9);
  border: 1px solid var(--line);
}
.now img {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--bg-3);
}
.now-label {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}
#nowTitle {
  margin: 2px 0 0;
  font-family: var(--display);
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: 0.03em;
  line-height: 1;
}
.now-group {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: #10161f;
  color: var(--text);
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 30px 100px rgba(0,0,0,0.55);
}
dialog::backdrop {
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
}
.settings {
  padding: 22px;
  display: grid;
  gap: 10px;
}
.settings h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 34px;
  letter-spacing: 0.04em;
}
.hint { margin: 0 0 8px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.settings label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.settings-msg { margin: 4px 0 0; font-size: 13px; color: var(--accent); }
.settings-msg.error { color: var(--danger); }
.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}
.btn {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  color: #04110c;
  border-color: transparent;
  font-weight: 700;
}
.btn.ghost:hover { border-color: rgba(255,255,255,0.2); }

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 1fr;
    height: auto;
    min-height: 100dvh;
  }
  .stage { order: -1; padding: 12px; }
  .sidebar { border-right: 0; border-top: 1px solid var(--line); height: auto; }
  .channels { max-height: 42vh; }
}

/* Now-playing bar: aggiunta colonna per il menu */
.now {
  grid-template-columns: 64px 1fr auto;
}
.now-info {
  min-width: 0;
}
.now-info #nowTitle,
.now-info .now-group {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Menu 3 puntini */
.now-menu {
  position: relative;
  align-self: center;
}
.now-menu .icon-btn {
  font-size: 20px;
  line-height: 1;
}
.menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  min-width: 210px;
  background: #10161f;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  z-index: 40;
  display: grid;
  gap: 2px;
}
.menu[hidden] {
  display: none;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.menu-item:hover {
  background: var(--bg-3);
}
.menu-ico {
  font-size: 15px;
  width: 18px;
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(12px);
  background: var(--accent);
  color: #04110c;
  font-weight: 600;
  font-size: 14px;
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: 0 14px 40px rgba(45, 212, 168, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
