:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #13213a;
  --muted: #5b6780;
  --border: #dde3ee;
  --primary: #0e2340;
  --primary-text: #ffffff;
  --accent: #d9a521;
  --accent-soft: #fbf1d6;
  --danger: #c0392b;
  --user-bubble: #0e2340;
  --user-text: #ffffff;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(14, 35, 64, 0.06);
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1424;
    --surface: #13203a;
    --surface-2: #1a2a48;
    --text: #e8edf6;
    --muted: #97a3bb;
    --border: #253656;
    --primary: #e2b23a;
    --primary-text: #13203a;
    --accent: #e2b23a;
    --accent-soft: #2b2a1d;
    --danger: #ef6b5b;
    --user-bubble: #2a4170;
    --user-text: #ffffff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.tiny { font-size: 0.75rem; }
.gold { color: var(--accent); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 8px; align-items: center; font-size: 1.05rem; }
.brand b { color: var(--accent); }
.badge {
  font-size: 0.72rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent);
}

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.view { display: flex; flex-direction: column; gap: 14px; }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.hero { padding: 6px 2px 4px; }
.countdown {
  margin-top: 10px; display: inline-flex; gap: 8px; align-items: baseline;
  background: var(--primary); color: var(--primary-text);
  padding: 8px 14px; border-radius: 12px; font-size: 0.9rem;
}
.countdown b { font-size: 1.4rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; }
.notify-card { border-color: var(--accent); }

/* Botones */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 12px; padding: 10px 16px; min-height: 44px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.full { width: 100%; margin-top: 12px; }
.btn.big { font-size: 1.05rem; padding: 14px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.link {
  font: inherit; font-size: 0.9rem; background: none; border: 0; padding: 8px 4px;
  color: var(--accent); font-weight: 600; cursor: pointer;
}
.row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip.sel { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  font: inherit; font-size: 1.1rem; line-height: 1; cursor: pointer;
  width: 36px; height: 36px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.field-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin: 14px 0; cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }
#fraseForm label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.chip {
  font: inherit; font-size: 0.88rem; cursor: pointer;
  padding: 8px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}

/* Formularios */
.form label, #ideaForm label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
input, textarea, select {
  font: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Eventos */
.event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.event {
  display: grid; grid-template-columns: 58px 1fr; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px;
}
.event-list.compact .event { background: var(--surface-2); border: 0; }
.event-time { font-weight: 700; font-size: 0.95rem; color: var(--accent); }
.event h3 { margin: 0; font-size: 1rem; }
.event .meta { font-size: 0.82rem; color: var(--muted); }
.event .actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.event .actions button { font-size: 0.8rem; padding: 6px 8px; }
.event.past { opacity: 0.6; }
.day-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 2px 8px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 0.92rem; }

