/* 小津助手 v2.1 — 生活 (js/views/life.js): weather-scene header, todos (priority rings + tags, swipe to
   delete, check pop), habits (streak bars, check-in burst, heatmap sheet), 今日单词 teal cards, sheets.
   Owned by the 生活 view developer. Tokens only (the word card's white overlays are alpha whites on teal).
   Compatibility: no color-mix(), :has(), nesting, @container, @layer, dvh. */

/* Status-bar scrim: has height only with a safe-area inset (iOS standalone / notch), shows once scrolled.
   The scene header is the page title, so there is no compact top bar (DESIGN-v21 §2 / FOUNDATION §4). */
#view-life .life-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  height: var(--safe-top);
  background: var(--bg-elev);
  box-shadow: 0 1px 0 var(--line);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease-out);
}
#view-life .life-bar.is-scrolled { opacity: 1; }

/* ---------- header: the live weather scene ---------- */
.life-hero {
  display: flex;
  flex-direction: column;
  min-height: calc(var(--safe-top) + 248px);
  padding: calc(var(--safe-top) + 12px) var(--page-x) 16px;
}
.life-hero .life-pill {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: var(--page-x);
  z-index: 2;
  max-width: calc(100% - 2 * var(--page-x) - 140px);
}
.life-kicker {
  max-width: calc(100% - 150px);
  min-height: 28px;
  overflow: hidden;
  color: var(--scene-ink-2, var(--text-2));
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 28px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.life-date {
  margin-top: 2px;
  color: var(--scene-ink, var(--text));
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: 0;
}
.life-sub {
  min-height: 22px;
  margin-top: 4px;
  color: var(--scene-ink-2, var(--text-2));
  font-size: var(--fs-base);
  line-height: var(--lh-wrap);
}
.life-sub b { color: var(--scene-ink, var(--text)); font-weight: var(--fw-semibold); }
[data-ink="light"] .life-kicker, [data-ink="light"] .life-date, [data-ink="light"] .life-sub { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); }

.life-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
  margin-top: auto;
  padding-top: var(--sp-4);
}
.life-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  min-height: 60px;
  padding: 10px 12px;
  border-radius: var(--r-lg);
  background: var(--on-scene-chip);
  color: var(--text);
  text-align: left;
  box-shadow: 0 1px 2px rgba(84, 48, 24, 0.06);
  transition: transform var(--dur) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.life-stat strong {
  max-width: 100%;
  overflow: hidden;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.life-stat span { color: var(--text-2); font-size: var(--fs-xs); line-height: var(--lh-ui); white-space: nowrap; }
.life-stat:active, .life-stat.is-pressed { transform: scale(var(--press-scale)); background: var(--surface); transition-duration: var(--dur-press); }

@media (max-height: 700px) {
  .life-hero { min-height: calc(var(--safe-top) + 228px); padding-bottom: 12px; }
  .life-stats { padding-top: var(--sp-3); }
  .life-stat { min-height: 54px; padding: 8px 12px; }
}

/* section titles with an inline count ("待办 4") */
.sec-count { margin-left: 6px; color: var(--text-3); font-weight: var(--fw-regular); }
.life-tip { margin-top: var(--sp-2); color: var(--text-3); font-size: var(--fs-xs); line-height: var(--lh-ui); }
@media (hover: hover) and (pointer: fine) { .life-tip { display: none; } }

/* ---------- todos ---------- */
.todo-group .row { --row-inset: 52px; }
.todo-add { gap: var(--sp-3); }
.todo-add .row-title { flex: none; font-weight: var(--fw-semibold); }
.add-row .add-icon.is-filled {
  width: 28px;
  height: 28px;
  margin-left: -3px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--lip);
  transition: transform var(--dur) var(--ease-spring);
}
.todo-add:active .add-icon, .todo-add.is-pressed .add-icon { transform: scale(0.88) rotate(90deg); }
.add-hint {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text-3);
  font-size: var(--fs-sm);
  text-align: right;
  white-space: nowrap;
  text-overflow: ellipsis;
}
@media (max-width: 359px) { .add-hint { display: none; } }

