@font-face { font-family: 'Outfit'; src: url('fonts/outfit.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Manrope'; src: url('fonts/manrope.woff2') format('woff2'); font-weight: 200 800; font-display: swap; }

/* Paleta tomada del logo: azul noche, cian y naranja */
:root {
  --bg: #EEF3FA;
  --surface: #FFFFFF;
  --ink: #0A1A45;
  --muted: #56688F;
  --line: #D5DEEC;
  --done: #0B8FD8;
  --done-ink: #FFFFFF;
  --min: #BDE5F8;
  --warm: #E36A0E;
  --relapse: #E4502A;
  --focus: #FF8A1F;
  --shadow: 0 1px 0 rgba(10, 26, 69, .04), 0 8px 24px -16px rgba(10, 26, 69, .25);
  --display: 'Outfit', system-ui, sans-serif;
  --sans: 'Manrope', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #040F32;
    --surface: #0B1B48;
    --ink: #E9F2FF;
    --muted: #93A6CC;
    --line: #1B2D62;
    --done: #22C6F3;
    --done-ink: #04102F;
    --min: #12456E;
    --warm: #FF9A2E;
    --relapse: #FF6A3A;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--sans);
  min-height: 100dvh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 34rem;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) 16px 32px;
  outline: none;
}
h1, h2 { font-family: var(--display); font-weight: 500; margin: 0; }
p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 24px 0; }

/* ---------- Cabecera del día ---------- */
.day { margin-bottom: 24px; position: relative; }
.day h1 { font-size: 2.6rem; line-height: 1.05; letter-spacing: -.02em; font-weight: 600; }
.day-num { color: var(--done); }
.day-month { font-family: var(--display); font-size: 1.35rem; color: var(--muted); margin-top: 2px; }
.tally { margin-top: 14px; color: var(--muted); font-size: .95rem; }
.day-logo { position: absolute; right: 0; top: 4px; width: 44px; height: 44px; border-radius: 11px; }

.page { margin-bottom: 20px; }
.page h1 { font-size: 2.2rem; line-height: 1.1; font-weight: 600; letter-spacing: -.02em; }
.lede { color: var(--muted); margin-top: 8px; max-width: 32ch; }

