/* ============================================================
   STYLES.CSS — Manual Interactiu de Scratch
   ============================================================ */

:root {
  --sidebar-w: clamp(200px, 18vw, 260px);
  --header-h: 60px;  /* px fix — el JS llegeix offsetHeight, no aquesta variable */
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active-bg: rgba(255,255,255,0.1);
  --sidebar-active-text: #fff;
  --header-bg: #1e293b;
  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text-1: #1e293b;
  --text-2: #475569;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 16px rgba(0,0,0,0.10);
  /* ORBYS tàctil */
  --touch-min: clamp(52px, 5vh, 72px);
  --font-nav: clamp(14px, 1.3vw, 17px);
  --font-ui: clamp(13px, 1.1vw, 16px);
}

/* ---- Reset ---- */
*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  touch-action: manipulation;          /* elimina delay 300ms en taps */
  -webkit-tap-highlight-color: transparent; /* elimina flash gris en iOS */
}
html { scroll-behavior: smooth; font-size: clamp(14px, 1.2vw, 17px); }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  color: var(--text-1);
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }

/* ---- Feedback tàctil — ORBYS i mòbils ---- */
.nav-item, .act-nav-item, .proj-nav-item, .act-nav-btn, .act-back-btn,
.act-step-dot, .act-comp-btn-primary, .act-comp-btn-secondary {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
@media (hover: none) {
  .nav-item:active, .act-nav-item:active, .proj-nav-item:active {
    background: rgba(255,255,255,0.12); color: #cbd5e1;
    transform: scale(0.97);
  }
  .search-result-item:active { background: #e2e8f0; border-radius: 6px; padding-left: 8px; }
  .block-card:active         { box-shadow: var(--shadow); transform: translateY(-2px) scale(0.99); }
  .act-nav-btn:active:not(:disabled) { transform: scale(0.95); filter: brightness(0.9); }
  .act-step-dot:active:not(:disabled){ transform: scale(0.92); }
}
/* Classe .tocat per feedback JS immediat (touchstart) */
.nav-item.tocat, .act-nav-item.tocat, .proj-nav-item.tocat { background: rgba(255,255,255,0.12); transform: scale(0.97); }
.act-nav-btn.tocat:not(:disabled) { transform: scale(0.95); filter: brightness(0.9); }
.nav-item:focus-visible,
.act-nav-item:focus-visible,
.proj-nav-item:focus-visible { outline: 2px solid #4C97FF; outline-offset: -2px; border-radius: 2px; }

/* ============================================================
   LOADING
   ============================================================ */
#loading {
  position: fixed; inset: 0;
  background: #1e293b;
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity .4s ease;
}
#loading.fade-out { opacity: 0; pointer-events: none; }

.loading-inner { text-align: center; }
.loading-cat   { font-size: 4rem; margin-bottom: 12px; animation: bob 1s ease-in-out infinite; }
.loading-title { font-size: 2rem; font-weight: 700; color: #fff; letter-spacing: -0.5px; }
.loading-sub   { font-size: 0.9rem; color: #94a3b8; margin-bottom: 20px; }
.loading-bar   { width: 160px; height: 4px; background: rgba(255,255,255,0.15); border-radius: 4px; margin: 0 auto; overflow: hidden; }
.loading-fill  { height: 100%; background: #4C97FF; border-radius: 4px; animation: loadbar 1.2s ease-in-out infinite; }

@keyframes bob     { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes loadbar { 0% { width:0%; margin-left:0; } 50% { width:60%; margin-left:20%; } 100% { width:0%; margin-left:100%; } }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-hidden { display: none; }

.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--header-bg);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-brand {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0; min-width: calc(var(--sidebar-w) - 20px);
}
.brand-cat  { font-size: 1.5rem; }
.brand-name { font-size: 1rem; font-weight: 700; color: #fff; white-space: nowrap; }
.brand-sub  { font-weight: 400; color: #94a3b8; }

/* ---- Barra de cerca ---- */
.header-search {
  flex: 1; max-width: 520px;
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 0 12px;
}
.search-icon { font-size: 0.85rem; color: #94a3b8; }
#search-input {
  flex: 1; background: none; border: none; outline: none;
  color: #fff; font-size: 0.88rem; padding: 9px 0;
}
#search-input::placeholder { color: #64748b; }
.search-clear {
  min-width: 32px; min-height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: #64748b; font-size: 0.9rem; padding: 4px;
  border-radius: 4px; transition: color .15s; flex-shrink: 0;
}
.search-clear:hover { color: #fff; }
.search-clear[hidden] { display: none; }

/* ---- Mini progrés al header ---- */
.header-progress {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.progress-pct { font-size: 0.8rem; color: #94a3b8; min-width: 30px; text-align: right; }
.progress-mini { width: 80px; height: 5px; background: rgba(255,255,255,0.1); border-radius: 5px; overflow: hidden; }
.progress-mini-bar { height: 100%; background: #4C97FF; border-radius: 5px; width: 0; transition: width .4s ease; }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.app-body {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: var(--header-h); left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--sidebar-bg);
  overflow-y: auto;
  display: flex; flex-direction: column;
  padding: 16px 0 12px;
  flex-shrink: 0;
  z-index: 50;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* ---- Capçalera de grup (acordió) ---- */
.sidebar-group-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  min-height: var(--touch-min, 52px);
  padding: 0 16px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sidebar-text, #94a3b8);   /* contrast ~4.6:1 sobre #1e293b */
  cursor: pointer; text-align: left;
  background: transparent; border: none;
  border-left: 2px solid transparent;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.sidebar-group-btn:hover,
.sidebar-group-btn:focus-visible {
  color: var(--sidebar-active-text, #fff);
  background: rgba(255,255,255,0.07);
  border-left-color: #38bdf8;
  outline: none;
}
.sidebar-group-btn:active { background: rgba(255,255,255,0.10); }
.sidebar-group-btn.tocat  { background: rgba(255,255,255,0.10); }

.sidebar-group-btn--act {
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ---- Fletxa CSS pura (chevron >) ---- */
.sidebar-group-arrow {
  display: inline-block;
  width: 16px; height: 16px;
  flex-shrink: 0;
  position: relative;
}
.sidebar-group-arrow::before,
.sidebar-group-arrow::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 7px; height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform .25s ease;
}
/* Chevron (>) quan col·lapsat */
.sidebar-group-arrow::before { left: 1px; transform: translateY(-3px) rotate( 45deg); }
.sidebar-group-arrow::after  { left: 1px; transform: translateY( 1px) rotate(-45deg); }

/* Chevron (v) quan expandit */
.sidebar-group-btn[aria-expanded="true"] .sidebar-group-arrow::before {
  transform: translateY(-1px) rotate( 135deg);
}
.sidebar-group-btn[aria-expanded="true"] .sidebar-group-arrow::after {
  transform: translateY( 3px) rotate(-135deg);
}

/* ---- Ítem de navegació ---- */
.nav-list {
  overflow: hidden;
  max-height: 800px;    /* prop del contingut real → transició suau */
  transition: max-height .35s ease-out, opacity .25s ease;
  opacity: 1;
}
.nav-list.collapsed {
  max-height: 0;
  opacity: 0;
  transition: max-height .3s ease-in, opacity .2s ease;
}
#nav-list { flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  min-height: var(--touch-min);
  color: var(--sidebar-text);
  font-size: var(--font-nav);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
  user-select: none;
  -webkit-user-select: none;
}
.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: #cbd5e1;
}
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--item-color, #4C97FF);
}
.nav-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--item-color, #4C97FF);
  flex-shrink: 0;
}
.nav-icon  { font-size: 1rem; flex-shrink: 0; }
.nav-title { flex: 1; }
.nav-check {
  font-size: 0.75rem; color: #22c55e;
  opacity: 0; transition: opacity .2s;
}
.nav-item.visited .nav-check { opacity: 1; }

/* ---- Progrés al sidebar ---- */
.sidebar-progress-wrap {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: auto;
}
.sidebar-progress-label {
  font-size: 0.75rem; color: #64748b; margin-bottom: 6px;
}
.sidebar-progress-bar {
  height: 5px; background: rgba(255,255,255,0.08);
  border-radius: 5px; overflow: hidden;
}
.sidebar-progress-fill {
  height: 100%; background: #4C97FF;
  border-radius: 5px; width: 0; transition: width .4s ease;
}

/* ---- Contingut principal ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 28px 64px;
  max-width: 900px;
}

/* ============================================================
   RESULTATS DE CERCA
   ============================================================ */
.search-results {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 24px;
}
.search-results[hidden] { display: none; }
.search-results-title {
  font-size: 0.8rem; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 16px;
}
.search-results-empty {
  color: var(--text-2); font-size: 0.9rem;
  padding: 16px 0;
}
.search-result-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f8fafc; border-radius: 6px; padding-left: 8px; }
.sr-cat-badge {
  font-size: 0.7rem; font-weight: 700; color: white;
  padding: 2px 8px; border-radius: 100px;
  background: var(--sr-color);
  flex-shrink: 0; margin-top: 2px;
}
.sr-body {}
.sr-desc { font-size: 0.83rem; color: var(--text-2); margin-top: 3px; }
/* Terme cercat ressaltat */
.sr-body mark, .sr-desc mark {
  background: #fef9c3;
  color: #713f12;
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 700;
}

/* ============================================================
   ANIMACIÓ D'ENTRADA
   ============================================================ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes celebrate {
  0%,100% { transform: scale(1); }
  30%      { transform: scale(1.18) rotate(-3deg); }
  60%      { transform: scale(1.12) rotate(3deg); }
}

/* ============================================================
   SECCIONS DEL MANUAL
   ============================================================ */
.content-section {
  margin-bottom: 48px;
  scroll-margin-top: calc(var(--header-h) + 16px);
  opacity: 0;
  animation: fadeInUp .45s ease forwards;
}
/* Escalonar l'animació per ordre de secció */
.content-section:nth-child(1)  { animation-delay: .05s; }
.content-section:nth-child(2)  { animation-delay: .10s; }
.content-section:nth-child(3)  { animation-delay: .15s; }
.content-section:nth-child(4)  { animation-delay: .20s; }
.content-section:nth-child(5)  { animation-delay: .25s; }
.content-section:nth-child(n+6){ animation-delay: .30s; }

/* ---- Capçalera de secció ---- */
.section-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.section-icon-wrap {
  width: 44px; height: 44px;
  background: var(--sec-color);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}
.section-title   { font-size: 1.5rem; font-weight: 700; color: var(--text-1); }
.section-divider { height: 3px; border-radius: 3px; background: var(--sec-color); margin-bottom: 16px; opacity: 0.7; }
.section-intro   { color: var(--text-2); margin-bottom: 24px; font-size: 0.93rem; line-height: 1.7; }

/* ============================================================
   SECCIÓ D'INTERFÍCIE (especial)
   ============================================================ */
.interface-areas {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 28px;
}
@media (max-width: 700px) { .interface-areas { grid-template-columns: 1fr; } }

.area-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  border-left: 4px solid var(--area-color);
  box-shadow: var(--shadow-sm);
}
.area-card-head {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 0.9rem; color: var(--text-1);
  margin-bottom: 4px;
}
.area-card-icon { font-size: 1.1rem; }
.area-card-desc { font-size: 0.83rem; color: var(--text-2); line-height: 1.55; }

/* ---- Diagrama IDE Scratch ---- */
.ide-diagram {
  background: #2d3748;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 28px;
  font-size: 0.78rem; font-weight: 600;
}
.ide-diagram-title {
  color: #94a3b8; font-size: 0.75rem; letter-spacing: 0.05em;
  text-transform: uppercase; margin-bottom: 10px;
}
.ide-row { display: flex; gap: 6px; margin-bottom: 6px; }
.ide-cell {
  border-radius: 6px; padding: 8px 10px;
  color: white; text-align: center; font-size: 0.75rem;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.ide-palette  { background: #4C97FF; flex: 0 0 90px; }
.ide-stage    { background: #FF8C1A; flex: 1; min-height: 70px; }
.ide-scripts  { background: #59C059; flex: 2; min-height: 90px; }
.ide-sprites  { background: #CF63CF; flex: 1; min-height: 50px; }

/* ---- Diagrama de coordenades ---- */
.coord-diagram {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 28px;
}
.coord-title   { font-weight: 700; margin-bottom: 12px; color: var(--text-1); }
.coord-stage   {
  position: relative; margin: 0 auto;
  width: min(280px, 100%); height: auto; aspect-ratio: 480 / 360;
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: 6px;
}
.coord-axis-x {
  position: absolute; top: 50%; left: 0; right: 0; height: 1px;
  background: #cbd5e1;
}
.coord-axis-y {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 1px;
  background: #cbd5e1;
}
.coord-point {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 0.65rem; font-weight: 700; color: var(--text-2);
  white-space: nowrap;
}
.coord-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #4C97FF; margin: 0 auto 2px;
}

/* ============================================================
   GRAELLA DE BLOCS
   ============================================================ */
.blocks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}
.block-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  border-top: 4px solid var(--sec-color);
  transition: box-shadow .18s, transform .18s;
  position: relative;
  overflow: hidden;
}
.block-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: var(--sec-color);
  opacity: 0;
  transition: opacity .18s;
  pointer-events: none;
}
.block-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  transform: translateY(-2px);
}
.block-card:hover::after { opacity: 0.04; }
.block-card-script { margin-bottom: 10px; }
.block-card-desc   { font-size: clamp(12px, 1vw, 14px); color: var(--text-2); line-height: 1.55; }

/* ============================================================
   EXEMPLES
   ============================================================ */
.examples-section { margin-top: 8px; }
.examples-title {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text-3);
  margin-bottom: 14px;
}
.example-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.example-header {
  padding: 10px 16px;
  background: var(--sec-color);
  color: white;
  display: flex; align-items: baseline; gap: 10px;
}
.example-name { font-weight: 700; font-size: 0.9rem; }
.example-desc { font-size: 0.8rem; opacity: 0.85; }
.example-body {
  padding: 14px 16px;
  background: #1e293b;
  overflow-x: auto;
}

/* ============================================================
   BOTÓ HAMBURGER
   ============================================================ */
.sidebar-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  transition: background .2s, transform .1s;
  flex-shrink: 0;
  min-width: 48px; min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.sidebar-toggle:hover  { background: rgba(255,255,255,0.18); }
.sidebar-toggle:active { transform: scale(0.93); }
.sidebar-toggle span {
  display: block;
  width: 20px; height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .25s ease, opacity .2s;
}
.sidebar-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar-toggle.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.sidebar-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ============================================================
   OVERLAY DEL SIDEBAR (mòbil)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: opacity .25s;
}
.sidebar-overlay.visible { display: block; }

/* ============================================================
   MODE FOSC AUTOMÀTIC
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --body-bg: #0f172a;
    --card-bg: #1e293b;
    --text-1: #f1f5f9;
    --text-2: #94a3b8;
    --text-3: #64748b;
    --border: #334155;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow: 0 4px 16px rgba(0,0,0,0.4);
  }
  .sr-body mark, .sr-desc mark { background: #854d0e; color: #fef3c7; }
  .act-step-tip { background: #1c1917; border-color: #92400e; color: #fde68a; }
  .ide-diagram  { background: #1e293b; }
  .coord-stage  { background: #0f172a; border-color: #334155; }
  #search-input { color: #f1f5f9; }
  #search-input::placeholder { color: #475569; }
  .act-comp-stats { background: #14532d; border-color: #166534; color: #86efac; }
}

/* ============================================================
   RESPONSIVE — TABLET (≤1024px)
   ============================================================ */
@media (max-width: 1024px) {
  :root { --sidebar-w: 180px; }
  .header-brand { min-width: calc(180px - 16px); }
  .blocks-grid  { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

/* ============================================================
   RESPONSIVE — MÒBIL/TABLET PETIT (≤780px)
   ============================================================ */
@media (max-width: 780px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    transform: translateX(-210px); width: 210px;
    transition: transform .25s ease;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .main-content { margin-left: 0; padding: 20px 16px 48px; }
  .blocks-grid  { grid-template-columns: 1fr; }
  #search-input { font-size: 16px; } /* Evita zoom automàtic en iOS */
  .header-brand { min-width: 0; }
}

/* ============================================================
   RESPONSIVE — MÒBIL PETIT (≤480px)
   ============================================================ */
@media (max-width: 480px) {
  .app-header  { padding: 0 12px; gap: 10px; }
  .header-progress { display: none; }
  .header-search { max-width: 100%; }
  .brand-name  { font-size: 0.9rem; }
  .main-content { padding: 16px 12px 40px; }
  .block-card  { padding: 12px; }
  .block-card-desc { font-size: 0.88rem; }
  .section-title { font-size: 1.25rem; }
  .coord-diagram { padding: 16px 12px; }
  .interface-areas { grid-template-columns: 1fr; }
  .example-body { overflow-x: auto; }
}
