/* ================= Tokens ================= */
:root {
  --bg: #161b26;
  --surface: #1f2533;
  --surface-2: #283043;
  --line: #343d52;
  --text: #ece7dc;
  --muted: #98a1b3;
  --accent: #e9b44c;
  --accent-ink: #231a05;
  --done: #8cc5a4;
  --danger: #e58a7b;

  --font-ui: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-title: "Fraunces", Georgia, "Times New Roman", serif;

  --topbar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
img { max-width: 100%; display: block; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: .9em; word-break: break-all; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ================= Botões e formulários ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font: 600 14px var(--font-ui); text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.check[aria-pressed="true"] { background: transparent; border-color: var(--done); color: var(--done); }

input[type=text], input[type=email], input[type=password], input[type=search], select {
  width: 100%; min-height: 42px; padding: 0 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: 15px var(--font-ui);
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
select { width: auto; min-height: 34px; padding: 0 8px; }

/* ================= Login / cadastro ================= */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
}
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.brand-title { font: 700 34px/1.1 var(--font-title); margin: 0; letter-spacing: -.01em; }
.auth-card > p { margin: 0 0 8px; }
.alert { padding: 10px 12px; border-radius: 8px; background: rgba(229, 138, 123, .12); border: 1px solid var(--danger); color: var(--danger); font-size: 14px; }
.alert.ok { background: rgba(140, 197, 164, .12); border-color: var(--done); color: var(--done); }

/* ================= Barra superior ================= */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: rgba(22, 27, 38, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font: 700 20px var(--font-title); color: var(--text); text-decoration: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.back { display: flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600; }
.back:hover { color: var(--text); }

/* ================= Estante (index) ================= */
.page { max-width: 1240px; margin: 0 auto; padding: 32px 24px 64px; }

.resume {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 36px; align-items: center;
  margin-bottom: 56px;
}
.resume-cover { aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; }
.resume-cover img { width: 100%; height: 100%; object-fit: cover; }
.resume-body > p:first-child { margin: 0 0 4px; }
.resume-title { font: 700 clamp(30px, 4vw, 48px)/1.05 var(--font-title); margin: 0 0 10px; letter-spacing: -.015em; }
.resume-lesson { font-size: 18px; margin: 0 0 18px; }
.resume .bar { max-width: 420px; margin-bottom: 6px; }
.resume .btn { margin-top: 14px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.section-head .section-title { margin: 0; }
.section-title { font: 600 22px var(--font-title); margin: 0 0 18px; }
.count { color: var(--muted); font: 500 15px var(--font-ui); margin-left: 6px; }
.search { max-width: 280px; }
section + section { margin-top: 44px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 28px 22px; }

.course-card { color: var(--text); text-decoration: none; display: flex; flex-direction: column; gap: 10px; }
.cover { aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--surface); outline: 1px solid var(--line); outline-offset: -1px; }
.cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.course-card:hover .cover img { transform: scale(1.03); }
.course-card:hover h3 { color: var(--accent); }
.course-meta h3 { font: 600 16px/1.3 var(--font-ui); margin: 0 0 8px; }
.course-meta p { margin: 6px 0 0; }

/* Capa gerada (quando a pasta não tem capa.jpg) */
.generated {
  display: grid; place-items: center;
  background: hsl(var(--h) 32% 26%);
  color: hsl(var(--h) 55% 82%);
}
.generated span { font: 700 clamp(40px, 6vw, 64px)/1 var(--font-title); letter-spacing: -.03em; }
.resume-cover.generated span { font-size: clamp(64px, 9vw, 120px); }

/* Barras de progresso */
.bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s ease; }
.bar.thick { height: 6px; }

.empty { max-width: 560px; margin: 12vh auto; text-align: center; }
.empty h2 { font: 700 30px var(--font-title); margin: 0 0 10px; }
.empty p { color: var(--muted); margin: 0 0 20px; }

/* ================= Página do curso ================= */
.course-heading { flex: 1; min-width: 0; display: flex; align-items: center; gap: 20px; }
.course-heading h1 {
  font: 600 18px var(--font-title); margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.course-progress { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.course-progress .bar { width: 140px; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px;
  min-height: calc(100vh - var(--topbar-h));
}
.stage { padding: 24px; min-width: 0; }

.player {
  position: relative;
  background: #000;
  border-radius: 10px; overflow: hidden;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - var(--topbar-h) - 180px);
  width: 100%;
  margin: 0 auto;
}
.player video, .player iframe { width: 100%; height: 100%; border: 0; display: block; background: #000; }
.player iframe { background: #fff; }
video::cue { font-family: var(--font-ui); background: rgba(0, 0, 0, .72); }

.file-box, .video-error, .next-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center;
  background: var(--surface);
}
.video-error p, .file-box p { max-width: 460px; margin: 0; color: var(--muted); }
.next-overlay { background: rgba(10, 13, 20, .88); }
.next-overlay p { margin: 0; }
.next-title { font: 600 24px/1.2 var(--font-title); max-width: 600px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.toast {
  position: absolute; left: 16px; top: 16px;
  padding: 8px 14px; border-radius: 8px;
  background: rgba(22, 27, 38, .92); border: 1px solid var(--line);
  font-size: 14px; pointer-events: none;
}

.lesson-bar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  padding: 20px 0 16px; border-bottom: 1px solid var(--line);
}
.lesson-info { min-width: 0; flex: 1 1 320px; }
.lesson-info p { margin: 0 0 4px; }
.lesson-info h2 { font: 700 clamp(22px, 2.4vw, 28px)/1.2 var(--font-title); margin: 0; letter-spacing: -.01em; }
.lesson-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.prefs { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; padding: 14px 0; font-size: 14px; }
.prefs label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.prefs .switch input { accent-color: var(--accent); width: 16px; height: 16px; }

/* Barra lateral de aulas */
.sidebar {
  border-left: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.module { border-bottom: 1px solid var(--line); }
.module-head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; background: none; border: 0; color: var(--text);
  font: 600 14px/1.35 var(--font-ui); text-align: left; cursor: pointer;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.module-title { flex: 1; }
.chev { color: var(--muted); display: flex; transition: transform .2s ease; }
.module.closed .chev { transform: rotate(-90deg); }
.module.closed .lessons { display: none; }

.lessons { list-style: none; margin: 0; padding: 0 0 10px; }
.lesson {
  position: relative;
  display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start;
  padding: 10px 18px 12px;
  color: var(--text); text-decoration: none;
}
.lesson:hover { background: var(--surface-2); }
.lesson.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.state {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid; place-items: center; color: var(--muted);
  margin-top: 1px;
}
.lesson.file .state { border-radius: 5px; border-style: dashed; }
.lesson.active .state { border-color: var(--accent); color: var(--accent); }
.lesson.done .state { background: var(--done); border-color: var(--done); color: var(--bg); }
.lesson-text { min-width: 0; display: flex; flex-direction: column; }
.lesson-name { font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.lesson.done:not(.active) .lesson-name { color: var(--muted); }
.lesson-sub { margin-top: 2px; }
.mini {
  position: absolute; left: 50px; right: 18px; bottom: 5px;
  height: 2px; background: transparent; overflow: hidden; border-radius: 2px;
}
.mini span { display: block; height: 100%; width: 0; background: var(--accent); opacity: .7; }
.lesson.done .mini span { background: var(--done); opacity: .4; }

/* ================= Responsivo ================= */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
  .player { max-height: none; }
  .course-progress .bar { width: 80px; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .hide-sm { display: none !important; }
  .page { padding: 20px 14px 48px; }
  .stage { padding: 0 0 8px; }
  .player { border-radius: 0; }
  .lesson-bar, .prefs { padding-left: 14px; padding-right: 14px; }
  .resume { grid-template-columns: 1fr; gap: 18px; }
  .course-heading { flex-direction: column; align-items: flex-start; gap: 2px; }
  .course-heading h1 { font-size: 16px; max-width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 22px 14px; }
  .lesson-actions { width: 100%; }
  .lesson-actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
