/* tes-drive — car-friendly dark UI. No build step; hex/rgba only (older Chromium in the car). */

:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #151a21;
  --surface-2: #1e252f;
  --surface-3: #2a333f;
  --text: #f2f5f8;
  --muted: #9aa6b2;
  --accent: #e82127;
  --accent-hover: #ff3b41;
  --ok: #3ddc84;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --glass: rgba(14, 17, 22, 0.78);
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 64px;
  --topbar: 88px;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, Roboto, "Helvetica Neue", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 20px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
input, button, select { font: inherit; color: inherit; }
img, canvas, svg { display: block; }
a { color: inherit; text-decoration: none; }
.icon { flex: none; }
[hidden] { display: none !important; }

#app { height: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: var(--tap); padding: 0 28px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 1.05rem; letter-spacing: 0.01em;
  cursor: pointer; transition: background 140ms, transform 140ms var(--ease), border-color 140ms;
}
.btn:active { transform: scale(0.97); background: var(--surface-3); }
.btn:focus-visible, .tab:focus-visible, .icon-btn:focus-visible, .card:focus-visible, .tile:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:active { background: var(--accent-hover); }
.btn.danger { color: #ff7a7e; border-color: rgba(255, 90, 95, 0.35); background: rgba(232, 33, 39, 0.1); }
.btn.big { min-height: 80px; padding: 0 44px; font-size: 1.25rem; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); flex: none;
  border: 1px solid transparent; border-radius: 50%;
  background: transparent; cursor: pointer;
  transition: background 140ms, transform 140ms var(--ease);
}
.icon-btn:active { background: var(--surface-3); transform: scale(0.92); }

