@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #090b12;
  --panel: #121622;
  --panel2: #1a2030;
  --line: #262d40;
  --text: #eef1f8;
  --muted: #8d96ad;
  --accent: #ff4d6d;
  --accent2: #7c5cff;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font-family: inherit; }
button { cursor: pointer; }
.hide { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }

/* header */
header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 24px;
  padding: 14px 4vw; background: rgba(9, 11, 18, .92);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 800; font-size: 24px; letter-spacing: -.5px; white-space: nowrap; }
.logo span { color: var(--accent); }
nav { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; color: var(--muted); font-weight: 600;
  padding: 9px 14px; border-radius: 9px; font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--panel2); }
.tab.active { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.searchbox { margin-left: auto; position: relative; }
.searchbox input {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px 10px 38px; border-radius: 10px; width: 240px; outline: none;
}
.searchbox input:focus { border-color: var(--accent2); }
.searchbox::before { content: '🔍'; position: absolute; left: 12px; top: 9px; font-size: 14px; opacity: .7; }
.iconbtn { background: var(--panel); border: 1px solid var(--line); color: var(--muted); border-radius: 10px; padding: 9px 12px; }
.iconbtn:hover { color: var(--text); border-color: var(--accent2); }
.iconbtn.on { color: #fff; border-color: var(--accent); background: #ff4d6d22; }

/* conta (sessao autenticada) */
.profile-wrap { position: relative; }
.profile { color: #fff; border-color: var(--accent2); white-space: nowrap; }
.profile-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  min-width: 170px; padding: 6px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); box-shadow: 0 14px 36px #0009;
}
.profile-menu.open { display: block; }
.profile-menu button {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border: 0; background: none; color: var(--muted); font-weight: 600;
  padding: 10px 12px; border-radius: 8px; font-size: 13px;
}
.profile-menu button:hover { background: var(--panel2); color: #fff; }
.profile-menu button.active {
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2));
}

main { max-width: 1500px; margin: 0 auto; padding: 28px 4vw 80px; }
#loading { padding: 80px 0; text-align: center; color: var(--muted); }
h2.sec { font-size: 20px; margin: 34px 0 16px; display: flex; align-items: center; gap: 10px; }
h2.sec::before { content: ''; width: 4px; height: 20px; background: var(--accent); border-radius: 3px; }
#resultCount { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 500; }