.todo-row { min-height: 60px; padding: 0; }
.todo-body {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  min-height: 60px;
  padding: 8px var(--sp-3) 8px var(--sp-4);
}
.todo-main {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 44px;
  margin: -2px 0;
  padding: 6px 8px 6px 6px;
  border-radius: var(--r-md);
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-out);
}
.todo-main:active, .todo-main.is-pressed { background: var(--surface-2); transform: scale(0.985); transition-duration: var(--dur-press); }
.todo-main .row-title { overflow-wrap: anywhere; }
.todo-text {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 60%;
  background-size: 0% 1.5px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-size 300ms var(--ease-out), color var(--dur) var(--ease-out);
}
.todo-row.is-done .todo-text { background-size: 100% 1.5px; color: var(--text-3); }
.todo-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  line-height: 20px;
}
.todo-meta .prio, .todo-meta .due { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.todo-meta .icon { width: 13px; height: 13px; flex: none; }
.todo-meta .pill { height: 22px; padding: 0 8px 0 6px; border-radius: var(--r-full); font-weight: var(--fw-semibold); }
.prio.is-urgent { background: var(--danger-soft); color: var(--danger); }
.prio.is-important { background: var(--amber-soft); color: var(--amber-text); }
.due.is-over { background: var(--danger-soft); color: var(--danger); }
.due.is-soon { background: var(--warning-soft); color: var(--warning); }
.todo-row.is-done .pill { background: var(--surface-2); color: var(--text-3); }
.todo-row.is-leaving { pointer-events: none; }
.todo-row .swipe-actions { display: none; }
.todo-row.is-swiping .swipe-actions, .todo-row.is-revealed .swipe-actions, .todo-row.is-leaving .swipe-actions { display: flex; }

/* check: pop + ring when completed */
.todo-row .check::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--teal);
  opacity: 0;
  pointer-events: none;
}
.todo-row .check.is-popping::before { animation: lf-pop 420ms var(--ease-spring); }
.todo-row .check.is-popping::after { animation: lf-ring 540ms var(--ease-out); }
@keyframes lf-pop { 0% { transform: scale(0.72); } 55% { transform: scale(1.16); } 100% { transform: scale(1); } }
@keyframes lf-ring { 0% { opacity: 0.75; transform: scale(1); } 100% { opacity: 0; transform: scale(2.2); } }

.todo-empty, .habit-empty { gap: var(--sp-3); color: var(--text-3); font-size: var(--fs-sm); line-height: var(--lh-wrap); }

/* ---------- habits ---------- */
.habit-group .row { --row-inset: 68px; }
.habit-group .add-row .add-icon { width: 40px; }
.habit-row { gap: 0; padding: 0 var(--sp-2) 0 0; }
.habit-main {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
  min-height: 68px;
  padding: 12px 8px 12px var(--sp-4);
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.habit-main .tile { transition: transform var(--dur) var(--ease-out); }
.habit-main:active, .habit-main.is-pressed { background: var(--surface-2); transition-duration: var(--dur-press); }
.habit-main:active .tile, .habit-main.is-pressed .tile { transform: scale(0.94); }
.habit-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--sp-2); min-width: 0; }
.habit-name {
  min-width: 0;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-wrap);
  overflow-wrap: anywhere;
}
.streak { display: inline-flex; align-items: center; gap: 2px; flex: none; color: var(--text-3); font-size: var(--fs-xs); line-height: 18px; }
.streak.is-on { color: var(--primary-text); font-weight: var(--fw-semibold); }
.streak .icon { width: 14px; height: 14px; color: var(--primary); --dt: .3; }
.streak.is-bump .icon { animation: lf-flame 560ms var(--ease-spring); }
@keyframes lf-flame { 0% { transform: scale(0.6) rotate(-12deg); } 60% { transform: scale(1.3) rotate(6deg); } 100% { transform: none; } }
.week { display: flex; gap: 5px; margin-top: 8px; }
.week i { display: block; width: 18px; height: 6px; border-radius: 3px; background: var(--surface-3); transition: background-color var(--dur) var(--ease-out); }
.week i.is-on { background: var(--hc, var(--teal)); }
.week i.is-today { box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 3px var(--line-strong); }
@media (max-width: 359px) { .week i { width: 14px; } }