/* ---------- Shell + top bar ---------- */
.shell { display: flex; flex-direction: column; height: 100%; }
.topbar {
  flex: none; height: var(--topbar);
  display: flex; align-items: center; gap: 28px; padding: 0 28px;
  background: rgba(11, 13, 16, 0.92); border-bottom: 1px solid var(--border);
  position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 14px; font-weight: 800; font-size: 1.3rem; letter-spacing: -0.02em; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent);
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(232, 33, 39, 0.35);
}
.brand-mark .icon { color: #fff; margin-left: 3px; }
.tabs { display: flex; gap: 8px; flex: 1; }
.tab {
  min-height: var(--tap); padding: 0 26px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted);
  font-weight: 600; font-size: 1.1rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 10px;
  transition: background 140ms, color 140ms;
}
.tab:active { background: var(--surface-2); }
.tab[aria-current="page"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }
/* provider switch (segmented) */
.provider-switch { display: flex; padding: 5px; gap: 4px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.seg {
  min-height: 54px; padding: 0 22px; border: 0; border-radius: 999px; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 1.05rem; cursor: pointer; transition: background 140ms, color 140ms;
}
.seg:active { background: var(--surface-3); }
.seg[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.seg:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }
.actions { display: flex; gap: 6px; }
.actions .icon-btn[aria-current="page"] { background: var(--surface-2); }

.content { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 32px 36px 56px; position: relative; }
.content.watching { padding: 0; overflow: hidden; }
.view-title { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 24px; display: flex; align-items: center; gap: 18px; }
.view-title .spacer { flex: 1; }
.view-sub { color: var(--muted); font-size: 1.1rem; margin: -12px 0 24px; }

/* ---------- Card grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 28px 24px; }
.card {
  display: flex; flex-direction: column; gap: 14px; min-width: 0;
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
  border-radius: var(--radius);
}
.card .thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); box-shadow: 0 0 0 1px var(--border);
  transition: transform 200ms var(--ease), box-shadow 200ms;
}
.card:active .thumb { transform: scale(0.975); box-shadow: 0 0 0 2px var(--border-strong); }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card[aria-disabled="true"] { cursor: not-allowed; opacity: 0.55; }
.badge {
  position: absolute; right: 10px; bottom: 10px; padding: 3px 9px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.82); font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.badge.folder { left: 10px; right: auto; display: inline-flex; align-items: center; gap: 6px; background: rgba(0, 0, 0, 0.82); }
.thumb-folder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.badge.live { left: 10px; right: auto; background: var(--accent); letter-spacing: 0.08em; }
.card-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(255, 255, 255, 0.25); }
.card-progress i { display: block; height: 100%; background: var(--accent); }
.card-body { display: flex; flex-direction: column; gap: 4px; padding: 0 4px; }
.card-title {
  font-weight: 700; font-size: 1.05rem; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { color: var(--muted); font-size: 0.9rem; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.channel-link {
  background: none; border: 0; padding: 8px 0; margin: -8px 0; color: var(--muted); font-weight: 600; cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.channel-link:active { color: var(--text); }

/* channel tiles (subscriptions) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.tile {
  display: flex; align-items: center; gap: 18px; min-height: 96px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-align: left; cursor: pointer; min-width: 0;
  transition: background 140ms, transform 140ms var(--ease);
}
.tile:active { background: var(--surface-2); transform: scale(0.98); }
.avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--surface-3); object-fit: cover; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 1.5rem; color: var(--muted); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.tile-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.load-more-wrap { display: flex; justify-content: center; padding: 40px 0 8px; }
.empty, .error-state { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 96px 24px; color: var(--muted); text-align: center; font-size: 1.2rem; }
.error-state strong { color: var(--text); font-size: 1.4rem; }
.loading-state { display: flex; justify-content: center; padding: 96px 0; }

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

/* ---------- Banner + toast ---------- */
.banner {
  display: flex; align-items: center; gap: 20px; padding: 16px 20px 16px 24px; margin-bottom: 28px;
  background: rgba(232, 33, 39, 0.12); border: 1px solid rgba(232, 33, 39, 0.45); border-radius: var(--radius);
  animation: rise 280ms var(--ease);
}
.banner-text { flex: 1; font-weight: 600; }
@keyframes rise { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Search ---------- */
.search-form { display: flex; gap: 14px; margin-bottom: 32px; }
.search-input {
  flex: 1; min-height: 80px; padding: 0 28px; font-size: 1.5rem; font-weight: 500;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); outline: none;
  user-select: text; -webkit-user-select: text;
}
.search-input:focus { border-color: var(--accent); }

/* ---------- PIN ---------- */
.pin-screen { height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 600px at 50% 30%, #1a2029, var(--bg)); }
.pin-card { display: flex; flex-direction: column; align-items: center; gap: 24px; width: min(560px, 100%); }
.pin-card h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.03em; display: flex; align-items: center; gap: 16px; }
.pin-sub { color: var(--muted); margin-top: -12px; }
.pin-display { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.pin-dot { width: 20px; height: 20px; border-radius: 50%; background: var(--text); animation: pop 160ms var(--ease); }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
.pin-hint { height: 1.4em; color: #ff7a7e; font-weight: 600; }
.pin-card.shake { animation: shake 360ms; }
@keyframes shake { 20%, 60% { transform: translateX(-14px); } 40%, 80% { transform: translateX(14px); } }
.pin-input {
  width: 100%; min-height: 64px; text-align: center; font-size: 1.5rem; letter-spacing: 0.4em; padding: 0 20px;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); outline: none;
  user-select: text; -webkit-user-select: text;
}
.pin-input:focus { border-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 96px); gap: 14px; }
.key {
  height: 96px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  font-size: 2rem; font-weight: 600; cursor: pointer; display: grid; place-items: center;
  transition: background 120ms, transform 120ms var(--ease);
}
.key:active { background: var(--surface-3); transform: scale(0.92); }
.key.go { background: var(--accent); border-color: transparent; }
.key.muted { color: var(--muted); }

/* ---------- Settings ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 28px; max-width: 980px; }
.panel h2 { font-size: 0.9rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); padding: 22px 28px 6px; font-weight: 700; }
.setting-row { display: flex; align-items: center; gap: 24px; min-height: 96px; padding: 16px 28px; border-top: 1px solid var(--border); }
.panel h2 + .setting-row { border-top: 0; }
.setting-label { flex: 1; min-width: 0; }
.setting-label b { display: block; font-size: 1.15rem; }
.setting-label span { color: var(--muted); font-size: 0.95rem; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; background: var(--surface-3); font-size: 0.9rem; font-weight: 700; }
.pill.ok { color: var(--ok); background: rgba(61, 220, 132, 0.12); }
.pill.bad { color: #ff7a7e; background: rgba(232, 33, 39, 0.14); }
select.select {
  min-height: var(--tap); min-width: 260px; padding: 0 20px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border-strong); font-weight: 600; font-size: 1.05rem; cursor: pointer;
}
.notice { margin-bottom: 24px; padding: 16px 24px; border-radius: var(--radius); font-weight: 600; max-width: 980px; }
.notice.ok { background: rgba(61, 220, 132, 0.12); color: var(--ok); border: 1px solid rgba(61, 220, 132, 0.35); }
.notice.bad { background: rgba(232, 33, 39, 0.12); color: #ff9a9d; border: 1px solid rgba(232, 33, 39, 0.4); }

/* login form (providers with loginForm) */
.login-form { display: flex; flex-direction: column; gap: 16px; padding: 8px 28px 28px; }
.login-form .field { display: flex; flex-direction: column; gap: 8px; }
.login-form .field > span { color: var(--muted); font-size: 0.95rem; font-weight: 600; }
.text-input {
  min-height: 72px; padding: 0 24px; font-size: 1.3rem; font-weight: 500;
  background: var(--surface-2); border: 2px solid var(--border); border-radius: var(--radius); outline: none;
  user-select: text; -webkit-user-select: text;
}
.text-input:focus { border-color: var(--accent); }
.login-form .notice { margin-bottom: 0; }
.login-form .btn-row { justify-content: flex-start; }

/* ---------- Player ---------- */
.watch { position: relative; width: 100%; height: 100%; background: #000; overflow: hidden; }
.player-stage { position: absolute; inset: 0; display: grid; place-items: center; }
.player-canvas { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; background: #000; }
.watch.idle { cursor: none; }

.controls { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; opacity: 1; transition: opacity 260ms; }
.controls.hidden { opacity: 0; pointer-events: none; }
.controls::before, .controls::after { content: ""; position: absolute; left: 0; right: 0; height: 220px; pointer-events: none; z-index: 0; }
.controls::before { top: 0; background: linear-gradient(rgba(0, 0, 0, 0.78), transparent); }
.controls::after { bottom: 0; background: linear-gradient(transparent, rgba(0, 0, 0, 0.85)); }
.controls > * { position: relative; z-index: 1; }

.ctl-top { display: flex; align-items: center; gap: 20px; padding: 24px 28px; }
.ctl-title { flex: 1; min-width: 0; font-size: 1.4rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); }
.engine-badge { padding: 8px 16px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); font-size: 0.85rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.engine-badge.mpeg1 { background: rgba(232, 33, 39, 0.4); }

.ctl-center { display: flex; align-items: center; justify-content: center; gap: 56px; }
.ctl-round {
  width: 96px; height: 96px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(20, 24, 30, 0.6); display: grid; place-items: center; cursor: pointer;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  transition: transform 140ms var(--ease), background 140ms;
}
.ctl-round:active { transform: scale(0.9); background: rgba(60, 68, 80, 0.8); }
.ctl-round.main { width: 140px; height: 140px; background: rgba(232, 33, 39, 0.9); border-color: transparent; }
.ctl-round.main .icon { width: 64px; height: 64px; }
.ctl-round .seek-label { position: absolute; font-size: 0.8rem; font-weight: 800; margin-top: 2px; }
.ctl-round.seek { position: relative; }

.ctl-bottom { display: flex; flex-direction: column; gap: 6px; padding: 0 28px 24px; }
.progress { position: relative; height: 56px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.progress-track { position: relative; width: 100%; height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.26); transition: height 120ms; }
.progress.scrubbing .progress-track, .progress:hover .progress-track { height: 12px; }
.progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 99px; background: var(--accent); }
.progress-thumb {
  position: absolute; top: 50%; left: 0; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
.progress-tip {
  position: absolute; bottom: 44px; transform: translateX(-50%); padding: 4px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.85); font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums; pointer-events: none;
}
.ctl-row { display: flex; align-items: center; gap: 22px; }
.time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.15rem; min-width: 170px; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7); }
.ctl-spacer { flex: 1; }
.vol { display: flex; align-items: center; gap: 12px; }
.vol input[type="range"] { width: 180px; accent-color: var(--accent); height: 56px; cursor: pointer; }
.ctl-field { display: flex; align-items: center; gap: 10px; }
.ctl-field span { font-size: 0.85rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(255, 255, 255, 0.7); }
.ctl-select {
  min-height: 56px; padding: 0 16px; border-radius: var(--radius-sm); background: rgba(30, 37, 47, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.24); font-weight: 700; font-size: 1rem; cursor: pointer;
}

