@charset "utf-8";
/*
 * El robot que pren decisions · Pensem com una màquina, sessió 4
 * estils.css: aparença del joc (disseny pla i clar, amb el full d’sprites img/sprites.png).
 */

/* ---------- Tipus de lletra (Nunito, SIL Open Font License) ---------- */
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/nunito-400.woff2") format("woff2"); }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/nunito-700.woff2") format("woff2"); }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 800; font-display: swap; src: url("../fonts/nunito-800.woff2") format("woff2"); }

/* ---------- Colors ---------- */
:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
  --bg: #EEF2FB;
  --surface: #FFFFFF;
  --surface-2: #F5F7FD;
  --line: #E1E6F2;
  --line-2: #CBD3E6;
  --ink: #1E2240;
  --ink-2: #4E5677;
  --ink-3: #858DAA;
  --brand: #4F46E5;
  --brand-2: #6366F1;
  --brand-soft: #ECEDFF;
  --c-fwd: #3B82F6;
  --c-turn: #8B5CF6;
  --c-if: #F59E0B;
  --c-if-ink: #3B2500;
  --if-soft: #FFF5E1;
  --if-ink: #9A5B00;
  --red: #E5484D;
  --red-soft: #FDECEC;
  --red-ink: #B4232B;
  --green: #1FAE5B;
  --green-soft: #E2F6EA;
  --green-ink: #12783D;
  --go: #16A34A;
  --outline: #34344A;
  --shadow-sm: 0 1px 2px rgba(30, 34, 64, .07);
  --shadow: 0 1px 2px rgba(30, 34, 64, .05), 0 8px 24px rgba(30, 34, 64, .08);
  --font: "Nunito", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: inherit; }
