/* ════════════════════════════════════════════════════════
   curs.css — Estils per a les pàgines del curs
   (índex de capítols + plantilla de capítol)
════════════════════════════════════════════════════════ */

/* ── Variables (coherents amb style.css) ────────────────── */

:root {
  --bg:           #000000;
  --surface:      #141414;
  --border:       #2a2a2a;
  --text:         #ddddd8;
  --muted:        #8a8a85;
  --accent:       #a8a8a2;
  --accent-hi:    #B9138D;       /* rosa medusa */
  --error:        #ff5252;
  --mono:         'Space Mono', 'Courier New', monospace;
  --sans:         system-ui, -apple-system, 'Segoe UI', sans-serif;

  --sidebar-w:    240px;
  --header-h:     48px;
  --content-max:  960px;
  --gap:          2rem;
}

/* ── Mode clar ──────────────────────────────────────────── */
body.curs-light {
  --bg:      #ffffff;
  --surface: #f5f5f5;
  --border:  #d0d0d0;
  --text:    #1a1a1a;
  --muted:   #6b7280;
  --accent:  #2563eb;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
}
a { color: var(--accent-hi); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--mono); line-height: 1.3; }
code, pre {
  font-family: var(--mono);
  background: var(--surface);
  border-radius: 3px;
}
code { padding: 1px 5px; font-size: 0.88em; }
pre  { padding: 1rem; overflow-x: auto; border: 1px solid var(--border); }


/* ════════════════════════════════════════════════════════
   CAPÇALERA DEL CURS (present a totes les pàgines)
════════════════════════════════════════════════════════ */

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

.curs-header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
  text-decoration: none;
}
a.curs-header-logo:hover { text-decoration: none; color: var(--accent-hi); }
.curs-header-logo .logo-icon { color: var(--accent-hi); }

.curs-header-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
  pointer-events: none;
}
.curs-header-title::before,
.curs-header-title::after {
  content: "|";
  margin: 0 0.6em;
  color: var(--border);
  font-weight: 400;
}

.curs-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

/* Botó hamburger (visible en mòbil vertical < 820px o mòbil horitzontal) */
#sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

/* Botó tema */
.btn-curs-theme {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.btn-curs-theme:hover { border-color: var(--accent-hi); color: var(--accent-hi); }

/* Variant: enllaç al simulador lliure (botó de text, més petit) */
.btn-curs-sim {
  font-size: 0.75rem;
  padding: 5px 10px;
  text-decoration: none;
}


/* ════════════════════════════════════════════════════════
   PÀGINA ÍNDEX DEL CURS (B.1)
════════════════════════════════════════════════════════ */

.curs-index-hero {
  max-width: var(--content-max);
  margin: 3rem auto 2rem;
  padding: 0 1.5rem;
}

.curs-index-hero h1 {
  font-size: 2rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.curs-index-hero p {
  color: var(--muted);
  font-size: 1rem;
  max-width: 500px;
}

.capitols-list {
  max-width: var(--content-max);
  margin: 0 auto 4rem;
  padding: 0 1.5rem;
  list-style: none;
}

.capitol-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}

.capitol-card:hover {
  border-color: var(--accent-hi);
  background: color-mix(in srgb, var(--surface) 90%, var(--accent-hi) 10%);
}

.capitol-card a {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem 1.25rem;
  color: var(--text);
  text-decoration: none;
}

.capitol-card-num {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-hi);
  min-width: 2rem;
  text-align: right;
  line-height: 1;
}

.capitol-card-info { flex: 1; }
.capitol-card-titol {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
  display: block;
  color: #000;
}

.capitol-card-arrow {
  color: var(--muted);
  font-size: 1rem;
  transition: transform 0.15s;
}
.capitol-card:hover .capitol-card-arrow { transform: translateX(4px); color: var(--accent-hi); }

/* Distintiu "pendent" */
.capitol-card--pendent .capitol-card-num { opacity: 0.4; }
.capitol-card--pendent .capitol-card-titol { opacity: 0.5; }
.capitol-card--pendent .capitol-card-arrow { opacity: 0.2; }
.capitol-card--pendent { pointer-events: none; }


/* ════════════════════════════════════════════════════════
   LAYOUT CAPÍTOL (sidebar + contingut) — B.2 + B.3
════════════════════════════════════════════════════════ */

