/* Club Codec — estilo inspirado en Apple */

:root {
  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --line: rgba(0, 0, 0, 0.08);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-2: rgba(118, 118, 128, 0.2);
  --glass: rgba(255, 255, 255, 0.72);
  --glass-edge: rgba(255, 255, 255, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.25), 0 4px 12px -4px rgba(0, 0, 0, 0.08);
  --brand: #f91d21;
  --accent: #d7141a;
  --green: #28a745;
  --green-strong: #1f9d55;
  --red: #e5383b;
  --orange: #ff9500;

  /* Paleta sobria: rojo Codec, grafito y burdeos */
  --g-5: linear-gradient(145deg, #f91d21 0%, #d7141a 60%, #b10f14 100%);
  --g-6: linear-gradient(145deg, #3a3a3c 0%, #2a2a2c 60%, #1c1c1e 100%);
  --g-mer: linear-gradient(145deg, #8f1a1f 0%, #741318 60%, #5a0e12 100%);
  --g-form: linear-gradient(145deg, #8f1a1f 0%, #741318 60%, #5a0e12 100%);
  --g-prec: linear-gradient(145deg, #3a3a3c 0%, #2a2a2c 60%, #1c1c1e 100%);
  --glow-red: rgba(215, 20, 26, 0.55);
  --glow-dark: rgba(0, 0, 0, 0.45);
  --glow-wine: rgba(116, 19, 24, 0.55);

  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;

  /* Muelles: los sobrescribe app.js con curvas linear() reales */
  --spring: cubic-bezier(0.2, 0.9, 0.3, 1.15);
  --spring-dur: 600ms;
  --spring-soft: cubic-bezier(0.25, 1, 0.3, 1);
  --spring-soft-dur: 450ms;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #6e6e73;
    --line: rgba(255, 255, 255, 0.1);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.36);
    --glass: rgba(28, 28, 30, 0.72);
    --glass-edge: rgba(255, 255, 255, 0.08);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --accent: #ff453a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 100%/1.47 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* Fondo: degradados suaves y estáticos */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -1;
  background:
    radial-gradient(45% 35% at 10% 0%, rgba(249, 29, 33, 0.07), transparent 70%),
    radial-gradient(40% 35% at 95% 100%, rgba(249, 29, 33, 0.05), transparent 70%);
  pointer-events: none;
}

.wrap {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-left)) calc(48px + env(safe-area-inset-bottom));
}

/* ---------- Barra superior translúcida ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); text-decoration: none; }
.brand img { width: 34px; height: 34px; flex: none; }
.brand span { display: grid; min-width: 0; line-height: 1.15; }
.brand b { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.brand small { font-size: 11px; font-weight: 500; color: var(--text-2); letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.back {
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--accent); font-size: 17px; height: 44px; padding-right: 8px;
  margin-left: -6px;
}
.back svg { width: 24px; height: 24px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--fill); color: var(--text);
  transition: transform 120ms ease-out, background 150ms;
}
.icon-btn:active { transform: scale(0.9); background: var(--fill-2); }
.icon-btn svg { width: 19px; height: 19px; }

/* ---------- Tipografía ---------- */
.display { font-size: clamp(2.1rem, 6vw, 3.4rem); line-height: 1.05; letter-spacing: -0.035em; font-weight: 750; margin: 0; }
.title-2 { font-size: 1.6rem; line-height: 1.15; letter-spacing: -0.025em; font-weight: 700; margin: 0; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text-2); }
.muted { color: var(--text-2); }
.greeting { padding: 28px 0 22px; }
.greeting p { margin: 8px 0 0; font-size: 19px; color: var(--text-2); letter-spacing: -0.015em; }

/* ---------- Pop-cards ---------- */
.cards {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  perspective: 1200px;
}
.cards.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
/* Tarjetas compactas de Formación y Conversación */
.cards.two .pop-card { min-height: 158px; padding: 18px 20px; border-radius: 24px; }
.cards.two .pop-card .card-title { font-size: 1.4rem; }
.cards.two .pop-card .card-sub { font-size: 14px; }
.cards.two .pop-card .emoji { font-size: 38px; }
.cards.two .pop-card .card-foot { margin-top: 12px; }
.cards.two .pop-card .arrow { width: 34px; height: 34px; }
.cards.two .pop-card .arrow svg { width: 17px; height: 17px; }
.cards.two .pop-card::after { width: 160px; height: 160px; right: -50px; bottom: -70px; }
.cards.one { grid-template-columns: 1fr; }
.cards.one .pop-card { min-height: 200px; }
.cards.pair { grid-template-columns: 1fr 1fr; gap: 14px; }
.section-label { text-align: center; margin: 30px 4px 14px; font-size: 20px; font-weight: 700; letter-spacing: -0.022em; line-height: 1.2; }

/* Tarjetas de nivel compactas, dos por fila también en móvil */
.pop-card.small { min-height: 160px; padding: 18px; border-radius: 24px; }
.pop-card.small .card-title { font-size: 1.3rem; }
.pop-card.small .card-sub { font-size: 13.5px; }
.pop-card.small .emoji { font-size: 38px; }
.pop-card.small .card-foot { margin-top: 14px; }
.pop-card.small .arrow { width: 34px; height: 34px; }
.pop-card.small .arrow svg { width: 17px; height: 17px; }
.pop-card.small::after { width: 150px; height: 150px; right: -50px; bottom: -60px; }
@media (max-width: 480px) {
  .cards.pair { gap: 10px; }
  .pop-card.small { min-height: 150px; padding: 16px 14px; }
  .pop-card.small .card-top { flex-direction: column-reverse; gap: 8px; }
  .pop-card.small .card-title { font-size: 1.15rem; }
  .pop-card.small .card-sub { display: none; }
  .pop-card.small .emoji { font-size: 32px; }
  .pop-card.small .chip-glass { padding: 5px 9px; font-size: 12px; }
}

.pop-card {
  --rx: 0deg; --ry: 0deg; --gx: 50%; --gy: 0%;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 230px;
  padding: 24px;
  border-radius: var(--radius-xl);
  color: #fff;
  text-align: left;
  overflow: hidden;
  background: var(--g);
  box-shadow: 0 18px 40px -18px var(--glow, rgba(0,0,0,.4)), 0 2px 6px rgba(0, 0, 0, 0.08);
  transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform 500ms var(--spring-soft), scale var(--spring-dur) var(--spring), box-shadow 300ms ease;
  animation:
    pop-fade 500ms cubic-bezier(0.2, 0.8, 0.2, 1) backwards,
    pop-move var(--spring-dur) var(--spring) backwards;
  animation-delay: calc(var(--i, 0) * 90ms + 60ms);
  will-change: transform;
}
.pop-card.tracking { transition: transform 120ms ease-out, scale var(--spring-dur) var(--spring), box-shadow 300ms ease; }
.pop-card.pressed { scale: 0.965; transition: transform 120ms ease-out, scale 120ms ease-out; }
.pop-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

@keyframes pop-fade { from { opacity: 0; filter: blur(12px); } }
@keyframes pop-move { from { translate: 0 46px; scale: 0.86; } }

/* Brillo que sigue al puntero */
.pop-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle at var(--gx) var(--gy), rgba(255, 255, 255, 0.38), transparent 55%);
  opacity: 0.55;
  transition: opacity 300ms;
}
.pop-card:hover::before { opacity: 1; }
/* Burbujas decorativas */
.pop-card::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 220px; height: 220px;
  right: -60px; bottom: -80px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: -150px -170px 0 -60px rgba(255, 255, 255, 0.1);
  transition: translate 700ms var(--spring-soft);
}
.pop-card:hover::after { translate: -14px -10px; }

