/* ════════════════════════════════════════════════════════
   curs/curs.css — Estils del curs GeoCat
   Derivat de PyCat: mateixa estètica per al curs
════════════════════════════════════════════════════════ */

:root {
  --mono: 'Space Mono','Courier New',monospace;
  --bg:      #ffffff;
  --surface: #f5f5f5;
  --border:  #d0d0d0;
  --text:    #1a1a1a;
  --muted:   #6b7280;
  --accent:  #2563eb;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--mono);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}


/* ══════════════════════════════════════════════════════
   CAPÇALERA DEL CURS
══════════════════════════════════════════════════════ */

.curs-header {
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.curs-header-logo {
  font-weight: 800;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Títol del capítol/repte: centrat dins de la capçalera */
.curs-header-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}

/* Contenidor d'accions a la dreta (Glossari, etc.) */
.curs-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.curs-nav {
  display: flex;
  gap: 4px;
  margin-left: 16px;
}
.curs-nav a {
  font-size: 0.72rem;
  padding: 4px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.curs-nav a:hover  { background: var(--accent); color: #fff; }
.curs-nav a.active { background: var(--accent); color: #fff; }


/* ══════════════════════════════════════════════════════
   LAYOUT: SIDEBAR + CONTINGUT
══════════════════════════════════════════════════════ */

.curs-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 48px);
}

/* Sidebar — sticky */
.curs-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 48px;
  height: calc(100vh - 48px);
  overflow-y: auto;
  align-self: start;
}

.sidebar-section-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 16px;
  margin-bottom: 6px;
}

.sidebar-list { list-style: none; }

.sidebar-item a {
  display: block;
  padding: 5px 16px;
  font-size: 0.75rem;
  color: var(--text);
  text-decoration: none;
  transition: background 0.12s;
}
.sidebar-item a:hover { background: rgba(37,99,235,0.08); }
.sidebar-item.active a {
  background: rgba(37,99,235,0.12);
  color: var(--accent);
  font-weight: 700;
}


/* ══════════════════════════════════════════════════════
   CONTINGUT DEL CAPÍTOL
══════════════════════════════════════════════════════ */

.curs-content {
  padding: 2rem 3rem;
  max-width: 800px;
  overflow-y: auto;
}

.chapter-header { margin-bottom: 2rem; }
.chapter-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(37,99,235,0.1);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.chapter-header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.3;
}

.chapter-section { margin-bottom: 2rem; }
.chapter-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.7rem;
  color: var(--text);
}
.chapter-section p { margin-bottom: 0.8rem; }