.curs-layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}


/* ── Barra lateral (B.2) ─────────────────────────────── */

.curs-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  flex-shrink: 0;
  transition: left 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem 1rem 0.75rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.sidebar-header a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.1s;
}
.sidebar-header a:hover { color: var(--accent-hi); }
.sidebar-header a.active {
  color: #000;
  font-weight: 700;
}

.sidebar-list {
  list-style: none;
  padding: 0.25rem 0;
}

.sidebar-item a, .sidebar-link {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.sidebar-item a:hover, .sidebar-link:hover {
  background: var(--border);
  text-decoration: none;
  border-left-color: var(--muted);
}
.sidebar-item.active .sidebar-link,
.sidebar-item.active a {
  border-left-color: var(--accent-hi);
  background: color-mix(in srgb, var(--bg) 80%, var(--accent-hi) 20%);
}

.sidebar-num {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-hi);
  min-width: 1.6rem;
  line-height: 1.5;
  flex-shrink: 0;
}
.sidebar-item.active .sidebar-num { color: var(--accent-hi); }

.sidebar-titol {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* Overlay fosc (mòbil) */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}
#sidebar-overlay.visible { display: block; }


/* ── Contingut del capítol ───────────────────────────── */

.curs-content {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 1.5rem 4rem;
}

.chapter-content-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* Capçalera del capítol */
.chapter-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.chapter-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent-hi);
  margin-bottom: 0.5rem;
}

.chapter-header h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.chapter-lead {
  color: var(--muted);
  font-size: 1rem;
  max-width: 560px;
}

/* Seccions del capítol.
   El text (paràgrafs, títols, llistes) es limita a ~720px per llegibilitat.
   Els simuladors (fora d'aquesta restricció) poden ocupar tot l'amplada
   del contenidor (960px) per tenir prou espai horitzontal. */
.chapter-section {
  margin-bottom: 2.5rem;
}

.chapter-section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--text);
  max-width: 720px;
}
body.curs-light .chapter-section h2 { color: #1a1a1a; }

.chapter-section p {
  margin-bottom: 0.85rem;
  max-width: 720px;
}
.chapter-section ul,
.chapter-section ol {
  padding-left: 1.5rem;
  margin-bottom: 0.85rem;
  max-width: 720px;
}
.chapter-section li { margin-bottom: 0.3rem; }


/* ── Simulador incrustat (B.4) ───────────────────────── */

/* El simulador ocupa tot l'amplada del contenidor de text del capítol.
   Amb .chapter-content-inner a 960px, el simulador interior té prou
   espai per mantenir layout horitzontal (editor | món) sense caure
   a mode mòbil vertical. */
.simulador-wrap {
  position: relative;
  margin: 1.75rem 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}

.simulador-frame {
  display: block;
  width: 100%;
  border: none;
  background: var(--bg);
}

.simulador-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 4px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  width: 100%;
}
.simulador-badge--exemple { color: var(--muted); }
.simulador-badge--exercici { color: var(--accent-hi); }

.simulador-caption {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 6px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-style: italic;
}

