/* ===========================================================================
   Les hores en català — estils
   =========================================================================== */
:root {
  --bg: #f6f4ef;
  --bg-2: #efe9df;
  --ink: #20222b;
  --ink-soft: #5a5e6b;
  --card: #ffffff;
  --line: #e6e1d6;
  --red: #d62828;
  --red-dark: #a51d1d;
  --gold: #f4c20d;
  --blue: #2b6cb0;
  --green: #2e9e5b;
  --green-soft: #e6f5ec;
  --red-soft: #fdebeb;
  --shadow: 0 6px 22px rgba(30, 25, 15, .10);
  --shadow-sm: 0 2px 8px rgba(30, 25, 15, .08);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -10%, #fffdf8 0%, rgba(255,253,248,0) 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 22px 16px 60px;
}

/* ---- Capçalera ---------------------------------------------------------- */
header.app-head { text-align: center; margin-bottom: 18px; }
.senyera-bar {
  height: 8px; width: 84px; margin: 0 auto 14px;
  border-radius: 6px;
  background: repeating-linear-gradient(90deg,
    var(--gold) 0 10px, var(--red) 10px 17px);
  box-shadow: var(--shadow-sm);
}
header.app-head h1 {
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  margin: 0 0 4px; letter-spacing: -.02em;
}
header.app-head p { margin: 0; color: var(--ink-soft); font-size: .98rem; }

/* ---- Barra superior (capçalera fixa, estil família Basic) --------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(120%) blur(8px);
  -webkit-backdrop-filter: saturate(120%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar-inner {
  max-width: 760px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 14px; min-height: 56px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); font-weight: 800; font-size: 1.02rem;
  letter-spacing: -.01em; text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; box-shadow: inset 0 0 0 1px var(--line);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-text { white-space: nowrap; }
.site-nav { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.site-nav a {
  font-size: .92rem; font-weight: 700; color: var(--ink-soft); text-decoration: none;
  padding: 7px 12px; border-radius: 999px; white-space: nowrap; transition: background .15s, color .15s;
}
.site-nav a:hover { background: var(--bg-2); color: var(--ink); }
.site-nav a.is-active { background: var(--red); color: #fff; }
@media (max-width: 380px) {
  .brand-text { display: none; }
  .bar-inner { gap: 10px; }
  .site-nav a { padding: 7px 10px; }
}

/* ---- Targetes ----------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}
.card h2 {
  font-size: 1.05rem; margin: 0 0 14px; text-align: center;
  color: var(--ink-soft); font-weight: 700; letter-spacing: .01em;
}

/* ---- Rellotge ----------------------------------------------------------- */
.clock-card { text-align: center; }
.clock-svg { width: min(280px, 78vw); height: auto; display: block; margin: 0 auto; }
.clock-svg text { font-family: var(--font); }
.hand { stroke-linecap: round; }
.hand-hour { stroke: var(--ink); }
.hand-min  { stroke: var(--ink); }
.hand-sec  { stroke: var(--red); }

.digital {
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(2.2rem, 11vw, 3.2rem);
  letter-spacing: .04em;
  color: var(--ink);
}
.digital .sec { color: var(--red); font-size: .5em; vertical-align: middle; }
.live-phrase {
  margin-top: 2px; color: var(--red-dark); font-size: 1.05rem; font-weight: 600;
  min-height: 1.5em;
}
.live-phrase::first-letter { text-transform: uppercase; }

/* ---- Joc: progrés ------------------------------------------------------- */
.progress-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.level-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .92rem;
}
.level-badge .num {
  background: var(--ink); color: #fff; border-radius: 999px;
  width: 22px; height: 22px; display: grid; place-items: center; font-size: .8rem;
}
.dots { display: inline-flex; gap: 6px; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--line); transition: background .2s, transform .2s; }
.dot.on { background: var(--green); transform: scale(1.12); }
.stats { color: var(--ink-soft); font-size: .9rem; display: flex; gap: 14px; }
.stats b { color: var(--ink); }
.stats .fire { color: var(--red); }

/* ---- Joc: enunciat ------------------------------------------------------ */
.prompt { text-align: center; margin-bottom: 6px; }
.prompt .ask { color: var(--ink-soft); font-size: .95rem; margin-bottom: 8px; }
.puzzle-time {
  display: inline-block;
  font-variant-numeric: tabular-nums; font-weight: 800;
  font-size: clamp(2.6rem, 14vw, 4rem); letter-spacing: .05em;
  color: #fff; background: linear-gradient(180deg, #2a2d38, #1b1d26);
  border-radius: 14px; padding: 6px 22px; box-shadow: var(--shadow);
  border: 2px solid #11131a;
}
.tier-hint { color: var(--ink-soft); font-size: .85rem; margin-top: 8px; min-height: 1.2em; }

