/* =========================================================================
   Curso Player — tema "capivara caramelo"
   Inspiração de paleta/clima: capybarabr.com (escuro, quente, terroso).
   Sem fontes externas (CSP font-src 'self'): stack serif do sistema p/ títulos,
   sans do sistema p/ corpo. Zero dependências, zero inline.
   ========================================================================= */

:root {
  --bg:            #17120d;
  --bg-2:          #1d1710;
  --surface:       #261d15;
  --surface-2:     #2f241a;
  --surface-3:     #38291b;
  --line:          #3d2f22;
  --line-soft:     #2c2118;
  --text:          #f1e7d6;
  --muted:         #b6a489;
  --muted-2:       #8c7d66;
  --accent:        #d9954c;
  --accent-strong: #e9a85b;
  --accent-dim:    #a8763c;
  --green:         #8aa06a;
  --danger:        #cf6b54;
  --radius:        14px;
  --radius-sm:     9px;
  --shadow:        0 18px 40px -22px rgba(0,0,0,.75);
  --shadow-soft:   0 8px 24px -16px rgba(0,0,0,.6);
  --serif:         "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans:          ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono:          ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 78% -8%, rgba(217,149,76,.10), transparent 60%),
    radial-gradient(900px 600px at -5% 110%, rgba(138,160,106,.07), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Textura sutil de grão para dar "atmosfera" sem imagens externas */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .035;
  background-image:
    repeating-linear-gradient(0deg, #fff 0, #fff 1px, transparent 1px, transparent 3px);
  mix-blend-mode: overlay;
}

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; letter-spacing: .2px; }

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

.hidden { display: none !important; }

::selection { background: rgba(217,149,76,.32); color: #fff; }

/* Scrollbars discretas e quentes */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--line); background-clip: content-box; }

/* ----------------------------- Logo / marca ----------------------------- */

.brand { display: inline-flex; align-items: center; gap: 11px; }
.brand .logo { width: 34px; height: 34px; flex: none; color: var(--accent); }
.brand .logo svg { width: 100%; height: 100%; display: block; }
.brand .name { font-family: var(--serif); font-size: 20px; font-weight: 600; color: var(--text); }
.brand .name b { color: var(--accent-strong); font-weight: 600; }

/* ============================ TELA DE LOGIN ============================= */

#login-view {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-card {
  width: 100%;
  max-width: 405px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 32px 30px;
  animation: rise .55s cubic-bezier(.2,.7,.2,1) both;
}

.login-card .brand { margin-bottom: 4px; }
.login-tagline {
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 14.5px;
  margin: 8px 0 22px;
}

.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 12px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 7px;
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 13px;
  font-size: 15px;
  font-family: inherit;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.input::placeholder { color: var(--muted-2); }
.input:focus {
  outline: none;
  border-color: var(--accent-dim);
  background: var(--bg-2);
  box-shadow: 0 0 0 3px rgba(217,149,76,.16);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2px;
  transition: transform .12s, filter .16s, background .16s, border-color .16s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #2a1c0c;
  box-shadow: var(--shadow-soft);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; filter: none; }
.btn-ghost {
  width: auto;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 500;
  padding: 8px 13px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent-dim); }

/* Aviso "primeiro acesso → será criado" */
.bootstrap-note {
  display: none;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 18px;
  padding: 12px 13px;
  border-radius: var(--radius-sm);
  background: rgba(138,160,106,.10);
  border: 1px solid rgba(138,160,106,.3);
  color: #cdd6b8;
  font-size: 13.5px;
  line-height: 1.5;
}
.bootstrap-note.show { display: flex; animation: fade .4s both; }
.bootstrap-note .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-top: 6px; flex: none; box-shadow: 0 0 0 4px rgba(138,160,106,.18); }

.login-msg {
  min-height: 18px;
  margin: 14px 2px 0;
  font-size: 13.5px;
  color: var(--danger);
  text-align: center;
}

/* Fato rotativo de capivara — homenagem ao capybarabr */
.capy-fact {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
  min-height: 40px;
}
.capy-fact .paw { color: var(--accent-dim); flex: none; margin-top: 1px; }
.capy-fact .fact-text { font-style: italic; }
.capy-fact .fact-text.swap { animation: fade .5s both; }

/* ============================== APP / PLAYER =========================== */

#app-view { position: relative; z-index: 1; min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 22px;
  background: rgba(29,23,16,.86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .who { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13.5px; }
.topbar .who .email { color: var(--text); }
.badge-admin {
  font-size: 11px;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--accent-strong);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 2px 9px;
}

.layout { flex: 1; display: grid; grid-template-columns: 310px 1fr; min-height: 0; }