.pop-card .emoji {
  font-size: 54px;
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.18));
  transform-origin: 50% 80%;
  display: inline-block;
  animation: emoji-in var(--spring-dur) var(--spring) backwards;
  animation-delay: calc(var(--i, 0) * 90ms + 260ms);
}
@keyframes emoji-in { from { scale: 0.2; rotate: -25deg; opacity: 0; } }
.pop-card .emoji > span { display: inline-block; transform-origin: 50% 80%; }
.pop-card:hover .emoji > span { animation: wiggle 700ms ease-in-out; }
@keyframes wiggle { 0%, 100% { rotate: 0deg; } 20% { rotate: -12deg; } 45% { rotate: 10deg; } 70% { rotate: -5deg; } }

.pop-card .card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.pop-card .card-title { font-size: 1.75rem; font-weight: 750; letter-spacing: -0.03em; line-height: 1.08; margin: 0; text-shadow: 0 1px 12px rgba(0,0,0,.08); }
.pop-card .card-sub { margin: 6px 0 0; font-size: 15px; opacity: 0.88; font-weight: 500; letter-spacing: -0.005em; }
.pop-card .card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 18px; }
.chip-glass {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 650; letter-spacing: 0; white-space: nowrap;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.28);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.arrow {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.24);
  transition: translate 400ms var(--spring-soft), background 200ms;
}
.arrow svg { width: 20px; height: 20px; }
.pop-card:hover .arrow { translate: 4px 0; background: rgba(255, 255, 255, 0.34); }