/* ---- Joc: barra de resposta i fitxes ------------------------------------ */
.answer-bar {
  min-height: 56px; margin: 16px 0 12px;
  border: 2px dashed var(--line); border-radius: var(--radius-sm);
  padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  justify-content: center; background: #fcfbf8; transition: border-color .2s, background .2s;
}
.answer-bar.empty::before {
  content: "Construeix la frase aquí ↓"; color: #b9b3a5; font-size: .92rem;
}
.answer-bar.ok   { border-color: var(--green); border-style: solid; background: var(--green-soft); }
.answer-bar.bad  { border-color: var(--red); border-style: solid; background: var(--red-soft); }

.tray { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; margin-bottom: 6px; }

.chip {
  font-family: var(--font); font-size: 1.02rem; font-weight: 600;
  color: var(--ink); background: #fff;
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 11px 16px; cursor: pointer; min-height: 44px;
  box-shadow: var(--shadow-sm); transition: transform .08s, box-shadow .15s, background .15s, border-color .15s;
  user-select: none;
}
.chip:hover { border-color: #cdc6b6; transform: translateY(-1px); }
.chip:active { transform: translateY(0); }
.chip.in-answer { background: #fff5d6; border-color: var(--gold); }
.chip.used { opacity: .32; pointer-events: none; }
.chip:disabled { cursor: default; }

/* ---- Botons ------------------------------------------------------------- */
.btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 6px; }
.btn {
  font-family: var(--font); font-size: 1rem; font-weight: 700;
  border-radius: 12px; padding: 12px 22px; cursor: pointer; border: 1.5px solid transparent;
  min-height: 46px; transition: transform .08s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--red); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #cdc6b6; }
.btn-link { background: none; border: none; color: var(--ink-soft); text-decoration: underline; cursor: pointer; font-size: .9rem; padding: 6px; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---- Retroacció --------------------------------------------------------- */
.feedback { margin-top: 14px; text-align: center; min-height: 1.4em; }
.feedback .verdict { font-weight: 800; font-size: 1.1rem; }
.feedback.ok .verdict { color: var(--green); }
.feedback.bad .verdict { color: var(--red); }
.feedback .solution { margin-top: 4px; font-size: 1.05rem; }
.feedback .solution b { color: var(--ink); }
.feedback .why { margin-top: 6px; color: var(--ink-soft); font-size: .92rem; }

/* ---- Mode escriptura ---------------------------------------------------- */
.write-toggle { text-align: center; margin-top: 10px; }
.write-box { margin-top: 10px; display: none; gap: 8px; justify-content: center; flex-wrap: wrap; }
.write-box.show { display: flex; }
.write-box input {
  font-family: var(--font); font-size: 1.05rem; padding: 11px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; min-width: min(360px, 70vw);
}
.write-box input:focus { outline: none; border-color: var(--red); }

/* ---- Banner prova final ------------------------------------------------- */
.exam-banner {
  display: none; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(90deg, var(--gold), #ffd84d);
  color: #5a4500; font-weight: 800; border-radius: 12px; padding: 10px 14px; margin-bottom: 14px;
  text-align: center;
}
.exam-banner.show { display: flex; }
.unlock-box { text-align: center; margin-top: 14px; }

/* ---- Toast -------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-weight: 700; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 50; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Certificat --------------------------------------------------------- */
.cert-badge { text-align: center; margin-top: 10px; }
.cert-overlay {
  position: fixed; inset: 0; background: rgba(20,18,12,.55);
  display: none; align-items: center; justify-content: center; padding: 18px; z-index: 100;
}
.cert-overlay.show { display: flex; }
.certificate {
  background:
    radial-gradient(900px 400px at 50% 0%, #fffef9, #fbf7ea);
  border: 3px double var(--red-dark);
  border-radius: 12px; max-width: 560px; width: 100%; padding: 34px 30px;
  text-align: center; font-family: var(--serif); color: #23201a;
  box-shadow: 0 20px 60px rgba(0,0,0,.4); position: relative;
}
.certificate .seal {
  width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 50%;
  background: repeating-linear-gradient(90deg, var(--gold) 0 7px, var(--red) 7px 12px);
  border: 3px solid var(--red-dark); display: grid; place-items: center;
  font-size: 1.6rem; box-shadow: var(--shadow);
}
.certificate .kicker { letter-spacing: .22em; text-transform: uppercase; font-size: .72rem; color: var(--red-dark); }
.certificate h3 { font-size: 1.55rem; margin: 8px 0 6px; }
.certificate .cert-name {
  font-size: 1.7rem; margin: 12px 0; font-weight: bold; border-bottom: 1px solid #cbb; padding-bottom: 6px;
}
.certificate p { font-size: 1rem; margin: 8px 0; }
.certificate .cert-date { margin-top: 16px; font-style: italic; color: #6a6253; }
.certificate .cert-sign { margin-top: 6px; font-size: .85rem; color: #6a6253; }
.cert-name-input {
  font-family: var(--serif); font-size: 1.3rem; text-align: center;
  border: none; border-bottom: 2px dashed #c9b; background: transparent;
  width: 80%; padding: 6px; margin: 10px 0;
}
.cert-name-input:focus { outline: none; border-color: var(--red); }
.cert-actions { margin-top: 18px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---- Ajuda / regles ----------------------------------------------------- */
details.rules { margin-top: 8px; }
details.rules summary {
  cursor: pointer; color: var(--ink-soft); font-size: .92rem; font-weight: 600;
  list-style: none; text-align: center; padding: 6px;
}
details.rules summary::-webkit-details-marker { display: none; }
details.rules .rules-body { font-size: .9rem; color: var(--ink-soft); padding: 6px 4px 0; }
details.rules table { width: 100%; border-collapse: collapse; margin-top: 8px; }
details.rules td { padding: 4px 8px; border-bottom: 1px solid var(--line); }
details.rules td:first-child { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); white-space: nowrap; }

footer.app-foot { text-align: center; color: var(--ink-soft); font-size: .82rem; margin-top: 8px; }

/* ---- Animacions --------------------------------------------------------- */
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.pop { animation: pop .18s ease-out; }
@keyframes shake { 10%,90%{transform:translateX(-1px)} 30%,70%{transform:translateX(3px)} 50%{transform:translateX(-4px)} }
.shake { animation: shake .35s; }

/* ---- Impressió del certificat ------------------------------------------ */
@media print {
  body * { visibility: hidden; }
  .cert-overlay, .cert-overlay * { visibility: visible; }
  .cert-overlay { position: absolute; inset: 0; background: #fff; display: flex !important; }
  .cert-actions, .cert-name-input { display: none !important; }
  .certificate { box-shadow: none; border-color: #999; }
}

/* ---- Bàner d'instal·lació (PWA) ------------------------------------------ */
.install-banner {
  position: fixed; left: 50%; bottom: 14px; transform: translate(-50%, 160%);
  width: min(560px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 12px 14px; z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  transition: transform .35s cubic-bezier(.2, .8, .3, 1);
}
.install-banner.show { transform: translate(-50%, 0); }
.ib-msg { display: flex; align-items: center; gap: 10px; font-size: .94rem; font-weight: 600; color: var(--ink); }
.ib-ic { font-size: 1.4rem; }
.ib-actions { display: flex; align-items: center; gap: 8px; }
.install-banner .btn { padding: 9px 16px; min-height: auto; }

/* ---- Pàgina de normes ---------------------------------------------------- */
.doc-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.back-link { color: var(--red-dark); font-weight: 700; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.doc h2 { text-align: left; color: var(--ink); font-size: 1.3rem; margin: 26px 0 10px; scroll-margin-top: 72px; }
.doc h3 { color: var(--red-dark); font-size: 1.05rem; margin: 18px 0 6px; }
.doc p { margin: 8px 0; }
.doc ul { margin: 8px 0; padding-left: 22px; }
.doc li { margin: 4px 0; }
.doc strong { color: var(--ink); }
.doc .callout {
  background: var(--bg); border-left: 4px solid var(--gold); border-radius: 8px;
  padding: 10px 14px; margin: 14px 0; font-size: .95rem;
}
.doc table.htab { width: 100%; border-collapse: collapse; margin: 12px 0; }
.doc table.htab td { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.doc table.htab td:first-child { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; width: 86px; color: var(--ink); }
.doc table.htab tr:hover td { background: #fcfbf8; }
.doc .src { font-size: .88rem; color: var(--ink-soft); }
.doc .src a { color: var(--red-dark); }
.systems { display: grid; gap: 12px; grid-template-columns: 1fr; margin: 14px 0; }
@media (min-width: 600px) { .systems { grid-template-columns: 1fr 1fr 1fr; } }
.sys-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fcfbf8; }
.sys-card h4 { margin: 0 0 6px; font-size: 1rem; }
.sys-card.is-main { border-color: var(--red); box-shadow: 0 0 0 2px rgba(214, 40, 40, .12); background: #fff; }
.sys-card p { margin: 4px 0; font-size: .92rem; }
.tag { display: inline-block; font-size: .68rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--red); color: #fff; margin-left: 6px; vertical-align: middle; }
.doc-link-card {
  display: flex; align-items: center; gap: 12px; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 20px; box-shadow: var(--shadow-sm); transition: border-color .15s, transform .08s;
}
.doc-link-card:hover { border-color: var(--gold); transform: translateY(-1px); }
.doc-link-card .dl-ic { font-size: 1.6rem; }
.doc-link-card .dl-txt { color: var(--ink); }
.doc-link-card .dl-txt b { display: block; }
.doc-link-card .dl-txt span { color: var(--ink-soft); font-size: .9rem; }
.doc-link-card .dl-go { margin-left: auto; color: var(--red-dark); font-weight: 700; }

/* ---- Teaser d'història (portada) ---------------------------------------- */
.teaser-hook { text-align: center; color: var(--ink-soft); max-width: 56ch; margin: 0 auto; }
.teaser-hook strong { color: var(--ink); }
.teaser-cta { text-align: center; margin-top: 14px; margin-bottom: 0; }
.teaser-cta .btn { text-decoration: none; display: inline-block; }

/* ---- Peu amb segells (XKNO + NDF) + legal ------------------------------- */
.site-footer { border-top: 1px solid var(--line); margin-top: 28px; background: var(--bg-2); }
.footer-inner { max-width: 760px; margin: 0 auto; padding: 26px 16px 40px; }
.footer-badges { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
@media (min-width: 640px) {
  .footer-badges { flex-direction: row; align-items: stretch; }
  .footer-badges > * { flex: 1 1 0; }
}
.xkno-link, .ndf-seal-badge {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  text-decoration: none; box-shadow: var(--shadow-sm);
  transition: border-color .15s, background .15s;
}
.xkno-link:hover, .ndf-seal-badge:hover { border-color: var(--gold); background: #fff; text-decoration: none; }
.xkno-link picture { display: contents; }
.xkno-link img, .ndf-seal-badge img { width: 56px; height: 56px; flex: 0 0 56px; border-radius: 12px; object-fit: contain; }
.xkno-link > span, .ndf-seal-badge > span {
  display: flex; flex-direction: column; gap: 2px; font-size: .9rem; line-height: 1.42; color: var(--ink-soft);
}
.xkno-link strong, .ndf-seal-badge strong { color: var(--ink); font-weight: 700; }
.ndf-seal-badge .ndf-line { opacity: .85; }
.footer-legal { text-align: center; color: var(--ink-soft); }
.footer-credit { margin: 0 0 8px; font-size: .92rem; }
.footer-credit strong { color: var(--ink); }
.footer-legal-links { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; margin-bottom: 8px; }
.footer-legal-link {
  background: none; border: none; font: inherit; font-size: .9rem; color: var(--red-dark);
  cursor: pointer; text-decoration: underline; padding: 4px 4px; border-radius: 6px;
}
.footer-legal-link:hover { color: var(--red); }
.footer-sep { color: var(--line); }
.footer-rights { margin: 0; font-size: .82rem; }

/* Promoció creuada discreta (dalt del peu) */
.footer-explore { text-align: center; max-width: 60ch; margin: 0 auto 22px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.footer-explore p { margin: 0; font-size: .9rem; line-height: 1.5; color: var(--ink-soft); }
.footer-explore a { color: var(--ink); font-weight: 600; text-decoration: none; border-bottom: 1px dotted var(--ink-soft); white-space: nowrap; }
.footer-explore a:hover { color: var(--red-dark); border-bottom-color: var(--red); }
.footer-explore .fe-intro { margin: 0 0 8px; }
.footer-explore .fe-item { margin: 3px 0; }

/* ---- Modal legal -------------------------------------------------------- */
.legal-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 18, 12, .55); align-items: center; justify-content: center; padding: 16px;
}
.legal-overlay:not([hidden]) { display: flex; }
.legal-card {
  background: var(--card); border-radius: var(--radius); max-width: 640px; width: 100%;
  max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
  animation: pop .18s ease-out;
}
.legal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.legal-head h3 { margin: 0; font-size: 1.15rem; color: var(--ink); }
.legal-close {
  background: none; border: none; font-size: 1.4rem; line-height: 1; color: var(--ink-soft);
  cursor: pointer; padding: 4px 10px; border-radius: 8px;
}
.legal-close:hover { background: var(--bg-2); color: var(--ink); }
.legal-body { overflow-y: auto; padding: 16px 20px 22px; color: var(--ink-soft); font-size: .94rem; line-height: 1.55; -webkit-overflow-scrolling: touch; }
.legal-body h4 { color: var(--ink); font-size: 1rem; margin: 16px 0 4px; }
.legal-body p, .legal-body li { margin: 6px 0; }
.legal-body ul, .legal-body ol { padding-left: 22px; margin: 6px 0; }
.legal-body a { color: var(--red-dark); }
.legal-body code { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: .86em; }