.habit-check {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: var(--text-3);
}
.habit-check::before {
  content: "";
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1.75px var(--line-strong);
  transition: background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-spring);
}
.habit-check .icon { position: relative; transition: color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-spring); }
.habit-check[aria-checked="true"] { color: var(--on-teal); }
.habit-check[aria-checked="true"]::before { background: var(--hc, var(--teal)); box-shadow: none; }
.habit-check:active::before, .habit-check.is-pressed::before { transform: scale(0.88); }
.habit-check:active .icon, .habit-check.is-pressed .icon { transform: scale(0.9); }
.habit-check.is-celebrating::before { animation: lf-pop 460ms var(--ease-spring); }
.habit-check.is-celebrating .icon { animation: lf-pop 460ms var(--ease-spring); }
.burst { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; }
.burst i {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--hc, var(--teal));
  opacity: 0;
  animation: lf-burst 640ms var(--ease-out) forwards;
}
.burst i:nth-child(even) { left: -2px; top: -2px; width: 4px; height: 4px; background: var(--amber); }
@keyframes lf-burst {
  0% { opacity: 1; transform: rotate(var(--a)) translate3d(0, -14px, 0) scale(1); }
  100% { opacity: 0; transform: rotate(var(--a)) translate3d(0, -31px, 0) scale(0.4); }
}

/* ---------- 今日单词: B's teal cards, swipe through the group ---------- */
.word-track {
  display: flex;
  gap: 12px;
  margin: 0 calc(-1 * var(--page-x));
  padding: 2px var(--page-x) 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 var(--page-x);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.word-track::-webkit-scrollbar { display: none; }
.word-card {
  --wd-dim: rgba(255, 255, 255, 0.8);
  --wd-panel: rgba(255, 255, 255, 0.12);
  --wd-press: rgba(255, 255, 255, 0.22);
  --wd-art: rgba(255, 255, 255, 0.08);
  --wd-art-0: rgba(255, 255, 255, 0);
  position: relative;
  flex: 0 0 calc(100% - 12px);
  min-width: 0;
  overflow: hidden;
  padding: 16px 18px 18px;
  border-radius: var(--r-xl);
  background-color: var(--teal);
  background-image: radial-gradient(circle at calc(100% - 40px) calc(100% - 32px), var(--wd-art) 44px, var(--wd-art-0) 44.5px),
    radial-gradient(circle at calc(100% - 40px) calc(100% - 32px), var(--wd-art) 70px, var(--wd-art-0) 70.5px);
  color: var(--on-teal);
  box-shadow: var(--shadow-1);
  scroll-snap-align: start;
}
[data-theme="dark"] .word-card {
  --wd-dim: var(--teal-text);
  --wd-panel: rgba(255, 255, 255, 0.06);
  --wd-press: rgba(255, 255, 255, 0.12);
  --wd-art: rgba(255, 255, 255, 0.04);
  background-color: var(--teal-soft);
  color: var(--text);
}
.word-track > .word-card:only-child { flex-basis: 100%; }
.word-card.is-skeleton { display: flex; flex-direction: column; gap: var(--sp-3); min-height: 180px; background: var(--surface); }
[data-theme="dark"] .word-card.is-skeleton { background: var(--surface); }
.word-kicker { position: relative; color: var(--wd-dim); font-size: var(--fs-sm); font-weight: var(--fw-semibold); line-height: var(--lh-ui); }
.word-top { position: relative; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); min-height: 44px; margin-top: 2px; }
.word-en { min-width: 0; font-size: var(--fs-3xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); overflow-wrap: anywhere; }
.word-say { flex: none; margin-right: -10px; color: inherit; }
.word-say::before { background: var(--wd-press); }
.word-card .word-say:active, .word-card .word-say.is-pressed { color: inherit; }
.word-ph { position: relative; margin-top: 2px; color: var(--wd-dim); font-size: var(--fs-base); line-height: var(--lh-ui); }
.word-mean { position: relative; margin-top: 10px; font-size: var(--fs-base); line-height: var(--lh-wrap); }
.word-mean .pos { margin-right: 2px; color: var(--wd-dim); font-size: var(--fs-sm); }
.word-ex {
  position: relative;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--wd-panel);
  font-size: var(--fs-base);
  line-height: var(--lh-wrap);
  overflow-wrap: anywhere;
}
.word-ex b { font-weight: var(--fw-semibold); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; text-decoration-color: var(--amber); }
.word-dots { display: flex; justify-content: center; gap: 6px; margin-top: 2px; }
.word-dots i { display: block; width: 6px; height: 6px; border-radius: 3px; background: var(--line-strong); transition: width var(--dur) var(--ease-out), background-color var(--dur) var(--ease-out); }
.word-dots i.is-on { width: 18px; background: var(--teal); }
.word-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-3); }
.word-progress { min-width: 0; color: var(--text-3); font-size: var(--fs-sm); }
.word-foot .btn { flex: none; }