/* Chat */
.chat-view { min-height: calc(100dvh - 140px - var(--tabbar-h)); }
.chat-log { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.error { border-color: var(--danger); color: var(--danger); }
.chat-form {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg); padding-top: 8px;
}
.chat-form textarea { max-height: 140px; }
.send { width: 48px; padding: 0; font-size: 1.1rem; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Salida IA (markdown sencillo) */
.ai-output { margin-top: 12px; }
.ai-output p, .msg.ai p { margin: 0 0 8px; }
.ai-output ul, .ai-output ol, .msg.ai ul, .msg.ai ol { margin: 0 0 8px; padding-left: 20px; }
.ai-output h3, .msg.ai h3, .ai-output h4, .msg.ai h4 { margin: 10px 0 6px; font-size: 1rem; }
.msg.ai > :last-child, .ai-output > :last-child { margin-bottom: 0; }

/* Ideas */
.idea-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.idea-btn {
  font: inherit; text-align: left; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 4px; min-height: 92px;
}
.idea-btn.sel { border-color: var(--accent); outline: 2px solid var(--accent); }
.idea-btn .ico { font-size: 1.4rem; }
.idea-btn b { font-size: 0.95rem; }
.idea-btn span.d { font-size: 0.78rem; color: var(--muted); }
.saved-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.saved-list details { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.saved-list summary { cursor: pointer; font-weight: 600; font-size: 0.92rem; }

/* Barra inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar button {
  font: inherit; font-size: 0.72rem; background: none; border: 0; cursor: pointer;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar button span { font-size: 1.25rem; filter: grayscale(1); opacity: 0.7; }
.tabbar button.active { color: var(--text); font-weight: 700; }
.tabbar button.active span { filter: none; opacity: 1; }

/* Modal */
dialog {
  border: 0; border-radius: 20px; padding: 18px; width: min(520px, calc(100vw - 24px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(5, 12, 25, 0.55); }

/* Suscripción */
.paywall {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto;
  background: linear-gradient(180deg, #0e2340 0%, #07162b 100%);
  display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.paywall-box { color: #fff; max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.paywall-box .muted { color: #b7c3da; }
.paywall-box h1 { font-size: 1.8rem; }
.paywall .gold { color: #e2b23a; }
.benefits { list-style: none; padding: 0; margin: 10px 0; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.benefits li { background: rgba(255,255,255,0.07); padding: 10px 12px; border-radius: 12px; font-size: 0.95rem; }
.price { font-size: 1.1rem; margin-top: 6px; }
.price b { font-size: 2.2rem; color: #e2b23a; }
.paywall .btn.primary { background: #e2b23a; color: #13203a; border-color: #e2b23a; }
.paywall .link { color: #b7c3da; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 0.9rem; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* Entrar / crear cuenta */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; width: 100%; background: rgba(255,255,255,0.08); padding: 4px; border-radius: 12px; margin-top: 8px; }
.seg button { font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: 10px; cursor: pointer; background: transparent; color: #b7c3da; }
.seg button.on { background: #fff; color: #13203a; }
.auth-form { width: 100%; text-align: left; margin-top: 8px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 600; color: #b7c3da; margin-bottom: 10px; }
.auth-form input:not([type=checkbox]) { background: rgba(255,255,255,0.95); color: #13203a; border-color: transparent; }
.auth-form label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
.auth-form label.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: #e2b23a; }
.paywall a { color: #e2b23a; }
.auth-error { background: rgba(239,107,91,0.15); color: #ffb3a8; border-radius: 10px; padding: 8px 12px; font-size: 0.9rem; margin: 4px 0 0; }
a { color: var(--accent); }

/* Pausa activa */
.center { text-align: center; }
.pausa-cta {
  font: inherit; color: var(--text); text-align: left; cursor: pointer; width: 100%;
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(135deg, var(--surface), var(--accent-soft));
}
.pausa-ico { font-size: 2rem; }
.pausa-cta > span:nth-child(2) { flex: 1; }
.breath-wrap { display: grid; place-items: center; height: 240px; margin: 8px 0; }
.breath {
  width: 110px; height: 110px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: radial-gradient(circle at 35% 30%, #9fd8c9, #3f8f7d);
  color: #fff; font-weight: 600; box-shadow: 0 0 0 10px rgba(63, 143, 125, 0.15);
  transition-property: width, height; transition-timing-function: ease-in-out; transition-duration: 1s;
}
.breath.grande { width: 220px; height: 220px; }
.breath.chico { width: 110px; height: 110px; }
.breath b { font-size: 1.6rem; }
.bubbles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 10px 0; }
.bubble {
  aspect-ratio: 1; border-radius: 50%; cursor: pointer; padding: 0;
  border: 1px solid rgba(120, 160, 220, 0.5);
  background: radial-gradient(circle at 30% 30%, #ffffff, #cfe2ff 45%, #9fbff0);
  box-shadow: inset -3px -4px 6px rgba(60, 100, 170, 0.25);
  transition: transform 0.08s;
}
.bubble:active { transform: scale(0.9); }
.bubble.popped { background: var(--surface-2); box-shadow: none; border-style: dashed; transform: scale(0.85); }
.memory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.card-mem {
  aspect-ratio: 1; border-radius: 12px; cursor: pointer; font-size: 1.8rem;
  background: var(--primary); border: 0; color: transparent;
}
.card-mem span { visibility: hidden; }
.card-mem.open { background: var(--surface-2); border: 1px solid var(--border); }
.card-mem.open span { visibility: visible; }
.card-mem.done { background: var(--accent-soft); border: 1px solid var(--accent); }
.sudoku {
  display: grid; grid-template-columns: repeat(9, 1fr); margin: 10px 0;
  border: 2px solid var(--text); border-radius: 6px; overflow: hidden;
}
.sudoku .cel {
  aspect-ratio: 1; font: inherit; font-size: 1.05rem; font-weight: 600; padding: 0; cursor: pointer;
  background: var(--surface); color: var(--accent); border: 0;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.sudoku .cel:nth-child(3n) { border-right: 2px solid var(--text); }
.sudoku .cel:nth-child(9n) { border-right: 0; }
.sudoku .cel:nth-child(n+19):nth-child(-n+27), .sudoku .cel:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--text); }
.sudoku .cel.fija { color: var(--text); background: var(--surface-2); cursor: default; }
.sudoku .cel.sel { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: -2px; }
.sudoku .cel.mal { color: var(--danger); }
.sud-pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 8px; }
.sud-pad button {
  font: inherit; font-size: 1.1rem; font-weight: 600; padding: 10px 0; cursor: pointer;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}

/* Instalar la app */
.install-card { border: 1px solid var(--accent); background: linear-gradient(135deg, var(--surface), var(--accent-soft)); }
.pasos { padding-left: 22px; margin: 8px 0 14px; display: flex; flex-direction: column; gap: 10px; }
.pasos li { line-height: 1.5; }
.kbd { display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
