/* Barbaritat! — estils */
:root {
  --bg: #f7f1e6;
  --bg2: #efe6d6;
  --card: #fffdf8;
  --ink: #1d2733;
  --muted: #6b7280;
  --line: #e6dccb;
  --blue: #1f3a5f;
  --blue2: #2f5d8c;
  --terra: #e2603f;
  --terra2: #c94b2c;
  --gold: #f2b134;
  --ok: #2f9e6e;
  --ok-bg: #e5f5ec;
  --ko: #d64545;
  --ko-bg: #fbe9e7;
  --half: #c98a12;
  --half-bg: #fdf3dc;
  --shadow: 0 1px 2px rgba(29, 39, 51, .06), 0 8px 24px rgba(29, 39, 51, .08);
  --r: 20px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121820; --bg2: #18202b; --card: #1c2531; --ink: #eef1f5; --muted: #9aa5b1; --line: #2c3746;
    --blue: #9cc3ef; --blue2: #7fb0e6; --terra: #f07a5a; --terra2: #e2603f;
    --ok-bg: #173527; --ko-bg: #3a1d1d; --half-bg: #3a2f14;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: radial-gradient(1200px 500px at 50% -200px, var(--bg2), var(--bg)) fixed;
  color: var(--ink); font: 16px/1.5 var(--sans);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Capçalera ── */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  max-width: 720px; width: 100%; margin: 0 auto; padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px);
}
.brand { font: 800 22px/1 var(--serif); color: var(--blue); text-decoration: none; letter-spacing: -.01em; }
.brand span, .hero h1 span { color: var(--terra); }
.icon-btn[hidden] { display: none; }
.icon-btn { border: 0; background: var(--card); width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; box-shadow: var(--shadow); }
.pill { margin-left: auto; background: var(--card); padding: 6px 12px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); }

main:focus, main:focus-visible { outline: none; }
main { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; outline: none; }
.foot { max-width: 720px; margin: 0 auto; padding: 16px; font-size: 12.5px; color: var(--muted); text-align: center; }
.foot a { color: inherit; }

/* ── Inici ── */
.hero { text-align: center; padding: 18px 0 10px; }
.hero h1 { font: 800 clamp(40px, 11vw, 64px)/1 var(--serif); margin: 0; color: var(--blue); letter-spacing: -.02em; }
.hero p { margin: 10px 0 0; color: var(--muted); font-size: 17px; }