/* Mini barra de progreso dentro de tarjetas */
.mini-progress { flex: 1; max-width: 160px; height: 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.mini-progress i { display: block; height: 100%; width: var(--p, 0%); background: #fff; border-radius: inherit; transition: width 600ms var(--spring-soft); }

/* ---------- Cabecera "hero" de cada sección ---------- */
.hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  margin: 18px 0 20px;
  padding: 26px 24px;
  border-radius: var(--radius-xl);
  color: #fff;
  background: var(--g);
  box-shadow: 0 18px 40px -22px var(--glow, rgba(0,0,0,.4));
  display: flex;
  align-items: center;
  gap: 18px;
  animation: hero-in var(--spring-soft-dur) var(--spring-soft) backwards;
}
@keyframes hero-in { from { opacity: 0; translate: 0 -10px; scale: 0.98; } }
.hero::after {
  content: ""; position: absolute; z-index: -1;
  width: 260px; height: 260px; right: -70px; top: -120px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
}
.hero .emoji { font-size: 46px; line-height: 1; filter: drop-shadow(0 6px 10px rgba(0,0,0,.18)); }
.hero .hero-text { flex: 1; min-width: 0; }
.hero h1 { margin: 0; font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.05; letter-spacing: -0.03em; font-weight: 750; }
.hero p { margin: 6px 0 0; opacity: 0.9; font-weight: 500; }

/* Anillo de progreso */
.ring { --p: 0; position: relative; width: 74px; height: 74px; flex: none; }
.ring svg { width: 100%; height: 100%; rotate: -90deg; }
.ring circle { fill: none; stroke-width: 8; }
.ring .track { stroke: rgba(255, 255, 255, 0.25); }
.ring .bar { stroke: #fff; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--p)); transition: stroke-dashoffset 700ms var(--spring-soft); }
.ring[data-empty="true"] .bar { opacity: 0; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 750; font-size: 15px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* Selector de viernes */
.datebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.datebar.center { justify-content: center; }
.date-pill {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--bg-elev); border-radius: 999px; padding: 4px;
  box-shadow: var(--shadow-sm);
}
.date-pill button { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); transition: background 150ms, transform 120ms; }
.date-pill button:active { transform: scale(0.88); background: var(--fill); }
.date-pill button svg { width: 18px; height: 18px; }
.date-pill strong { padding: 0 8px; font-size: 15px; font-weight: 600; min-width: 150px; text-align: center; font-variant-numeric: tabular-nums; }
.date-pill .today { font-size: 12px; font-weight: 600; color: var(--accent); padding: 0 10px 0 0; }

/* ---------- Búsqueda y filtros ---------- */
.toolbar {
  position: sticky;
  top: calc(52px + env(safe-area-inset-top));
  z-index: 10;
  margin: 0 -16px 10px;
  padding: 10px 16px 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.search {
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 14px;
  border-radius: 12px;
  background: var(--fill);
  transition: background 150ms, box-shadow 200ms;
}
.search:focus-within { background: var(--bg-elev); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.search svg { width: 18px; height: 18px; color: var(--text-2); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; height: 100%; }
.search input::placeholder { color: var(--text-2); }
.search .clear { width: 22px; height: 22px; border-radius: 50%; background: var(--text-3); color: var(--bg); display: grid; place-items: center; }
.search .clear svg { width: 12px; height: 12px; color: var(--bg); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; overscroll-behavior-x: contain; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  background: var(--bg-elev); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 200ms, color 200ms, transform 120ms ease-out, box-shadow 200ms;
}
.chip:active { transform: scale(0.94); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); box-shadow: none; }
.chip small { font-weight: 600; opacity: 0.6; margin-left: 4px; }

.summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; font-size: 14px; color: var(--text-2); }
.summary b { color: var(--text); font-weight: 650; }

/* ---------- Listas ---------- */
.list {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.row {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 64px;
  padding: 10px 16px;
  width: 100%;
  text-align: left;
  transition: background 150ms;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 68px; right: 0; height: 1px; background: var(--line); }
.row.enter { animation: row-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1) backwards; animation-delay: calc(min(var(--i, 0), 14) * 28ms); }
@keyframes row-in { from { opacity: 0; translate: 0 10px; } }
.row.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { background: color-mix(in srgb, var(--accent) 14%, transparent); } }
button.row:active, .row.tappable:active { background: var(--fill); }