/* ---- Sidebar: cursos + árvore ---- */
.sidebar {
  border-right: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(38,29,21,.5), transparent);
  overflow-y: auto;
  padding: 16px 12px 40px;
}
.sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted-2);
  margin: 6px 8px 12px;
  font-family: var(--sans);
  font-weight: 700;
}
.home-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: calc(100% - 8px);
  margin: 2px 4px 18px;
  padding: 10px 12px;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
.home-btn:hover { border-color: var(--accent-dim); }

.home-loading { padding: 12px; }

.course-home { animation: fade .28s both; }
.home-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 20px;
}
.home-head h1 {
  margin: 0;
  font-size: 30px;
}
.home-head p {
  margin: 0 0 5px;
  color: var(--muted);
}
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 15px;
}
.course-card {
  display: block;
  overflow: hidden;
  padding: 0;
  text-align: left;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  transition: transform .14s, border-color .14s, background .14s;
}
.course-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-dim);
  background: var(--surface-2);
}
.course-card.active { border-color: var(--accent-dim); }
.course-media {
  aspect-ratio: 16 / 9;
  background: #0d0a07;
  display: grid;
  place-items: center;
  color: var(--accent-dim);
}
.course-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.course-media.placeholder svg {
  width: 62px;
  height: 62px;
  opacity: .7;
}
.course-card-body {
  padding: 13px 14px 15px;
}
.course-card-body h2 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.25;
}
.course-card-body p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.course-landing {
  display: grid;
  grid-template-columns: minmax(280px, 52%) 1fr;
  gap: 24px;
  align-items: center;
  min-height: 62vh;
  animation: fade .28s both;
}
.course-hero {
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: #0d0a07;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--accent-dim);
  box-shadow: var(--shadow);
}
.course-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.course-hero.placeholder svg {
  width: 96px;
  height: 96px;
  opacity: .65;
}
.course-hero-info h1 {
  margin: 0 0 10px;
  font-size: 34px;
  line-height: 1.12;
}
.course-hero-info p {
  margin: 0 0 22px;
  color: var(--muted);
}
.course-actions .btn {
  width: auto;
  min-width: 170px;
}

.tree-section {
  margin: 16px 8px 7px;
  padding: 0 0 6px;
  color: var(--accent-strong);
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--serif);
  font-size: 14.5px;
  line-height: 1.25;
}
.tree-section.depth-1 { margin-left: 18px; color: var(--muted); font-size: 13px; }
.tree-section.depth-2 { margin-left: 28px; color: var(--muted-2); font-size: 12px; }
.tree-section.depth-3,
.tree-section.depth-4 { margin-left: 36px; color: var(--muted-2); font-size: 12px; }

.module { margin: 4px 4px 6px; }
.module.depth-1 { margin-left: 14px; }
.module.depth-2 { margin-left: 24px; }
.module.depth-3,
.module.depth-4 { margin-left: 32px; }
.module > .m-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 8px;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: .4px;
  text-transform: uppercase;
  font-weight: 600;
  border-radius: var(--radius-sm);
  user-select: none;
}
.module > .m-head:hover { color: var(--text); }
.module > .m-head .chev { transition: transform .18s; color: var(--accent-dim); }
.module > .m-head span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.module > .m-head em { flex: none; color: var(--muted-2); font-style: normal; font-size: 11px; letter-spacing: 0; text-transform: none; font-weight: 500; }
.module.collapsed > .m-head .chev { transform: rotate(-90deg); }
.module.collapsed > .lessons { display: none; }

.lesson {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  color: var(--muted);
  padding: 8px 10px 8px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13.5px;
  transition: background .12s, color .12s, border-color .12s;
}
.lesson:hover { background: var(--surface); color: var(--text); }
.lesson.active { background: var(--surface-2); color: var(--text); border-left-color: var(--accent); }
.lesson .l-ico { flex: none; color: var(--muted-2); }
.lesson.active .l-ico { color: var(--accent); }
.lesson.done .l-ico { color: var(--green); }
.lesson .l-name {
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.lesson .l-format {
  flex: none;
  min-width: 0;
  color: var(--accent-strong);
  border: 1px solid rgba(217,149,76,.45);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 10px;
  line-height: 1.25;
  font-weight: 700;
}
.lesson .l-format:empty { display: none; }
.lesson.uses-transmux .l-ico { color: var(--accent-dim); }
.lesson.needs-conversion { color: var(--muted-2); }
.lesson .l-check { flex: none; color: var(--green); opacity: 0; }
.lesson.done .l-check { opacity: 1; }

/* ---- Área principal / player ---- */
.main { overflow-y: auto; padding: 26px 30px 60px; }
.main-inner { max-width: 1000px; margin: 0 auto; }

.player-wrap {
  background: #0d0a07;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
}
.player-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.ts-player {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}
.ts-player video { cursor: pointer; }
.ts-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 38px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.72) 24%, rgba(0,0,0,.86));
  color: #fff;
}
.ts-player.native-controls .ts-controls { display: none; }
.ts-play,
.ts-native {
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(0,0,0,.35);
  color: #fff;
  border-radius: 7px;
  height: 30px;
}
.ts-play {
  width: 34px;
  padding: 0;
  font-size: 13px;
}
.ts-native {
  padding: 0 10px;
  font-size: 12px;
}
.ts-play:hover,
.ts-native:hover { border-color: rgba(255,255,255,.5); }
.ts-seek {
  width: 100%;
  accent-color: #22c5e8;
}
.ts-seek:disabled { opacity: .45; }
.ts-time {
  color: rgba(255,255,255,.92);
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
}
.unsupported-video {
  max-width: 560px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}
