/* ============ Tema ============
   Los colores base (--accent, --accent2, --paper) los pone app.js según el tema elegido.
   Todo lo demás se calcula a partir de ellos. */
:root {
  --accent: #d9667f;
  --accent2: #f6c9b5;
  --paper: #fbf4f3;
  --on-accent: #fff;
  --hand: 'Caveat', 'Noteworthy', 'Bradley Hand', cursive;
  --body: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --bg: var(--paper);
  --card: color-mix(in srgb, var(--paper) 30%, #fff);
  --text: color-mix(in srgb, var(--accent) 14%, #2b2226);
  --ink: color-mix(in srgb, var(--accent) 82%, #000);
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 6px 18px color-mix(in srgb, var(--accent) 13%, transparent);

  --muted: color-mix(in srgb, var(--text) 55%, var(--bg));
  --line: color-mix(in srgb, var(--accent) 16%, var(--bg));
  --accent-soft: color-mix(in srgb, var(--accent) 15%, var(--card));
  --dot: color-mix(in srgb, var(--accent) 24%, var(--bg));
  --tape: var(--accent2);
  --radius: 18px;
  color-scheme: light;
}
html[data-mode=dark] {
  --bg: color-mix(in srgb, var(--accent) 6%, #141115);
  --card: color-mix(in srgb, var(--accent) 9%, #221d22);
  --text: #f2eaee;
  --ink: color-mix(in srgb, var(--accent) 60%, #fff);
  --shadow: 0 4px 16px rgb(0 0 0 / .35);
  --dot: color-mix(in srgb, var(--accent) 16%, var(--bg));
  --tape: color-mix(in srgb, var(--accent2) 70%, var(--bg));
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-mode=auto] {
    --bg: color-mix(in srgb, var(--accent) 6%, #141115);
    --card: color-mix(in srgb, var(--accent) 9%, #221d22);
    --text: #f2eaee;
    --ink: color-mix(in srgb, var(--accent) 60%, #fff);
    --shadow: 0 4px 16px rgb(0 0 0 / .35);
    --dot: color-mix(in srgb, var(--accent) 16%, var(--bg));
    --tape: color-mix(in srgb, var(--accent2) 70%, var(--bg));
    color-scheme: dark;
  }
}
html[data-font=serif] { --hand: 'Playfair Display', Georgia, serif; }
html[data-font=simple] { --hand: 'Nunito', -apple-system, sans-serif; }

/* ============ Base ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background-color: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--body);
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
html[data-pattern=dots] body {
  background-image: radial-gradient(circle, var(--dot) 1.1px, transparent 1.6px);
  background-size: 22px 22px;
}
html[data-pattern=grid] body {
  background-image:
    linear-gradient(color-mix(in srgb, var(--dot) 65%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--dot) 65%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--ink); }

/* ============ Encabezado ============ */
header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
header h1 {
  font-family: var(--hand); font-size: 40px; line-height: 1; margin: 0;
  color: var(--ink); font-weight: 700;
}
html[data-font=serif] header h1, html[data-font=simple] header h1 { font-size: 28px; }
header .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.head-right { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--card); box-shadow: var(--shadow); font-size: 18px;
}
.cloud { font-size: 12px; color: var(--muted); font-weight: 700; }
.cloud.error { color: #d0564b; }

main { padding: 0 16px; max-width: 640px; margin: 0 auto; }

/* ============ Piezas comunes ============ */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
  display: block; width: 100%; text-align: left;
}
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

h2 {
  font-family: var(--hand); font-weight: 700; font-size: 30px; line-height: 1.1;
  color: var(--ink); margin: 26px 2px 10px;
}
h2 span {
  background: linear-gradient(transparent 58%, color-mix(in srgb, var(--accent2) 60%, transparent) 58%);
  padding: 0 6px 0 2px;
}
html[data-font=serif] h2, html[data-font=simple] h2 { font-size: 22px; }
.card-title { font-weight: 800; }

/* Cinta washi */
.taped { position: relative; margin-top: 20px; }
.taped::before {
  content: ''; position: absolute; top: -11px; left: 50%;
  width: 96px; height: 22px; border-radius: 2px;
  transform: translateX(-50%) rotate(-2.5deg);
  background: repeating-linear-gradient(-45deg,
    color-mix(in srgb, var(--tape) 92%, transparent) 0 7px,
    color-mix(in srgb, var(--tape) 55%, transparent) 7px 14px);
  box-shadow: 0 1px 2px rgb(0 0 0 / .06);
}
.taped.alt::before { left: 26px; transform: rotate(3deg); width: 70px; }
.taped.right::before { left: auto; right: 22px; transform: rotate(-4deg); width: 64px; }

/* Botones segmentados / chips */
.seg { display: flex; gap: 6px; overflow-x: auto; padding: 4px 1px 8px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button, .chip {
  padding: 7px 14px; border-radius: 999px; background: var(--card);
  box-shadow: var(--shadow); white-space: nowrap; font-size: 14px; font-weight: 600;
}
.seg button.on, .chip.on { background: var(--accent); color: var(--on-accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { box-shadow: none; border: 1px solid var(--line); }
.chips-sm { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chips-sm span { font-size: 12px; background: var(--accent-soft); color: var(--ink); padding: 1px 8px; border-radius: 999px; font-weight: 600; }

.pill {
  display: inline-block; font-size: 13px; font-weight: 700; padding: 5px 11px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink); text-decoration: none; white-space: nowrap;
}
.tag { background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 0 8px; font-size: 12px; font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 22px 12px; }
.empty .big { font-size: 34px; margin-bottom: 4px; }

/* ============ Hoy ============ */
.cover { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 18px; }
.cover-day { font-family: var(--hand); font-size: 72px; line-height: .9; color: var(--ink); font-weight: 700; }
.cover-wd { font-size: 20px; font-weight: 800; }
.quote {
  flex-basis: 100%; margin: 10px 0 0; padding-top: 10px; border-top: 1px dashed var(--line);
  font-family: var(--hand); font-size: 22px; color: var(--muted); line-height: 1.2;
}
html[data-font=serif] .quote { font-size: 16px; font-style: italic; }
html[data-font=simple] .quote { font-size: 15px; }

.quick {
  display: flex; gap: 6px; align-items: center; background: var(--card);
  border-radius: 999px; padding: 5px; box-shadow: var(--shadow);
}
.quick input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 4px; font-size: 16px; outline: none; }
.quick .kind { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; flex: none; }
.quick .add { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: 24px; line-height: 1; flex: none; }
.legend { font-size: 12px; color: var(--muted); margin: 6px 14px 10px; }

.now-row { display: flex; gap: 10px; overflow-x: auto; padding: 2px 1px 8px; scrollbar-width: none; }
.now { display: flex; gap: 10px; align-items: center; min-width: 200px; max-width: 260px; }
.now > span { font-size: 28px; }

/* ============ Registro (bullets) ============ */
.log { padding: 4px 14px; }
.log-row { display: flex; gap: 8px; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.log-row:last-child { border-bottom: 0; }
.log-row .body { flex: 1; min-width: 0; }
.bullet {
  flex: none; width: 28px; height: 28px; margin-top: -2px;
  display: grid; place-items: center; color: var(--ink); font-weight: 800;
}
.bullet::before { content: ''; display: block; }
.bullet.task { border-radius: 50%; }
.bullet.task::before { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.bullet.task.done::before { content: '✕'; width: auto; height: auto; background: none; font-size: 17px; }
.bullet.event::before { width: 11px; height: 11px; border-radius: 50%; border: 2px solid currentColor; }
.bullet.note::before { width: 13px; height: 2.5px; border-radius: 2px; background: currentColor; }
.log-row.done .t-title { text-decoration: line-through; color: var(--muted); }
.log-row.k-note .t-title { font-weight: 500; }
.t-title { font-weight: 700; overflow-wrap: anywhere; }
.t-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 2px; }
.late { color: #d9784a; font-weight: 700; }

/* ============ Ánimo ============ */
.mood-card { cursor: pointer; }
.mood-pick { display: flex; justify-content: space-between; margin-top: 12px; gap: 4px; }
.mood-pick button {
  font-size: 30px; width: 54px; height: 54px; border-radius: 50%;
  background: color-mix(in srgb, var(--mc) 35%, var(--card));
  transition: transform .15s;
}
.mood-pick button:active { transform: scale(.9); }
.mood-pick button.on { box-shadow: 0 0 0 3px var(--mc); transform: scale(1.08); }
.mood-card.filled { display: flex; gap: 14px; align-items: flex-start; border-left: 6px solid var(--mc); }
.mood-big { font-size: 40px; line-height: 1; }
.mood-card .body { flex: 1; min-width: 0; }

.year-head { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 4px 0 10px; }
.year-head strong { font-family: var(--hand); font-size: 32px; color: var(--ink); }
html[data-font=serif] .year-head strong, html[data-font=simple] .year-head strong { font-size: 22px; }
.pixels { display: grid; grid-template-columns: 20px repeat(12, 1fr); gap: 3px; font-size: 10px; }
.pixels .lbl { color: var(--muted); text-align: center; line-height: 14px; font-weight: 700; }
.px { height: 14px; border-radius: 4px; background: var(--line); }
.px.na { background: transparent; }
.px.future { opacity: .35; }
.px.today { box-shadow: 0 0 0 2px var(--ink); }
.mood-legend { display: flex; justify-content: space-between; margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; }
.mood-legend i { display: block; width: 18px; height: 18px; border-radius: 5px; margin: 0 auto 3px; }
.dist { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--line); margin: 10px 0 4px; }
.dist i { display: block; height: 100%; }
.stat-row { display: flex; gap: 10px; }
.stat-row .card { text-align: center; padding: 12px 6px; }
.stat-row b { display: block; font-size: 24px; line-height: 1.2; }
.stat-row span { font-size: 12px; color: var(--muted); }

/* ============ Calendario ============ */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head strong { font-family: var(--hand); font-size: 27px; color: var(--ink); white-space: nowrap; }
html[data-font=serif] .cal-head strong, html[data-font=simple] .cal-head strong { font-size: 21px; }
.cal-head button { font-size: 24px; width: 38px; height: 38px; border-radius: 50%; color: var(--ink); }
.cal-head button:active { background: var(--accent-soft); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid .dow { font-size: 12px; color: var(--muted); padding-bottom: 4px; font-weight: 700; }
.day {
  aspect-ratio: 1; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
}
.day.mood { background: color-mix(in srgb, var(--mc) 45%, transparent); }
.day.other { opacity: .35; }
.day.today { color: var(--ink); font-weight: 900; text-decoration: underline wavy color-mix(in srgb, var(--accent) 60%, transparent); text-underline-offset: 3px; }
.day.sel { background: var(--accent); color: var(--on-accent); text-decoration: none; }
.day.sel.mood { box-shadow: inset 0 0 0 3px var(--mc); }
.day .dots { display: flex; gap: 2px; height: 5px; margin-top: 2px; }
.day .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--ink); }
.day .dots i.done { opacity: .35; }
.day.sel .dots i { background: var(--on-accent); }

/* ============ Biblioteca y deseos ============ */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 8px; }
.stats .card { text-align: center; padding: 12px 6px; }
.stats b { display: block; font-size: 24px; line-height: 1.2; color: var(--ink); }
.stats span { font-size: 12px; color: var(--muted); }
.item { display: flex; gap: 12px; cursor: pointer; }
.item .emoji {
  flex: none; width: 54px; height: 72px; border-radius: 6px 12px 12px 6px;
  background: var(--accent-soft); display: grid; place-items: center; font-size: 28px;
  border-left: 5px solid color-mix(in srgb, var(--accent) 55%, var(--card));
}
.item.wish .emoji { height: 54px; border-radius: 14px; border-left: 0; }
.item .body { flex: 1; min-width: 0; }
.stars { color: #f2b33d; letter-spacing: 1px; }
.stars .off, .hearts .off { color: var(--line); }
.hearts { color: var(--accent); letter-spacing: 1px; }
.review {
  margin-top: 6px; font-size: 14px; opacity: .85; font-style: italic;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.status { font-size: 12px; font-weight: 800; }
.status.s-done { color: #4f9a74; }
.status.s-doing { color: var(--ink); }
.status.s-todo { color: var(--muted); }
.price { font-weight: 800; color: var(--text); }
.wish-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.item.got .t-title { text-decoration: line-through; text-decoration-color: var(--accent); }

/* ============ Navegación ============ */
nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav button { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 10.5px; font-weight: 700; color: var(--muted); padding: 3px 0; }
nav button span { font-size: 22px; line-height: 1.25; filter: grayscale(1); opacity: .55; transition: transform .15s; }
nav button.on { color: var(--ink); }
nav button.on span { filter: none; opacity: 1; transform: translateY(-2px) scale(1.1); }

.fab {
  position: fixed; right: 18px; z-index: 11;
  bottom: calc(80px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* ============ Hoja (formularios) ============ */
.backdrop {
  position: fixed; inset: 0; background: rgb(20 10 15 / .42); z-index: 20;
  display: none; align-items: flex-end; justify-content: center;
}
.backdrop.open { display: flex; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px;
  border-radius: 24px 24px 0 0; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 16px calc(22px + env(safe-area-inset-bottom));
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 12px; font-family: var(--hand); font-size: 34px; color: var(--ink); line-height: 1.1; }
html[data-font=serif] .sheet h3, html[data-font=simple] .sheet h3 { font-size: 24px; }
.sheet h4 { margin: 22px 2px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 12px 2px 4px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 16px; /* 16px evita el zoom automático de iOS */
  -webkit-appearance: none; appearance: none; outline-color: var(--accent);
}
textarea { min-height: 110px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > div { flex: 1; min-width: 0; }
.star-input { display: flex; gap: 6px; font-size: 36px; }
.star-input button { color: var(--line); line-height: 1; }
.star-input button.on { color: #f2b33d; }
.star-input.hearts-in button.on { color: var(--accent); }
.actions { display: flex; gap: 10px; margin-top: 22px; }
.btn { flex: 1; padding: 13px; border-radius: 14px; font-weight: 800; background: var(--card); box-shadow: var(--shadow); text-align: center; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { color: #c9425d; flex: 0 0 auto; padding: 13px 16px; }
.btn.full { width: 100%; display: block; }

/* Ajustes */
.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.swatch {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 14px;
  background: var(--card); border: 2px solid transparent; font-weight: 700; font-size: 14px; text-align: left;
}
.swatch.on { border-color: var(--accent); }
.swatch i {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  box-shadow: 0 0 0 3px var(--sp) inset, 0 0 0 1px rgb(0 0 0 / .08);
}
.colors { display: flex; gap: 10px; }
.colors label { flex: 1; text-align: center; margin: 0; background: var(--card); border-radius: 14px; padding: 10px 4px; }
input[type=color] {
  -webkit-appearance: none; appearance: none; border: 0; padding: 0; background: none;
  width: 44px; height: 44px; border-radius: 50%; display: block; margin: 0 auto 4px; cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 2px solid var(--line); border-radius: 50%; }
input[type=color]::-moz-color-swatch { border: 2px solid var(--line); border-radius: 50%; }
.note-box { background: var(--card); border-radius: 14px; padding: 12px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 700; opacity: 0; transition: opacity .2s; pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* Ajustes de tamaño */
.stat-row .card, .stats .card { flex: 1; min-width: 0; width: auto; }
.stat-row b.txt { font-size: 16px; line-height: 1.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-row .card { width: auto; }
html[data-mode=dark] h2 span { background: linear-gradient(transparent 62%, color-mix(in srgb, var(--accent2) 30%, transparent) 62%); }
@media (prefers-color-scheme: dark) {
  html[data-mode=auto] h2 span { background: linear-gradient(transparent 62%, color-mix(in srgb, var(--accent2) 30%, transparent) 62%); }
}

/* ============ Portadas ============ */
.item .emoji { width: 60px; height: 90px; }
.item.wish .emoji { width: 54px; height: 54px; }
.item .emoji, .cover-prev, .now .thumb { position: relative; overflow: hidden; }
.item .emoji img, .cover-prev img, .now .thumb img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.now .thumb {
  flex: none; width: 40px; height: 60px; border-radius: 4px 8px 8px 4px;
  background: var(--accent-soft); display: grid; place-items: center; font-size: 22px;
}
.cover-edit { display: flex; gap: 14px; align-items: center; }
.cover-prev {
  flex: none; width: 84px; height: 126px; border-radius: 6px 12px 12px 6px;
  background: var(--accent-soft); display: grid; place-items: center; font-size: 34px;
  box-shadow: var(--shadow); border-left: 5px solid color-mix(in srgb, var(--accent) 55%, var(--card));
}
.cover-btns { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.cover-btns .pill { font-size: 14px; padding: 7px 13px; }
.cover-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 10px; margin: 14px 0 6px; }
.cover-grid button { text-align: left; font-size: 12px; line-height: 1.25; min-width: 0; }
.cover-grid img {
  display: block; width: 100%; aspect-ratio: 2 / 3; object-fit: cover; margin-bottom: 5px;
  border-radius: 4px 8px 8px 4px; background: var(--accent-soft); box-shadow: var(--shadow);
}
.cover-grid button:active img { outline: 3px solid var(--accent); }
.cover-grid span { font-weight: 800; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cover-grid small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cover-grid img { animation: cargando 1.2s ease-in-out infinite alternate; }
@keyframes cargando { from { opacity: .55; } to { opacity: 1; } }
.cover-grid img.ok { animation: none; }
.cover-btns [hidden] { display: none; }
