:root {
  --bg: #f7f0e8;
  --surface: #fffaf5;
  --surface-2: #f0e2d3;
  --surface-3: #ead7c3;
  --text: #432f25;
  --muted: #806b5e;
  --accent: #7a563f;
  --accent-2: #9b7456;
  --border: #dfcdbd;
  --success: #6f7d5c;
  --danger: #9d5d52;
  --shadow: 0 16px 40px rgba(86, 55, 36, .10);
  --radius: 24px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% -10%, rgba(209, 174, 140, .22), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 500; }

.config-warning {
  position: fixed;
  inset: 0 0 auto;
  z-index: 100;
  padding: 10px 16px;
  background: #5d4031;
  color: #fff8f1;
  text-align: center;
  font-size: 13px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}
.auth-card {
  width: min(100%, 430px);
  padding: 34px;
  background: rgba(255, 250, 245, .94);
  border: 1px solid rgba(223, 205, 189, .9);
  border-radius: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.brand-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: var(--surface-2);
  font-size: 36px;
}
.auth-card h1 { margin: 0; font-size: 34px; letter-spacing: -.04em; }
.auth-subtitle { margin: 8px 0 24px; color: var(--muted); line-height: 1.5; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 5px;
  background: #efe2d5;
  border-radius: 16px;
  margin-bottom: 20px;
}
.auth-tab {
  border: 0;
  border-radius: 12px;
  padding: 10px;
  background: transparent;
  cursor: pointer;
}
.auth-tab.active { background: var(--surface); box-shadow: 0 4px 14px rgba(86, 55, 36, .08); font-weight: 700; }
.auth-form { display: grid; gap: 14px; text-align: left; }
.auth-form label, .task-form label { display: grid; gap: 7px; font-size: 14px; color: var(--muted); }
.auth-link-btn {
  justify-self: end;
  margin-top: -6px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.auth-link-btn:disabled { opacity: .55; cursor: default; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fffdf9;
  color: var(--text);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(155,116,86,.12); }
textarea { resize: vertical; min-height: 108px; }

.primary-btn, .soft-btn, .ghost-btn, .icon-btn, .round-add {
  border: 0;
  cursor: pointer;
  transition: transform .16s ease, opacity .16s ease, background .16s ease;
}
.primary-btn:active, .soft-btn:active, .ghost-btn:active, .icon-btn:active, .round-add:active { transform: scale(.97); }
.primary-btn {
  min-height: 48px;
  border-radius: 16px;
  background: var(--accent);
  color: #fffaf5;
  padding: 12px 18px;
  font-weight: 750;
}
.soft-btn {
  border-radius: 14px;
  background: var(--surface-2);
  padding: 10px 13px;
  font-weight: 650;
}
.ghost-btn { background: transparent; color: var(--accent); padding: 10px; }
.lang-btn { margin-top: 14px; }
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--surface-2);
  font-weight: 800;
  font-size: 17px;
}
.round-add {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 25px;
  line-height: 1;
}
.form-message { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.form-message.success { color: var(--success); }
.center { text-align: center; }

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 10px 16px calc(104px + var(--safe-bottom));
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 8px;
  background: linear-gradient(var(--bg) 78%, rgba(247,240,232,0));
}
.topbar-actions { display: flex; gap: 8px; }
.eyebrow, .section-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.app-title { margin: 0; font-size: 25px; letter-spacing: -.03em; }
.screen { display: none; animation: fade .18s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: .55; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.date-row, .screen-title-row, .card-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.date-row, .screen-title-row { margin: 2px 0 12px; }
h2, h3 { margin: 0; letter-spacing: -.025em; }
h2 { font-size: 27px; }
h3 { font-size: 20px; }

.card {
  background: rgba(255, 250, 245, .94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 9px 30px rgba(92, 62, 42, .06);
  margin-bottom: 14px;
}
.state-card { background: linear-gradient(145deg, #fffaf5, #f1e1d0); }
.mood-face { width: 76px; height: 76px; object-fit: contain; filter: drop-shadow(0 8px 10px rgba(90, 56, 35, .08)); }
.mood-slider {
  appearance: none;
  height: 8px;
  padding: 0;
  margin: 20px 0 8px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #b88a73, #c5a27f, #8f765a);
}
.mood-slider::-webkit-slider-thumb {
  appearance: none;
  width: 27px;
  height: 27px;
  border: 4px solid #fffaf5;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 4px 14px rgba(75,53,39,.24);
}
.mood-slider::-moz-range-thumb {
  width: 21px;
  height: 21px;
  border: 4px solid #fffaf5;
  border-radius: 50%;
  background: var(--accent);
}
.scale-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.tiny-note { color: var(--muted); font-size: 12px; white-space: nowrap; }

.emotion-families { display: grid; gap: 12px; margin-top: 16px; }
.emotion-family {
  padding: 12px;
  border-radius: 18px;
  background: #fbf5ef;
  border: 1px solid #eadbcc;
}
.emotion-family-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.emotion-family-icon { width: 34px; height: 34px; flex: 0 0 auto; }
.emotion-family-dot { width: 13px; height: 13px; border-radius: 50%; flex: 0 0 auto; }
.emotion-family-name { font-weight: 800; }
.emotion-levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.emotion-chip {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: white;
  cursor: pointer;
  padding: 8px 6px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.15;
}
.emotion-chip small { display: none; }
.emotion-chip.active { border-color: transparent; color: #3f2c23; box-shadow: inset 0 0 0 2px rgba(255,255,255,.65); font-weight: 800; }

.task-list { display: grid; gap: 8px; margin-top: 14px; }
.task-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  background: #fffdf9;
  border: 1px solid var(--border);
  border-radius: 16px;
}
.task-check {
  width: 24px;
  height: 24px;
  border: 2px solid var(--task-color, var(--accent));
  border-radius: 8px;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: white;
  font-size: 15px;
  padding: 0;
}
.task-check.done { background: var(--task-color, var(--accent)); }
.task-title { font-weight: 750; }
.task-title.done { text-decoration: line-through; opacity: .55; }
.task-meta { display: flex; align-items: center; gap: 7px; margin-top: 3px; color: var(--muted); font-size: 11px; }
.task-color-bar { width: 18px; height: 5px; border-radius: 999px; background: var(--task-color); }
.task-delete { border: 0; background: transparent; color: #9b7a68; cursor: pointer; font-size: 20px; padding: 6px; }
.empty-state { margin: 14px 0 0; color: var(--muted); text-align: center; font-size: 14px; }
.note-label { display: block; margin-bottom: 10px; font-weight: 800; }
.sticky-save { width: 100%; margin-top: 4px; }

.calendar-card { padding: 14px; }
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar-weekdays { margin-bottom: 7px; color: var(--muted); text-align: center; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.calendar-day {
  position: relative;
  aspect-ratio: 1;
  min-height: 46px;
  border: 0;
  border-radius: 15px;
  background: #fffdf9;
  color: var(--text);
  cursor: pointer;
}
.calendar-day.outside { opacity: .30; }
.calendar-day.today { box-shadow: inset 0 0 0 2px #c3a184; }
.calendar-day.selected { background: var(--accent); color: white; }
.calendar-day .day-number { font-weight: 750; }
.calendar-dots { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); display: flex; gap: 3px; }
.calendar-dot { width: 4px; height: 4px; border-radius: 50%; background: #bb8c68; }
.calendar-day.selected .calendar-dot { background: #f8e7d8; }
.month-nav { display: flex; gap: 7px; }

.segmented { display: flex; background: #eadccc; padding: 4px; border-radius: 14px; }
.segment { border: 0; background: transparent; padding: 8px 11px; border-radius: 10px; cursor: pointer; font-size: 12px; }
.segment.active { background: #fffaf5; font-weight: 800; box-shadow: 0 3px 12px rgba(80,55,40,.08); }
.chart-card { overflow: hidden; }
#moodChart { width: 100%; display: block; }
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.metric-card {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 15px;
  border-radius: 20px;
  background: #efe0d1;
  border: 1px solid #ddc7b5;
}
.metric-card span { color: var(--muted); font-size: 12px; line-height: 1.25; }
.metric-card strong { font-size: 27px; letter-spacing: -.04em; }
.bar-list { display: grid; gap: 10px; margin-top: 14px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; align-items: center; gap: 8px; font-size: 13px; }
.bar-track { height: 9px; background: #eadfd3; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; min-width: 4px; }

.info-card { color: var(--muted); font-size: 13px; line-height: 1.55; }
.info-card p { margin: 0; }
.correlation-list { display: grid; gap: 12px; }
.correlation-card {
  padding: 16px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: #fffaf5;
}
.correlation-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.correlation-head h3 { font-size: 17px; }
.correlation-r { font-size: 28px; font-weight: 850; letter-spacing: -.04em; }
.correlation-meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.correlation-meta div { padding: 9px; background: #f3e7dc; border-radius: 13px; }
.correlation-meta span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 3px; }
.correlation-meta strong { font-size: 14px; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(10px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 30;
  width: min(calc(100% - 24px), 720px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 7px;
  background: rgba(255, 250, 245, .94);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(214, 194, 177, .9);
  border-radius: 24px;
  box-shadow: 0 15px 42px rgba(71,48,34,.16);
}
.nav-btn {
  min-height: 56px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 0;
  border-radius: 17px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}
.nav-btn span { font-size: 20px; line-height: 1; }
.nav-btn small { font-size: 10px; }
.nav-btn.active { background: var(--surface-2); color: var(--accent); font-weight: 800; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: end center;
  background: rgba(52, 35, 26, .36);
  padding: 18px;
}
.modal-card {
  width: min(100%, 560px);
  max-height: 88vh;
  overflow: auto;
  padding: 20px;
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.task-form { display: grid; gap: 14px; margin-top: 18px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { margin-bottom: 9px; color: var(--muted); font-size: 14px; }
.color-picker { display: flex; flex-wrap: wrap; gap: 9px; }
.color-swatch {
  width: 36px;
  height: 36px;
  border: 3px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(65,46,34,.08);
}
.color-swatch.active { border-color: #fffaf5; box-shadow: 0 0 0 2px var(--accent); }

@media (min-width: 700px) {
  .app-shell { padding-top: 26px; }
  .emotion-families { grid-template-columns: repeat(2, 1fr); }
  .modal-backdrop { place-items: center; }
}

@media (max-width: 420px) {
  .auth-card { padding: 28px 20px; }
  .app-shell { padding-inline: 12px; }
  .card { padding: 15px; border-radius: 21px; }
  .emotion-chip { font-size: 11px; padding-inline: 3px; }
  .tiny-note { white-space: normal; text-align: right; }
  .two-col { grid-template-columns: 1fr; }
  .correlation-meta { grid-template-columns: 1fr; }
}

/* MoodDay v2: compact emotions, diary, task library */
.calendar-top-btn {
  background: #ead7c3;
  color: var(--accent);
  font-size: 20px;
}

/* Horizontal, collapsible emotion wheel families */
.emotion-card { overflow: hidden; }
.emotion-families {
  display: block;
  margin-top: 12px;
  min-width: 0;
}
.emotion-strip {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding: 2px 2px 6px;
  margin-inline: -2px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.emotion-strip::-webkit-scrollbar { display: none; }
.emotion-family-pill {
  --emotion-color: #9b7456;
  flex: 0 0 108px;
  min-height: 76px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  position: relative;
  border: 1px solid #eadbcc;
  border-radius: 18px;
  background: #fbf5ef;
  cursor: pointer;
  scroll-snap-align: center;
  padding: 9px 10px;
  text-align: center;
}
.emotion-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--emotion-color);
  display: block;
}
.emotion-family-pill .emotion-family-name { font-size: 12px; font-weight: 800; line-height: 1.1; }
.emotion-family-pill small { display: block; color: var(--muted); font-size: 10px; line-height: 1.25; }
.emotion-family-pill.selected { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--emotion-color) 55%, white); }
.emotion-family-pill.open {
  background: color-mix(in srgb, var(--emotion-color) 16%, #fffaf5);
  border-color: color-mix(in srgb, var(--emotion-color) 48%, #eadbcc);
}
.emotion-subtypes {
  --emotion-color: #9b7456;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 9px;
  padding: 11px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--emotion-color) 10%, #fbf5ef);
  border: 1px solid color-mix(in srgb, var(--emotion-color) 28%, #eadbcc);
  animation: fade .16s ease;
}
.emotion-subtypes .emotion-chip {
  min-height: 52px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 10px 8px;
}
.emotion-subtypes .emotion-chip.active {
  background: color-mix(in srgb, var(--emotion-color) 28%, white);
  border-color: var(--emotion-color);
}

/* Diary grid: intentionally Instagram-like 3 columns */
.diary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 4px;
}
.diary-tile {
  min-width: 0;
  aspect-ratio: .88;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #fffaf5;
  color: var(--text);
  cursor: pointer;
  padding: 9px 7px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(86,55,36,.05);
}
.diary-tile.mood-level-1 { background: #eee0d8; }
.diary-tile.mood-level-2 { background: #f0e2d8; }
.diary-tile.mood-level-3 { background: #f4e9de; }
.diary-tile.mood-level-4 { background: #f3e6d0; }
.diary-tile.mood-level-5 { background: #efe1c7; }
.diary-tile > img { width: 42px; height: 42px; object-fit: contain; }
.diary-tile > strong { font-size: 19px; line-height: 1; }
.diary-tile > strong small { font-size: 9px; color: var(--muted); font-weight: 700; }
.diary-tile p {
  width: 100%;
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.22;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-align: center;
}
.diary-date {
  position: absolute;
  top: 7px;
  left: 8px;
  display: flex;
  align-items: baseline;
  gap: 3px;
}
.diary-date b { font-size: 12px; }
.diary-date small { color: var(--muted); font-size: 8px; text-transform: uppercase; }
.diary-empty { margin-top: 40px; }

/* Day detail */
.day-detail-body { display: grid; gap: 14px; margin-top: 18px; }
.day-mood-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 20px;
  background: #f2e4d7;
}
.day-mood-summary img { width: 60px; height: 60px; object-fit: contain; }
.day-mood-summary span { display: block; color: var(--muted); font-size: 11px; }
.day-mood-summary strong { display: block; margin-top: 2px; font-size: 28px; }
.day-mood-summary strong small { font-size: 12px; color: var(--muted); }
.day-emotions { display: flex; flex-wrap: wrap; gap: 7px; }
.day-emotion-chip {
  padding: 7px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--chip-color) 20%, white);
  border: 1px solid color-mix(in srgb, var(--chip-color) 36%, #eadbcc);
  font-size: 12px;
  font-weight: 700;
}
.day-note-block, .day-tasks-block { padding: 13px; border: 1px solid var(--border); border-radius: 18px; background: #fffdf9; }
.day-note-block > span, .day-section-heading > span { font-size: 11px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.day-note-block p { margin: 7px 0 0; white-space: pre-wrap; line-height: 1.5; font-size: 14px; }
.day-section-heading { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 8px; }
.day-section-heading small { color: var(--muted); font-size: 10px; }
.day-task-row { display: grid; grid-template-columns: 20px 1fr auto; gap: 7px; align-items: center; padding: 7px 0; border-top: 1px solid #efe4d9; font-size: 12px; }
.day-task-row:first-of-type { border-top: 0; }
.day-task-row.done b { text-decoration: line-through; opacity: .55; }
.day-task-row small { color: var(--muted); }
.day-muted { color: var(--muted); font-size: 12px; margin: 7px 0 0; }
.day-modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 16px; }
.danger-btn {
  border: 0;
  border-radius: 14px;
  background: #f2dfdc;
  color: var(--danger);
  padding: 10px 13px;
  font-weight: 750;
  cursor: pointer;
}

/* Task template library */
.task-modal-card { max-height: 91vh; }
.picker-label { margin: 0 0 9px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.picker-heading-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.mini-link-btn { border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 800; cursor: pointer; padding: 4px; }
.task-template-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.task-template-grid.compact { grid-template-columns: repeat(2, 1fr); }
.task-template-btn {
  --template-color: #9b7456;
  min-height: 66px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  border: 1px solid #e5d5c7;
  border-radius: 15px;
  background: #fffdf9;
  cursor: pointer;
  padding: 8px 6px;
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
}
.task-template-icon { font-size: 20px; }
.task-template-btn.active { border-color: var(--template-color); background: color-mix(in srgb, var(--template-color) 13%, white); box-shadow: inset 0 0 0 1px var(--template-color); font-weight: 800; }
.custom-template-wrap { position: relative; min-width: 0; }
.custom-template-wrap .task-template-btn { width: 100%; min-height: 48px; padding-right: 25px; }
.template-remove { position: absolute; top: 2px; right: 3px; width: 24px; height: 24px; border: 0; background: transparent; color: #a68675; cursor: pointer; }
.small-empty { margin: 6px 0 0; color: var(--muted); font-size: 11px; }

/* Keep chart physically stable across week/month redraws */
.chart-card { min-height: 258px; }
#moodChart { width: 100%; height: 220px !important; max-height: 220px; }

@media (min-width: 700px) {
  .emotion-families { display: block; }
  .diary-grid { gap: 12px; }
  .diary-tile { aspect-ratio: 1.15; }
}

@media (max-width: 420px) {
  .emotion-family-pill { flex-basis: 100px; min-height: 72px; }
  .emotion-subtypes { gap: 5px; padding: 8px; }
  .emotion-subtypes .emotion-chip { font-size: 10px; }
  .emotion-subtypes .emotion-chip small { display: none; }
  .task-template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-title-row { align-items: flex-end; }
  .stats-title-row h2 { font-size: 23px; }
  .day-modal-actions { grid-template-columns: 1fr; }
}

/* AI diary analysis */
.ai-card { overflow: hidden; }
.ai-heading-row { align-items: flex-start; }
.ai-hint { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.ai-mode-switch { width: 100%; margin-top: 14px; }
.ai-mode-switch .segment { flex: 1; }
.ai-skip-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.ai-skip-row input { margin-top: 2px; accent-color: var(--accent); }
.ai-analyze-btn { width: 100%; margin-top: 13px; }
.ai-analyze-btn:disabled { opacity: .45; cursor: not-allowed; }
.ai-privacy { margin: 11px 0 0; color: #9b8374; font-size: 10px; line-height: 1.45; }
.ai-result {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.ai-summary-block > span,
.ai-result-section > span,
.day-ai-block > span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.ai-summary-block p { margin: 6px 0 0; font-size: 13px; line-height: 1.5; }
.ai-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.ai-metrics div { padding: 9px; border-radius: 13px; background: #f2e5d9; }
.ai-metrics span { display: block; color: var(--muted); font-size: 9px; }
.ai-metrics strong { display: block; margin-top: 3px; font-size: 12px; }
.ai-theme-list, .ai-text-chips, .day-ai-themes { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 7px; }
.ai-theme-list em { color: var(--muted); font-size: 11px; }
.ai-theme-chip {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name close" "meta close";
  column-gap: 8px;
  min-width: 110px;
  border: 1px solid #dcc6b4;
  border-radius: 13px;
  background: #fffaf5;
  color: var(--text);
  padding: 7px 8px;
  cursor: pointer;
  text-align: left;
}
.ai-theme-chip b { grid-area: name; font-size: 11px; }
.ai-theme-chip small { grid-area: meta; margin-top: 2px; color: var(--muted); font-size: 9px; }
.ai-theme-chip i { grid-area: close; align-self: center; color: #a18170; font-style: normal; font-size: 15px; }
.ai-text-chips span, .day-ai-themes span {
  padding: 6px 9px;
  border-radius: 999px;
  background: #efe1d5;
  font-size: 10px;
  line-height: 1.2;
}
.ai-text-chips.helpful span { background: #ece5d5; }
.day-ai-block { padding: 13px; border: 1px solid var(--border); border-radius: 18px; background: #f7eee6; }
.day-ai-block p { margin: 7px 0 0; font-size: 13px; line-height: 1.5; }
.day-ai-themes small { color: var(--muted); }
.diary-ai-mark {
  position: absolute;
  top: 7px;
  right: 8px;
  color: #987356;
  font-size: 12px;
}

/* v3 - quieter diary UI, saved-day state, recurring tasks and period insights */
.auth-splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.splash-orb {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: var(--surface-2);
  font-size: 30px;
  animation: splashPulse 1.1s ease-in-out infinite alternate;
}
@keyframes splashPulse { from { transform: scale(.96); opacity: .7; } to { transform: scale(1.03); opacity: 1; } }
.compact-auth-card { padding-top: 28px; }
.compact-auth-card .brand-mark { margin-bottom: 22px; }
.minimal-topbar { justify-content: flex-end; min-height: 0; }
.topbar-spacer { display: none; }

.saved-day-card { padding: 20px; }
.saved-day-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.saved-day-score { display: flex; align-items: center; gap: 13px; }
.saved-day-score img { width: 70px; height: 70px; object-fit: contain; }
.saved-day-score span { display: block; color: var(--muted); font-size: 12px; font-weight: 750; margin-bottom: 3px; }
.saved-day-score strong { font-size: 30px; letter-spacing: -.04em; }
.saved-day-score small { font-size: 14px; color: var(--muted); }
.saved-day-emotions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 14px; }
.saved-day-emotions span { padding: 7px 10px; border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.saved-day-note { margin: 14px 0 0; line-height: 1.5; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.saved-day-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.saved-day-footer strong { color: var(--text); font-size: 15px; }

.calendar-title-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; }
.calendar-title-main { text-align: center; }
.calendar-toolbar { display: flex; justify-content: flex-end; margin: -2px 0 12px; }
.aux-title { min-width: 0; flex: 1; }
.aux-title p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.recurring-list { display: grid; gap: 10px; }
.recurring-card {
  display: grid;
  grid-template-columns: 8px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}
.recurring-color { align-self: stretch; border-radius: 99px; background: var(--task-color); }
.recurring-content { min-width: 0; display: grid; gap: 4px; }
.recurring-content strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recurring-content small { color: var(--muted); line-height: 1.35; }
.recurring-edit { padding: 8px 10px; font-size: 12px; }
.recurring-stop { align-self: center; }
.recurring-badge { opacity: .75; font-size: 11px; }

.recurring-fields { display: grid; gap: 12px; }
.weekday-presets { display: flex; gap: 12px; margin-bottom: 8px; }
.weekday-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekday-chip {
  min-width: 0;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
}
.weekday-chip.active { background: var(--accent); color: white; border-color: var(--accent); font-weight: 750; }

.scroll-segments { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.scroll-segments::-webkit-scrollbar { display: none; }
.scroll-segments .segment { flex: 0 0 auto; white-space: nowrap; }
.stats-title-row { align-items: flex-start; flex-direction: column; }
.stats-title-row .segmented { width: 100%; }

.compact-hint { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.insight-range-switch { margin-top: 16px; }
.insight-summary { margin-top: 16px; }
.insight-summary h4 { margin: 0 0 10px; font-size: 18px; line-height: 1.35; }
.insight-summary ul { margin: 0; padding-left: 20px; display: grid; gap: 8px; line-height: 1.45; }
.insight-summary p { margin: 12px 0 0; color: var(--muted); line-height: 1.45; }
.insight-updated { margin: 14px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.analysis-settings { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.analysis-settings > summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 700; }
.settings-toggle { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; }
.settings-toggle input { width: auto; margin-top: 3px; }
.settings-toggle span { display: grid; gap: 3px; }
.settings-toggle b { font-size: 13px; }
.settings-toggle small { color: var(--muted); line-height: 1.4; }

.connection-section > h3 { margin-bottom: 13px; }
.correlation-list { display: grid; gap: 10px; }
.relation-card { padding: 14px; border: 1px solid var(--border); border-radius: 17px; background: #fffdf9; }
.relation-main h4 { margin: 0; font-size: 16px; }
.relation-main p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.relation-data { margin-top: 10px; }
.relation-data > summary { cursor: pointer; color: var(--accent); font-size: 12px; font-weight: 750; }
.relation-data-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.relation-data-grid span { padding: 9px; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: 11px; display: grid; gap: 3px; }
.relation-data-grid b { color: var(--text); font-size: 14px; }

.diary-tile p { -webkit-line-clamp: 3; }
.diary-ai-mark, .day-ai-block, .ai-card { display: none !important; }

@media (max-width: 520px) {
  .saved-day-top { align-items: flex-start; }
  .saved-day-score img { width: 60px; height: 60px; }
  .saved-day-score strong { font-size: 27px; }
  .recurring-card { grid-template-columns: 7px 1fr auto; }
  .recurring-edit { grid-column: 2; justify-self: start; }
  .recurring-stop { grid-column: 3; grid-row: 1 / span 2; }
  .weekday-picker { gap: 4px; }
  .weekday-chip { height: 36px; font-size: 11px; }
  .relation-data-grid { grid-template-columns: 1fr; }
}


/* v3.2 - compact insight block */
.compact-insight-card { padding: 16px; }
.insight-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.insight-card-top h3 { margin: 0; font-size: 18px; }
.insight-actions { display: flex; gap: 8px; }
.small-icon-btn {
  width: 38px;
  height: 38px;
  font-size: 16px;
}
.insight-info-text {
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.compact-range-switch {
  margin-bottom: 12px;
  padding: 4px;
  gap: 4px;
}
.compact-range-switch .segment {
  padding: 8px 10px;
  font-size: 12px;
}
.compact-insight-message {
  min-height: 0;
  margin: 0 0 8px;
  font-size: 12px;
}
.compact-insight-message:empty { display: none; }
.compact-insight-updated {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
}
.compact-insight-updated.hidden { display: none; }
#insightSummary h4 {
  margin: 0 0 10px;
  font-size: 18px;
}
#insightSummary ul { margin: 0; padding-left: 18px; }
#insightSummary li { margin-bottom: 7px; line-height: 1.45; }
#insightSummary p { margin: 10px 0 0; color: var(--muted); line-height: 1.45; }


/* v3.3 - multi-emotion selection + clear save feedback */
.primary-btn.is-loading {
  cursor: wait;
  opacity: .86;
}
.primary-btn.is-loading::before {
  content: '';
  width: 15px;
  height: 15px;
  display: inline-block;
  margin-right: 8px;
  border: 2px solid rgba(255,250,245,.42);
  border-top-color: #fffaf5;
  border-radius: 50%;
  vertical-align: -3px;
  animation: saveSpin .72s linear infinite;
}
@keyframes saveSpin { to { transform: rotate(360deg); } }
.emotion-family-pill small {
  max-width: 86px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.emotion-subtypes .emotion-chip.active::after {
  content: '✓';
  margin-left: 5px;
  font-size: 11px;
}


/* v3.4 - unified compact top header */
.app-topbar {
  min-height: 50px;
  padding: 5px 0 9px;
  gap: 12px;
}
.topbar-title {
  margin: 0;
  min-width: 0;
  flex: 1;
  color: var(--text);
  font-size: 22px;
  font-weight: 850;
  line-height: 1.05;
  letter-spacing: -.035em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-topbar .topbar-actions {
  flex: 0 0 auto;
}
.screen-kicker-hidden { display: none; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
#todayScreen .date-row {
  margin-top: 1px;
  margin-bottom: 12px;
}
#todayScreen .date-row h2 {
  font-size: 23px;
  line-height: 1.15;
}
#diaryScreen > .diary-grid,
#correlationScreen > .insight-card {
  margin-top: 2px;
}
.stats-range-row {
  display: flex;
  margin: 2px 0 12px;
}
.stats-range-row .segmented {
  width: 100%;
}
@media (max-width: 420px) {
  .app-topbar { min-height: 48px; gap: 8px; }
  .topbar-title { font-size: 21px; }
  .app-topbar .topbar-actions { gap: 6px; }
  #todayScreen .date-row h2 { font-size: 21px; }
}


/* v3.5 - compact emotion frequency list */
.emotion-stats-toggle {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 12px auto 0;
  padding: 7px 12px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.emotion-stats-toggle:active { transform: translateY(1px); }


/* v3.6 - show emotion family in frequency stats */
.emotion-stat-label {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.emotion-stat-name {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 750;
  line-height: 1.2;
}
.emotion-stat-dot {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--emotion-stat-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--emotion-stat-color) 16%, transparent);
}
.emotion-stat-label small {
  margin-left: 16px;
  color: var(--emotion-stat-color);
  font-size: 10px;
  font-weight: 800;
  opacity: .88;
}


/* v3.7 - main emotion families with expandable subtype details */
.emotion-family-stat {
  --emotion-stat-color: #9b7456;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
}
.emotion-family-stat:last-child { border-bottom: 0; }
.emotion-family-stat-main {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(90px, 2fr) auto 18px;
  align-items: center;
  gap: 9px;
  padding: 10px 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.emotion-family-stat-label {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.emotion-family-stat-label b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.emotion-family-stat-main > strong {
  min-width: 18px;
  text-align: right;
  font-size: 13px;
}
.emotion-family-chevron {
  color: var(--muted);
  font-size: 16px;
  transition: transform .16s ease;
}
.emotion-family-stat.open .emotion-family-chevron { transform: rotate(180deg); }
.emotion-family-breakdown {
  display: none;
  margin: -1px 0 8px 17px;
  padding: 7px 10px 9px;
  border-left: 2px solid color-mix(in srgb, var(--emotion-stat-color) 55%, white);
  border-radius: 0 10px 10px 0;
  background: color-mix(in srgb, var(--emotion-stat-color) 5%, transparent);
}
.emotion-family-stat.open .emotion-family-breakdown { display: grid; gap: 7px; }
.emotion-subtype-stat {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(70px, 1.6fr) auto;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.emotion-subtype-stat > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.emotion-subtype-stat > strong { font-size: 11px; }
@media (max-width: 420px) {
  .emotion-family-stat-main { grid-template-columns: minmax(88px, 1fr) minmax(58px, 1.3fr) auto 16px; gap: 7px; }
  .emotion-subtype-stat { grid-template-columns: minmax(88px, 1fr) minmax(48px, 1fr) auto; }
}


/* v3.9 - statistics explanation */
.topbar-title-wrap {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-title-wrap .topbar-title { flex: 0 1 auto; }
.topbar-info-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(255, 250, 245, .76);
  color: var(--muted);
  font: 800 14px/1 Georgia, serif;
  cursor: pointer;
}
.topbar-info-btn:active { transform: scale(.96); }
.stats-info-card { padding: 19px; }
.stats-info-heading { margin-bottom: 8px; }
.stats-info-intro, .stats-info-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.stats-info-list {
  display: grid;
  gap: 0;
  margin: 15px 0;
  border-top: 1px solid var(--border);
}
.stats-info-list section {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.stats-info-list h4 {
  margin: 0 0 4px;
  font-size: 14px;
  line-height: 1.25;
}
.stats-info-list p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* MoodDay v4.6.1 - stable mood faces and lighter interactions */
.mood-face,
.diary-tile > img,
.day-mood-summary img,
.saved-day-score img {
  display: block;
  object-fit: contain;
  object-position: 50% 50%;
  aspect-ratio: 1 / 1;
}
.mood-face { flex: 0 0 76px; }
.day-mood-summary img { flex: 0 0 60px; }
.saved-day-score img { flex: 0 0 70px; }
button,
input[type="range"] {
  touch-action: manipulation;
}
.task-check,
.task-delete,
.soft-btn,
.nav-btn,
.segment {
  transition: background-color .12s ease, opacity .12s ease, transform .12s ease;
}
.task-check:active,
.soft-btn:active,
.nav-btn:active,
.segment:active {
  transform: scale(.97);
}
@media (prefers-reduced-motion: reduce) {
  .task-check,
  .task-delete,
  .soft-btn,
  .nav-btn,
  .segment {
    transition: none;
  }
}