/* ---------- todo / habit sheets ---------- */
.todo-form .textarea { min-height: 72px; }
.todo-form .field, .habit-form .chip-row { margin-top: var(--sp-5); }
.todo-form .field-error, .habit-form .field-error { margin-top: var(--sp-1); }
.due-inputs { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: var(--sp-2); }
.due-quick { margin-top: var(--sp-1); }
.todo-form .field-hint { margin-left: 2px; }
.prio-dot { display: inline-block; width: 8px; height: 8px; margin: -1px 6px 0 0; border-radius: 50%; vertical-align: middle; }
.prio-dot.is-urgent { background: var(--pri-urgent); }
.prio-dot.is-important { background: var(--pri-important); }
.prio-dot.is-normal { background: var(--pri-normal); }

.habit-sheet-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.habit-sheet-title { display: block; color: var(--text); font-size: var(--fs-base); font-weight: var(--fw-semibold); line-height: var(--lh-ui); }
.habit-sheet-sub { display: block; margin-top: 2px; color: var(--text-3); font-size: var(--fs-sm); line-height: var(--lh-ui); }
.heat { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.heat-head { padding-bottom: 2px; color: var(--text-3); font-size: var(--fs-xs); text-align: center; }
.heat-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.heat-cell.is-on { background: var(--hc, var(--teal)); color: var(--on-teal); }
.heat-cell.is-future { background: transparent; color: var(--text-disabled); box-shadow: inset 0 0 0 1px var(--line); }
.heat-cell.is-today { box-shadow: inset 0 0 0 1.5px var(--text-2); color: var(--text); font-weight: var(--fw-semibold); }
.heat-cell.is-on.is-today { box-shadow: inset 0 0 0 2px var(--surface), 0 0 0 1.5px var(--hc, var(--teal)); color: var(--on-teal); }
.habit-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: var(--sp-5); text-align: center; }
.habit-stats > div + div { border-left: 1px solid var(--line); }
.habit-stats strong { display: block; font-size: var(--fs-2xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); }
.habit-stats span { color: var(--text-3); font-size: var(--fs-xs); }

/* ---------- reduced motion: no pops, bursts or strike sweeps ---------- */
@media (prefers-reduced-motion: reduce) {
  .todo-row .check.is-popping::before, .todo-row .check.is-popping::after,
  .habit-check.is-celebrating::before, .habit-check.is-celebrating .icon, .streak.is-bump .icon { animation: none; }
  .burst { display: none; }
  .todo-text { transition: none; }
  .todo-main:active, .todo-main.is-pressed { transform: none; }
}