/* ── Feedback d'exercici (B.6) ───────────────────────── */
.simulador-feedback {
  display: none;
  padding: 0.55rem 1rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.85rem;
  margin-top: 0.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.simulador-feedback.fb-ok {
  display: block;
  background: color-mix(in srgb, var(--bg) 60%, #22c55e 40%);
  color: #14532d;
  border: 1px solid #86efac;
}
body.curs-light .simulador-feedback.fb-ok {
  background: #dcfce7;
  color: #14532d;
}
.simulador-feedback.fb-error {
  display: block;
  background: color-mix(in srgb, var(--bg) 60%, #ef4444 40%);
  color: #7f1d1d;
  border: 1px solid #fca5a5;
}
body.curs-light .simulador-feedback.fb-error {
  background: #fee2e2;
  color: #7f1d1d;
}

/* ── Label de món actiu (overlay sobre el panel del mapa) ── */
.simulador-iframe-wrap {
  position: relative;
}
.mon-active-label {
  position: absolute;
  top: 10px;
  left: 62%;           /* el panel del mapa comença ~62% des de l'esquerra */
  right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-hi);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 10;
  opacity: 0.85;
}

/* ── Selector de mons (capítol 10 — mode N mons) ─────── */
.mon-switcher {
  display: flex;
  gap: 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  flex-wrap: wrap;
}

.mon-btn {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 16px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s,
              transform 0.12s, box-shadow 0.12s, font-size 0.12s, padding 0.12s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.mon-btn:hover {
  color: var(--fg);
  border-color: var(--accent-hi);
  background: var(--surface);
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
  transform: translateY(-1px);
}
.mon-btn--active {
  color: var(--accent-hi);
  border-color: var(--accent-hi);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-hi), 0 2px 6px rgba(0,0,0,0.12);
}
.mon-btn.status-ok               { color: #16a34a; border-color: #16a34a; }
.mon-btn.status-err              { color: #dc2626; border-color: #dc2626; }
.mon-btn--active.status-ok       { box-shadow: 0 0 0 2px #16a34a, 0 2px 6px rgba(0,0,0,0.12); }
.mon-btn--active.status-err      { box-shadow: 0 0 0 2px #dc2626, 0 2px 6px rgba(0,0,0,0.12); }
.mon-btn:hover.status-ok         { border-color: #16a34a; }
.mon-btn:hover.status-err        { border-color: #dc2626; }


/* ── Seccions d'exercici ─────────────────────────────── */

.chapter-exercise {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem;
  margin-top: 2.5rem;
}

.chapter-exercise h2 {
  margin-bottom: 0.5rem;
}

.exercise-enunciat {
  background: color-mix(in srgb, var(--bg) 70%, var(--accent-hi) 30%);
  border-left: 3px solid var(--accent-hi);
  border-radius: 0 4px 4px 0;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}


/* ── Navegació prev/next ─────────────────────────────── */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  transition: border-color 0.15s, color 0.15s;
}
.btn-nav:hover { border-color: var(--accent-hi); color: var(--accent-hi); text-decoration: none; }
.btn-nav--next { margin-left: auto; }
.btn-nav--disabled { opacity: 0.3; pointer-events: none; }




/* ── Badges de progrés al sidebar ───────────────────────── */
.prog-badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}
.prog-badge--all {
  color: var(--accent-hi);
  background: color-mix(in srgb, var(--accent-hi) 12%, transparent);
}
.prog-badge--part {
  color: var(--muted);
  background: color-mix(in srgb, var(--muted) 12%, transparent);
}
/* ── Navegació global dins el sidebar (mòbil only) ──────── */
.sidebar-global-nav {
  display: none;               /* amagat en desktop */
}

@media (max-width: 820px), (max-height: 500px) {
  .sidebar-global-nav {
    display: flex;
    flex-direction: column;
    border-bottom: 2px solid var(--border);
    padding: 0.5rem 0;
    margin-bottom: 0.25rem;
  }
  .sgn-link {
    display: block;
    padding: 0.75rem 1.25rem;
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    text-decoration: none;
    transition: color 0.12s, background 0.12s;
  }
  .sgn-link:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--border) 50%, transparent);
    text-decoration: none;
  }
  .sgn-active {
    color: var(--text);
    font-weight: 700;
  }
}
/* ════════════════════════════════════════════════════════
   RESPONSIVE MÒBIL  (< 820px)
════════════════════════════════════════════════════════ */

@media (max-width: 820px), (max-height: 500px) {
  #sidebar-toggle { display: flex; align-items: center; }

  .curs-header-title { display: none; }

  .curs-sidebar {
    position: fixed;
    top: var(--header-h);
    left: calc(-1 * var(--sidebar-w));
    height: calc(100vh - var(--header-h));
    z-index: 50;
    box-shadow: none;
    transition: left 0.25s ease, box-shadow 0.25s;
  }
  .curs-sidebar.open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }

  .curs-content { padding: 1.5rem 1rem 3rem; }
  .chapter-header h1 { font-size: 1.4rem; }

  .simulador-frame { height: 320px !important; }
}

@media (max-width: 540px) {
  .mon-active-label { display: none; }
  .capitols-list { padding: 0 0.75rem; }
  .capitol-card a { padding: 0.85rem 1rem; }
  .chapter-nav { flex-direction: column; }
  .btn-nav--next { margin-left: 0; width: 100%; justify-content: center; }
  .btn-nav--prev { width: 100%; justify-content: center; }
}