.subtitle-overlay {
  position: absolute; left: 6%; right: 6%; bottom: 7%; z-index: 3; text-align: center; pointer-events: none;
  transition: bottom 260ms var(--ease);
}
.watch:not(.idle) .subtitle-overlay { bottom: 250px; }
.subtitle-overlay span {
  display: inline-block; padding: 6px 18px; border-radius: 10px; background: rgba(0, 0, 0, 0.72);
  color: #fff; font-size: 34px; line-height: 1.3; font-weight: 600; white-space: pre-line;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

.player-overlay { position: absolute; inset: 0; display: grid; place-items: center; z-index: 5; }
.player-overlay.start { background: rgba(0, 0, 0, 0.55); }
.start-card { display: flex; flex-direction: column; align-items: center; gap: 24px; text-align: center; padding: 0 40px; }
.start-card .thumb-bg { width: min(520px, 60vw); aspect-ratio: 16/9; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--surface-2); }
.start-card .thumb-bg img { width: 100%; height: 100%; object-fit: cover; }
.start-card h1 { font-size: 1.8rem; font-weight: 800; max-width: 900px; letter-spacing: -0.01em; }
.start-card p { color: var(--muted); }
.big-play { width: 132px; height: 132px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 14px 40px rgba(232, 33, 39, 0.5); transition: transform 140ms var(--ease); }
.big-play:active { transform: scale(0.92); }
.big-play .icon { width: 64px; height: 64px; margin-left: 6px; }
.player-spinner { z-index: 4; pointer-events: none; }
.player-error { background: rgba(0, 0, 0, 0.82); z-index: 6; }
.player-error .start-card h1 { color: #ff9a9d; font-size: 1.5rem; }
.btn-row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.fullscreen-msg { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* narrower windows (desktop testing) */
@media (max-width: 1100px) {
  .brand span { display: none; }
  .tab { padding: 0 18px; }
  .content { padding: 24px 20px 48px; }
  .time { min-width: 0; }
  .vol input[type="range"] { width: 100px; }
}

.content.watching .view { height: 100%; }
