:root {
  --bg: #e9f0f2;
  --surface: #ffffff;
  --ink: #0f2a3a;
  --muted: #53707f;
  --line: #c8d7dd;
  --sea: #1f6f8b;
  --sea-deep: #164f63;
  --sun: #f2b33d;
  --danger: #b3261e;
  --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius-s: 8px;
  --radius-l: 18px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1e29;
    --surface: #132b38;
    --ink: #e4edf1;
    --muted: #8fa7b3;
    --line: #24404f;
    --sea: #4fa3bf;
    --sea-deep: #2e7f9b;
    --sun: #f5be4f;
    --danger: #f2b8b5;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.15; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.hint { color: var(--muted); font-size: 0.92rem; }

/* ---------- botones y campos ---------- */
.btn {
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-weight: 700;
}
.btn-primary { background: var(--sea); border-color: var(--sea); color: #fff; }
.link-btn {
  background: none; border: 0; padding: 0.4rem 0; cursor: pointer;
  color: var(--sea); font-weight: 700; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn.danger { color: var(--danger); }
.icon-btn {
  background: none; border: 0; color: var(--muted); padding: 0.5rem; margin: -0.5rem; cursor: pointer;
}

input, select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  padding: 0.6rem 0.75rem;
}
textarea { resize: vertical; }

.stack { display: grid; gap: 0.45rem; }
.stack label { font-size: 0.92rem; color: var(--muted); margin-top: 0.35rem; }
.stack .btn { margin-top: 0.6rem; justify-self: start; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; }
.check { display: flex; gap: 0.6rem; align-items: center; }
.check input { width: auto; }

/* ---------- acceso ---------- */
.login { max-width: 26rem; margin: 0 auto; padding: 18vh 1.5rem 3rem; }
.brand { font-size: 3.2rem; font-weight: 700; letter-spacing: -0.02em; color: var(--sea); }
.lead { font-size: 1.2rem; margin: 0.3rem 0 2.2rem; color: var(--muted); }
#login-msg { margin-top: 1rem; }

/* ---------- inicio ---------- */
.home { max-width: 34rem; margin: 0 auto; padding: 1.25rem 1.25rem 4rem; }

.top { display: flex; justify-content: space-between; align-items: flex-start; }
.greeting { font-size: 2rem; font-weight: 700; letter-spacing: -0.015em; }
.date { color: var(--muted); }
.date::first-letter { text-transform: uppercase; }

/* El botón de hablar: un sol sobre ondas */
.talk { display: grid; justify-items: center; padding: 2.2rem 0 1rem; }
.talk-btn {
  position: relative;
  width: 11rem; height: 11rem;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 50% 62%, var(--sea) 0 58%, var(--sea-deep) 100%);
  cursor: pointer;
  display: grid; place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms ease;
}
.talk-btn:active { transform: scale(0.97); }
.sun {
  width: 38%; height: 38%;
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 0 0 0.6rem color-mix(in srgb, var(--sun) 22%, transparent);
  transition: transform 300ms ease;
}
.ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid var(--sea);
  opacity: 0;
  pointer-events: none;
}
.talk-state { margin-top: 1.1rem; font-family: var(--font-display); font-size: 1.15rem; font-weight: 500; }
.interim { min-height: 1.5em; margin-top: 0.3rem; color: var(--muted); text-align: center; max-width: 28rem; }

/* estados */
.talk-btn[data-state="listening"] .ring { animation: wave 1.8s ease-out infinite; }
.talk-btn[data-state="listening"] .r2 { animation-delay: 0.6s; }
.talk-btn[data-state="listening"] .r3 { animation-delay: 1.2s; }
.talk-btn[data-state="thinking"] .sun { animation: breathe 1.2s ease-in-out infinite; }
.talk-btn[data-state="speaking"] .ring { border-color: var(--sun); animation: wave 1.1s ease-out infinite; }
.talk-btn[data-state="speaking"] .r2 { animation-delay: 0.37s; }
.talk-btn[data-state="speaking"] .r3 { animation-delay: 0.74s; }
.talk-btn[data-state="ready"] { outline: 3px dashed var(--sun); outline-offset: 8px; }

@keyframes wave {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.82); }
}

@media (prefers-reduced-motion: reduce) {
  .ring, .sun { animation: none !important; }
  .talk-btn[data-state="listening"] .r1,
  .talk-btn[data-state="speaking"] .r1 { opacity: 0.8; transform: scale(1.12); }
}

/* conversación */
.chat { display: grid; gap: 0.8rem; margin: 0.5rem 0 1rem; }
.msg { max-width: 92%; }
.msg.user { justify-self: end; color: var(--muted); text-align: right; }
.msg.assistant { justify-self: start; font-size: 1.12rem; }
.msg.error { color: var(--danger); }
.msg a { color: var(--sea); font-weight: 700; }

/* borrador pendiente */
.pending {
  background: var(--surface);
  border: 2px solid var(--sun);
  border-radius: var(--radius-l);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  display: grid; gap: 0.6rem;
}
.pending-to { font-weight: 700; }
.pending-body { white-space: pre-wrap; }
.pending .row { justify-content: flex-start; }

.ask { display: flex; gap: 0.5rem; margin-bottom: 2rem; }

/* vistazo: tiempo y cripto */
.glance {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  overflow: hidden;
  margin-bottom: 1.8rem;
}
.glance-item { background: var(--surface); padding: 0.9rem 1rem; min-height: 5.2rem; }
.big { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.up { color: #2f7d4f; }
.down { color: var(--danger); }
@media (prefers-color-scheme: dark) { .up { color: #8fd3a8; } }
.coin { display: flex; justify-content: space-between; gap: 0.5rem; }
.coin + .coin { margin-top: 0.2rem; }

/* bloques */
.block { margin-bottom: 1.8rem; }
.block h2 { margin-bottom: 0.6rem; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li {
  display: flex; gap: 0.8rem; align-items: flex-start;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}
.list > li:last-child { border-bottom: 0; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.2rem; color: var(--sea); }
.grow { flex: 1; min-width: 0; }
.sub { color: var(--muted); font-size: 0.92rem; }
.empty { color: var(--muted); }
.urgent { border-left: 4px solid var(--sun); padding-left: 0.6rem; }

.done-btn {
  width: 1.6rem; height: 1.6rem; flex: none;
  border-radius: 50%;
  border: 2px solid var(--sea);
  background: none; cursor: pointer; margin-top: 0.1rem;
}
.done-btn:hover { background: color-mix(in srgb, var(--sea) 18%, transparent); }

.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; margin-top: 0.8rem; }
.inline-form input:first-of-type { grid-column: 1 / -1; }

/* ajustes */
.sheet {
  width: 100%; max-width: 34rem; max-height: 100dvh; height: 100dvh;
  margin: 0 auto; padding: 1.25rem 1.25rem 3rem;
  border: 0; background: var(--bg); color: var(--ink);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.sheet-head h2 { font-size: 1.6rem; }
.setting { padding: 1.1rem 0; border-top: 1px solid var(--line); display: grid; gap: 0.6rem; justify-items: start; }
.setting .stack, .setting.stack { justify-items: stretch; }
.setting .list { width: 100%; }

/* aviso */
.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 0.7rem 1.1rem; border-radius: var(--radius-s);
  max-width: calc(100% - 2rem);
  z-index: 10;
}
