:root {
  --ink: #05060a;
  --panel: #0e1017;
  --panel2: #080910;
  --f1: #e10600;
  --mgp: #4fd8ff;
  --tv8: #3d8bff;
  --amber: #ffc107;
  --green: #4cd964;
  --hair: rgba(255, 255, 255, 0.10);
  --mute: rgba(255, 255, 255, 0.55);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--ink); color: #fff; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
img { display: block; }
.mute { color: var(--mute); }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding-left: var(--sal); padding-right: var(--sar);
  background:
    radial-gradient(circle at 95% 0%, rgba(225, 6, 0, 0.20), transparent 95vw),
    radial-gradient(circle at 0% 80%, rgba(79, 216, 255, 0.10), transparent 110vw),
    var(--ink);
}

/* ---------- intestazione ---------- */
header { padding: calc(var(--sat) + 16px) 16px 0; flex: none; }
.hrow { display: flex; justify-content: space-between; align-items: flex-start; }
.logos { display: flex; align-items: center; gap: 10px; }
.logos .sep { width: 1px; height: 14px; background: var(--hair); }
.slogo { object-fit: contain; }
h1 { margin: 10px 0 0; font-size: 32px; font-weight: 900; font-style: italic; letter-spacing: -0.5px; line-height: 1.1; }
.tools { display: flex; gap: 8px; align-items: center; }
.pill {
  border-radius: 999px; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--hair);
  padding: 8px 14px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px;
}
.pill.flag { padding: 4px 12px; font-size: 18px; line-height: 1.4; }
.filters { display: flex; gap: 8px; align-items: center; margin: 14px 0 6px; }
.fpill {
  border-radius: 999px; padding: 10px 14px; border: 1px solid var(--hair); background: rgba(255, 255, 255, 0.04);
  display: inline-flex; align-items: center; justify-content: center; transition: background .2s, border-color .2s;
}
.fpill.sel { background: color-mix(in srgb, var(--c) 22%, transparent); border-color: var(--c); }
.stpill {
  flex: 1; min-width: 0; border-radius: 999px; padding: 10px 12px; text-align: center; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid var(--c);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- pagine ---------- */
#series {
  flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
#series::-webkit-scrollbar, .gps::-webkit-scrollbar { display: none; }
.spage { flex: 0 0 100%; min-width: 0; scroll-snap-align: start; scroll-snap-stop: always; display: flex; flex-direction: column; }
.navrow { display: flex; align-items: center; padding: 4px 12px; font-size: 12px; color: var(--mute); flex: none; }
.navrow .slot { flex: 1; display: flex; }
.navrow .slot.r { justify-content: flex-end; }
.chip { border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 600; letter-spacing: .5px; color: var(--mute); display: inline-flex; gap: 4px; align-items: center; }
.chip .fl { font-size: 12px; }
.gps {
  position: relative; flex: 1; min-height: 0; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
.gp { min-height: 100%; scroll-snap-align: start; scroll-snap-stop: always; padding: 4px 16px 8px; }
.gp-in { display: flex; flex-direction: column; gap: 14px; padding-bottom: 16px; will-change: transform, opacity; transform-origin: 50% 0; }

/* ---------- card ---------- */
.card {
  border-radius: 20px; background: var(--panel); border: 1px solid var(--hair); padding: 16px; overflow: hidden;
}
.card.wk { border-radius: 24px; padding: 0; background: linear-gradient(var(--panel), var(--panel2)); }
.card.wk::before { content: ''; display: block; height: 2px; background: linear-gradient(90deg, var(--ac), transparent); }
.card.wk .in { padding: 16px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.b { font-weight: 700; }
.t16 { font-size: 16px; } .t15 { font-size: 15px; } .t14 { font-size: 14px; } .t13 { font-size: 13px; } .t12 { font-size: 12px; } .t11 { font-size: 11px; }
.amber { color: var(--amber); }

.nextup {
  border-radius: 28px; padding: 20px; border: 1px solid transparent;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--ac) 30%, transparent), var(--panel) 60%) padding-box,
    linear-gradient(135deg, color-mix(in srgb, var(--ac) 90%, transparent), var(--hair) 40%) border-box;
}
.nextup h2 { margin: 22px 0 4px; font-size: 24px; font-weight: 900; font-style: italic; letter-spacing: -0.3px; line-height: 1.15; }
.nextup .sub { display: flex; gap: 10px; font-size: 15px; }
.nextup .sub b { color: var(--ac); }
.live { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; }
.live i { width: 9px; height: 9px; border-radius: 50%; background: var(--ac); animation: pulse .8s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
.cd { display: flex; gap: 8px; margin-top: 20px; }
.cd > div { flex: 1; border-radius: 16px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--hair); padding: 12px 0; text-align: center; }
.cd b { display: block; font: 300 32px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.cd > div:last-child b { color: var(--ac); }
.cd span { font-size: 11px; color: var(--mute); }

.wk .head { display: flex; align-items: center; gap: 12px; }
.wk .head .ttl { flex: 1; font-weight: 700; font-size: 16px; }
.tl { position: relative; margin-top: 12px; }
.tl::before { content: ''; position: absolute; left: 4px; top: 10px; bottom: 10px; width: 1px; background: rgba(255, 255, 255, 0.12); }
.ses { position: relative; display: flex; align-items: center; padding: 6px 0; font-size: 14px; }
.ses .dot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--dc); background: var(--panel); margin-right: 14px; z-index: 1; flex: none; box-sizing: border-box; }
.ses.key .dot { background: var(--dc); }
.ses.past .dot { background: var(--panel); }
.ses .n { flex: 1; }
.ses.key .n { font-weight: 700; }
.ses.past { color: rgba(255, 255, 255, 0.30); }
.ses:not(.key):not(.past) { color: var(--mute); }
.ses .live-t { color: var(--ac); font-weight: 700; }