[hidden] { display: none !important; }
#avis-fitxers { display: none !important; }
html {
  height: 100%;
  scroll-padding-top: env(safe-area-inset-top, 0px);
  font-size: 16px;
  font-size: clamp(14px, calc(0.55vw + 1.05vh + 2px), 26px);
  -webkit-text-size-adjust: 100%;
}
body {
  height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #F4F6FD 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.35;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }
.ico { width: 1.25em; height: 1.25em; flex: none; }
.sym { font-family: Arial, Helvetica, sans-serif; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Sprites del full img/sprites.png (4 columnes i 3 files de 128 píxels) */
.star, .leg-spr, .logo-robot, .big-robot {
  display: inline-block;
  flex: none;
  background-image: url("../img/sprites.png");
  background-repeat: no-repeat;
  background-size: 400% 300%;
}
.s-robot, .logo-robot, .big-robot { background-position: 0 0; }
.s-crate { background-position: 33.333% 0; }
.s-lock-R { background-position: 66.667% 0; }
.s-lock-G { background-position: 100% 0; }
.s-key-R { background-position: 0 50%; }
.s-key-G { background-position: 33.333% 50%; }
.s-qblock { background-position: 66.667% 50%; }
.s-flag-a { background-position: 100% 50%; }
.star { width: 1em; height: 1em; background-position: 66.667% 100%; }
.star.on { background-position: 33.333% 100%; }

/* ---------- Capçalera ---------- */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1.2rem;
  padding: .5rem 1rem;
  background: rgba(255, 255, 255, .85);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; }
.logo-robot { width: 2.3rem; height: 2.3rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand .over { font-size: .72rem; font-weight: 700; color: var(--ink-3); }
.brand h1 { margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--ink); letter-spacing: -.01em; }
.levels { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem .8rem; }
.lv-strip { display: flex; gap: .3rem; list-style: none; margin: 0; padding: 0; }
.lv {
  width: 2.5rem;
  height: 2.65rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: .8rem;
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .18rem;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.lv-n { font-size: .95rem; line-height: 1; }
.lv-stars { display: flex; gap: 1px; }
.lv-stars .star { width: .62rem; height: .62rem; }
.lv:not(:disabled):hover { transform: translateY(-1px); box-shadow: var(--shadow); color: var(--ink); }
.lv.done { color: var(--ink); }
.lv[aria-current="true"], .lv[aria-current="true"]:hover { background: var(--brand); border-color: var(--brand); color: #FFF; box-shadow: 0 6px 16px rgba(79, 70, 229, .35); }
.lv.locked { background: var(--surface-2); color: var(--ink-3); box-shadow: none; cursor: not-allowed; }
.lv-lock { width: .85rem; height: .85rem; color: var(--ink-3); }
.star-total {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .7rem .25rem .45rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-weight: 800;
  font-size: .92rem;
}
.star-total .star { width: 1.35rem; height: 1.35rem; }
.tools { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 0 .55rem;
  color: var(--ink-2);
  font-weight: 700;
  font-size: .9rem;
  box-shadow: var(--shadow-sm);
}
.iconbtn:hover { color: var(--brand); border-color: var(--line-2); }
.iconbtn[aria-pressed="true"] { color: var(--ink-3); background: var(--surface-2); }
.iconbtn .lbl-wide { display: none; }
@media (min-width: 1500px) { .iconbtn .lbl-wide { display: inline; } }

/* ---------- Disposició ---------- */
.app-main { flex: 1; min-height: 0; container-type: size; }
.layout {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  grid-template-columns: min(calc(100vh - 5rem), calc(100vw - 25rem - 2rem)) minmax(0, 1fr);
  grid-template-columns: min(calc(100cqh - 1.4rem), calc(100cqw - 25rem - 2rem)) minmax(0, 1fr);
  gap: .8rem;
  padding: .7rem;
}
.stage { min-width: 0; min-height: 0; }
.board-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border-radius: 1.4rem;
  box-shadow: var(--shadow);
  padding: .45rem;
}
#board { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.desk { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: .6rem; overflow: auto; container: desk / inline-size; }
.play-ui { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: .6rem; }

/* ---------- Informació del nivell ---------- */
.route-info { padding: .65rem .8rem .7rem; background: var(--surface); border-radius: 1.1rem; box-shadow: var(--shadow); }
.route-head { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .6rem; }
.pill { font-size: .74rem; font-weight: 800; padding: .16rem .6rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.route-head h2 { margin: 0; font-size: 1.18rem; font-weight: 800; letter-spacing: -.01em; }
.route-meta { margin: .25rem 0 0; font-size: .88rem; color: var(--ink-2); }
.route-meta b { color: var(--brand); font-weight: 800; }
.route-brief { margin: .25rem 0 0; font-size: .92rem; }
.goal-row { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .8rem; margin-top: .4rem; }
.goal { margin: 0; flex: 1 1 18rem; font-size: .82rem; color: var(--ink-2); }
.goal .record { color: var(--brand); font-weight: 800; }
.hint { margin: .45rem 0 0; padding: .45rem .7rem; border-radius: .8rem; background: var(--if-soft); color: var(--ink); font-size: .9rem; }

/* ---------- Paleta ---------- */
.palette { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.k-F { --k: var(--c-fwd); }
.k-R, .k-L { --k: var(--c-turn); }
.k-IF { --k: var(--c-if); }
.pcard {
  position: relative;
  display: flex;
  align-items: center;
  gap: .5rem;
  border: 0;
  border-radius: .95rem;
  background: var(--k);
  padding: .45rem .6rem;
  min-height: 3rem;
  color: #FFF;
  font-weight: 800;
  font-size: .9rem;
  line-height: 1.1;
  text-align: left;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .14), 0 4px 10px rgba(30, 34, 64, .1);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.k-IF.pcard { color: var(--c-if-ink); }
.pcard .ico { width: 1.6rem; height: 1.6rem; }
.pcard .short { display: none; }
.k-IF .long { font-size: .82rem; }
@container desk (max-width: 30rem) {
  .pcard { gap: .3rem; padding: .4rem .45rem; }
  .pcard .long { display: none; }
  .pcard .short { display: inline; }
}
.pcard:hover { transform: translateY(-1px); filter: brightness(1.05); }
.pcard:active { transform: translateY(1px); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .14); }

/* ---------- Programa ---------- */
.prog-panel {
  flex: 1 1 0;
  min-height: 9rem;
  display: flex;
  flex-direction: column;
  border-radius: 1.1rem;
  overflow: hidden;
  background-color: var(--surface);
  box-shadow: var(--shadow);
}
.prog-head { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; padding: .45rem .7rem; border-bottom: 1px solid var(--line); }
.prog-head h3 { margin: 0; font-size: .95rem; font-weight: 800; }
.count { margin-left: auto; font-weight: 800; font-size: .9rem; color: var(--brand); background: var(--brand-soft); padding: .1rem .65rem; border-radius: 999px; }
.small-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: .22rem .65rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--ink-2);
}
.small-btn .ico { width: 1.05rem; height: 1.05rem; }
.small-btn:hover { color: var(--brand); border-color: var(--line-2); }
.small-btn:disabled { opacity: .45; cursor: default; }
.small-btn[data-armed] { border-color: var(--red); color: var(--red-ink); background: var(--red-soft); }
.program {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: .6rem;
  container: prog / inline-size;
  background-color: var(--surface-2);
  background-image: radial-gradient(#D9DFEE 1px, transparent 1.4px);
  background-size: 1.1rem 1.1rem;
}
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: .42rem; }
.empty-hint { flex: 1 1 12rem; align-self: center; margin: 0; font-size: .86rem; color: var(--ink-2); max-width: 36ch; }

.cwrap { position: relative; display: flex; }
.card {
  position: relative;
  width: 3.5rem;
  min-height: 3.55rem;
  border: 0;
  border-radius: .85rem;
  background: var(--k);
  color: #FFF;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: .05rem;
  padding: 1.1rem .1rem .25rem;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .14), 0 3px 8px rgba(30, 34, 64, .08);
  transition: transform .15s ease, opacity .2s ease, box-shadow .15s ease;
}
.card .ico { width: 1.5rem; height: 1.5rem; }
.card .lbl { font-size: .62rem; line-height: 1.05; text-align: center; font-weight: 800; white-space: nowrap; }
.card .num, .if-grab .num {
  position: absolute;
  top: .2rem;
  left: .2rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 .22rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: .68rem;
  font-weight: 800;
  background: rgba(255, 255, 255, .95);
  color: var(--ink);
}
.cwrap.sel .card, .ifblock.sel { outline: 3px solid var(--brand-2); outline-offset: 2px; }
.del {
  position: absolute;
  top: -.5rem;
  right: -.5rem;
  z-index: 2;
  width: 1.45rem;
  height: 1.45rem;
  padding: 0;
  border-radius: 999px;
  border: 2px solid var(--surface);
  background: var(--ink);
  color: #FFF;
  display: grid;
  place-items: center;
}
.del .ico { width: .85rem; height: .85rem; }
.caret { width: .28rem; min-height: 3rem; border-radius: 999px; background: var(--brand-2); animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { to { opacity: .15; } }
.slot {
  width: 2.5rem;
  min-height: 3.55rem;
  border: 2px dashed var(--line-2);
  border-radius: .85rem;
  background: rgba(255, 255, 255, .6);
  color: var(--ink-3);
  display: grid;
  place-items: center;
  padding: 0;
}
.slot .ico { width: 1.2rem; height: 1.2rem; }
.slot:hover { color: var(--brand); border-color: var(--brand-2); }
.slot.active { border-style: solid; border-color: var(--brand-2); color: var(--brand); background: var(--brand-soft); }
.lane-empty { align-self: center; font-size: .76rem; color: var(--ink-3); }

.ifblock {
  position: relative;
  flex: 1 1 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .4rem;
  padding: .35rem;
  border-radius: 1rem;
  background: var(--if-soft);
  border: 2px solid #F8C76B;
}
.if-head { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; padding: .1rem; border-radius: .8rem; transition: box-shadow .15s ease; }
.if-grab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  border: 0;
  border-radius: .7rem;
  padding: .32rem .75rem .32rem 1.75rem;
  background: var(--c-if);
  color: var(--c-if-ink);
  font-weight: 800;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .12);
}
.if-grab .num { top: 50%; transform: translateY(-50%); left: .25rem; }
.if-grab .kw { font-size: 1rem; letter-spacing: .02em; }
.if-grab .ico { width: 1.1rem; height: 1.1rem; }
.cond-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  border: 2px solid var(--line-2);
  border-radius: .75rem;
  padding: .18rem .6rem .24rem;
  background: var(--surface);
  line-height: 1.12;
  text-align: left;
}
.cond-chip .cc-top { font-size: .72rem; color: var(--ink-2); }
.cond-chip .cc-bot { display: inline-flex; align-items: center; gap: .3rem; font-size: .92rem; font-weight: 800; }
.cond-chip.R { border-color: var(--red); }
.cond-chip.R b, .cond-chip.R .sym { color: var(--red-ink); }
.cond-chip.G { border-color: var(--green); }
.cond-chip.G b, .cond-chip.G .sym { color: var(--green-ink); }
.ifblock > .del { top: -.6rem; right: -.6rem; }
.lanes { display: grid; gap: .3rem; min-width: 0; }
.lane {
  display: grid;
  grid-template-columns: 3.6rem minmax(0, 1fr);
  align-items: center;
  gap: .3rem;
  padding: .25rem .3rem;
  border-radius: .8rem;
  background: var(--surface);
  border: 1px solid #F3DEB0;
  transition: opacity .25s ease, background-color .25s ease;
}
.lane-label { font-size: .66rem; font-weight: 800; letter-spacing: .03em; color: var(--if-ink); padding-left: .15rem; }
.lane.taken { background: var(--brand-soft); border-color: var(--brand-2); }
.lane.skipped { opacity: .4; }
@container prog (max-width: 25rem) {
  .ifblock { grid-template-columns: minmax(0, 1fr); }
  .if-head { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .lane { grid-template-columns: minmax(0, 1fr); }
}
/* Ressalt durant l’execució */
.card.current, .if-head.current .if-grab { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--brand-2); transform: translateY(-2px) scale(1.05); }
.card.done, .if-head.done .if-grab { opacity: .45; }
.card.crash, .if-head.crash .if-grab { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--red); }