/* ---------- Lista de hábitos ---------- */
.habits { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.group { font-size: 1.15rem; color: var(--muted); margin: 28px 0 10px; }
.habit {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px 12px 12px;
  box-shadow: var(--shadow);
}
.check {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  display: grid; place-items: center;
  cursor: pointer;
  padding: 0;
}
.check svg { width: 24px; height: 24px; fill: none; stroke: var(--done-ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.is-full .check { background: var(--done); border-color: var(--done); }
.is-full .check svg { opacity: 1; }
.is-min .check { border-color: var(--done); background: linear-gradient(to top, var(--min) 50%, transparent 50%); }
.is-min .check svg { opacity: 1; stroke: var(--done); }
.check.just { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.82); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

.habit-body {
  background: none; border: 0; padding: 4px 0; text-align: left; cursor: pointer;
  display: grid; gap: 2px; min-width: 0;
}
.habit-name { font-weight: 700; letter-spacing: -.005em; font-size: 1.05rem; line-height: 1.3; overflow-wrap: anywhere; }
.emoji { margin-right: .4em; }
.habit-anchor { color: var(--muted); font-size: .9rem; }
.habit-note { color: var(--warm); font-size: .88rem; }
.habit-count { display: grid; justify-items: end; line-height: 1; }
.habit-count .num { font-family: var(--display); font-size: 2rem; font-weight: 500; }
.habit-count .unit { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.min-btn {
  grid-column: 2 / 4;
  justify-self: start;
  background: none;
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .88rem;
  color: var(--muted);
  cursor: pointer;
}
.min-done { grid-column: 2 / 4; font-size: .88rem; color: var(--done); }

.is-quit { grid-template-columns: 48px 1fr auto; }
.quit-mark {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.35rem;
  background: color-mix(in srgb, var(--warm) 14%, transparent);
  border: 2px solid color-mix(in srgb, var(--warm) 55%, transparent);
}
.is-quit .habit-count .num { color: var(--warm); }

.add { width: 100%; margin-top: 14px; }

.why {
  margin: -8px 0 22px;
  padding: 14px 16px 10px;
  border-radius: 18px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--done) 16%, transparent), color-mix(in srgb, var(--warm) 14%, transparent));
  border: 1px solid color-mix(in srgb, var(--done) 30%, var(--line));
}
.why-label { font-size: .85rem; color: var(--muted); }
.why-text { font-family: var(--display); font-size: 1.2rem; line-height: 1.4; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.why .link { margin-top: 4px; }
.why-quote { margin: 14px 0 0; padding: 2px 0 2px 14px; border-left: 2px solid var(--warm); font-family: var(--display); font-size: 1.1rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.why-quote span { display: block; font-family: var(--sans); font-size: .8rem; color: var(--muted); margin-bottom: 2px; }
[data-for] { display: grid; gap: 16px; }
.freq legend { font-weight: 700; font-size: .95rem; padding: 0; margin-bottom: 6px; }
.freq { display: grid; gap: 10px; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented.three span { font-size: .9rem; padding: 10px 4px; }
.freq-opt[hidden] { display: none; }
.stepper { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stepper .step { background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-size: 1.3rem; }
.stepper output { font-family: var(--display); font-size: 1.8rem; font-weight: 600; min-width: 1.4ch; text-align: center; }
.stepper-label { color: var(--muted); font-size: .9rem; flex-basis: 100%; }
.daypick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.daypick label { position: relative; }
.daypick input { position: absolute; opacity: 0; inset: 0; }
.daypick span { display: grid; place-items: center; aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-weight: 700; color: var(--muted); cursor: pointer; }
.daypick input:checked + span { background: var(--done); border-color: var(--done); color: var(--done-ink); }
.daypick input:focus-visible + span { outline: 2.5px solid var(--focus); }
.freq-line { font-weight: 700; color: var(--done); margin-top: 2px; }
.habit-week { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--done); }
.dots i.on { background: var(--done); }
.is-rest .check { border-style: dashed; opacity: .7; }
.cell.is-off { opacity: .45; }
.heat-weeks { display: grid; gap: 3px; margin-bottom: 4px; }
.heat-weeks span { height: 4px; border-radius: 2px; background: var(--line); }
.heat-weeks span.is-met { background: var(--warm); }
.heat-legend .week-key { display: inline-block; width: 14px; height: 4px; border-radius: 2px; background: var(--warm); }
[data-for][hidden] { display: none; }

.empty { text-align: center; padding: 56px 12px; display: grid; gap: 20px; justify-items: center; }
.empty p { font-family: var(--display); font-size: 1.4rem; max-width: 18ch; }

.echo { margin-top: 36px; padding: 0 4px; }
.echo-date { color: var(--muted); font-size: .9rem; }
.echo blockquote { margin: 6px 0 0; font-family: var(--sans); font-size: 1.05rem; line-height: 1.6; border-left: 2px solid var(--warm); padding-left: 14px; white-space: pre-wrap; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 20px; border-radius: 14px;
  border: 1px solid transparent; cursor: pointer; font-weight: 700; font-size: 1rem;
}
.btn-primary { background: var(--done); color: var(--done-ink); }
.btn-quiet { background: var(--surface); border-color: var(--line); color: var(--ink); }
.danger { color: var(--relapse); }
.link { background: none; border: 0; padding: 6px 0; color: var(--done); cursor: pointer; font-size: .92rem; }
.link.danger { color: var(--relapse); }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.row-btns.end { justify-content: flex-end; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- Monedas ---------- */
.coin { display: block; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .25)); }
.coin-locked .cl-face { fill: var(--surface); stroke: var(--line); stroke-width: 2; }
.coin-locked .cl-ring { fill: none; stroke: var(--line); stroke-width: 1.2; stroke-dasharray: 2 3; }
.coin-locked .cl-num { fill: var(--muted); opacity: .55; font-family: var(--display); font-weight: 600; }
.coin-locked .cl-unit { fill: var(--muted); opacity: .55; font-family: var(--display); font-size: 6.5px; letter-spacing: 2px; }
.coin-locked { filter: none; }

.hero-coin { display: grid; justify-items: center; text-align: center; padding: 8px 0 28px; gap: 4px; }
.hero-coin .coin { margin-bottom: 14px; }
.hero-title { font-family: var(--display); font-size: 1.7rem; }
.hero-sub { color: var(--muted); max-width: 28ch; }
.hero-count { margin-top: 10px; font-size: .9rem; color: var(--warm); }

.coin-row { padding: 18px 0; border-top: 1px solid var(--line); }
.coin-row h2 { font-family: var(--sans); font-weight: 700; font-size: 1.05rem; }
.coin-next { color: var(--muted); font-size: .92rem; margin: 2px 0 12px; }
.coins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 8px; justify-items: center; }
.coin-cell { position: relative; }
.coin-times { position: absolute; right: -4px; bottom: -2px; background: var(--ink); color: var(--bg); font-size: .72rem; border-radius: 999px; padding: 1px 6px; font-weight: 700; }
.coins-sheet { grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 18px; }
.coins-sheet .coin { width: 100%; height: auto; max-width: 52px; }

/* ---------- Hojas (dialog) ---------- */
dialog { border: 0; padding: 0; color: var(--ink); background: transparent; max-width: none; max-height: none; }
dialog::backdrop { background: rgba(2, 8, 30, .55); }
.sheet { width: 100%; margin: auto auto 0; }
.sheet[open] { animation: up .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-inner {
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  max-width: 34rem; margin: 0 auto;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; }
.sheet-head h2 { font-size: 1.6rem; line-height: 1.2; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stats dt { font-size: .8rem; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-family: var(--display); font-size: 1.7rem; line-height: 1.1; }

.heat { margin-top: 6px; }
.heat-months { display: grid; font-size: .72rem; color: var(--muted); margin-bottom: 4px; }
.heat-months span { white-space: nowrap; }
.heat-grid { display: grid; grid-template-rows: repeat(7, auto); grid-auto-flow: column; gap: 3px; }
.cell { display: block; aspect-ratio: 1; border-radius: 4px; background: var(--line); border: 0; padding: 0; min-width: 0; cursor: pointer; }
span.cell { cursor: default; }
.cell.is-full { background: var(--done); }
.cell.is-min { background: var(--min); box-shadow: inset 0 0 0 1.5px var(--done); }
.cell.is-relapse { background: var(--relapse); }
.cell.is-before { opacity: .35; }
.cell.is-future { visibility: hidden; }
.cell.is-today { box-shadow: inset 0 0 0 2px var(--warm); }
.cell.is-min.is-today { box-shadow: inset 0 0 0 2px var(--warm); }
.heat-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: .8rem; color: var(--muted); margin-top: 10px; }
.heat-legend .cell { width: 12px; height: 12px; display: inline-block; cursor: default; }
.heat-legend .hint { flex-basis: 100%; }

/* ---------- Formularios ---------- */
.habit-form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 700; font-size: .95rem; }
.field small { color: var(--muted); font-size: .85rem; }
.field.inline { grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 12px; }
input:not([type=radio]):not([type=file]), textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
}
input[type=time], input[type=date] {
  -webkit-appearance: none; appearance: none;
  width: 7.5rem; min-width: 0; max-width: 100%;
  text-align: center; display: block; line-height: 1.2;
}
input[type=date] { width: 10rem; }
input::-webkit-date-and-time-value { text-align: center; }
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span { display: block; text-align: center; padding: 10px 6px; border-radius: 10px; font-weight: 700; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--done); color: var(--done-ink); }
.segmented input:focus-visible + span { outline: 2.5px solid var(--focus); }
.segmented[disabled] span { cursor: default; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.emoji-input { width: 64px !important; text-align: center; font-size: 1.3rem; }
.emoji-opt { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 1.2rem; cursor: pointer; padding: 0; }

.journal-form { display: grid; gap: 10px; margin-bottom: 28px; }
.journal-form .btn { justify-self: end; }
.entries { list-style: none; padding: 0; margin: 0; }
.entries li { padding: 16px 0; border-top: 1px solid var(--line); }
.entries time { font-size: .88rem; color: var(--muted); }
.entries p { font-family: var(--sans); font-size: 1.05rem; line-height: 1.65; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Ajustes ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px; margin-bottom: 14px; }
.panel h2 { font-size: 1.3rem; margin-bottom: 10px; }
.panel p { color: var(--muted); }
.panel p.ok { color: var(--done); font-weight: 700; }
.panel .field.inline { margin-bottom: 14px; }
#push-status .btn-primary { margin-top: 14px; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.about p { font-size: .95rem; line-height: 1.6; }

/* ---------- Revelado de ficha ---------- */
.reveal { margin: auto; width: min(100% - 32px, 24rem); }
.reveal-inner { background: var(--bg); border-radius: 26px; padding: 32px 22px 22px; text-align: center; display: grid; gap: 8px; justify-items: center; }
.reveal-coin { perspective: 600px; margin-bottom: 10px; }
.reveal[open] .reveal-coin .coin { animation: flip 1.1s cubic-bezier(.2, .7, .2, 1); }
@keyframes flip { from { transform: rotateY(-540deg) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.reveal h2 { font-size: 2rem; }
.reveal-habit { font-weight: 700; }
.reveal-note { color: var(--muted); max-width: 30ch; margin-bottom: 14px; }
.reveal .btn { width: 100%; }

/* ---------- Pestañas ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 5;
}
.tabs button { background: none; border: 0; display: grid; justify-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: .76rem; cursor: pointer; }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--ink); font-weight: 700; }
.tabs button[aria-current="page"] svg { stroke: var(--done); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: .92rem; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .2s, transform .2s; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Botones de los paneles a todo el ancho */
.panel .row-btns .btn, .panel #push-status .btn { flex: 1 1 auto; }
#push-status .btn-primary { width: 100%; }

/* ---------- Consejos ---------- */
.tip-day { margin: 0 0 18px; }
.tip-body { color: var(--muted); margin-top: 6px; line-height: 1.5; }
.tips { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; margin-bottom: 12px; }
.tips summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; cursor: pointer; }
.tips summary::-webkit-details-marker { display: none; }
.tips summary h2 { font-size: 1.2rem; }
.tips-count { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tips-count::after { content: ''; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .2s; margin-top: -4px; }
.tips[open] .tips-count::after { transform: rotate(-135deg); margin-top: 4px; }
.tips ul { list-style: none; margin: 0; padding: 0 16px 8px; }
.tips li { padding: 12px 0; border-top: 1px solid var(--line); }
.tips li strong { display: block; font-size: 1rem; }
.tips li p { color: var(--muted); font-size: .94rem; line-height: 1.5; margin-top: 2px; }
.about { margin-top: 18px; }