.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 700; color: #fff; letter-spacing: 0;
  background: var(--av, #8e8e93);
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; font-weight: 550; letter-spacing: -0.02em; line-height: 1.25; overflow-wrap: break-word; }
.row-sub { font-size: 13.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #fff; background: var(--b, #8e8e93); }
.badge.l5 { --b: var(--accent); }
.badge.l6 { --b: #48484a; }

/* Interruptor estilo iOS */
.switch {
  flex: none; position: relative;
  width: 51px; height: 31px; border-radius: 999px;
  background: var(--fill-2);
  transition: background 250ms ease;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
  transition: translate var(--spring-soft-dur) var(--spring-soft), width 200ms ease;
}
.row:active .switch::after { width: 32px; }
.switch.on { background: #34c759; }
.switch.on::after { translate: 20px 0; }
.row:active .switch.on::after { translate: 15px 0; }

/* Meriendas: saldo y botones de pago */
.balance {
  flex: none; display: inline-flex; flex-direction: column; align-items: flex-end;
  padding: 4px 10px; border-radius: 10px; min-width: 66px;
  transition: background 150ms, transform 120ms;
}
.balance:active { transform: scale(0.94); background: var(--fill); }
.balance b { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.balance small { font-size: 11px; color: var(--text-2); font-weight: 600; }
.balance.low b { color: var(--orange); }
.balance.neg b { color: var(--red); }

.pay { flex: none; display: flex; gap: 6px; }
.pay button {
  height: 38px; padding: 0 12px; border-radius: 11px;
  font-size: 14px; font-weight: 650; white-space: nowrap;
  background: var(--fill); color: var(--text);
  display: inline-flex; align-items: center; gap: 5px;
  transition: background 200ms, color 200ms, transform 120ms ease-out, box-shadow 200ms;
}
.pay button:active { transform: scale(0.93); }
.pay button.on.cash { background: #2f9e57; color: #fff; box-shadow: 0 6px 14px -6px rgba(47, 158, 87, 0.7); }
.pay button.on.bizum { background: var(--text); color: var(--bg); box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.5); }
.pay button.pop { animation: btn-pop var(--spring-dur) var(--spring); }
@keyframes btn-pop { 0% { scale: 0.85; } 100% { scale: 1; } }

.row.meri { flex-wrap: wrap; }
@media (max-width: 560px) {
  .row.meri { row-gap: 8px; }
  .row.meri .pay { width: 100%; padding-left: 52px; }
  .row.meri .pay button { flex: 1; justify-content: center; }
}

.empty { text-align: center; padding: 48px 20px; color: var(--text-2); }
.empty .emoji { font-size: 44px; display: block; margin-bottom: 8px; }

/* ---------- Formación ---------- */
.panel { background: var(--bg-elev); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 22px; }
.panel + .panel { margin-top: 14px; }
.tema { font-size: clamp(1.5rem, 4.5vw, 2rem); font-weight: 750; letter-spacing: -0.03em; line-height: 1.12; margin: 6px 0 0; }
.esquema { list-style: none; padding: 0; margin: 18px 0 0; counter-reset: p; display: grid; gap: 10px; }
.esquema li {
  counter-increment: p;
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px 16px; border-radius: 14px; background: var(--fill);
  font-size: 16.5px; line-height: 1.4; letter-spacing: -0.012em;
  animation: row-in 460ms cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 60ms + 120ms);
}
.esquema li::before {
  content: counter(p);
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 750; color: #fff;
  background: var(--g-form);
}
.by { margin-top: 14px; font-size: 13px; color: var(--text-3); }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px; border-radius: 12px;
  font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff;
  transition: transform 120ms ease-out, filter 150ms, opacity 150ms;
}
.btn:active { transform: scale(0.97); filter: brightness(0.92); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn.secondary { background: var(--fill); color: var(--accent); }
.btn.danger { background: rgba(229, 56, 59, 0.12); color: var(--red); }
.btn.small { height: 36px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); padding-left: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 11px 14px;
  border-radius: 12px; border: 0; outline: 0;
  background: var(--fill); font-size: 17px;
  transition: background 150ms, box-shadow 200ms;
}
textarea.input { resize: vertical; line-height: 1.45; min-height: 140px; }
.input:focus { background: var(--bg-elev); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent), inset 0 0 0 1px var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }
.hint { font-size: 13px; color: var(--text-2); margin: -4px 0 12px 4px; }
.error-text { color: var(--red); font-size: 14px; min-height: 20px; margin: 4px 0 8px; font-weight: 500; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%; max-width: 380px;
  padding: 34px 28px 28px;
  border-radius: 30px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: pop-fade 600ms ease-out backwards, pop-move var(--spring-dur) var(--spring) backwards;
}
.login-card .logo {
  display: block; width: 92px; height: 92px; margin: 0 auto 16px;
  filter: drop-shadow(0 10px 18px rgba(215, 20, 26, 0.3));
  animation: emoji-in var(--spring-dur) var(--spring) 200ms backwards;
}
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; font-weight: 750; line-height: 1.1; }
.login-card .tagline { margin-top: 6px; font-size: 13px; color: var(--text-2); letter-spacing: 0; }
.login-card > p { margin: 18px 0 20px; color: var(--text); font-weight: 500; }
.login-card form { text-align: left; }
.login-card .lock { margin-top: 18px; font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; justify-content: center; gap: 6px; }
.login-card .lock svg { width: 13px; height: 13px; }
.shake { animation: shake 420ms cubic-bezier(.36,.07,.19,.97); }
@keyframes shake { 15%, 85% { translate: -2px 0; } 30%, 70% { translate: 5px 0; } 45%, 55% { translate: -7px 0; } }