.unsupported-video h2 {
  margin: 0 0 9px;
  color: var(--text);
  font-size: 21px;
}
.unsupported-video p {
  margin: 0 auto 16px;
  max-width: 470px;
  font-size: 14px;
}
.unsupported-video code {
  display: block;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--accent-strong);
  font-family: var(--mono);
  font-size: 12px;
  white-space: normal;
  word-break: break-word;
}

.lesson-head { margin: 22px 2px 4px; }
.lesson-head .crumb { color: var(--muted-2); font-size: 12.5px; letter-spacing: .3px; }
.lesson-head h1 { font-size: 25px; margin: 5px 0 0; line-height: 1.25; }

/* Abas Notas / Anexos */
.tabs { display: flex; gap: 4px; margin: 26px 0 0; border-bottom: 1px solid var(--line-soft); }
.tab {
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 11px 15px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .14s, border-color .14s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tab .pill { font-size: 11px; color: var(--muted-2); margin-left: 6px; }

.tab-panel { padding: 22px 2px; animation: fade .3s both; }

/* Notas */
.note-editor { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.note-editor textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 13px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  transition: border-color .16s, box-shadow .16s;
}
.note-editor textarea:focus { outline: none; border-color: var(--accent-dim); box-shadow: 0 0 0 3px rgba(217,149,76,.14); }
.note-editor .row { display: flex; justify-content: space-between; align-items: center; }
.note-editor .count { color: var(--muted-2); font-size: 12px; }
.note-editor .btn { width: auto; padding: 9px 18px; }

.note {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-bottom: 11px;
  animation: fade .3s both;
}
.note .note-body { white-space: pre-wrap; word-break: break-word; color: var(--text); font-size: 14.5px; line-height: 1.6; }
.note .note-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 12px; }
.note .note-date { color: var(--muted-2); font-size: 12px; }
.note .note-actions { display: flex; gap: 6px; }
.icon-btn {
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12.5px;
  transition: color .14s, border-color .14s, background .14s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent-dim); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

/* Anexos */
.attach {
  display: flex;
  align-items: center;
  gap: 13px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 9px;
  transition: border-color .14s, background .14s;
}
.attach:hover { border-color: var(--accent-dim); background: var(--surface-2); }
.attach .a-ico { color: var(--accent); flex: none; }
.attach .a-info { flex: 1; min-width: 0; }
.attach .a-name { color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach .a-size { color: var(--muted-2); font-size: 12px; margin-top: 1px; }
.attach .icon-btn { flex: none; }

/* Estados vazios / boas-vindas */
.empty {
  display: grid;
  place-items: center;
  text-align: center;
  height: 100%;
  min-height: 60vh;
  color: var(--muted);
  padding: 40px;
}
.empty .e-logo { width: 64px; height: 64px; color: var(--accent-dim); opacity: .8; margin-bottom: 18px; }
.empty h2 { font-size: 23px; color: var(--text); margin: 0 0 8px; }
.empty p { max-width: 380px; margin: 0; font-size: 14.5px; line-height: 1.6; }

.muted { color: var(--muted); }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(241,231,214,.25);
  border-top-color: var(--accent-strong);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

/* Toast discreto */
#toast {
  position: fixed;
  z-index: 60;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Reveal com stagger na árvore */
.stagger > * { animation: rise .4s both; }
.stagger > *:nth-child(1){animation-delay:.02s} .stagger > *:nth-child(2){animation-delay:.05s}
.stagger > *:nth-child(3){animation-delay:.08s} .stagger > *:nth-child(4){animation-delay:.11s}
.stagger > *:nth-child(5){animation-delay:.14s} .stagger > *:nth-child(6){animation-delay:.17s}
.stagger > *:nth-child(7){animation-delay:.20s} .stagger > *:nth-child(8){animation-delay:.23s}

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Responsivo */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line-soft); max-height: 38vh; }
  .main { padding: 20px 16px 50px; }
  .home-head { display: block; }
  .home-head h1 { font-size: 26px; }
  .course-grid { grid-template-columns: 1fr; }
  .course-landing { grid-template-columns: 1fr; min-height: 0; }
  .course-hero-info h1 { font-size: 27px; }
  .lesson-head h1 { font-size: 21px; }
}
