/*
 * Memory, Goals and History pages. Only page-specific layout lives here; buttons,
 * fields, chips, dialogs, empty states and tokens come from /ui/senpai.css.
 * Direction: editorial and personal. Notes and conversations sit like pages in a
 * journal (varied sizes, soft uneven corners), not rows in a table.
 */

/* ---------- shared page frame ---------- */
.pg { position: relative; isolation: isolate; overflow-x: clip; }
.pg > * { position: relative; z-index: 1; }

/* One quiet organic shape behind each heading; differs per page so they don't feel stamped. */
.pg > .pg-shape {
  position: absolute; z-index: 0; pointer-events: none;
  width: clamp(220px, 34vw, 420px); aspect-ratio: 1;
  border-radius: 58% 42% 55% 45% / 48% 60% 40% 52%;
  opacity: .7;
}
.pg-shape--a { top: -40px; right: -90px; background: var(--lav); }
.pg-shape--b { top: -30px; right: -120px; background: var(--bg-2); border-radius: 40% 60% 38% 62% / 58% 38% 62% 42%; }
.pg-shape--c { top: 10px; right: -140px; background: var(--lav); opacity: .55; border-radius: 999px 999px 42% 58%; }

.pg-title { font-size: clamp(42px, 6.2vw, 86px); }
.pg-title em { padding-right: .06em; }

.pg-top {
  display: grid; gap: var(--s-6);
  margin-bottom: clamp(28px, 4vw, 48px);
}
.pg-top .page__head { margin-bottom: 0; }
@media (min-width: 980px) {
  .pg-top { grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); align-items: end; }
}
.pg-head__action { margin-top: var(--s-3); }

.pg-skeleton { display: grid; gap: var(--s-4); padding-block: var(--s-4); }
.pg-skeleton__block { height: 72px; width: var(--w, 80%); border-radius: var(--r-l); }
.pg-skeleton__block:nth-child(odd) { height: 108px; }

.pg-problem { max-width: 640px; }
.pg-empty { max-width: 720px; }

.is-pending { opacity: .55; }

/* Confirm dialog */
.pg-dialog { width: min(460px, 100% - 32px); }
.pg-dialog__body { display: grid; gap: var(--s-4); }
.pg-dialog__title { font-size: clamp(26px, 3vw, 32px); }
.pg-dialog__text { color: var(--ink-2); overflow-wrap: anywhere; }
.pg-dialog__actions { justify-content: flex-end; margin-top: var(--s-2); }

/* ---------- memory ---------- */
.mem-controls {
  display: grid; gap: var(--s-3); justify-items: start;
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl) var(--r-l) var(--r-xl) var(--r-m);
  box-shadow: var(--shadow-1);
}
.mem-switch__label { font-family: var(--font-display); font-size: 22px; letter-spacing: -0.01em; }
.mem-controls__hint { font-size: 15px; color: var(--ink-2); line-height: 1.5; }
.mem-clear { margin-left: -14px; color: var(--err); }
.mem-clear:hover { color: var(--err); }

.mem-add {
  display: grid; gap: var(--s-3);
  margin-bottom: clamp(32px, 5vw, 56px);
  padding: var(--s-5);
  background: var(--lav);
  border-radius: var(--r-l) var(--r-xl) var(--r-m) var(--r-xl);
}
.mem-add__title { font-weight: 600; }
.mem-add__row {
  display: grid; gap: var(--s-3);
  grid-template-columns: minmax(180px, 230px) minmax(0, 1fr) auto;
  align-items: start;
}
@media (max-width: 720px) {
  .mem-add__row { grid-template-columns: 1fr; }
  .mem-add__row .btn { justify-self: start; }
}

.mem-offnote {
  margin-bottom: var(--s-5); padding: var(--s-4) var(--s-5);
  border: 1.5px dashed rgba(36,21,43,.22); border-radius: var(--r-l);
  color: var(--ink-2);
}
body.mem-off .mem-flow { opacity: .72; }