/* ---------- Hoja inferior (sheet) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.32);
  animation: fade-in 250ms ease-out;
}
.scrim.out { animation: fade-out 220ms ease-in forwards; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.sheet {
  position: fixed; z-index: 51;
  left: 50%; bottom: 0;
  width: min(560px, 100%);
  max-height: 88dvh;
  overflow: auto;
  translate: -50% 0;
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--bg-elev);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  animation: sheet-in var(--spring-dur) var(--spring);
  touch-action: pan-y;
}
@keyframes sheet-in { from { translate: -50% 100%; } }
@media (min-width: 700px) {
  .sheet { bottom: auto; top: 50%; translate: -50% -50%; border-radius: 26px; padding-bottom: 24px; animation: dialog-in var(--spring-dur) var(--spring); }
  @keyframes dialog-in { from { translate: -50% -46%; scale: 0.92; opacity: 0; } }
}
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--fill-2); margin: 0 auto 14px; cursor: grab; }
.sheet h2 { margin: 6px 0 4px; font-size: 22px; letter-spacing: -0.025em; }
.sheet .sub { margin: 0 0 18px; color: var(--text-2); }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }
.amounts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 12px; }
.amounts button.minus { color: var(--red); background: rgba(229, 56, 59, 0.1); }
.amounts button { height: 52px; border-radius: 14px; background: var(--fill); font-weight: 700; font-size: 17px; transition: transform 120ms, background 150ms; }
.amounts button:active { transform: scale(0.94); background: var(--fill-2); }

/* Menú de usuario */
.menu {
  position: fixed; z-index: 40;
  min-width: 220px; padding: 6px;
  border-radius: 16px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow-lg);
  transform-origin: top right;
  animation: menu-in var(--spring-soft-dur) var(--spring-soft);
}
@keyframes menu-in { from { opacity: 0; scale: 0.85; } }
.menu .who { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who b { display: block; font-size: 15px; }
.menu .who small { color: var(--text-2); }
.menu button { width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; font-size: 15px; display: flex; gap: 10px; align-items: center; }
.menu button:hover, .menu button:active { background: var(--fill); }
.menu button svg { width: 18px; height: 18px; color: var(--text-2); }
.menu button.danger { color: var(--red); }
.menu button.danger svg { color: var(--red); }

/* ---------- Ajustes ---------- */
.segmented {
  display: flex; padding: 3px; border-radius: 11px; background: var(--fill);
  margin: 18px 0 16px; overflow-x: auto; scrollbar-width: none;
}
.segmented button {
  flex: 1; height: 34px; padding: 0 12px; border-radius: 9px; font-size: 14px; font-weight: 600; white-space: nowrap;
  color: var(--text-2);
  transition: background 200ms, color 200ms, box-shadow 200ms;
}
.segmented button[aria-selected="true"] { background: var(--bg-elev); color: var(--text); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0,0,0,.04); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 4px 10px; }
.section-head h3 { margin: 0; font-size: 20px; letter-spacing: -0.022em; }
.log-item { padding: 12px 16px; font-size: 14.5px; }
.log-item + .log-item { border-top: 1px solid var(--line); }
.log-item small { display: block; color: var(--text-2); font-size: 12.5px; margin-top: 2px; }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; z-index: 100;
  left: 50%; top: calc(12px + env(safe-area-inset-top));
  translate: -50% 0;
  display: grid; gap: 8px; justify-items: center;
  pointer-events: none;
  width: max-content; max-width: calc(100% - 32px);
}
.toast {
  padding: 10px 18px; border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow-lg);
  font-size: 14.5px; font-weight: 600;
  animation: toast-in var(--spring-dur) var(--spring);
}
.toast.error { color: var(--red); }
.toast.out { animation: toast-out 250ms ease-in forwards; }
@keyframes toast-in { from { translate: 0 -30px; scale: 0.9; opacity: 0; } }
@keyframes toast-out { to { translate: 0 -20px; opacity: 0; scale: 0.95; } }

