/* ===================== RUMB LAB ===================== */
:root{
  --bg:        #ffffff;
  --surface:   #ffffff;
  --ink:       #1a1d24;
  --ink-soft:  #5b6472;
  --line:      #e8ebf0;
  --accent:    #2f6df6;
  --accent-dk: #1f4fc0;
  --green:     #17b978;
  --green-dk:  #0f9b64;
  --red:       #ef4655;
  --red-dk:    #d12f3f;
  --shadow:    0 12px 40px rgba(24,32,54,.14);
  --shadow-sm: 0 4px 16px rgba(24,32,54,.08);
  --radius:    22px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

*{ box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }
html,body{ height:100%; }
body{
  font-family:var(--font);
  color:var(--ink);
  background:var(--bg);
  overflow:hidden;
  overscroll-behavior:none;
}

.app{
  height:100%;
  display:flex;
  flex-direction:column;
  max-width:640px;
  margin:0 auto;
  position:relative;
  background:var(--bg);
  overflow:hidden;          /* retalla el panell de config quan està amagat fora de l'àrea */
}

/* ---------- HEADER ---------- */
.app-header{
  flex:0 0 auto;
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 18px;
  border-bottom:1px solid var(--line);
  background:#fff;
  z-index:5;
}
.logo-link{ display:inline-flex; align-items:center; transition:opacity .15s; }
.logo-link:hover{ opacity:.85; }
.logo-main{ height:38px; width:auto; object-fit:contain; display:block; }
.gear{
  border:none; background:transparent; color:var(--ink-soft);
  width:40px; height:40px; border-radius:12px; cursor:pointer;
  display:grid; place-items:center; transition:.2s;
}
.gear:hover{ background:#f2f4f8; color:var(--accent); transform:rotate(35deg); }

/* ---------- MAIN / SCREENS ---------- */
.app-main{ flex:1 1 auto; position:relative; overflow:hidden; }
.screen{
  position:absolute; inset:0;
  display:none; flex-direction:column;
  padding:18px;
}
.screen.is-active{ display:flex; }

/* ---------- START ---------- */
.start-inner{
  margin:auto; text-align:center; max-width:440px;
  display:flex; flex-direction:column; gap:16px;
  animation:fadeUp .5s ease both;
}
.start-title{ font-size:clamp(28px,7vw,40px); font-weight:800; letter-spacing:-.02em; }
.start-tagline{ color:var(--ink-soft); font-size:15px; line-height:1.5; }
.rules-grid{ display:flex; flex-direction:column; gap:10px; margin:4px 0; }
.rule{
  display:flex; align-items:center; gap:12px; text-align:left;
  background:#f7f9fc; border:1px solid var(--line); border-radius:16px; padding:12px 14px;
}
.rule-ico{ font-size:24px; flex:0 0 auto; }
.rule strong{ display:block; font-size:14px; }
.rule span{ font-size:13px; color:var(--ink-soft); }
.rule-ico.left ~ div strong{ color:var(--red-dk); }
.rule-ico.right ~ div strong{ color:var(--green-dk); }
.start-meta{ font-size:13px; color:var(--ink-soft); }
.start-warning{ color:var(--red); font-size:13px; font-weight:600; }

/* ---------- DB STATS ---------- */
.db-stats{
  display:flex; align-items:center; justify-style:space-around; justify-content:space-around;
  background:#f7f9fc; border:1px solid var(--line); border-radius:16px;
  padding:10px 14px; margin:2px 0;
}
.db-stat-item{ display:flex; flex-direction:column; align-items:center; gap:2px; }
.db-stat-val{ font-size:18px; font-weight:800; color:var(--accent); }
.db-stat-lbl{ font-size:11px; color:var(--ink-soft); font-weight:600; text-transform:uppercase; letter-spacing:.03em; }
.db-stat-divider{ width:1px; height:24px; background:var(--line); }

/* ---------- HUD ---------- */
.hud{
  flex:0 0 auto;
  display:flex; justify-content:space-between; gap:10px;
  margin-bottom:8px;
}
.hud-item{
  flex:1; text-align:center;
  background:#f7f9fc; border:1px solid var(--line); border-radius:14px;
  padding:8px 6px;
}
.hud-label{ display:block; font-size:10px; letter-spacing:.08em; text-transform:uppercase; color:var(--ink-soft); }
.hud-value{ display:block; font-size:22px; font-weight:800; line-height:1.1; margin-top:2px; }
.hud-timer.is-low .hud-value{ color:var(--red); animation:pulse .8s infinite; }
.hud-score .hud-value{ color:var(--accent); }

.timebar-wrap{ flex:0 0 auto; height:6px; background:#eef1f6; border-radius:99px; overflow:hidden; margin-bottom:14px; }
.timebar{ height:100%; width:100%; background:linear-gradient(90deg,var(--green),var(--accent)); transition:width .1s linear; }
.timebar.is-low{ background:linear-gradient(90deg,#ff9d3f,var(--red)); }

/* ---------- DECK / CARDS ---------- */
.deck{
  flex:1 1 auto; position:relative;
  display:grid; place-items:center;
  min-height:0;
  touch-action:none;
}
.card{
  position:absolute;
  width:min(92%, 400px);
  aspect-ratio:3/4;
  max-height:100%;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  display:flex; flex-direction:column;
  padding:26px 24px;
  will-change:transform;
  user-select:none;
  cursor:grab;
}
.card:active{ cursor:grabbing; }
.card-chip{
  align-self:flex-start;
  display:inline-flex; align-items:center; gap:7px;
  font-size:12px; font-weight:700; letter-spacing:.01em;
  color:var(--ink-soft);
  background:#f2f4f8; border-radius:99px; padding:6px 13px;
}
.card-chip .chip-icon{ font-size:18px; }
.card-concept{
  flex:1; display:flex; align-items:center; justify-content:center; text-align:center;
  font-size:clamp(22px,5.5vw,30px); font-weight:800; line-height:1.25;
  letter-spacing:-.01em;
  padding:8px 0;
  hyphens:auto;
}
.card-foot{
  display:flex; justify-content:space-between; align-items:center;
  font-size:12px; color:var(--ink-soft);
}
.card-foot .foot-left{ color:var(--red-dk); font-weight:700; }
.card-foot .foot-right{ color:var(--green-dk); font-weight:700; }

/* stacked depth cards */
.card.stack-1{ transform:translateY(14px) scale(.94); opacity:.7; filter:saturate(.8); box-shadow:var(--shadow-sm); }
.card.stack-2{ transform:translateY(26px) scale(.88); opacity:.4; box-shadow:none; }

/* decision stamp on the card */
.card-stamp{
  position:absolute; top:26px;
  font-size:26px; font-weight:900; letter-spacing:.05em;
  padding:8px 16px; border-radius:12px; border:4px solid;
  text-transform:uppercase; opacity:0; pointer-events:none;
}
.card-stamp.stamp-avoid{ left:22px; color:var(--red); border-color:var(--red); transform:rotate(-14deg); }
.card-stamp.stamp-include{ right:22px; color:var(--green); border-color:var(--green); transform:rotate(14deg); }

/* result flash */
.card.flash-ok{ animation:flashOk .5s ease; }
.card.flash-bad{ animation:flashBad .5s ease; }
@keyframes flashOk{ 0%{ box-shadow:0 0 0 0 rgba(23,185,120,.6);} 100%{ box-shadow:0 0 0 22px rgba(23,185,120,0);} }
@keyframes flashBad{ 0%{ box-shadow:0 0 0 0 rgba(239,70,85,.6);} 100%{ box-shadow:0 0 0 22px rgba(239,70,85,0);} }

/* swipe hints (behind top card, on deck edges) */
.swipe-hint{
  position:absolute; top:50%; transform:translateY(-50%);
  display:flex; flex-direction:column; align-items:center; gap:2px;
  font-weight:900; opacity:0; transition:opacity .12s; pointer-events:none; z-index:0;
}
.swipe-hint span{ font-size:44px; line-height:1; }
.swipe-hint em{ font-style:normal; font-size:13px; letter-spacing:.1em; text-transform:uppercase; }
.swipe-hint-left{ left:2px; color:var(--red); }
.swipe-hint-right{ right:2px; color:var(--green); }

/* ---------- ACTIONS ---------- */
.actions{
  flex:0 0 auto;
  display:flex; gap:14px; padding-top:16px;
}
.action-btn{
  flex:1; border:2px solid; border-radius:18px; background:#fff;
  padding:14px 10px; cursor:pointer; font-family:inherit;
  display:flex; flex-direction:column; align-items:center; gap:3px;
  font-weight:800; transition:.15s; touch-action:manipulation;
}
.action-btn:active{ transform:scale(.95); }
.action-arrow{ font-size:26px; line-height:1; }
.action-text{ font-size:12px; letter-spacing:.08em; text-transform:uppercase; }
.action-left{ color:var(--red-dk); border-color:#f3c3c8; }
.action-left:hover{ background:#fdeef0; border-color:var(--red); }
.action-right{ color:var(--green-dk); border-color:#bfe8d6; }
.action-right:hover{ background:#eafaf3; border-color:var(--green); }

/* ---------- END ---------- */
.end-inner{
  margin:auto; text-align:center; max-width:420px;
  display:flex; flex-direction:column; gap:14px; align-items:center;
  animation:fadeUp .5s ease both;
}
.rank-badge{ font-size:58px; line-height:1; }
.end-rank{ font-size:clamp(22px,6vw,30px); font-weight:800; }
.end-score-wrap{ display:flex; align-items:baseline; gap:8px; }
.end-score{ font-size:56px; font-weight:900; color:var(--accent); line-height:1; }
.end-score-label{ font-size:15px; color:var(--ink-soft); font-weight:600; }
.end-stats{ display:flex; gap:12px; width:100%; }
.end-stat{ flex:1; background:#f7f9fc; border:1px solid var(--line); border-radius:14px; padding:12px 6px; }
.end-stat-val{ display:block; font-size:24px; font-weight:800; }
.end-stat-lbl{ display:block; font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:var(--ink-soft); margin-top:2px; }
.end-stat:nth-child(1) .end-stat-val{ color:var(--green-dk); }
.end-stat:nth-child(2) .end-stat-val{ color:var(--red-dk); }
.end-tip{ font-size:13px; color:var(--ink-soft); line-height:1.5; }

/* ---------- BUTTONS ---------- */
.btn{
  border:none; border-radius:14px; cursor:pointer; font-family:inherit;
  font-weight:700; font-size:16px; padding:14px 30px; transition:.15s;
}
.btn-primary{ background:var(--accent); color:#fff; box-shadow:0 6px 18px rgba(47,109,246,.32); }
.btn-primary:hover{ background:var(--accent-dk); transform:translateY(-1px); }
.btn-primary:active{ transform:translateY(0); }
.btn-block{ width:100%; margin-top:8px; }

/* ---------- FOOTER ---------- */
.app-footer{
  flex:0 0 auto;
  display:flex; align-items:center; justify-content:center; gap:10px;
  padding:9px 18px;
  border-top:1px solid var(--line); background:#fff;
}
.footer-text{ font-size:11px; color:var(--ink-soft); }
.footer-link{ display:inline-flex; align-items:center; transition:opacity .15s, transform .15s; }
.footer-link:hover{ opacity:1; transform:translateY(-1px); }
.logo-footer{ height:22px; width:auto; object-fit:contain; opacity:.9; display:block; }
.footer-link:hover .logo-footer{ opacity:1; }

/* ---------- FEEDBACK ---------- */
.feedback{
  position:absolute; inset:0; z-index:30;
  display:none; align-items:center; justify-content:center;
  background:rgba(20,24,34,.5); backdrop-filter:blur(3px); padding:22px;
}
.feedback.is-open{ display:flex; animation:fadeIn .2s ease; }
.feedback-card{
  background:#fff; border-radius:20px; padding:24px 22px; max-width:400px; width:100%;
  box-shadow:var(--shadow); text-align:center; animation:popIn .28s cubic-bezier(.2,.9,.3,1.3) both;
}
.feedback-head{
  display:flex; align-items:center; justify-content:center; gap:8px;
  color:var(--red); font-weight:800; font-size:15px; letter-spacing:.03em; text-transform:uppercase;
}
.feedback-x{ font-size:22px; }
.feedback-concept{ font-size:20px; font-weight:800; margin:14px 0 6px; }
.feedback-correct{ font-size:13px; font-weight:700; margin-bottom:10px; }
.feedback-correct.is-include{ color:var(--green-dk); }
.feedback-correct.is-avoid{ color:var(--red-dk); }
.feedback-text{ font-size:14px; color:var(--ink-soft); line-height:1.55; margin-bottom:18px; }

/* ---------- LOADER ---------- */
.loader{
  position:absolute; inset:0; z-index:25; background:#fff;
  display:none; flex-direction:column; align-items:center; justify-content:center; gap:30px; padding:24px;
}
.loader.is-open{ display:flex; animation:fadeIn .2s ease; }
.loader-cards{ position:relative; width:110px; height:145px; }
.loader-cards span{
  position:absolute; inset:0; border-radius:16px;
  background:#fff; border:2px solid var(--line); box-shadow:var(--shadow-sm);
  animation:shuffle 1.4s cubic-bezier(.5,0,.5,1) infinite;
}
.loader-cards span:nth-child(1){ animation-delay:0s; }
.loader-cards span:nth-child(2){ animation-delay:.18s; }
.loader-cards span:nth-child(3){ animation-delay:.36s; }
.loader-cards .lc-top{
  animation-delay:.54s;
  background:linear-gradient(135deg,var(--accent),var(--green));
  border-color:transparent;
}
.loader-text{
  max-width:360px; text-align:center; font-size:16px; font-weight:700; line-height:1.5;
  color:var(--ink); animation:pulseText 1.4s ease-in-out infinite;
}
.loader-text b{ color:var(--accent); }
@keyframes shuffle{
  0%   { transform:translate(0,0) rotate(0) scale(1);     z-index:1; }
  25%  { transform:translate(-64px,-14px) rotate(-13deg); z-index:2; }
  50%  { transform:translate(0,0) rotate(0) scale(1);     z-index:1; }
  75%  { transform:translate(64px,-14px) rotate(13deg);   z-index:2; }
  100% { transform:translate(0,0) rotate(0) scale(1);     z-index:1; }
}
@keyframes pulseText{ 0%,100%{ opacity:.65; } 50%{ opacity:1; } }

/* ---------- CONFIG ---------- */
.config-backdrop{
  position:absolute; inset:0; z-index:20; background:rgba(20,24,34,.4);
  opacity:0; pointer-events:none; transition:.25s;
}
.config-backdrop.is-open{ opacity:1; pointer-events:auto; }
.config-panel{
  position:absolute; top:0; right:0; bottom:0; z-index:21;
  width:min(340px, 88%); background:#fff;
  box-shadow:-12px 0 40px rgba(24,32,54,.16);
  transform:translateX(100%); transition:transform .28s cubic-bezier(.3,.8,.3,1);
  display:flex; flex-direction:column; padding:20px;
  overflow-y:auto;
}
.config-panel.is-open{ transform:translateX(0); }
.config-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:18px; }
.config-head h3{ font-size:19px; font-weight:800; }
.config-close{ border:none; background:#f2f4f8; width:34px; height:34px; border-radius:10px; cursor:pointer; font-size:15px; color:var(--ink-soft); }
.config-close:hover{ background:#e6e9ef; }
.config-section{ margin-bottom:22px; }
.config-section h4{ font-size:12px; text-transform:uppercase; letter-spacing:.07em; color:var(--ink-soft); margin-bottom:10px; }
.lang-row{ display:flex; gap:8px; }
.lang-btn{
  flex:1; border:2px solid var(--line); background:#fff; border-radius:12px;
  padding:11px 0; font-weight:800; font-size:14px; cursor:pointer; color:var(--ink-soft); transition:.15s;
}
.lang-btn.is-active{ border-color:var(--accent); color:var(--accent); background:#f0f5ff; }
.level-row{ display:flex; gap:8px; }
.level-btn{
  flex:1; border:2px solid var(--line); background:#fff; border-radius:12px;
  padding:9px 0; cursor:pointer; color:var(--ink-soft); transition:.15s; font-family:inherit;
  display:flex; flex-direction:column; align-items:center; gap:2px;
}
.level-btn .lvl-name{ font-weight:800; font-size:13px; }
.level-btn .lvl-time{ font-size:11px; font-weight:600; opacity:.85; }
.level-btn.is-active{ border-color:var(--accent); color:var(--accent); background:#f0f5ff; }
.cat-list{ display:flex; flex-direction:column; gap:8px; }
.cat-item{
  display:flex; align-items:center; gap:11px; cursor:pointer;
  border:1px solid var(--line); border-radius:12px; padding:11px 13px; transition:.15s;
}
.cat-item:hover{ background:#f7f9fc; }
.cat-item.is-checked{ border-color:var(--accent); background:#f0f5ff; }
.cat-check{
  flex:0 0 auto; width:22px; height:22px; border-radius:7px; border:2px solid var(--line);
  display:grid; place-items:center; color:#fff; font-size:13px; font-weight:900; transition:.15s;
}
.cat-item.is-checked .cat-check{ background:var(--accent); border-color:var(--accent); }
.cat-icon{ font-size:22px; color:var(--ink-soft); transition:color .15s; }
.cat-item.is-checked .cat-icon{ color:var(--accent); }
.cat-name{ font-size:13.5px; font-weight:600; line-height:1.25; flex:1; }
.cat-count{
  font-size:11px; font-weight:700; color:var(--ink-soft);
  background:#f2f4f8; padding:3px 8px; border-radius:99px;
  white-space:nowrap; margin-left:6px; flex:0 0 auto; transition:.15s;
}
.cat-item.is-checked .cat-count{ background:#e1ebff; color:var(--accent); }

/* ---------- ANIMATIONS ---------- */
@keyframes fadeUp{ from{ opacity:0; transform:translateY(14px);} to{ opacity:1; transform:none;} }
@keyframes fadeIn{ from{ opacity:0;} to{ opacity:1;} }
@keyframes popIn{ from{ opacity:0; transform:scale(.85);} to{ opacity:1; transform:scale(1);} }
@keyframes pulse{ 0%,100%{ transform:scale(1);} 50%{ transform:scale(1.12);} }

/* ---------- RESPONSIVE / SHORT SCREENS ---------- */
@media (max-height:620px){
  .card{ aspect-ratio:auto; height:100%; }
  .card-concept{ font-size:clamp(18px,5vw,24px); }
  .hud-value{ font-size:18px; }
}
@media (min-width:641px){
  .app{ box-shadow:0 0 0 1px var(--line); }
}
