:root {
  --bg: #0d0f12;
  --panel: #171a1f;
  --panel-2: #20242b;
  --line: #2c313a;
  --text: #eef0f3;
  --muted: #9aa3ae;
  --accent: #3e8bff;
  --danger: #ff6b6b;
  --live: #e5383b;
  --radius: 14px;
  --tap: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.btn {
  min-height: var(--tap);
  padding: 0 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--panel-2);
}
.btn:active { background: var(--line); }
.btn.big { min-height: 64px; padding: 0 36px; font-size: 20px; background: var(--accent); }
.btn.more { grid-column: 1 / -1; justify-self: center; margin: 12px 0 24px; }

.message { color: var(--muted); padding: 24px; margin: 0; }
.message.error { color: var(--danger); }
.notice { margin: 0; padding: 6px 24px; font-size: 14px; color: var(--muted); background: var(--panel); border-bottom: 1px solid var(--line); }

.spinner {
  width: 56px; height: 56px; margin: 48px auto;
  border: 5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Innlogging */
.login {
  margin: auto; width: min(420px, 90vw);
  display: flex; flex-direction: column; gap: 16px; align-items: stretch;
}
.login h1 { margin: 0 0 8px; font-size: 40px; text-align: center; }
.login input { min-height: 64px; padding: 0 20px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); }

/* Toppfelt og faner */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); }
.brand { font-weight: 700; font-size: 22px; margin-right: 12px; }
.tabs { display: flex; gap: 8px; flex: 1; }
.tab { min-height: var(--tap); padding: 0 24px; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted); }
.tab.active { background: var(--panel-2); color: var(--text); }
.tab.logout { font-size: 15px; }

.content { flex: 1; min-height: 0; overflow: hidden; }
.view { height: 100%; display: flex; flex-direction: column; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 14px 24px; }
.search { display: flex; gap: 10px; flex: 1 1 420px; }
.search input, .tv-main .toolbar input {
  flex: 1; min-height: var(--tap); padding: 0 18px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel);
}
.tv-main .toolbar input { max-width: 480px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--line); background: transparent; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Rutenett med videoer */
.grid {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 22px 18px; padding: 4px 24px 32px; align-content: start;
  -webkit-overflow-scrolling: touch;
}
.card { padding: 0; border: 0; background: none; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--panel-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; right: 8px; bottom: 8px; padding: 2px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.8); font-size: 15px; }
.badge.live { background: var(--live); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(255, 255, 255, 0.25); }
.progress-fill { height: 100%; background: var(--live); }
.card-title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-sub { color: var(--muted); font-size: 16px; }

/* TV */
.tv-body { flex: 1; min-height: 0; display: flex; }
.tv-cats { width: 300px; flex-shrink: 0; overflow-y: auto; padding: 0 12px 24px 24px; display: flex; flex-direction: column; gap: 4px; }
.cat { min-height: var(--tap); padding: 0 16px; border: 0; border-radius: 10px; background: transparent; text-align: left; color: var(--muted); }
.cat.active { background: var(--panel-2); color: var(--text); }
.tv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tv-main .toolbar { padding-top: 0; }
.tv-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tv-main.episodes .tv-grid { grid-template-columns: 1fr; gap: 8px; }
.tile { border: 0; padding: 12px; border-radius: var(--radius); background: var(--panel); display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; }
.tile.started { box-shadow: inset 0 -4px 0 var(--live); }
.tile-icon { width: 100%; aspect-ratio: 16 / 10; display: grid; place-items: center; border-radius: 10px; background: var(--panel-2); overflow: hidden; }
.tile-icon img { max-width: 85%; max-height: 85%; object-fit: contain; }
.tile-letter { font-size: 40px; color: var(--muted); }
.tile-name { font-size: 16px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.episode { display: flex; gap: 16px; align-items: center; min-height: 64px; padding: 0 18px; border: 0; border-radius: var(--radius); background: var(--panel); text-align: left; }
.episode.started { box-shadow: inset 4px 0 0 var(--live); }
.ep-label { color: var(--muted); font-variant-numeric: tabular-nums; }
.tv-main.episodes .tv-grid > .btn { justify-self: start; }

/* Spiller */
.player { position: fixed; inset: 0; z-index: 10; background: #000; }
.player.hidden { display: none; }
.player-canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player-tap { position: absolute; inset: 0; }
.player-top, .player-bottom {
  position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  transition: opacity 0.25s;
}
.player-top { top: 0; background: linear-gradient(rgba(0, 0, 0, 0.75), transparent); }
.player-bottom { bottom: 0; background: linear-gradient(transparent, rgba(0, 0, 0, 0.8)); padding-bottom: 20px; }
.player.idle .player-top, .player.idle .player-bottom { opacity: 0; pointer-events: none; }
.player-heading { min-width: 0; }
.player-title { font-size: 20px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-sub { color: var(--muted); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; }
.player-center .spinner { margin: 0; }
.player-error { background: rgba(0, 0, 0, 0.75); padding: 24px 32px; border-radius: var(--radius); max-width: 70vw; }
.player-error p { margin: 0 0 16px; }
.ctl { min-width: var(--tap); min-height: var(--tap); padding: 0 14px; border: 0; border-radius: var(--radius); background: rgba(255, 255, 255, 0.12); font-size: 20px; }
.ctl:active { background: rgba(255, 255, 255, 0.25); }
.ctl-play { min-width: 72px; font-size: 22px; }
.ctl-select { min-height: var(--tap); padding: 0 12px; border-radius: var(--radius); border: 0; background: rgba(255, 255, 255, 0.12); }
.time { font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
.seek { flex: 1; height: var(--tap); accent-color: var(--live); }
.live-badge { padding: 6px 12px; border-radius: 8px; background: var(--live); font-weight: 700; font-size: 15px; margin-right: auto; }
.toast {
  position: absolute; left: 50%; top: 90px; transform: translateX(-50%);
  padding: 12px 20px; border-radius: var(--radius); background: rgba(0, 0, 0, 0.8);
}

@media (max-width: 800px) {
  .tv-body { flex-direction: column; }
  .tv-cats { width: auto; flex-direction: row; overflow-x: auto; padding: 0 24px 8px; flex-shrink: 0; }
  .cat { white-space: nowrap; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

/* Abonnementer, spillelister og Google-innlogging */
.grid-head { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; }
.grid-head h2 { margin: 0; font-size: 24px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.channel { align-items: center; text-align: center; }
.avatar { width: 140px; height: 140px; border-radius: 50%; overflow: hidden; background: var(--panel-2); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.google-panel { grid-column: 1 / -1; max-width: 640px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; padding: 12px 0; }
.google-panel h2 { margin: 0; }
.google-panel p { margin: 0; }
.google-panel .muted { color: var(--muted); }
.device-code { font-size: 48px; font-weight: 700; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; padding: 12px 24px; border-radius: var(--radius); background: var(--panel-2); user-select: all; }