/* ---------- Transiciones entre pantallas (View Transitions) ---------- */
::view-transition-old(root) { animation: vt-out 220ms ease-in both; }
::view-transition-new(root) { animation: vt-in 380ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes vt-out { to { opacity: 0; scale: 0.985; } }
@keyframes vt-in { from { opacity: 0; } }
::view-transition-group(hero) { animation-duration: 520ms; animation-timing-function: var(--spring-soft); }
::view-transition-old(hero), ::view-transition-new(hero) { height: 100%; animation-duration: 300ms; }

/* ---------- Accesibilidad ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 120ms !important;
  }
  .pop-card { transform: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar, .menu, .toast, .login-card { background: var(--bg-elev); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .list, .panel, .chip, .date-pill { box-shadow: inset 0 0 0 1px var(--text-2); }
}
@media (hover: none) {
  .pop-card:hover .emoji > span { animation: none; }
  .pop-card:hover::after, .pop-card:hover .arrow { translate: none; }
}

/* Símbolo de euro en Meriendas, en lugar de un emoji */
.euro { display: inline-block; font-weight: 800; color: #fff; letter-spacing: -0.04em; line-height: 1; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", system-ui, sans-serif; }

/* Botón de añadir chaval al final de Meriendas */
.add-row {
  width: 100%; margin-top: 12px; height: 52px; border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 16px; font-weight: 600; color: var(--accent);
  background: var(--bg-elev); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 35%, transparent);
  border: 0; transition: transform 120ms ease-out, background 150ms;
}
.add-row:active { transform: scale(0.98); background: var(--fill); }
.add-row svg { width: 18px; height: 18px; }

/* Foto de usuario por defecto (inicial) */
.user-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; transition: transform 120ms ease-out; }
.user-btn:active { transform: scale(0.9); }
.avatar.user { width: 36px; height: 36px; font-size: 16px; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.row .avatar.user { width: 40px; height: 40px; font-size: 17px; }
.avatar.user.lg { width: 44px; height: 44px; font-size: 19px; margin-bottom: 8px; }
.avatar.user.xl { width: 56px; height: 56px; font-size: 24px; }

/* Móvil: los nombres largos bajan de línea en vez de cortarse */
@media (max-width: 560px) {
  .row { align-items: center; }
  .row.meri { align-items: flex-start; }
  .row.meri .avatar { margin-top: 2px; }
  .row-title { font-size: 16px; }
  .balance { min-width: 0; padding: 2px 6px; }
  .balance b { font-size: 16px; }
}