/* Two flowing columns; groups keep their own shape and size. */
.mem-flow { columns: 2 340px; column-gap: clamp(20px, 3vw, 36px); }
.mem-group {
  break-inside: avoid;
  margin-bottom: clamp(20px, 3vw, 36px);
  padding: clamp(20px, 2.6vw, 30px);
  border-radius: var(--r-xl) var(--r-l) var(--r-xl) var(--r-m);
}
.mem-group--0 { background: var(--surface); box-shadow: var(--shadow-1); }
.mem-group--1 { background: var(--bg-2); border-radius: var(--r-l) var(--r-xl) var(--r-m) var(--r-xl); }
.mem-group--2 { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m) var(--r-xl) var(--r-xl) var(--r-l); }
.mem-group--3 { background: var(--lav); border-radius: var(--r-xl) var(--r-m) var(--r-l) var(--r-xl); }

.mem-group__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-2); }
.mem-group__title { font-size: clamp(24px, 2.4vw, 30px); font-style: italic; }
.mem-group__count { font-size: 13px; white-space: nowrap; }
.mem-group__list { list-style: none; margin: 0; padding: 0; }

.note { padding-block: var(--s-4); border-top: 1px solid var(--line); }
.note:first-child { border-top: 0; padding-top: var(--s-2); }
.note__text { font-size: 17px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }
.note--lg .note__text { font-family: var(--font-display); font-size: clamp(21px, 2vw, 25px); line-height: 1.25; letter-spacing: -0.01em; }
.note--sm .note__text { font-size: 15px; color: var(--ink-2); }

.note__meta {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--s-2) var(--s-3); margin-top: var(--s-2);
}
.note__kind {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
}
.note__kind::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); }
.note__kind--tentative { color: var(--ink-2); font-style: italic; }
.note__kind--tentative::before { background: transparent; border: 1.5px solid var(--ink-2); }
.note--tentative .note__text { font-style: italic; }
.note__verdict { --gap: 6px; }
.note--tentative .note__kind { flex-basis: 100%; }
.note__tools { --gap: 0; margin-left: auto; }
.note__tools .btn { opacity: .78; }
.note:hover .note__tools .btn, .note__tools .btn:focus-visible { opacity: 1; }

.note__form { display: grid; gap: var(--s-3); }
.note__edit { min-height: 88px; }
.note__form-row { --gap: var(--s-2); }
.note__form .note__cat { width: auto; min-height: 40px; padding-block: 6px; font-size: 14px; }
.note__spacer { flex: 1; }

/* ---------- goals ---------- */
.goals-progress {
  display: flex; align-items: center; gap: var(--s-5);
  padding: var(--s-5);
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) var(--r-m) var(--r-xl);
  box-shadow: var(--shadow-1);
}
.goals-progress__big { font-family: var(--font-display); font-size: clamp(22px, 2.2vw, 28px); line-height: 1.15; letter-spacing: -0.015em; }
.goals-progress__small { font-size: 14px; margin-top: var(--s-1); }

/* A small flower: one petal per goal in play this month, filled when done. */
.petals { position: relative; flex: none; width: 112px; height: 112px; }
.petal {
  position: absolute; left: calc(50% - 11px); top: calc(50% - 46px);
  width: 22px; height: 46px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  border: 1.5px solid rgba(36,21,43,.28);
  background: var(--bg);
  transform-origin: 50% 100%;
  transform: rotate(calc(360deg / var(--n) * var(--k)));
  transition: background-color var(--dur-3) var(--ease), border-color var(--dur-3) var(--ease);
}
.petal--done { background: var(--ink); border-color: var(--ink); }
.petals__core {
  position: absolute; left: calc(50% - 9px); top: calc(50% - 9px);
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--coral);
}

.goals-empty { margin-bottom: var(--s-4); }
.goal-add {
  display: grid; gap: var(--s-2); justify-items: start;
  margin-bottom: clamp(32px, 5vw, 56px);
  max-width: 760px;
}
.goal-add__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-3); width: 100%; align-items: start; }
.goal-add__title .input { min-height: 56px; font-size: 18px; padding-inline: 24px; background: var(--surface); }
.goal-add__more { margin-left: 10px; }
.goal-add__extra {
  display: grid; gap: var(--s-4); width: 100%;
  padding: var(--s-5); background: var(--bg-2); border-radius: var(--r-l);
}
.goal-add__due .input { max-width: 240px; }
@media (max-width: 560px) {
  .goal-add__row { grid-template-columns: 1fr; }
  .goal-add__row .btn { justify-self: start; }
}