.stats { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; margin: 18px 0; }
.stat { background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.stat .big { font: 700 18px/1.2 var(--serif); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat small { font-size: 13px; color: var(--muted); font-family: var(--sans); }
.bar { display: block; height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--terra), var(--gold)); border-radius: inherit; transition: width .5s; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  border: 0; text-align: left; border-radius: var(--r); padding: 18px 16px; min-height: 150px;
  display: flex; flex-direction: column; gap: 4px; color: #fff; box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease; position: relative; overflow: hidden;
}
.mode::after { content: ""; position: absolute; right: -30px; bottom: -30px; width: 110px; height: 110px; border-radius: 50%; background: rgba(255,255,255,.12); }
.mode:not(:disabled):hover { transform: translateY(-2px); }
.mode:not(:disabled):active { transform: scale(.98); }
.mode .emoji { font-size: 28px; }
.mode .t { font: 800 22px/1.1 var(--serif); margin-top: 6px; }
.mode .d { font-size: 13.5px; opacity: .92; line-height: 1.35; }
.m-caca { background: linear-gradient(135deg, #e2603f, #c94b2c); }
.m-escriu { background: linear-gradient(135deg, #2f5d8c, #1f3a5f); }
.m-llamp { background: linear-gradient(135deg, #f2b134, #d98b0b); color: #2b1d02; }
.m-repas { background: linear-gradient(135deg, #3d8f73, #24684f); }
.mode:disabled { filter: grayscale(.7); opacity: .6; }

/* ── Repte del dia ── */
.repte {
  width: 100%; border: 0; text-align: left; border-radius: var(--r); padding: 18px 18px; margin: 0 0 12px;
  display: flex; flex-direction: column; gap: 4px; color: #fff; box-shadow: var(--shadow); font: inherit;
  background: linear-gradient(135deg, #7a3e9d, #4b2a75); position: relative; overflow: hidden;
  transition: transform .15s ease;
}
.repte::after { content: ""; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.12); }
button.repte { cursor: pointer; }
button.repte:hover { transform: translateY(-2px); }
button.repte:active { transform: scale(.99); }
.repte .t { font: 800 23px/1.15 var(--serif); }
.repte .d { font-size: 14px; opacity: .92; line-height: 1.4; }
.repte .go { margin-top: 8px; font-weight: 700; }
.repte.off { background: var(--card); color: var(--ink); }
.repte.off .d { color: var(--muted); opacity: 1; }
.repte .sq { font-size: 22px; letter-spacing: 2px; margin: 4px 0; }
.repte .rfoot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 4px; position: relative; z-index: 1; }
.repte .rfoot .primary { flex: 0 0 auto; padding-inline: 22px; }
.repte b { font-variant-numeric: tabular-nums; }
.sq.big { font-size: 26px; letter-spacing: 3px; margin: 8px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.links { display: flex; gap: 10px; margin-top: 14px; }
.links .ghost { flex: 1; }

/* ── Botons ── */
.primary, .ghost, .danger {
  border-radius: 14px; padding: 13px 18px; font-weight: 600; border: 0; transition: transform .1s, filter .15s;
}
.primary { background: var(--terra); color: #fff; box-shadow: 0 6px 16px rgba(226, 96, 63, .3); }
.primary:hover { filter: brightness(1.05); }
.primary:active, .ghost:active { transform: scale(.98); }
.ghost { background: var(--card); box-shadow: var(--shadow); }
.danger { background: transparent; color: var(--ko); border: 1.5px solid currentColor; width: 100%; margin-top: 12px; }
.wide { width: 100%; margin-top: 8px; }
.row { display: flex; gap: 10px; margin-top: 14px; }
.row > * { flex: 1; }

/* ── Targetes ── */
.card { background: var(--card); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); margin-top: 14px; }
.card h2 { font: 800 24px/1.2 var(--serif); margin: 0 0 10px; color: var(--blue); }
.card h3 { font: 700 17px/1.3 var(--serif); margin: 18px 0 8px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; color: var(--blue2); background: color-mix(in srgb, var(--blue2) 12%, transparent); padding: 3px 10px; border-radius: 99px; }
.prompt { font: 600 15px/1.3 var(--sans) !important; color: var(--muted) !important; margin: 12px 0 6px !important; text-transform: uppercase; letter-spacing: .06em; }
.sentence { font: 600 clamp(21px, 5.4vw, 26px)/1.45 var(--serif); margin: 6px 0 4px; }
.sentence.small { font-size: 17px; }
mark.barb { background: none; color: var(--terra2); text-decoration: underline wavy var(--terra); text-underline-offset: 5px; text-decoration-thickness: 2px; }
ins.fix { text-decoration: none; color: var(--ok); background: var(--ok-bg); padding: 0 3px; border-radius: 6px; }
.muted { color: var(--muted); font-size: 14px; }

/* ── Partida ── */
.ghead { position: sticky; top: 62px; z-index: 4; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(6px); padding: 4px 0 6px; }
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--terra), var(--gold)); transition: width .4s ease; }
.gmeta { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-top: 6px; }
.gmeta b { color: var(--ink); }
.streak.hot { color: var(--terra); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 8px 6px; }
.chip {
  border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px; padding: 6px 11px;
  font: 600 clamp(19px, 5vw, 23px)/1.3 var(--serif); transition: transform .1s, background .15s, border-color .15s;
}
.chip:not(:disabled):hover { border-color: var(--terra); }
.chip:not(:disabled):active { transform: scale(.95); }
.chip.target { border-color: var(--terra); color: var(--terra2); }
.chip.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.chip.wrong { background: var(--ko-bg); border-color: var(--ko); color: var(--ko); text-decoration: line-through; }

.answer input {
  width: 100%; margin-top: 14px; padding: 14px 16px; font: 600 19px var(--sans); color: var(--ink);
  background: var(--bg); border: 2px solid var(--line); border-radius: 14px; transition: border-color .15s;
}
.answer input:focus { outline: none; border-color: var(--blue2); }
.answer input.right { border-color: var(--ok); background: var(--ok-bg); }
.answer input.half { border-color: var(--half); background: var(--half-bg); }
.answer input.wrong { border-color: var(--ko); background: var(--ko-bg); }
.answer input.nudge { animation: shake .35s; }

.feedback { border-left: 6px solid var(--line); animation: rise .25s ease; }
.feedback.ok { border-left-color: var(--ok); }
.feedback.ko { border-left-color: var(--ko); }
.feedback.half { border-left-color: var(--half); }
.feedback h3 { margin: 0 0 6px; display: flex; align-items: center; gap: 10px; font-size: 20px; }
.feedback.ok h3 { color: var(--ok); }
.feedback.ko h3 { color: var(--ko); }
.feedback.half h3 { color: var(--half); }
.plus { font: 700 13px var(--sans); background: var(--gold); color: #2b1d02; padding: 2px 8px; border-radius: 99px; }
.pair { margin: 8px 0 0; font-size: 16px; }
.pair s, .misslist s, .dlist s { color: var(--ko); text-decoration-thickness: 2px; }
.alts { margin: 6px 0 0; font-size: 15px; }
.note { margin: 10px 0 0; font-size: 14.5px; color: var(--muted); }

/* ── Resultats ── */
.result { text-align: center; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.kpis div { background: var(--bg); border-radius: 14px; padding: 12px 6px; display: flex; flex-direction: column; }
.kpis b { font: 800 24px/1.1 var(--serif); }
.kpis span { font-size: 12.5px; color: var(--muted); }
.misslist { list-style: none; padding: 0; margin: 0; text-align: left; display: grid; gap: 6px; }
.misslist li { background: var(--bg); border-radius: 12px; padding: 9px 12px; }
.misslist small { color: var(--muted); }

/* ── Llamp ── */
.llamp { display: flex; flex-direction: column; min-height: calc(100dvh - 190px); }
.timer { height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--gold), var(--terra)); transition: width .1s linear; }
.timer i.low { background: var(--ko); }
.wordcard { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 230px; text-align: center; transition: background .2s; }
.wordcard .hint { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.wordcard .word { font: 800 clamp(36px, 11vw, 56px)/1.1 var(--serif); color: var(--blue); word-break: break-word; }
.wordcard .flash { min-height: 24px; font-weight: 600; color: var(--ko); }
.wordcard.ok { animation: okflash .35s; }
.wordcard.ko { animation: shake .35s, koflash .9s; }
.lbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.lbtn { border: 0; border-radius: var(--r); padding: 18px 10px; font-weight: 700; font-size: 17px; display: flex; flex-direction: column; align-items: center; gap: 2px; box-shadow: var(--shadow); color: #fff; }
.lbtn span { font-size: 28px; line-height: 1; }
.lbtn small { opacity: .7; font-weight: 500; font-size: 12px; }
.lbtn.no { background: linear-gradient(135deg, #e2603f, #c94b2c); }
.lbtn.yes { background: linear-gradient(135deg, #3d8f73, #24684f); }
.lbtn:active { transform: scale(.97); }
@media (hover: none) { .lbtn small { display: none; } }

/* ── Diccionari ── */
.search { width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); font: 500 16px var(--sans); }
.search:focus { outline: none; border-color: var(--blue2); }
.cats { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.cat { flex: none; border: 1.5px solid var(--line); background: transparent; padding: 6px 12px; border-radius: 99px; font-size: 13.5px; }
.cat.on { background: var(--blue); border-color: var(--blue); color: var(--card); }
.count { color: var(--muted); font-size: 13px; margin: 6px 0; }
.dlist { list-style: none; padding: 0; margin: 0; }
.dlist li { border-top: 1px solid var(--line); }
.dlist summary { padding: 11px 2px; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dlist summary::-webkit-details-marker { display: none; }
.dlist .arrow { color: var(--muted); }
.dlist details[open] { padding-bottom: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.ko { background: var(--ko); }
.empty { padding: 14px 0; color: var(--muted); }

/* ── Progrés ── */
.catbars { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.catbars li { display: grid; grid-template-columns: 1.4fr 2fr auto; gap: 10px; align-items: center; font-size: 14px; }
.cnum { min-width: 42px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── Animacions ── */
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { 50% { transform: scale(1.015); } }
@keyframes koflash { 0%, 60% { background: var(--ko-bg); } 100% { background: var(--card); } }
@keyframes okflash { 0% { background: var(--ok-bg); } 100% { background: var(--card); } }
.q.shake { animation: shake .35s; }
.q.pop { animation: pop .3s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:nth-child(2) { grid-column: 1 / -1; order: -1; }
  .mode { min-height: 140px; padding: 16px 14px; }
  .mode .t { font-size: 20px; }
  .card { padding: 18px 16px; }
}

/* ── Nivell ── */
.nvp { position: relative; border: 0; font: 600 14px var(--sans); color: var(--blue2); min-height: 32px; white-space: nowrap; }
.nvp::after { content: ""; position: absolute; inset: -6px -4px; } /* zona tàctil de 44 px sense canviar l'aspecte */
.nvp + .pill { margin-left: 0; }
.npanel {
  position: fixed; z-index: 30; top: 58px; right: max(16px, calc((100vw - 720px) / 2 + 16px)); width: min(340px, calc(100vw - 32px));
  background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow), 0 0 0 1px var(--line); animation: rise .15s ease;
}
.nphead { margin: 2px 4px 8px; font: 700 16px/1 var(--serif); }
.nopts { display: grid; gap: 4px; }
.nopt { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 8px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; font-weight: 600; }
.nopt:hover { background: var(--bg); }
.nopt.on { background: var(--blue); color: var(--card); }
.nopt small { font-weight: 500; font-size: 12.5px; opacity: .75; font-variant-numeric: tabular-nums; }
.nnote { margin: 10px 4px 2px; color: var(--muted); font-size: 12.5px; line-height: 1.4; }

/* ── Primera visita: nivell ── */
.onb { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px); }
.onbox { position: relative; width: min(420px, 100%); background: var(--card); border-radius: var(--r); padding: 24px 18px 16px; box-shadow: var(--shadow); animation: rise .2s ease; }
.onbox h2 { font: 800 24px/1.2 var(--serif); color: var(--blue); margin: 4px 40px 16px 2px; }
.onx { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; }
.onopts { display: grid; gap: 8px; }
.onopt { min-height: 48px; padding: 10px 16px; border: 2px solid var(--line); border-radius: 14px; background: var(--bg); font-weight: 600; font-size: 16.5px; text-align: left; }
.onopt:hover { border-color: var(--blue2); }
.onopt:last-child { background: transparent; }
.onnote { margin: 12px 2px 0; color: var(--muted); font-size: 12.5px; }
.notice { margin: 8px 0 0; padding: 8px 12px; border-radius: 12px; background: var(--half-bg); color: var(--ink); font-size: 13.5px; }
.nv { margin-left: auto; flex: none; font-size: 11.5px; font-weight: 700; color: var(--blue2); border: 1.5px solid currentColor; border-radius: 6px; padding: 1px 6px; }
.nv.sc { color: var(--muted); font-weight: 600; }
