/* Simulacre propi · Classe 21 · Estètica del model de prova de 2n FP Bàsica. */

:root {
  color-scheme: light;
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-soft: #f1f5f9;
  --border-color: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --primary: #d97706; /* Identitat de 2n FP Bàsica: ambre / daurat */
  --primary-hover: #b45309;
  --primary-light: #fef3c7;
  --accent: #0284c7;  /* Blau tècnic */
  --accent-light: #e0f2fe;
  --success: #059669; /* Verd èxit */
  --success-light: #d1fae5;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 24px rgba(15, 23, 42, 0.12);
  --transition: all 0.2s ease-in-out;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-main: #0d131f;
  --bg-surface: #151e2e;
  --bg-card: #151e2e;
  --bg-soft: #1e293b;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #fbbf24;
  --primary-hover: #fde68a;
  --primary-light: rgba(251, 191, 36, 0.15);
  --accent: #38bdf8;
  --accent-light: rgba(56, 189, 248, 0.15);
  --success: #34d399;
  --success-light: rgba(52, 211, 153, 0.15);
  --danger: #f87171;
  --danger-light: rgba(248, 113, 113, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.6);
}

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

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  padding-bottom: 3rem;
}

a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: var(--transition);
}

a:hover {
  color: var(--primary-hover);
}

/* Navegació superior */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.topbar-nav a {
  text-decoration: none;
  color: var(--text-muted);
}

.topbar-nav a:hover {
  color: var(--primary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Menú de navegació ràpida */
.lesson-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1.25rem 0;
  padding: 0.75rem;
  background: var(--bg-soft);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.lesson-nav a {
  padding: 0.35rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  transition: var(--transition);
}

.lesson-nav a:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Contenidor principal */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* Hero / Capçalera de classe */
.hero {
  background: linear-gradient(135deg, var(--bg-card) 60%, var(--primary-light) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  background: var(--bg-soft);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.chip.highlight {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.chip.official {
  background: #fee2e2;
  border-color: #ef4444;
  color: #b91c1c;
}

[data-theme="dark"] .chip.official {
  background: rgba(239, 68, 68, 0.18);
  border-color: #f87171;
  color: #fca5a5;
}

h1 {
  font-size: clamp(1.8rem, 3.5vw, 2.5rem);
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 0.75rem;
  color: var(--text-main);
}

.lead {
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Indicador de Marcador Global Flotant / Fix */
.score-banner {
  background: var(--bg-card);
  border: 2px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: var(--shadow-md);
}

.score-details {
  display: flex;
  flex-direction: column;
}

.score-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
}

.score-value {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--primary);
  font-family: 'Fira Code', monospace;
  line-height: 1;
}

.score-progress-bar {
  flex-grow: 1;
  min-width: 200px;
  height: 12px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.score-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--success) 100%);
  transition: width 0.4s ease;
}

/* Seccions d'exercici */
.exercise-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease;
}

.exercise-card:focus-within {
  border-color: var(--primary);
}

.exercise-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.exercise-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.points-badge {
  padding: 0.25rem 0.65rem;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  font-family: 'Fira Code', monospace;
  border: 1px solid var(--primary);
}

.problem-statement {
  font-size: 1.05rem;
  line-height: 1.65;
  margin-bottom: 1.25rem;
  color: var(--text-main);
}

.sub-question {
  background: var(--bg-soft);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.sub-question h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  color: var(--text-main);
}

/* Formularis i camps d'entrada */
.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

@media (max-width: 640px) {
  .input-row {
    grid-template-columns: 1fr;
  }
}

.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
}