/* carrossel continuar */
#continue { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: thin; }
.continue-card {
  position: relative; display: flex; gap: 12px; min-width: 330px; max-width: 330px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; cursor: pointer; transition: .2s;
}
.continue-card:hover { border-color: var(--accent2); transform: translateY(-2px); }
.continue-poster { width: 62px; height: 88px; border-radius: 7px; overflow: hidden; position: relative; flex-shrink: 0; background: var(--panel2); }
.continue-poster img { width: 100%; height: 100%; object-fit: cover; }
.playmini { position: absolute; inset: 0; margin: auto; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(255,255,255,.9); color: #111; opacity: 0; transition: .2s; }
.continue-card:hover .playmini { opacity: 1; }
.continue-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.continue-info b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-info small { color: var(--muted); font-size: 11px; }
.bar, .cardbar, .epbar { background: #333b52; border-radius: 5px; overflow: hidden; height: 4px; }
.bar i, .cardbar i, .epbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.x { position: absolute; top: 4px; right: 6px; background: none; border: 0; color: var(--muted); font-size: 18px; }
.x:hover { color: var(--accent); }

/* grid */
#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 22px 16px; }
.card { cursor: pointer; }
.card .poster {
  position: relative; aspect-ratio: 2/3; border-radius: 12px; overflow: hidden;
  background: linear-gradient(150deg, var(--panel2), #0e1220); border: 1px solid var(--line);
}
.card img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s; }
.card:hover img { transform: scale(1.06); }
.poster-fallback { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 800; color: #566; background: linear-gradient(140deg, #212940, #121622); }
.badge { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.7); backdrop-filter: blur(4px); border-radius: 5px; padding: 3px 6px; font-size: 9px; font-weight: 800; letter-spacing: .5px; }
.lang { position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,.72); border-radius: 5px; padding: 3px 6px; font-size: 9px; color: #ddd; max-width: 70%; overflow: hidden; white-space: nowrap; }
.fav { position: absolute; top: 7px; right: 7px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 16px; }
.fav.on { color: var(--accent); }
.cardbar { position: absolute; bottom: 0; left: 0; right: 0; height: 4px; border-radius: 0; }
.card h3 { font-size: 13px; margin: 10px 0 4px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card p { color: var(--muted); font-size: 11px; margin: 0; }
.empty { grid-column: 1/-1; color: var(--muted); text-align: center; padding: 60px 0; font-size: 14px; }

/* detalhes */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(3,5,10,.86); backdrop-filter: blur(8px); display: none; overflow-y: auto; }
.overlay.open { display: block; }
.detail-inner { max-width: 1100px; margin: 4vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.detail-hero {
  position: relative; min-height: 350px; display: flex; gap: 30px; padding: 30px;
  background: linear-gradient(90deg, rgba(18,22,34,.97), rgba(18,22,34,.75)), var(--bg);
}
.detail-hero::before { content: ''; position: absolute; inset: 0; background-image: var(--bg); background-size: cover; background-position: center; opacity: .25; filter: blur(2px); }
.detail-poster { position: relative; width: 200px; min-width: 200px; aspect-ratio: 2/3; border-radius: 12px; overflow: hidden; box-shadow: 0 15px 40px #0009; }
.detail-poster img { width: 100%; height: 100%; object-fit: cover; }
.detail-text { position: relative; align-self: center; max-width: 620px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); background: #ff4d6d1a; padding: 5px 10px; border-radius: 20px; }
.detail-text h1 { font-size: 32px; line-height: 1.15; margin: 14px 0; }
.desc { color: #b7bfd2; font-size: 14px; line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.detail-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 10px; padding: 11px 18px; font-weight: 600; font-size: 14px; }
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; color: #fff; }
.server-note { color: var(--muted); font-size: 11px; margin-top: 14px; }
.closex { position: absolute; top: 16px; right: 18px; z-index: 3; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: #0009; color: #fff; font-size: 22px; }
.season-tabs { display: flex; gap: 6px; padding: 16px 30px 0; overflow-x: auto; border-top: 1px solid var(--line); }
.st { background: var(--panel2); border: 1px solid var(--line); color: var(--muted); padding: 8px 13px; border-radius: 8px; font-size: 12px; white-space: nowrap; }
.st.active { color: #fff; border-color: var(--accent); background: #ff4d6d22; }
.episodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; padding: 18px 30px 30px; max-height: 45vh; overflow-y: auto; }
.ep {
  display: flex; align-items: center; gap: 9px; background: var(--panel2); border: 1px solid var(--line);
  color: var(--text); border-radius: 9px; padding: 9px 11px; text-align: left; font-size: 12px; min-width: 0;
}
.ep:hover { border-color: var(--accent2); background: #222a3d; }
.ep.active { border-color: var(--accent); background: #ff4d6d1c; }
.ep.watched .epnum { color: #4ade80; }
.epnum { color: var(--muted); font-weight: 800; min-width: 24px; }
.eptitle { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.epbar { width: 28px; height: 3px; flex-shrink: 0; }
.eppct { font-size: 9px; color: var(--muted); }
.epplay { opacity: 0; color: var(--accent); font-size: 10px; }
.ep:hover .epplay { opacity: 1; }

/* player */
#player { z-index: 200; background: #000; display: none; grid-template-rows: auto minmax(0, 1fr); }
#player.open { display: grid; }
.player-head { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 10px; padding: 10px 18px; background: #0d1018; border-bottom: 1px solid var(--line); }
.player-head .t { flex: 1; min-width: 0; }
.player-head .t b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-head .t small { color: var(--muted); font-size: 11px; }
.player-head select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 12px; outline: none; }
.player-body { display: grid; grid-template-columns: 1fr 320px; grid-template-rows: minmax(0, 1fr); min-height: 0; }
#videoWrap { position: sticky; top: var(--player-head-h, 57px); z-index: 5; display: flex; align-items: center; justify-content: center; background: #000; min-width: 0; min-height: 0; }
#video { width: 100%; height: 100%; max-height: calc(100vh - 66px); outline: none; }
/* Botao flutuante: so aparece quando faltam 60s (creditos finais). */
.video-next {
  position: absolute; right: 18px; bottom: 62px; z-index: 7; display: none;
  align-items: center; gap: 7px; padding: 10px 15px; border: 0; border-radius: 999px;
  background: rgba(255, 77, 109, .94); color: #fff; cursor: pointer;
  font-size: 13px; font-weight: 800; box-shadow: 0 8px 24px #000a;
}
.video-next.show { display: flex; }
.video-next:hover { background: #ff4d6d; }
.video-next small { font-size: 11px; font-weight: 600; opacity: .85; }
#videoWrap:fullscreen { width: 100vw; height: 100vh; }
#videoWrap:fullscreen #video { max-height: none; }
#videoWrap:fullscreen .video-next { right: 32px; bottom: 84px; }
.loader { color: var(--muted); font-size: 14px; }
.player-side { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#sideList { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.side-head { padding: 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.side-head select { width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px; font-size: 13px; }
.autonext { color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.episodes.side { display: flex; flex-direction: column; padding: 10px; gap: 5px; max-height: none; min-height: 0; overflow-y: auto; flex: 1; }
.episodes.side .ep { flex-shrink: 0; }
.shortcuts { padding: 12px 14px; color: var(--muted); font-size: 10px; line-height: 1.8; border-top: 1px solid var(--line); flex-shrink: 0; }
.shortcuts kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }

/* explorar */
.explore-help {
  margin: 22px 0 6px; padding: 16px 18px; border: 1px solid var(--line);
  border-radius: 12px; background: linear-gradient(120deg, #171d2e, #121622);
  color: #b9c2d6; font-size: 13px; line-height: 1.7;
}
.explore-help b { color: var(--text); }
.site-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.sitebtn { background: var(--panel2); border: 1px solid var(--line); color: var(--muted); border-radius: 8px; padding: 6px 10px; font-size: 11px; }
.sitebtn:hover { color: #fff; border-color: var(--accent2); }
.explore-card .addbtn { width: 100%; margin-top: 10px; padding: 8px; font-size: 11px; }
.explore-card .addbtn.done { opacity: .6; pointer-events: none; }

/* painel de links */
.links-panel { max-width: 720px; margin: 8vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; position: relative; }
.links-panel h2 { margin: 0 0 8px; font-size: 22px; }
.links-panel p { margin: 0 0 16px; font-size: 13px; line-height: 1.6; }
.links-panel code { background: var(--panel2); padding: 2px 5px; border-radius: 4px; }

/* adicao rapida de links */
.quick-add label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.quick-row { display: flex; gap: 8px; }
.quick-row input {
  flex: 1; min-width: 0; background: #0d1018; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  font-size: 13px; outline: none;
}
.quick-row input:focus { border-color: var(--accent2); }
.quick-row .btn { white-space: nowrap; }
.quick-add .small { margin-top: 8px; font-size: 12px; }
.links-sep { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

#linksText {
  width: 100%; min-height: 240px; resize: vertical; background: #0d1018; color: #d5e0ff;
  border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-family: ui-monospace, monospace;
  font-size: 12px; line-height: 1.7; outline: none;
}
#linksText:focus { border-color: var(--accent2); }
.links-actions { display: flex; gap: 10px; margin-top: 16px; }

/* login / conta / administracao */
.login-panel { max-width: 420px; }
.login-panel label { display: block; font-weight: 700; font-size: 12px; margin: 12px 0 6px; }
.login-panel .remember-row { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; margin: 14px 0 6px; cursor: pointer; }
.login-panel .remember-row input { width: auto; margin: 0; }
.login-panel input, .login-panel select, #createUserForm input, #createUserForm select {
  width: 100%; background: #0d1018; color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 11px 12px; font-size: 13px; outline: none;
}
.login-panel input:focus, #createUserForm input:focus { border-color: var(--accent2); }
.login-panel form > .btn { width: 100%; margin-top: 16px; }
.login-error { color: var(--accent) !important; min-height: 18px; margin: 10px 0 0 !important; }
#adminModal h3 { font-size: 14px; margin: 18px 0 10px; }
#createUserForm { display: flex; flex-direction: column; gap: 8px; }
#createUserForm .field { flex: 1; min-width: 0; }
#createUserForm .field label { display: block; font-weight: 700; font-size: 12px; margin-bottom: 6px; }
#createUserForm .btn { align-self: flex-start; }
.admin-user {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; margin-bottom: 6px; font-size: 12px;
}
.admin-user b { color: #fff; }
.admin-user .btn { padding: 6px 10px; font-size: 11px; margin-left: auto; }
.user-role { color: var(--accent); font-size: 10px; font-weight: 800; }
.empty.small { padding: 18px; font-size: 12px; line-height: 1.7; border: 1px dashed var(--line); border-radius: 10px; }

#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1b2233; border: 1px solid var(--line); color: #fff; padding: 11px 20px;
  border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: .25s; z-index: 400;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- responsividade ----------------
   O modo vem de html[data-layout], definido por script inline no <head>
   ANTES deste CSS. Assim a primeira pintura ja usa o layout correto.

   desktop = layout original (inalterado); tablet = intermediario;
   mobile = compacto. Nao usamos @media para trocar de modo: a escolha
   manual no navegador tem sempre prioridade sobre a largura atual. */
html[data-layout="mobile"], html[data-layout="mobile"] body { overflow-x: hidden; }

html[data-layout="mobile"] header { gap: 10px; padding: 10px 4vw; flex-wrap: wrap; }
html[data-layout="mobile"] .logo { font-size: 20px; }
html[data-layout="mobile"] nav {
  order: 2; width: 100%; display: grid;
  grid-template-columns: repeat(3, 1fr); gap: 6px;
}
html[data-layout="mobile"] .tab {
  width: 100%; text-align: center; font-size: 12px; padding: 10px 4px;
}
html[data-layout="mobile"] .searchbox { order: 3; width: 100%; margin-left: 0; }
html[data-layout="mobile"] .searchbox input { width: 100%; }
html[data-layout="mobile"] .iconbtn { padding: 9px 10px; font-size: 12px; }
html[data-layout="mobile"] .profile-wrap { margin-left: auto; }
html[data-layout="mobile"] .profile { margin-left: 0; }
html[data-layout="mobile"] .profile-menu {
  right: 0; left: auto; max-width: calc(100vw - 8vw);
}
html[data-layout="mobile"] main { padding: 18px 4vw 80px; }
html[data-layout="mobile"] h2.sec { margin: 24px 0 12px; font-size: 18px; }
html[data-layout="mobile"] #grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 10px;
}
html[data-layout="mobile"] .continue-card { min-width: 280px; max-width: 280px; }
html[data-layout="mobile"] .quick-row { flex-direction: column; }
html[data-layout="mobile"] .quick-row .btn { width: 100%; }
html[data-layout="mobile"] .links-panel,
html[data-layout="mobile"] .login-panel {
  max-width: none; margin: 0; min-height: 100vh; min-height: 100dvh;
  border-radius: 0; padding: 20px 16px;
}
html[data-layout="mobile"] .detail-inner {
  max-width: none; margin: 0; min-height: 100vh; min-height: 100dvh;
  border-radius: 0;
}
html[data-layout="mobile"] .overlay { height: 100vh; height: 100dvh; }
html[data-layout="mobile"] .detail-hero {
  flex-direction: column; padding: 56px 16px 18px; min-height: 0; gap: 16px;
}
html[data-layout="mobile"] .detail-poster { width: 120px; min-width: 120px; }
html[data-layout="mobile"] .detail-text h1 { font-size: 23px; }
html[data-layout="mobile"] .season-tabs { padding: 12px 16px 0; }
html[data-layout="mobile"] .episodes {
  grid-template-columns: 1fr; padding: 12px 16px 24px; max-height: none;
}
html[data-layout="mobile"] .player-head { flex-wrap: wrap; padding: 8px 10px; }
html[data-layout="mobile"] .player-head .t { flex-basis: 100%; }
html[data-layout="mobile"] .player-head select { flex: 1; min-width: 90px; }
html[data-layout="mobile"] .player-body {
  grid-template-columns: 1fr; grid-template-rows: 42vh minmax(0, 1fr);
}
html[data-layout="mobile"] #videoWrap { max-height: 360px; }
html[data-layout="mobile"] #video { max-height: none; }
html[data-layout="mobile"] .player-side { border-left: 0; border-top: 1px solid var(--line); }
html[data-layout="mobile"] .shortcuts { font-size: 9px; padding: 10px 12px; }
html[data-layout="mobile"] #videoWrap:fullscreen {
  width: 100vw; height: 100vh; height: 100dvh;
}

/* Tablet: mantem a identidade do desktop com header em duas linhas,
   colunas um pouco menores e painéis sem colar nas bordas. */
html[data-layout="tablet"] header { gap: 12px; padding: 12px 3vw; flex-wrap: wrap; }
html[data-layout="tablet"] .logo { font-size: 22px; }
html[data-layout="tablet"] nav { order: 2; width: 100%; justify-content: center; flex-wrap: wrap; }
html[data-layout="tablet"] .searchbox { margin-left: auto; }
html[data-layout="tablet"] .searchbox input { width: 200px; }
html[data-layout="tablet"] main { padding: 24px 3vw 80px; }
html[data-layout="tablet"] #grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 12px;
}
html[data-layout="tablet"] .links-panel,
html[data-layout="tablet"] .detail-inner { margin-left: 16px; margin-right: 16px; }
html[data-layout="tablet"] .detail-hero { padding: 24px; gap: 20px; min-height: 0; }
html[data-layout="tablet"] .detail-poster { width: 160px; min-width: 160px; }
html[data-layout="tablet"] .detail-text h1 { font-size: 27px; }
html[data-layout="tablet"] .player-body { grid-template-columns: 1fr 260px; }
html[data-layout="tablet"] .season-tabs,
html[data-layout="tablet"] .episodes { padding-left: 20px; padding-right: 20px; }

/* desktop: nenhuma regra extra — e exatamente o layout original. */
html[data-layout="desktop"] { --layout-mode: desktop; }