.goals-section { margin-bottom: clamp(32px, 5vw, 56px); }
.goals-section__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-4); }
.goals-section__title { font-family: var(--font-display); font-size: clamp(26px, 3vw, 36px); line-height: 1.1; letter-spacing: -0.02em; }
.goals-section__hint { font-size: 14px; }
.goals-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); max-width: 820px; }

.goal {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-4);
  padding: var(--s-4) var(--s-5) var(--s-4) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l) var(--r-l) var(--r-l) var(--r-m);
}
.goals-section--now .goal:nth-child(3n + 2) { margin-left: clamp(0px, 3vw, 32px); }
.goals-section--later .goal { background: transparent; border-style: dashed; }
.goal--done { background: transparent; border-color: transparent; padding-block: var(--s-2); }

.goal__check {
  position: relative; flex: none;
  width: 44px; height: 44px; margin-top: -4px;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer;
}
.goal__tick {
  position: absolute; inset: 8px;
  border: 2px solid rgba(36,21,43,.35); border-radius: 50%;
  transition: background-color var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
}
.goal__tick::after {
  content: ""; position: absolute; left: 50%; top: 45%;
  width: 6px; height: 11px;
  border: solid var(--bg); border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg) scale(0);
  transition: transform var(--dur-2) var(--ease);
}
.goal__check:hover .goal__tick { border-color: var(--ink); }
.goal__check:active .goal__tick { transform: scale(.9); }
.goal__check[aria-pressed="true"] .goal__tick { background: var(--ink); border-color: var(--ink); }
.goal__check[aria-pressed="true"] .goal__tick::after { transform: translate(-50%, -50%) rotate(45deg) scale(1); }
.goal__check:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-radius: 50%; }

.goal__title { font-family: var(--font-display); font-size: clamp(20px, 2vw, 24px); line-height: 1.25; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.goal--done .goal__title { color: var(--ink-2); text-decoration: line-through; text-decoration-color: rgba(36,21,43,.3); text-decoration-thickness: 1px; }
.goal__note { margin-top: var(--s-1); color: var(--ink-2); font-size: 15px; overflow-wrap: anywhere; }
.goal__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-top: var(--s-2); }
.goal__when {
  display: inline-flex; align-items: center; min-height: 26px; padding: 2px 12px;
  border-radius: var(--r-pill); background: var(--bg-2);
  font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.goal__when.is-soon { background: var(--lav); color: var(--ink); }
.goal__when.is-late { background: var(--coral-soft); color: var(--coral-ink); }
.goal--done .goal__when { background: transparent; padding-left: 0; font-weight: 500; color: var(--muted); }
.goal__tools { --gap: 0; margin-left: auto; }

.goal__form { display: grid; gap: var(--s-3); }
.goal__form .textarea { min-height: 72px; }
.goal__form-row { --gap: var(--s-2); align-items: end; }
.goal__form-row .input[type="date"] { width: auto; }
.goal__spacer { flex: 1; }
.goal:has(.goal__form) { grid-template-columns: minmax(0, 1fr); }

.goals-clear { font-family: var(--font-display); font-size: clamp(22px, 2.4vw, 28px); font-style: italic; color: var(--ink-2); margin-bottom: var(--s-6); max-width: 32ch; }

.goals-done { max-width: 820px; border-top: 1px solid var(--line); padding-top: var(--s-4); }
.goals-done__summary {
  display: inline-flex; align-items: center; gap: var(--s-3);
  min-height: 44px; cursor: pointer; list-style: none;
  border-radius: var(--r-s);
}
.goals-done__summary::-webkit-details-marker { display: none; }
.goals-done__summary::after {
  content: ""; width: 9px; height: 9px; margin-left: var(--s-1);
  border: solid var(--ink-2); border-width: 0 2px 2px 0;
  transform: rotate(-45deg);
  transition: transform var(--dur-2) var(--ease);
}
.goals-done[open] .goals-done__summary::after { transform: rotate(45deg) translate(-2px, -2px); }
.goals-done[open] .goals-list { margin-top: var(--s-3); gap: 0; }
.goals-done .goals-section__title { font-size: clamp(22px, 2.4vw, 28px); }

/* ---------- history ---------- */
.hist-tools { display: grid; gap: var(--s-3); margin-bottom: clamp(32px, 5vw, 56px); max-width: 560px; }
.hist-tools__search .input { background: var(--surface); }
.hist-tools__filter { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); color: var(--ink-2); }
.hist-tools__count:empty { display: none; }
.hist-tools__count { font-size: 14px; }