input[type="text"],
input[type="number"],
select {
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-size: 0.95rem;
  min-width: 130px;
  transition: var(--transition);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.unit-label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Botons */
button {
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  padding: 0.65rem 1.2rem;
  border-radius: var(--radius-sm);
  border: none;
  transition: var(--transition);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

button.primary {
  background: var(--primary);
  color: #ffffff;
}

button.primary:hover {
  background: var(--primary-hover);
}

button.secondary {
  background: var(--bg-soft);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

button.secondary:hover {
  background: var(--border-color);
}

/* Missatges de Feedback pedagògic */
.feedback-box {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  display: none;
}

.feedback-box.active {
  display: block;
}

.feedback-box.correct {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success);
}

.feedback-box.incorrect {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* Simuladors i visuals interactius */
.interactive-panel {
  background: var(--bg-soft);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin: 1.25rem 0;
  overflow: hidden;
}

.interactive-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.svg-diagram-wrap {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.svg-diagram {
  width: 100%;
  height: auto;
  display: block;
}

/* Gràfic de barres interactiu Ex 7 */
.barchart-container {
  width: 100%;
  max-width: 800px;
  margin: 1rem auto;
  position: relative;
}

.barchart-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
}

.barchart-table th,
.barchart-table td {
  padding: 0.45rem 0.5rem;
  text-align: center;
  border: 1px solid var(--border-color);
}

.barchart-table th {
  background: var(--bg-soft);
  font-weight: 700;
}

.bar-val {
  color: var(--primary);
  font-weight: 700;
}

/* Detalls i solucions oficials */
details.solution-card {
  background: var(--bg-soft);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
}

details.solution-card[open] {
  padding-bottom: 1.25rem;
}

details.solution-card summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.95rem;
  padding: 0.25rem 0;
  user-select: none;
}

.solution-content {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-color);
  font-size: 0.95rem;
  line-height: 1.6;
}

.criteria-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

/* Taula comparativa i peus de pàgina */
footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

@media print {
  .topbar,
  .lesson-nav,
  button,
  .feedback-box {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  .exercise-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }
  details.solution-card {
    display: block;
  }
}

[hidden] { display: none !important; }
.topbar-nav { flex-wrap: wrap; }
.container { width: min(1100px, calc(100% - 2rem)); }
.sub-question h3 { font-size: 1rem; margin-bottom: .7rem; }
.question-points { color: var(--text-muted); font-size: .9rem; }
.mode-controls { display: flex; flex-wrap: wrap; gap: .7rem; margin: 1rem 0; }
.time-plan { margin: 1rem 0 1rem 1.5rem; }
.time-plan li { margin: .4rem 0; }
.practice-support { margin: 1rem 0; }
.hint-card { margin: 1rem 0; padding: 1rem; border: 1px dashed var(--border-color); border-radius: 12px; }
.hint-card summary { cursor: pointer; font-weight: 700; }
.hint-card p { margin-top: .6rem; }
p + p, .solution-content p { margin-top: .7rem; }
.input-group { align-items: center; }
.input-group ul { flex-basis: 100%; margin-left: 1.5rem; }
.input-group input, .input-group select { max-width: 100%; }
.lesson-diagram { display: block; width: 100%; max-height: 240px; }
figure figcaption { margin-top: .75rem; color: var(--text-muted); }
.latency-chart { display: flex; gap: .5rem; align-items: end; height: 220px; margin: 1rem 0; }
.latency-bar { display: flex; flex: 1; min-width: 0; height: 100%; flex-direction: column; justify-content: end; align-items: stretch; padding: 0; background: transparent; color: var(--text-main); }
.bar-column { display: block; background: var(--accent); border-radius: 6px 6px 0 0; }
.latency-bar[aria-pressed="true"] .bar-column { background: var(--primary); }
.latency-bar > span:last-child { padding-top: .4rem; }
.table-scroll { overflow-x: auto; }
.barchart-table { min-width: 450px; }
.offline-note { padding: 1rem; background: var(--primary-light); }
body[data-mode="exam"] .score-banner { position: static; }
@media (max-width: 600px) { .exercise-card { padding: 1.2rem; } .exercise-header { align-items: start; } .points-badge { white-space: nowrap; } .score-banner { flex-wrap: wrap; } }
@media print {
  .score-banner, .mode-controls, .practice-support, .skip-link, .latency-chart, #mode-status, #final-summary { display: none !important; }
  .exercise-card { break-inside: auto; }
  .exercise-header, .sub-question { break-inside: avoid; }
  body:not(.print-solutions) .answer-solution { display: none !important; }
  .solution-content { display: block; }
  .feedback-box { display: none !important; }
  .container { width: 100%; }
  .hero { padding: 1rem 0; }
  .lesson-diagram { max-height: 150px; }
}

/* Totes les barres comparteixen l’altura útil, separada de les etiquetes. */
.bar-track { display: block; position: relative; flex: 1; min-height: 0; }
.bar-column { position: absolute; bottom: 0; width: 100%; }
