/* ───────────── Diario · stile ───────────── */
:root {
  --bg: #f6f1e9;
  --surface: #fffdf9;
  --surface-2: #efe8dd;
  --ink: #2a2420;
  --ink-soft: #5d544c;
  --muted: #998d81;
  --line: #e4dacc;
  --accent: #b5562f;
  --accent-ink: #fffaf4;
  --accent-soft: #f3dccd;
  --shadow: 0 1px 2px rgb(60 40 20 / .05), 0 8px 24px -12px rgb(60 40 20 / .18);
  --mood-1: #9aa7c7;
  --mood-2: #b9c3d6;
  --mood-3: #e5d7a8;
  --mood-4: #f0bd7d;
  --mood-5: #e8875a;
  --serif: "Iowan Old Style", "New York", "Charter", "Source Serif Pro", "Noto Serif", Georgia, ui-serif, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 18px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1715;
    --surface: #24201d;
    --surface-2: #2e2925;
    --ink: #efe7dc;
    --ink-soft: #c9bdaf;
    --muted: #8c8175;
    --line: #39332d;
    --accent: #e48a5e;
    --accent-ink: #1e1410;
    --accent-soft: #4a3023;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 30px -14px rgb(0 0 0 / .6);
    --mood-1: #5c6788;
    --mood-2: #6f7a91;
    --mood-3: #8f8458;
    --mood-4: #b0804a;
    --mood-5: #c86a40;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.shell {
  max-width: 640px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 20px)
    max(18px, env(safe-area-inset-right))
    calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 32px)
    max(18px, env(safe-area-inset-left));
}

.is-centered .shell { min-height: 100dvh; display: grid; place-items: center; }
.is-login .shell { padding-bottom: 32px; }

/* ── Testata ── */
.masthead { margin: 4px 0 22px; }
.masthead__row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

.eyebrow {
  margin: 0 0 4px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.streak { color: var(--accent); letter-spacing: .04em; }

.date-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(30px, 8vw, 40px);
  line-height: 1.08;
  letter-spacing: -.015em;
}
.date-title::first-letter { text-transform: uppercase; }