/* TV8 */
.tv8card .hd { display: flex; align-items: center; gap: 12px; }
.tv8row { display: flex; align-items: center; padding: 8px 6px; margin-top: 4px; border-radius: 12px; }
a.tv8row:active { background: rgba(255, 255, 255, .06); }
.tv8row.past { color: rgba(255, 255, 255, .3); }
.tv8row .nm { font-weight: 700; font-size: 14px; }
.badge { border-radius: 999px; padding: 4px 10px; font-size: 11px; font-weight: 700; border: 1px solid var(--bc); color: var(--bc); background: color-mix(in srgb, var(--bc) 12%, transparent); }
.badge.on { background: color-mix(in srgb, var(--bc) 22%, transparent); }

/* broadcaster */
.bcrow { display: flex; align-items: center; gap: 12px; margin-top: 10px; border-radius: 12px; padding: 2px; }
.bcrow:active { background: rgba(255, 255, 255, .06); }
.bclogo { width: 52px; height: 52px; border-radius: 12px; overflow: hidden; background: #fff; flex: none; display: flex; align-items: center; justify-content: center; }
.bclogo img { width: 100%; height: 100%; object-fit: contain; padding: 7px; }
.bclogo img.cover { object-fit: cover; padding: 0; }
.bclogo.txt { background: #1b2030; color: #fff; font-weight: 900; font-size: 10px; line-height: 11px; text-align: center; padding: 3px; }

/* podio */
.podium { padding: 14px 16px; }
.podium .r { display: flex; align-items: center; gap: 12px; padding: 5px 0; }
.podium .pos { width: 22px; font-weight: 900; font-size: 16px; }
.podium .pos.p1 { color: var(--ac); }
.btnpill {
  align-self: flex-start; border-radius: 999px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  background: color-mix(in srgb, var(--ac) 14%, transparent); border: 1px solid var(--ac);
}

/* ---------- footer ---------- */
footer { flex: none; padding: 6px 16px calc(var(--sab) + 10px); text-align: center; }
#clock { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 12px; color: var(--mute); }
#clock b { font: 700 15px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: #fff; }
footer .ver { font-size: 11px; color: var(--mute); opacity: .8; padding: 0 8px; }
#install { margin: 6px auto 0; display: none; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); animation: fade .2s; }
.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--panel); border-radius: 28px 28px 0 0; border: 1px solid var(--hair); border-bottom: 0;
  animation: up .25s cubic-bezier(.2, .8, .2, 1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.grab { width: 36px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .25); margin: 10px auto 4px; flex: none; }
.sbody { overflow-y: auto; padding: 8px 22px calc(var(--sab) + 24px); -webkit-overflow-scrolling: touch; user-select: text; -webkit-user-select: text; }
.sbody h3 { margin: 4px 0 0; font-size: 24px; font-weight: 900; font-style: italic; }
.search {
  width: 100%; margin: 12px 0 8px; border-radius: 14px; border: 1px solid var(--hair); background: rgba(255, 255, 255, .06);
  color: #fff; font: inherit; font-size: 15px; padding: 12px 14px; outline: none;
}
.item { display: flex; align-items: center; gap: 4px; padding: 10px 8px; border-radius: 12px; width: 100%; text-align: left; }
.item.sel { background: color-mix(in srgb, var(--f1) 14%, transparent); }
.item .fl { width: 44px; font-size: 24px; flex: none; }
.item .nm { font-weight: 600; font-size: 15px; flex: 1; }
.item .ck { color: var(--f1); font-weight: 700; font-size: 18px; }
.ctry { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border-radius: 12px; background: rgba(255, 255, 255, .06); padding: 10px 12px; margin: 10px 0 0; font-size: 14px; }
.ctry .grow { flex: 1; }

.tabs { display: flex; gap: 8px; margin: 12px 0 8px; }
.tab { border-radius: 999px; padding: 10px 18px; font-size: 13px; font-weight: 600; border: 1px solid var(--hair); background: rgba(255, 255, 255, .04); }
.tab.sel { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, transparent); }
.srow { display: flex; align-items: center; padding: 7px 0; }
.srow .pos { width: 34px; font-weight: 900; font-size: 16px; flex: none; }
.srow .pos.p1, .srow .pts.p1 { color: var(--c); }
.srow .who { flex: 1; min-width: 0; }
.srow .who b { font-weight: 600; font-size: 14px; display: block; }
.srow .who span { font-size: 12px; color: var(--mute); }
.srow .pts { font-weight: 600; font-size: 14px; text-align: right; flex: none; }
.srow .pts small { display: block; font-weight: 400; font-size: 12px; color: var(--mute); }
.note { font-size: 11px; color: var(--mute); opacity: .8; margin: 12px 0 0; }
.cta { border-radius: 12px; padding: 12px 18px; font-weight: 700; background: var(--c, var(--f1)); color: #000; }
.cta.red { color: #fff; }

/* impostazioni */
.grp { border-radius: 20px; border: 1px solid var(--hair); background: rgba(255, 255, 255, .04); overflow: hidden; margin-top: 12px; }
.grp::before { content: ''; display: block; height: 2px; background: linear-gradient(90deg, var(--c), transparent); }
.grp .gi { padding: 8px 16px 10px; }
.sw-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 15px; transition: opacity .2s; }
.sw-row.hdr { font-size: 17px; font-weight: 700; }
.sw-row.off { opacity: .4; pointer-events: none; }
.sw { position: relative; width: 52px; height: 32px; flex: none; }
.sw input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.sw span { position: absolute; inset: 0; border-radius: 16px; background: rgba(255, 255, 255, .08); border: 1px solid var(--hair); transition: background .2s; }
.sw span::after { content: ''; position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; border-radius: 50%; background: var(--mute); transition: transform .2s, background .2s; }
.sw input:checked + span { background: var(--c); border-color: var(--c); }
.sw input:checked + span::after { transform: translateX(20px); background: #fff; }
.leads { display: flex; gap: 8px; margin-top: 10px; }
.msg { font-size: 13px; font-weight: 600; margin: 18px 0 10px; white-space: pre-line; }
.msg.ok { color: var(--green); } .msg.warn { color: var(--amber); }
.full { width: 100%; text-align: center; }
.ghost { width: 100%; text-align: center; padding: 12px; color: var(--mute); margin-top: 8px; }
.empty { padding: 24px 24px; color: var(--mute); font-size: 14px; }

@media (min-width: 760px) {
  #app { max-width: 720px; margin: 0 auto; left: 0; right: 0; border-left: 1px solid var(--hair); border-right: 1px solid var(--hair); }
}
@media (prefers-reduced-motion: reduce) {
  .gps { scroll-behavior: auto; } .live i { animation: none; }
}