code {
  font-family: var(--mono);
  background: rgba(37,99,235,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.88em;
}

pre.code-example {
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.7;
  overflow-x: auto;
  margin: 0.8rem 0;
}

/* Navegació entre capítols */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.chapter-nav a {
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
}
.chapter-nav a:hover { text-decoration: underline; }


/* ══════════════════════════════════════════════════════
   WIDGETS GEOGEBRA INCRUSTATS (embed directe, sense iframe)
══════════════════════════════════════════════════════ */

.geogebra {
  margin: 1rem 0;
}
.geogebra-wrap {
  margin: 1rem 0;
}

/* Toolbar inline (Comprova + Reinicia + badge) */
.ggb-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--surface, #f5f5f5);
  border: 1px solid var(--border, #d0d0d0);
  border-top: none;
  border-radius: 0 0 8px 8px;
  font-family: var(--mono);
}

.ggb-badge {
  font-size: 0.78rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #e5e7eb;
  color: #6b7280;
  font-weight: 700;
}
.ggb-ready { background: #e5e7eb; color: #6b7280; }
.ggb-ok    { background: #dcfce7; color: #16a34a; }
.ggb-ko    { background: #fee2e2; color: #dc2626; }

.ggb-btn {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.ggb-btn:hover { opacity: 0.8; }

.ggb-btn-check {
  background: var(--accent, #2563eb);
  color: #fff;
  border: none;
}
.ggb-btn-reset {
  background: transparent;
  color: var(--muted, #6b7280);
  border: 1px solid var(--border, #d0d0d0);
}
.ggb-btn-reset:hover {
  border-color: var(--text, #1a1a1a);
  color: var(--text, #1a1a1a);
}

/* Feedback de validació */
.simulador-feedback {
  font-size: 0.82rem;
  padding: 0;
  margin-top: 6px;
  font-weight: 700;
  min-height: 1.4em;
}
.simulador-feedback.fb-ok { color: #16a34a; }
.simulador-feedback.fb-ko { color: #dc2626; }

/* Overlay de reload quan GeoGebra no renderitza */
.ggb-reload-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 248, 248, 0.92);
  cursor: pointer;
  z-index: 10;
  border-radius: 8px;
  transition: background 0.15s;
}
.ggb-reload-overlay:hover {
  background: rgba(240, 240, 240, 0.96);
}
.ggb-reload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent, #2563eb);
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
}
.ggb-reload-icon {
  font-size: 2.4rem;
  line-height: 1;
}


/* ══════════════════════════════════════════════════════
   PÀGINA INDEX DEL CURS
══════════════════════════════════════════════════════ */

.curs-index-hero {
  text-align: center;
  padding: 3rem 2rem 2rem;
}
.curs-index-hero h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.8rem;
}
.curs-index-hero p {
  color: var(--muted);
  max-width: 500px;
  margin: 0 auto;
  font-size: 0.85rem;
}

.capitols-list {
  list-style: none;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

.capitol-card { margin-bottom: 6px; }
.capitol-card a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.capitol-card a:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(37,99,235,0.12);
}
.capitol-card-num {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--accent);
  min-width: 28px;
}
.capitol-card-titol { font-size: 0.85rem; font-weight: 700; }
.capitol-card-arrow { margin-left: auto; color: var(--muted); }


/* ══════════════════════════════════════════════════════
   SIDEBAR TOGGLE MÒBIL
══════════════════════════════════════════════════════ */

#sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
}

#sidebar-overlay { display: none; }

@media (max-width: 700px) {
  .curs-layout { grid-template-columns: 1fr; }
  .curs-sidebar {
    position: fixed;
    left: -260px;
    top: 48px;
    bottom: 0;
    width: 260px;
    z-index: 200;
    transition: left 0.25s;
  }
  .curs-sidebar.open { left: 0; }
  #sidebar-toggle { display: block; }
  #sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  #sidebar-overlay.visible { opacity: 1; pointer-events: auto; }
  .curs-content { padding: 1.5rem 1rem; }
}


/* ════════════════════════════════════════════════════════
   GLOSSARI — Modal de referència ràpida
   ════════════════════════════════════════════════════════ */

.glossari-curs-btn {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.8px;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.glossari-curs-btn:hover { color: var(--text); border-color: var(--text); }
.curs-header > .glossari-curs-btn { margin-left: auto; }

/* Overlay */
.glossari-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0,0,0,0.45);
  justify-content: center;
  align-items: center;
}
.glossari-overlay.is-open { display: flex; }

/* Modal */
.glossari-modal {
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  width: min(540px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.glossari-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid #e5e5e5;
  flex-shrink: 0;
}
.glossari-title {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: #1a1a1a;
  letter-spacing: 0.5px;
}
.glossari-close {
  background: none;
  border: 1px solid #d0d0d0;
  color: #6b7280;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.glossari-close:hover { color: #1a1a1a; border-color: #1a1a1a; }

.glossari-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.glossari-section { margin-bottom: 18px; }
.glossari-section:last-child { margin-bottom: 0; }
.glossari-section h3 {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #1a1a1a;
  margin: 0 0 6px;
}

.glossari-hint {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: #6b7280;
  margin: 0 0 8px;
  line-height: 1.5;
}
.glossari-hint code { color: #2563eb; font-weight: 700; background: none; padding: 0; }

.glossari-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 14px;
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.7;
}
.glossari-grid > code { color: #2563eb; white-space: nowrap; background: none; padding: 0; }
.glossari-grid > span { color: #4b5563; }
.glossari-grid > span code { color: #2563eb; background: none; padding: 0; font-size: 0.95em; }

.glossari-example {
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.6;
  color: #1a1a1a;
  background: #f5f5f5;
  border: 1px solid #e5e5e5;
  border-radius: 4px;
  padding: 8px 12px;
  margin: 6px 0;
  overflow-x: auto;
  white-space: pre;
}

.glossari-rules .glossari-rule {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: #1a1a1a;
  line-height: 1.8;
}
.glossari-rules .glossari-rule code { color: #2563eb; font-weight: 700; background: none; padding: 0; }

/* Mobile: fullscreen */
@media (max-width: 640px) {
  .glossari-overlay { align-items: stretch; overflow: hidden; }
  .glossari-modal {
    width: 100vw;
    max-height: 100dvh;
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
    border: none;
    overflow: hidden;
  }
  .glossari-body {
    flex: 1 1 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 14px 16px 24px;
  }
  .glossari-grid { font-size: 0.63rem; gap: 2px 10px; }
  .glossari-example { font-size: 0.62rem; padding: 6px 10px; }
}

@media (max-width: 700px) {
  .curs-header-title { display: none; }
}


/* ── Progrés: checkmark a la sidebar ────────────────── */
.sidebar-check {
  display: inline-block;
  color: #4ade80;
  font-weight: 700;
  margin-right: 4px;
  font-size: 0.85em;
}
body.light .sidebar-check { color: #16a34a; }


/* ══════════════════════════════════════════════════════
   REPTES — Badge de dificultat
══════════════════════════════════════════════════════ */

.repte-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.repte-badge.facil  { background: rgba(74,222,128,0.15); color: #16a34a; }
.repte-badge.mitja  { background: rgba(251,191,36,0.15);  color: #b45309; }
.repte-badge.dificil { background: rgba(255,82,82,0.15);  color: #dc2626; }

/* Bloc de pistes (details/summary) */
details.pista {
  margin-top: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.82rem;
}
details.pista summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
  user-select: none;
}
details.pista[open] summary { color: var(--text); margin-bottom: 8px; }
details.pista p { color: var(--text); }