/* ── Bottoni ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px;
  border: 0; border-radius: 999px;
  font: 600 15px/1 var(--sans);
  text-decoration: none; cursor: pointer;
  transition: transform .12s ease, background .2s ease, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 16px -8px var(--accent); }
.btn--primary:disabled { opacity: .6; }
.btn--ghost { background: var(--surface-2); color: var(--ink); }
.btn--block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow); text-decoration: none;
}
.icon-btn.is-disabled { visibility: hidden; }

.link-quiet {
  font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none;
  padding: 8px 4px;
}

/* ── Scrittura ── */
.compose {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 12px;
  border: 1px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.compose:focus-within { border-color: var(--accent-soft); }

.compose-input, .edit-input {
  display: block; width: 100%;
  border: 0; outline: 0; resize: none;
  background: transparent; color: var(--ink);
  font-family: var(--serif);
  font-size: 19px; line-height: 1.6;
  min-height: 7.5em;
  max-height: 55dvh;
  overflow-y: auto;
}
.compose-input::placeholder { color: var(--muted); font-style: italic; }

.compose__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.compose__hint { font-size: 12.5px; color: var(--muted); }

.compose__tools, .edit-form__tools { display: flex; align-items: center; gap: 10px; min-width: 0; }
.edit-form__tools { margin-top: 8px; }

/* ── Emoji ── */
.emoji-toggle {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--surface-2); font-size: 20px; line-height: 1; cursor: pointer;
  transition: transform .12s, background .15s;
}
.emoji-toggle:active { transform: scale(.92); }
.emoji-toggle.is-active { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.emoji-panel {
  margin-top: 10px; padding: 4px 8px 10px;
  max-height: 260px; overflow-y: auto; overscroll-behavior: contain;
  border-top: 1px solid var(--line);
}
.emoji-panel__title {
  margin: 10px 4px 4px; font-size: 11.5px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.emoji-panel__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
.emoji-panel__item {
  height: 42px; border: 0; border-radius: 10px; background: none;
  font-size: 24px; line-height: 1; cursor: pointer;
}
.emoji-panel__item:hover { background: var(--surface-2); }
.emoji-panel__item:active { transform: scale(.88); }

.form-error { color: #c0392b; font-size: 14px; margin: 8px 0 0; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 2px 0; }

/* ── Umore ── */
.mood-picker {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 14px 2px 22px;
}
.mood-picker__label { font-size: 12.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.mood-picker__options { display: flex; gap: 6px; }
.mood-btn {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1.5px solid transparent;
  background: var(--surface-2);
  font-size: 22px; line-height: 1; color: var(--muted);
  cursor: pointer;
  filter: grayscale(.7); opacity: .75;
  transition: transform .15s ease, filter .2s, opacity .2s, border-color .2s, background .2s;
}
.mood-btn:active { transform: scale(.9); }
.mood-btn.is-selected { filter: none; opacity: 1; background: var(--accent-soft); border-color: var(--accent); transform: scale(1.06); }
.mood-btn input { position: absolute; opacity: 0; pointer-events: none; }
.mood-btn--none { font-size: 18px; font-weight: 600; }
.mood-picker--inline { margin: 0 0 16px; flex-wrap: wrap; }

/* ── Pagina del giorno ── */
.sheet {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px 24px;
  background-image: linear-gradient(to right, transparent 0, transparent 30px, var(--accent-soft) 30px, var(--accent-soft) 31px, transparent 31px);
  background-size: 100% 100%;
  padding-left: 46px;
}
.sheet__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet__meta { font-size: 12.5px; color: var(--muted); }

.prose {
  font-family: var(--serif);
  font-size: 18.5px;
  line-height: 1.7;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.prose p { margin: 0 0 1em; }
.prose p:last-child { margin-bottom: 0; }

/* ── Stati vuoti ── */
.empty { text-align: center; padding: 28px 12px; }
.sheet .empty { padding: 18px 0 10px; margin-left: -24px; }
.empty__icon { font-size: 44px; margin: 0; }
.empty__title { font-family: var(--serif); font-size: 21px; font-weight: 600; margin: 0 0 6px; }
.empty__text { color: var(--ink-soft); margin: 0 auto 16px; max-width: 34ch; }
.empty--hero { max-width: 420px; }

/* ── Archivio ── */
.stats { display: flex; gap: 10px; margin-top: 16px; }
.stat {
  flex: 1; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow);
}
.stat__num { font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1.1; }
.stat__label { font-size: 12.5px; color: var(--muted); }

.month-group { margin-bottom: 22px; }
.month-group__title {
  position: sticky; top: 0; z-index: 2;
  margin: 0 -4px 8px; padding: calc(env(safe-area-inset-top) + 8px) 4px 8px;
  background: linear-gradient(var(--bg) 75%, transparent);
  font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft);
}

.day-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.day-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
  transition: transform .12s ease;
}
.day-card:active { transform: scale(.985); }
.day-card__date { display: flex; flex-direction: column; align-items: center; min-width: 44px; }
.day-card__num { font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1; }
.day-card__dow { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.day-card__body { flex: 1; min-width: 0; border-left: 1px solid var(--line); padding-left: 14px; }
.day-card__excerpt {
  margin: 0; font-family: var(--serif); font-size: 15.5px; line-height: 1.45; color: var(--ink-soft);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.day-card__excerpt.is-muted { font-style: italic; color: var(--muted); }
.day-card__mood { font-size: 22px; }
.day-card--result .day-card__excerpt { -webkit-line-clamp: 4; }

mark { background: var(--accent-soft); color: var(--ink); border-radius: 3px; padding: 0 2px; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 22px; }
.pager__info { font-size: 13px; color: var(--muted); }

/* ── Calendario ── */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.month-nav .date-title { font-size: clamp(26px, 7vw, 34px); text-align: center; }

.cal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 10px 12px; }
.cal__head, .cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal__head { margin-bottom: 8px; }
.cal__head span { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .05em; }
.cal__cell {
  position: relative; aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border-radius: 12px;
  color: var(--ink); text-decoration: none;
  background: var(--surface-2);
  transition: transform .12s;
}
.cal__cell:active { transform: scale(.93); }
.cal__num { font-size: 14px; font-weight: 600; line-height: 1; }
.cal__mood { font-size: 15px; line-height: 1; }
.cal__dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal__cell.is-outside { opacity: .35; }
.cal__cell.is-future { background: transparent; color: var(--muted); }
.cal__cell.has-text { background: var(--accent-soft); }
.cal__cell.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal__cell.mood-1, .legend__swatch.mood-1 { background: var(--mood-1); }
.cal__cell.mood-2, .legend__swatch.mood-2 { background: var(--mood-2); }
.cal__cell.mood-3, .legend__swatch.mood-3 { background: var(--mood-3); }
.cal__cell.mood-4, .legend__swatch.mood-4 { background: var(--mood-4); }
.cal__cell.mood-5, .legend__swatch.mood-5 { background: var(--mood-5); }
.cal__cell[class*="mood-"] { color: #2a2420; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; margin-top: 16px; font-size: 12.5px; color: var(--ink-soft); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__swatch { width: 12px; height: 12px; border-radius: 4px; }

/* ── Ricerca ── */
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow);
  padding: 0 18px; margin-bottom: 18px; color: var(--muted);
}
.search-box input {
  flex: 1; min-width: 0; height: 52px;
  border: 0; outline: 0; background: transparent; color: var(--ink);
  font: 17px var(--sans);
}
.search-box input::-webkit-search-cancel-button { filter: grayscale(1); }
.result-count { font-size: 13px; color: var(--muted); margin: 0 4px 12px; }

/* ── Modifica ── */
.edit-form {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.edit-input { min-height: 16em; max-height: none; }
.edit-form__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ── Accesso ── */
.login { width: min(100%, 360px); text-align: center; }
.login__logo { border-radius: 20px; box-shadow: var(--shadow); margin-bottom: 14px; }
.login__sub { color: var(--ink-soft); margin: 8px 0 26px; font-family: var(--serif); font-style: italic; }
.login__form { display: grid; gap: 14px; text-align: left; }
.field { display: grid; gap: 6px; }
.field span { font-size: 12.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field input {
  height: 50px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink);
  font: 17px var(--sans); outline: 0;
}
.field input:focus { border-color: var(--accent); }

/* ── Barra in basso ── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 max(8px, env(safe-area-inset-left)) env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px -12px rgb(60 40 20 / .25);
}
.tab {
  flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-soft); text-decoration: none;
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
  transition: color .15s, background .15s;
}
.tab svg {
  width: 48px; height: 30px; padding: 4px 13px; border-radius: 999px;
  transition: background .15s;
}
.tab.is-active { color: var(--accent); }
.tab.is-active svg { stroke-width: 2.2; background: var(--accent-soft); }

/* Schermi larghi: la navigazione sta in alto, con pulsanti ben visibili. */
@media (min-width: 720px) {
  .shell { padding-top: calc(var(--tabbar-h) + 28px); padding-bottom: 40px; }
  .tabbar {
    top: 0; bottom: auto; gap: 6px; align-items: center;
    height: var(--tabbar-h); padding: 0 16px;
    border-top: 0; border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 20px -14px rgb(60 40 20 / .3);
  }
  .tab {
    flex: none; max-width: none; flex-direction: row; gap: 8px;
    height: 42px; padding: 0 18px; border-radius: 999px;
    font-size: 15px;
  }
  .tab svg, .tab.is-active svg { width: 20px; height: 20px; padding: 0; background: none; }
  .tab:hover { background: var(--surface-2); color: var(--ink); }
  .tab.is-active { background: var(--accent-soft); color: var(--accent); }
  .month-group__title { top: var(--tabbar-h); padding-top: 8px; }
  .toasts { top: calc(var(--tabbar-h) + 12px); }
}

/* Con la tastiera aperta (iOS/Android) la barra non deve coprire il testo. */
@media (max-width: 719px) and (max-height: 480px) { .is-home .tabbar { display: none; } }

/* ── Notifiche ── */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 12px); z-index: 20;
  display: grid; gap: 8px; pointer-events: none;
}
.toast {
  padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: toast-in .3s ease both;
  transition: opacity .5s, transform .5s;
}
.toast.is-hiding { opacity: 0; transform: translateY(-8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }

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