/* ---------- Ajustos i execució ---------- */
.settings { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem 1rem; font-size: .84rem; min-height: 1.9rem; }
.pista-ctrls { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .8rem; }
.pc-cap { font-weight: 800; color: var(--ink-2); }
.pista-ctrls label { display: inline-flex; align-items: center; gap: .35rem; font-weight: 700; color: var(--ink-2); }
.pista-ctrls select, .speed-sel select { border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); padding: .2rem .6rem; box-shadow: var(--shadow-sm); }
.speed-sel { margin-left: auto; position: relative; display: inline-flex; align-items: center; }
.speed-sel .ico { position: absolute; left: .55rem; width: 1.05rem; height: 1.05rem; color: var(--ink-2); pointer-events: none; }
.speed-sel select { appearance: none; -webkit-appearance: none; padding-left: 1.9rem; font-weight: 700; }
.seg { display: inline-flex; gap: .15rem; padding: .15rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { border: 0; border-radius: 999px; background: transparent; padding: .12rem .6rem; font-size: .78rem; font-weight: 700; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--brand); color: #FFF; }
.runbar { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  border: 1px solid var(--line);
  border-radius: .9rem;
  background: var(--surface);
  padding: .5rem .85rem;
  font-weight: 800;
  font-size: .9rem;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn .ico { width: 1.15rem; height: 1.15rem; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--go); border-color: var(--go); color: #FFF; min-width: 7rem; box-shadow: 0 6px 16px rgba(22, 163, 74, .3); }
.btn.accent { border: 2px solid var(--c-if); }
.btn.accent .ico { color: var(--if-ink); }

/* ---------- Consola: estat, resultat i traça ---------- */
.console {
  flex: none;
  height: 6rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: .5rem .7rem;
  background: var(--surface);
  border-radius: 1.1rem;
  box-shadow: var(--shadow);
}
.status-row { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .6rem; }
#status { margin: 0; font-weight: 800; font-size: .95rem; flex: 1 1 14rem; min-width: 0; }
.progress { font-size: .76rem; color: var(--ink-2); font-weight: 700; }
.keychip { display: inline-flex; align-items: center; gap: .3rem; padding: .08rem .6rem; border-radius: 999px; border: 2px solid var(--line); font-size: .76rem; font-weight: 800; color: var(--ink-2); }
.keychip .ico { width: 1em; height: 1em; }
.keychip.R { border-color: var(--red); color: var(--red-ink); background: var(--red-soft); }
.keychip.G { border-color: var(--green); color: var(--green-ink); background: var(--green-soft); }
.tabs { display: inline-flex; }
.banner { display: flex; align-items: flex-start; gap: .45rem; padding: .35rem .6rem; border-radius: .8rem; font-size: .84rem; line-height: 1.3; }
.banner .ico { margin-top: .05rem; }
.banner.win { background: var(--green-soft); color: var(--green-ink); }
.banner.crash { background: var(--red-soft); color: var(--red-ink); }
.banner.end { background: var(--surface-2); color: var(--ink); }
.banner.warn { background: var(--if-soft); color: var(--ink); }
.banner.warn > .ico { color: var(--if-ink); }
.banner .small-btn { padding: .1rem .5rem; vertical-align: middle; }
.trace, .cases { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: 0; }
.trace { list-style: none; font-size: .78rem; color: var(--ink-2); }
.trace li { display: flex; gap: .45rem; padding: .06rem 0; }
.trace li:last-child { color: var(--ink); font-weight: 700; }
.trace .tnum { flex: none; min-width: 1.3rem; text-align: right; font-weight: 800; color: var(--ink-3); }
.trace li.t-crash, .trace li.t-crash .tnum { color: var(--red-ink); }
.trace li.t-win { color: var(--green-ink); }
.console.expanded { height: auto; min-height: 6rem; max-height: 14rem; }
.console.expanded .cases { flex: 1 1 auto; }
.cases-sum { margin: 0 0 .2rem; font-size: .84rem; font-weight: 800; }
.cases-sum.ok { color: var(--green-ink); }
.cases-sum.ko { color: var(--red-ink); }
.cases-sum span { font-weight: 400; }
.case-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.case { display: flex; align-items: center; flex-wrap: wrap; gap: .2rem .6rem; font-size: .8rem; }
.case-name { min-width: 9rem; }
.cw.R { color: var(--red-ink); font-weight: 800; }
.cw.G { color: var(--green-ink); font-weight: 800; }
.case-res { display: inline-flex; align-items: center; gap: .25rem; flex: 1 1 10rem; }
.case-res.ok { color: var(--green-ink); }
.case-res.ko { color: var(--red-ink); }
.case-res .ico { width: 1em; height: 1em; }
.case .small-btn { padding: .12rem .5rem; }

/* ---------- Graella (SVG) ---------- */
.board-bg { fill: #E7ECF8; }
.tile { fill: #FFFFFF; }
.tile.alt { fill: #F6F8FE; }
.labels text { font-family: var(--font); font-weight: 800; font-size: 24px; fill: #A0A8C3; text-anchor: middle; dominant-baseline: central; }
.start-mark rect { fill: none; stroke: var(--brand-2); stroke-width: 3; stroke-dasharray: 8 7; opacity: .7; }
.start-mark text { font-family: var(--font); font-weight: 800; font-size: 14px; fill: var(--brand); text-anchor: middle; }
.start-mark.hide-label text { display: none; }
.target-bg { fill: #E4EEFF; }
.flag.fa { animation: flag-a 1.2s linear infinite; }
.flag.fb { animation: flag-b 1.2s linear infinite; }
@keyframes flag-a { 0%, 49.9% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes flag-b { 0%, 49.9% { opacity: 0; } 50%, 100% { opacity: 1; } }
.target-ring { fill: none; stroke: #3B82F6; stroke-width: 5; opacity: 0; transform-box: fill-box; transform-origin: center; }
.target.win .target-ring { animation: ring 1.1s ease-out 3; }
@keyframes ring { 0% { opacity: .9; transform: scale(.85); } 100% { opacity: 0; transform: scale(1.3); } }
.door .door-img, .door .badge { transition: opacity .35s ease; }
.door.open .door-img { opacity: .22; }
.door.open .badge { opacity: .35; }
.badge-bg { fill: #FFF; stroke: var(--outline); stroke-width: 3; }
.badge-sym.R { fill: var(--red); }
.badge-sym.G { fill: var(--green); }
.tile-bg.R { fill: var(--red-soft); stroke: var(--red); stroke-width: 4; }
.tile-bg.G { fill: var(--green-soft); stroke: var(--green); stroke-width: 4; }
.tile-word { font-family: var(--font); font-weight: 800; font-size: 15px; text-anchor: middle; }
.tile-word.R { fill: var(--red-ink); }
.tile-word.G { fill: var(--green-ink); }
.trail { fill: none; stroke: var(--brand-2); stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 0.1 17; opacity: .55; }
.robot-shadow { fill: rgba(30, 34, 64, .12); }
.robot .pointer { fill: var(--brand); stroke: #FFF; stroke-width: 3; stroke-linejoin: round; }
.robot.hit .robot-img { animation: flash .2s steps(2, start) 4; }
.keybadge-bg { fill: #FFF; stroke-width: 3; }
.keybadge-bg.R { stroke: var(--red); }
.keybadge-bg.G { stroke: var(--green); }
.bubble rect, .bubble path { fill: #FFF; stroke: var(--outline); stroke-width: 3; stroke-linejoin: round; }
.bubble .bubble-shadow { fill: rgba(30, 34, 64, .15); stroke: none; }
.bubble text { font-family: var(--font); font-size: 23px; font-weight: 800; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.bubble .yes { fill: var(--green-ink); }
.bubble .no { fill: var(--red-ink); }
.fx-crash rect { fill: rgba(229, 72, 77, .14); stroke: var(--red); stroke-width: 6; animation: flash .42s steps(2, start) 4; }
.fx-edge { stroke: var(--red); stroke-width: 10; stroke-linecap: round; animation: flash .42s steps(2, start) 4; }
@keyframes flash { to { opacity: .25; } }

/* Llegenda de l’ajuda */
.leg-spr { width: 2rem; height: 2rem; }

/* ---------- Diàlegs i avisos ---------- */
dialog {
  border: 0;
  padding: 0;
  border-radius: 1.4rem;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(30, 34, 64, .3);
  width: min(46rem, calc(100vw - 2rem));
  max-height: min(88vh, 60rem);
}
dialog::backdrop { background: rgba(30, 34, 64, .45); }
dialog:not([open]) { display: none; }
#dlg-welcome, #dlg-win { width: min(32rem, calc(100vw - 2rem)); }
.msg-dlg { align-items: center; padding: 1.5rem 1.6rem 1.35rem; text-align: center; overflow: auto; }
.msg-dlg h2 { margin: .45rem 0 .5rem; font-size: 1.45rem; font-weight: 800; letter-spacing: -.01em; }
.msg-dlg p { margin: .35rem 0; font-size: .96rem; color: var(--ink-2); max-width: 44ch; }
.msg-dlg p b { color: var(--ink); }
.big-robot { display: block; width: 5rem; height: 5rem; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-4deg); } }
.msg-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .55rem; margin-top: 1.1rem; }
.win-stars-row { display: inline-flex; gap: .4rem; }
.win-stars-row .star { width: 3.6rem; height: 3.6rem; }
.win-stars-row .star.on { animation: star-pop .55s cubic-bezier(.2, 1.6, .4, 1) both; }
.win-stars-row .star.on:nth-child(2) { animation-delay: .16s; }
.win-stars-row .star.on:nth-child(3) { animation-delay: .32s; }
@keyframes star-pop { from { opacity: 0; transform: scale(.3) rotate(-20deg); } to { opacity: 1; transform: scale(1) rotate(0); } }
/* Alternativa per als navegadors sense diàlegs modals */
dialog.fallback { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); margin: 0; z-index: 30; overflow: auto; }
.dlg-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(30, 34, 64, .45); z-index: 29; }
.dlg { display: flex; flex-direction: column; max-height: inherit; }
.dlg-head { display: flex; align-items: center; gap: .6rem; padding: .85rem 1rem .6rem 1.3rem; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 1.25rem; font-weight: 800; flex: 1; }
.dlg-body { overflow: auto; padding: .4rem 1.3rem 1.2rem; font-size: .92rem; }
.dlg-body h3 { font-size: 1rem; font-weight: 800; margin: 1.1rem 0 .3rem; color: var(--brand); }
.dlg-body p { margin: .3rem 0; max-width: 68ch; }
.credits { color: var(--ink-2); font-size: .86rem; }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .4rem .9rem; margin: .5rem 0; }
.legend span { display: inline-flex; align-items: center; gap: .55rem; font-size: .88rem; }
.keys { border-collapse: collapse; font-size: .88rem; }
.keys td { padding: .2rem .8rem .2rem 0; vertical-align: top; }
.keys kbd, .dlg-body kbd { font: 800 .78rem/1.2 var(--font); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: .4rem; padding: .02rem .4rem; background: var(--surface-2); }
details.teacher { margin-top: 1rem; border: 1px solid var(--line); border-radius: 1rem; padding: .6rem .9rem; background: var(--surface-2); }
details.teacher summary { cursor: pointer; font-weight: 800; }
.sol-btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; }
.muted { color: var(--ink-2); }
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 1rem);
  max-width: min(36rem, calc(100vw - 2rem));
  padding: .6rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: #FFF;
  font-size: .88rem;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(30, 34, 64, .25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 40;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Pantalles estretes o verticals ---------- */
@media (max-width: 1100px) {
  .lv { width: 2.25rem; height: 2.45rem; }
  .brand .over { display: none; }
}
@media (max-width: 640px) {
  .levels { order: 3; flex: 1 1 100%; justify-content: space-between; gap: .3rem; }
  .lv-strip { gap: .15rem; }
  .lv { width: 1.95rem; height: 2.35rem; border-radius: .6rem; }
  .lv-n { font-size: .85rem; }
  .lv-stars .star { width: .5rem; height: .5rem; }
  .brand h1 { font-size: .98rem; }
  .logo-robot { width: 1.9rem; height: 1.9rem; }
}
@media (max-width: 900px), (orientation: portrait) and (max-width: 1100px) {
  body { height: auto; min-height: 100%; overflow: auto; }
  .app-main { container-type: normal; flex: none; }
  .layout { height: auto; grid-template-columns: minmax(0, 1fr); }
  .board-box { max-width: 40rem; margin: 0 auto; }
  .desk { overflow: visible; }
  .prog-panel { flex: none; min-height: 15rem; }
  .console { height: 9rem; }
}
/* ---------- Alternatives per a navegadors més antics ---------- */
@supports not (aspect-ratio: 1 / 1) {
  .board-box { position: relative; height: 0; padding: 0 0 100%; }
  #board { position: absolute; top: .45rem; left: .45rem; width: calc(100% - .9rem); height: calc(100% - .9rem); }
}
@supports not (container-type: inline-size) {
  @media (max-width: 1150px) {
    .pcard { gap: .3rem; padding: .4rem .45rem; }
    .pcard .long { display: none; }
    .pcard .short { display: inline; }
    .ifblock { grid-template-columns: minmax(0, 1fr); }
    .if-head { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .lane { grid-template-columns: minmax(0, 1fr); }
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .flag.fb { opacity: 0; }
}