/* Below the two-column layout the timeline dots sit at the page edge; give them room. */
@media (max-width: 899px) { .hist-timeline { padding-left: var(--s-2); } }
.hist-day { display: grid; gap: var(--s-4); margin-bottom: clamp(28px, 4vw, 48px); }
.hist-day__label { font-size: clamp(26px, 3vw, 36px); font-style: italic; color: var(--ink); }
@media (min-width: 900px) {
  .hist-day { grid-template-columns: 220px minmax(0, 1fr); gap: var(--s-6); align-items: start; }
  .hist-day__label { position: sticky; top: var(--s-6); padding-top: var(--s-4); text-align: right; }
}

.hist-day .hist-day__list {
  list-style: none; margin: 0; padding: 0 0 0 28px;
  border-left: 1.5px dashed rgba(36,21,43,.2);
  display: grid; gap: var(--s-4);
  max-width: 760px;
}
.hist-entry { position: relative; }
.hist-entry__dot {
  position: absolute; left: -36px; top: 26px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--ink-2);
}
/* The most recent conversation gets the page's one coral accent. */
.hist-day:first-child .hist-entry:first-child .hist-entry__dot { background: var(--coral); border-color: var(--coral); }

.hist-card {
  display: grid; gap: var(--s-2);
  padding: clamp(18px, 2.4vw, 26px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l) var(--r-l) var(--r-l) var(--r-s);
  box-shadow: var(--shadow-1);
}
.hist-entry:nth-child(even) .hist-card { border-radius: var(--r-s) var(--r-l) var(--r-l) var(--r-l); }
.hist-card__meta { font-size: 13px; }
.hist-card__title { font-size: clamp(21px, 2.1vw, 26px); line-height: 1.2; overflow-wrap: anywhere; }
.hist-card__summary { color: var(--ink-2); max-width: 62ch; overflow-wrap: anywhere; }
.hist-card__topics { list-style: none; margin: var(--s-1) 0 0; padding: 0; --gap: 6px; }
.hist-card__topics .chip { min-height: 32px; font-size: 13px; padding: 0 12px; }
@media (pointer: coarse) { .hist-card__topics .chip { min-height: 40px; } }
.hist-card__actions { --gap: var(--s-1); margin-top: var(--s-2); }

.hist-nomatch { max-width: 560px; }

/* ---------- small screens ---------- */
@media (max-width: 600px) {
  .pg > .pg-shape { display: none; } /* clipped by the page edge at this width, it reads as a glitch */
  .mem-controls, .mem-add, .goals-progress { padding: var(--s-4); }
  .goals-progress { gap: var(--s-4); }
  .petals { width: 88px; height: 88px; }
  .petal { left: calc(50% - 9px); top: calc(50% - 36px); width: 18px; height: 36px; }
  .goal { padding: var(--s-3) var(--s-4) var(--s-3) var(--s-2); gap: var(--s-2); }
  .goals-section--now .goal:nth-child(3n + 2) { margin-left: 0; }
  .hist-day .hist-day__list { padding-left: 20px; }
  .hist-entry__dot { left: -28px; }
}

@media (prefers-reduced-motion: reduce) {
  .petal, .goal__tick, .goal__tick::after, .goals-done__summary::after { transition: none; }
}
