/* 小津助手 v2.1 — generic components (docs/DESIGN-v21.md §1, §8; API in docs/FOUNDATION-v21.md).
   Class names from the v2 contract (.btn, .chip, .seg, .sheet, .row, .group …) are kept: the 斗地主 UI
   relies on them. Press feedback: every rule has both :active and .is-pressed (js/motion.js adds
   .is-pressed on pointerdown so it fires instantly on iOS and Android).
   Compatibility: no color-mix(), :has(), nesting, @container, @layer. */

/* ================================================================ press feedback (shared) */
.press, .card.is-tappable {
  cursor: pointer;
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.press:active, .press.is-pressed,
.card.is-tappable:active, .card.is-tappable.is-pressed { transform: scale(var(--press-scale)); transition-duration: var(--dur-press); }
.card.is-tappable:active, .card.is-tappable.is-pressed { box-shadow: var(--shadow-press); }

/* ================================================================ buttons */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: transform var(--dur) var(--ease-out), background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur) var(--ease-out), color var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.btn .icon { width: 20px; height: 20px; }
.btn:active:not(:disabled), .btn.is-pressed:not(:disabled) { transform: scale(var(--press-scale)); transition-duration: var(--dur-press); }
.btn:disabled, .btn[aria-disabled="true"] {
  color: var(--text-disabled);
  background: var(--surface-2);
  border-color: transparent;
  box-shadow: none;
}
.btn-sm { min-width: 44px; height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-full); gap: 4px; }
.btn-sm::after { content: ""; position: absolute; top: -4px; bottom: -4px; left: 0; right: 0; }
.btn-sm .icon { width: 18px; height: 18px; }
.btn-lg { height: 52px; border-radius: var(--r-lg); font-size: var(--fs-lg); }
.btn-block { display: flex; width: 100%; }
a.btn { text-decoration: none; }

.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--lip), 0 1px 2px rgba(84, 48, 24, 0.16); }
@media (hover: hover) { .btn-primary:hover:not(:disabled) { background: var(--primary-hover); } }
.btn-primary:active:not(:disabled), .btn-primary.is-pressed:not(:disabled) { background: var(--primary-press); box-shadow: none; transform: scale(var(--press-scale)) translateY(1px); }

.btn-secondary { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
@media (hover: hover) { .btn-secondary:hover:not(:disabled) { background: var(--surface-2); } }
.btn-secondary:active:not(:disabled), .btn-secondary.is-pressed:not(:disabled) { background: var(--surface-2); }

.btn-tonal { background: var(--primary-soft); color: var(--primary-text); }
.btn-tonal:active:not(:disabled), .btn-tonal.is-pressed:not(:disabled) { background: var(--primary-soft-press); }

.btn-teal { background: var(--teal); color: var(--on-teal); box-shadow: var(--lip); }
.btn-teal:active:not(:disabled), .btn-teal.is-pressed:not(:disabled) { background: var(--teal-press); box-shadow: none; }

.btn-quiet { background: var(--surface-2); color: var(--text); }
.btn-quiet:active:not(:disabled), .btn-quiet.is-pressed:not(:disabled) { background: var(--surface-3); }

.btn-ghost { background: transparent; color: var(--text-2); }
@media (hover: hover) { .btn-ghost:hover:not(:disabled) { background: var(--surface-2); } }
.btn-ghost:active:not(:disabled), .btn-ghost.is-pressed:not(:disabled) { background: var(--surface-2); }
.btn-ghost:disabled { background: transparent; }

.btn-danger { background: transparent; color: var(--danger); }
@media (hover: hover) { .btn-danger:hover:not(:disabled) { background: var(--danger-soft); } }
.btn-danger:active:not(:disabled), .btn-danger.is-pressed:not(:disabled) { background: var(--danger-soft); }
.btn-danger.is-filled { background: var(--danger); color: var(--on-primary); box-shadow: var(--lip); }
[data-theme="dark"] .btn-danger.is-filled { color: var(--bg); }
.btn-danger.is-filled:active:not(:disabled), .btn-danger.is-filled.is-pressed:not(:disabled) { background: var(--danger); opacity: .88; }

.btn.is-loading { pointer-events: none; opacity: .72; }

/* ================================================================ icon button */
.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: var(--r-full);
  color: var(--text-2);
  transition: color var(--dur-fast) var(--ease-out);
}
.icon-btn::before {
  content: "";
  position: absolute;
  top: 4px; right: 4px; bottom: 4px; left: 4px;
  border-radius: 50%;
  background: var(--surface-3);
  opacity: 0;
  transform: scale(0.55);
  transition: transform var(--dur) var(--ease-out), opacity var(--dur) var(--ease-out);
}
.icon-btn .icon { position: relative; width: 24px; height: 24px; }
@media (hover: hover) { .icon-btn:hover:not(:disabled)::before { opacity: .6; transform: scale(1); } }
.icon-btn:active:not(:disabled)::before, .icon-btn.is-pressed:not(:disabled)::before { opacity: 1; transform: scale(1); transition-duration: var(--dur-press); }
.icon-btn:active:not(:disabled), .icon-btn.is-pressed:not(:disabled) { color: var(--text); }
.icon-btn.is-quiet, .icon-btn-quiet { color: var(--text-3); }
.icon-btn.is-quiet .icon { width: 20px; height: 20px; }
.icon-btn:disabled { color: var(--text-disabled); }
.icon-btn.is-on-scene { color: var(--scene-ink, var(--text)); }
.icon-btn.is-on-scene::before { background: var(--on-scene-chip); }

/* ================================================================ inputs */
.input, .textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-input);
  line-height: var(--lh-ui);
  -webkit-appearance: none;
  appearance: none;
  transition: background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.textarea { resize: none; line-height: var(--lh-wrap); }
.input-lg { min-height: 52px; padding: 14px 16px; border-radius: var(--r-lg); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
.input:focus, .textarea:focus { background: var(--surface); box-shadow: 0 0 0 1.5px var(--primary), var(--focus-ring); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { box-shadow: 0 0 0 1.5px var(--danger); }
.input[type="date"], .input[type="time"] { min-width: 0; }
.input::-webkit-date-and-time-value { text-align: left; }
.input::-webkit-calendar-picker-indicator { opacity: .55; }
[data-theme="dark"] .input::-webkit-calendar-picker-indicator { filter: invert(1); }

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field + .field { margin-top: var(--sp-4); }
.field-label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2); }
.field-error { font-size: var(--fs-sm); line-height: var(--lh-wrap); color: var(--danger); }
.field-error:empty { display: none; }
.field-hint { font-size: var(--fs-sm); font-weight: var(--fw-regular); color: var(--text-3); }

/* input with a trailing icon button (password eye) and/or a leading glyph */
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 48px; }
.input-wrap > .icon-btn { position: absolute; right: 0; top: 50%; margin-top: -22px; color: var(--text-3); }
.input-wrap > .icon-btn .icon { width: 20px; height: 20px; }
.input-wrap.has-lead .input { padding-left: 46px; }
.input-lead { position: absolute; left: 14px; top: 50%; margin-top: -10px; width: 20px; height: 20px; color: var(--text-3); pointer-events: none; }
.input-wrap.has-lead:focus-within .input-lead { color: var(--primary-text); }

/* ================================================================ chips, tags, badges */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: none;
  height: 34px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-regular);
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-out);
}
.chip::after { content: ""; position: absolute; top: -5px; bottom: -5px; left: 0; right: 0; }
.chip .icon { width: 16px; height: 16px; }
.chip:active:not(:disabled), .chip.is-pressed:not(:disabled) { transform: scale(0.95); background: var(--surface-3); transition-duration: var(--dur-press); }
.chip.is-active, .chip.is-on, .chip[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary-text); font-weight: var(--fw-semibold); }
.chip.is-active .icon, .chip.is-on .icon, .chip[aria-pressed="true"] .icon { --dt: .25; }
.chip:disabled { color: var(--text-disabled); }
.chip.is-on-scene { background: var(--on-scene-chip); color: var(--scene-ink, var(--text)); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip-scroll {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(-1 * var(--page-x));
  padding: 5px var(--page-x);
}
.chip-scroll::-webkit-scrollbar { display: none; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
}
.tag .icon { width: 13px; height: 13px; }
.tag-primary { background: var(--primary-soft); color: var(--primary-text); }
.tag-teal { background: var(--teal-soft); color: var(--teal-text); }
.tag-amber { background: var(--amber-soft); color: var(--amber-text); }
.tag-rose { background: var(--rose-soft); color: var(--rose-text); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-quiet { background: var(--surface-2); color: var(--text-2); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.badge-new, .badge.is-new { background: var(--primary); color: var(--on-primary); padding: 0 6px; }
.badge-dot { width: 8px; min-width: 8px; height: 8px; padding: 0; background: var(--primary); box-shadow: 0 0 0 2px var(--bg-elev); }

/* ================================================================ duotone icon tiles (A's style) */
.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--tone-soft, var(--surface-2));
  color: var(--tone-ink, var(--text-2));
}
.tile .icon { --dt: .24; width: 22px; height: 22px; }
.tile-sm { width: 32px; height: 32px; border-radius: var(--r-sm); }
.tile-sm .icon { width: 18px; height: 18px; }
.tile-lg { width: 48px; height: 48px; border-radius: var(--r-lg); }
.tile-lg .icon { width: 26px; height: 26px; }
.tone-chat { --tone-ink: var(--chat-ink); --tone-soft: var(--chat-soft); --tone-text: var(--chat-text); }
.tone-life { --tone-ink: var(--life-ink); --tone-soft: var(--life-soft); --tone-text: var(--life-text); }
.tone-workshop { --tone-ink: var(--workshop-ink); --tone-soft: var(--workshop-soft); --tone-text: var(--workshop-text); }
.tone-ddz { --tone-ink: var(--ddz-ink); --tone-soft: var(--ddz-soft); --tone-text: var(--ddz-text); }
.tone-me { --tone-ink: var(--me-ink); --tone-soft: var(--me-soft); --tone-text: var(--me-text); }
.tone-paint { --tone-ink: var(--paint-ink); --tone-soft: var(--paint-soft); --tone-text: var(--paint-text); }
.tone-primary { --tone-ink: var(--primary); --tone-soft: var(--primary-soft); --tone-text: var(--primary-text); }
.tone-teal { --tone-ink: var(--teal); --tone-soft: var(--teal-soft); --tone-text: var(--teal-text); }
.tone-amber { --tone-ink: var(--amber-text); --tone-soft: var(--amber-soft); --tone-text: var(--amber-text); }
.tone-rose { --tone-ink: var(--rose-text); --tone-soft: var(--rose-soft); --tone-text: var(--rose-text); }
.tone-quiet { --tone-ink: var(--text-2); --tone-soft: var(--surface-2); --tone-text: var(--text-2); }

/* ================================================================ segmented control */
.seg {
  position: relative;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-3);
}
.seg > button {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-regular);
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.seg > button::after { content: ""; position: absolute; top: -7px; bottom: -7px; left: 0; right: 0; }
.seg > button:active, .seg > button.is-pressed { transform: scale(0.96); transition-duration: var(--dur-press); }
.seg > button[aria-pressed="true"], .seg > button[aria-selected="true"], .seg > button.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: var(--fw-semibold);
  box-shadow: 0 1px 2px rgba(84, 48, 24, 0.10), 0 1px 6px rgba(84, 48, 24, 0.06);
}
[data-theme="dark"] .seg > button[aria-pressed="true"], [data-theme="dark"] .seg > button[aria-selected="true"], [data-theme="dark"] .seg > button.is-active { background: var(--surface-2); box-shadow: 0 0 0 1px rgba(255, 230, 210, 0.06); }
.seg-lg > button { height: 40px; font-size: var(--fs-base); }
.seg.is-compact > button { height: 30px; font-size: var(--fs-xs); padding: 0 var(--sp-3); }
.seg.is-inline { display: inline-flex; }
.seg.is-inline > button { flex: none; }

/* ================================================================ cards, grouped lists */
.card {
  position: relative;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: var(--sp-4); }
.card-raised { box-shadow: var(--shadow-2); }

.group {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.group + .group { margin-top: var(--sp-3); }
.row {
  --row-inset: var(--sp-4);
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 52px;
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  color: var(--text);
}
.group.inset-icon .row { --row-inset: calc(var(--sp-4) + 36px + var(--sp-3)); }
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--row-inset);
  right: 0;
  height: 1px;
  background: var(--line);
}
button.row, a.row, .row.is-button { cursor: pointer; transition: background-color var(--dur-fast) var(--ease-out); text-decoration: none; }
button.row:active:not(:disabled), a.row:active, .row.is-button:active,
button.row.is-pressed:not(:disabled), a.row.is-pressed, .row.is-button.is-pressed { background: var(--surface-2); transition-duration: var(--dur-press); }
@media (hover: hover) { button.row:hover:not(:disabled), a.row:hover { background: var(--surface-2); } }
/* .row-icon: v2 neutral tile, now duotone; add a tone-* class for a section accent */
.row-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--tone-soft, var(--surface-2));
  color: var(--tone-ink, var(--text-2));
}
.row-icon .icon { --dt: .22; width: 20px; height: 20px; }
.row-lead { display: inline-flex; flex: none; color: var(--text-2); }
.row.is-danger .row-lead { color: var(--danger); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-size: var(--fs-base); line-height: var(--lh-wrap); color: var(--text); }
.row-sub { display: block; margin-top: 2px; font-size: var(--fs-sm); line-height: var(--lh-wrap); color: var(--text-3); }
.row-value { flex: none; max-width: 50%; color: var(--text-3); font-size: var(--fs-base); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-chevron { flex: none; color: var(--text-3); margin-right: -4px; }
.row-chevron .icon, .row .icon.row-chevron { width: 18px; height: 18px; }
.row.is-danger, .row.is-danger .row-title { color: var(--danger); }
.row:disabled, .row.is-disabled { cursor: default; }
.row:disabled .row-title, .row.is-disabled .row-title { color: var(--text-disabled); }
.row-check { flex: none; color: var(--primary-text); }
.row-check .icon { width: 20px; height: 20px; }
.row-empty { color: var(--text-3); font-size: var(--fs-sm); }
.row-error { justify-content: space-between; }
.row-error .inline-error { flex: 1; min-width: 0; }
.add-row .add-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 22px;
  height: 22px;
  color: var(--primary-text);
}
.add-row .row-title { color: var(--primary-text); }

/* Section titles (B: dark, 17px semibold); inside sheets they stay small and quiet */
.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 32px;
  margin: var(--sp-6) 0 var(--sp-2);
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
}
.section-label:first-child { margin-top: var(--sp-4); }
.section-label > span + span, .section-label .section-aside { color: var(--text-3); font-size: var(--fs-sm); font-weight: var(--fw-regular); }
.section-label .btn-sm { margin-right: calc(-1 * var(--sp-2)); }
.sheet .section-label { min-height: 28px; margin: var(--sp-5) var(--sp-1) var(--sp-2); color: var(--text-3); font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.section-note { margin: var(--sp-2) 0 0; color: var(--text-3); font-size: var(--fs-sm); line-height: var(--lh-wrap); }

/* ================================================================ switch & round check */
.switch {
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  transition: background-color var(--dur) var(--ease-out);
}
.switch::before { content: ""; position: absolute; top: -7px; bottom: -7px; left: -2px; right: -2px; }
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(43, 30, 23, 0.22), 0 0 0 0.5px rgba(43, 30, 23, 0.06);
  transition: transform var(--dur) var(--ease-spring), width var(--dur) var(--ease-out);
}
.switch:active, .switch.is-pressed { box-shadow: inset 0 0 0 30px var(--press-tint); }
.switch:active::after, .switch.is-pressed::after { width: 28px; }
.switch[aria-checked="true"] { background: var(--teal); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch[aria-checked="true"]:active::after, .switch[aria-checked="true"].is-pressed::after { transform: translateX(16px); }
[data-theme="dark"] .switch::after { background: #F5ECE3; }

.check {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  margin: -10px -6px -10px -12px;
  border-radius: var(--r-full);
  color: var(--on-teal);
}
.check::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.75px solid var(--check-ring, var(--line-strong));
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-spring);
}
.check:active, .check.is-pressed { background-color: var(--press-tint); }
.check:active::before, .check.is-pressed::before { transform: scale(0.86); }
.check .icon { position: relative; width: 14px; height: 14px; opacity: 0; transform: scale(.6); transition: opacity var(--dur-fast), transform var(--dur) var(--ease-spring); }
.check[aria-checked="true"]::before { background: var(--teal); border-color: var(--teal); }
.check[aria-checked="true"] .icon { opacity: 1; transform: none; }

/* ================================================================ overlays: scrim, sheet, dialog, drawer */
.scrim {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: var(--z-sheet);
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--dur-sheet) var(--ease-out);
}
.scrim.is-open { opacity: 1; }
.scrim:not(.is-open) { pointer-events: none; } /* don't eat taps while fading out */
.scrim.is-drawer { z-index: var(--z-drawer); }
.scrim.is-dragging { transition: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: calc(100% - var(--safe-top) - var(--sp-10));
  margin: 0 auto;
  padding-bottom: var(--safe-bottom);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform: translate3d(0, 100%, 0);
  transition: transform var(--dur-sheet) var(--ease-sheet);
  will-change: transform;
}
.sheet.is-open { transform: translate3d(0, 0, 0); }
.sheet.is-dragging { transition: none; }
.sheet.is-closing { transition-timing-function: var(--ease-out); }
.sheet-grab {
  flex: none;
  display: flex;
  justify-content: center;
  padding: var(--sp-2) 0 var(--sp-1);
  touch-action: none;
  cursor: grab;
}
.sheet-grab::before {
  content: "";
  width: 36px;
  height: 5px;
  border-radius: var(--r-full);
  background: var(--line-strong);
}
.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 var(--sp-12) var(--sp-2);
  touch-action: none;
}
.sheet-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  text-align: center;
}
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--page-x) var(--sp-4);
}
.sheet-body > .section-label:first-child { margin-top: var(--sp-1); }
.sheet .group { background: var(--surface-2); box-shadow: none; }
.sheet .group .row + .row::before { background: var(--line); }
.sheet .group button.row:active:not(:disabled), .sheet .group button.row.is-pressed:not(:disabled) { background: var(--surface-3); }
@media (hover: hover) { .sheet .group button.row:hover:not(:disabled) { background: var(--surface-3); } }
.sheet .input, .sheet .textarea { background: var(--surface-2); }
.sheet .group .tag { background: var(--surface-3); }
.sheet .input:focus, .sheet .textarea:focus { background: var(--surface); }
.sheet .note { margin-bottom: var(--sp-2); }
.sheet-actions { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-5); }
.sheet-cancel { margin-top: var(--sp-2); }
.sheet.is-viewer .sheet-body { padding-bottom: var(--sp-5); }
.viewer img { width: 100%; height: auto; max-height: 70vh; object-fit: contain; border-radius: var(--r-md); }

.dialog-wrap {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: var(--z-sheet);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  pointer-events: none;
}
.dialog {
  width: 100%;
  max-width: 320px;
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  opacity: 0;
  transform: scale(.94);
  transition: opacity var(--dur) var(--ease-out), transform var(--dur-slow) var(--ease-spring);
  pointer-events: auto;
}
.dialog.is-open { opacity: 1; transform: none; }
.dialog-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
.dialog-msg { margin-top: var(--sp-2); color: var(--text-2); font-size: var(--fs-base); line-height: var(--lh-wrap); }
.dialog .input { margin-top: var(--sp-4); }
.dialog .field-error { margin-top: var(--sp-1); }
.dialog-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-5); }
.dialog-actions .btn { flex: 1; padding: 0 var(--sp-3); }

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  width: 84%;
  max-width: 340px;
  padding: var(--safe-top) 0 var(--safe-bottom) var(--safe-left);
  background: var(--bg-elev);
  box-shadow: var(--shadow-3);
  transform: translate3d(-104%, 0, 0);
  transition: transform var(--dur-sheet) var(--ease-sheet);
}
.drawer.is-open { transform: translate3d(0, 0, 0); }
.drawer.is-dragging { transition: none; }

/* ================================================================ toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-4));
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: calc(100% - 2 * var(--sp-6));
  min-height: 44px;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-full);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: var(--fs-sm);
  line-height: var(--lh-wrap);
  box-shadow: var(--shadow-2);
  opacity: 0;
  transform: translate(-50%, 10px) scale(.98);
  transition: opacity var(--dur) var(--ease-out), transform var(--dur-slow) var(--ease-out);
  pointer-events: none;
}
.toast.is-open { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-msg { min-width: 0; }
.toast-action {
  position: relative;
  flex: none;
  margin: -8px -10px -8px 0;
  height: 44px;
  padding: 0 var(--sp-3);
  border-left: 1px solid var(--toast-divider);
  color: var(--toast-action);
  font-weight: var(--fw-semibold);
}
.toast-action:active, .toast-action.is-pressed { opacity: .7; }
/* Chat: float above the composer (chat.js may publish its live height as --composer-h on <html>);
   while typing, drop in under the top bar so it never covers the input. */
html.is-authed[data-tab="chat"] .toast { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--composer-h, 104px)); }
html.composer-focus[data-tab="chat"] .toast {
  top: calc(var(--app-top, 0px) + var(--safe-top) + var(--topbar-h) + var(--sp-2));
  bottom: auto;
  transform: translate(-50%, -10px) scale(.98);
}
html.composer-focus[data-tab="chat"] .toast.is-open { transform: translate(-50%, 0); }
html.ddz-immersive[data-tab="ddz"] .toast,
html:not(.is-authed) .toast { bottom: calc(var(--safe-bottom) + var(--sp-6)); }

/* ================================================================ empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-6);
  text-align: center;
}
.empty > .icon { width: 48px; height: 48px; color: var(--text-3); --dt: .14; }
.empty > .tile { margin-bottom: var(--sp-1); }
.empty-art { width: 120px; height: auto; margin-bottom: var(--sp-1); }
.empty-title { color: var(--text); font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.empty-sub { margin-top: calc(-1 * var(--sp-2)); color: var(--text-3); font-size: var(--fs-sm); line-height: var(--lh-wrap); }
.empty .btn { margin-top: var(--sp-1); }

/* ================================================================ skeleton (soft shimmer) */
.skeleton {
  display: block;
  height: 12px;
  border-radius: var(--r-xs);
  background-color: var(--surface-2);
  background-image: linear-gradient(90deg, var(--sheen-0) 0%, var(--sheen) 50%, var(--sheen-0) 100%);
  background-size: 60% 100%;
  background-repeat: no-repeat;
  background-position: -150% 0;
  animation: shimmer 1.5s var(--ease-in-out) infinite;
}
.skeleton + .skeleton { margin-top: var(--sp-2); }
.skeleton.is-block { height: auto; border-radius: var(--r-lg); }
@keyframes shimmer { from { background-position: -150% 0; } to { background-position: 250% 0; } }

/* ================================================================ avatar (the owner's photo is the assistant's face) */
.avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-3);
  box-shadow: 0 0 0 2px var(--surface), var(--edge);
}
.avatar-28 { width: 28px; height: 28px; }
.avatar-ring {
  position: relative;
  flex: none;
  padding: 4px;
  border-radius: 50%;
  background: var(--avatar-ring);
  box-shadow: var(--shadow-avatar);
}
.avatar-ring img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.monogram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1;
}

/* ================================================================ misc */
.hairline { height: 1px; background: var(--line); border: 0; margin: 0; }
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin .8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.note {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: var(--lh-wrap);
}
.note .icon { width: 18px; height: 18px; margin-top: 1px; color: var(--text-3); flex: none; }
.inline-error {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: var(--lh-wrap);
}
.inline-error .icon { width: 18px; height: 18px; margin-top: 1px; color: var(--danger); flex: none; --dt: .14; }

/* ================================================================ sub-pages (js/subpage.js): push from the right
   over a parallax underlay; edge-swipe-back drags them (js/motion.js sets inline transforms). */
.view-root {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: transform var(--dur-page) var(--ease-out);
}
.view-root::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 30;
  background: rgba(30, 20, 14, 0.12);
  opacity: var(--underlay-o, 0);
  pointer-events: none;
  transition: opacity var(--dur-page) var(--ease-out);
}
.view.has-subpage .view-root { transform: translate3d(-28%, 0, 0); pointer-events: none; }
.view.has-subpage .view-root::after { opacity: var(--underlay-o, 1); }
.subpage {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translate3d(100%, 0, 0);
  visibility: hidden;
  box-shadow: -1px 0 0 var(--line), -12px 0 32px rgba(43, 30, 23, 0.10);
  transition: transform var(--dur-page) var(--ease-out), visibility 0s linear var(--dur-page);
}
.subpage.is-open { transform: none; visibility: visible; transition: transform var(--dur-page) var(--ease-out), visibility 0s; }
.subpage.is-dragging, .view.is-swiping .view-root, .view.is-swiping .view-root::after { transition: none; }
.view.no-anim .view-root, .view.no-anim .view-root::after, .view.no-anim .subpage { transition: none; }

/* ================================================================ list helpers (js/motion.js) */
/* swipeToReveal(row): the row's children slide left over its own background, actions slide in at the right */
.swipe-host { position: relative; overflow: hidden; touch-action: pan-y; }
.swipe-host > :not(.swipe-actions) { transform: translate3d(var(--swipe-x, 0px), 0, 0); transition: transform var(--dur-slow) var(--ease-out); }
.swipe-host.is-swiping > :not(.swipe-actions) { transition: none; }
.swipe-host:not(.is-revealed):not(.is-swiping) > .swipe-actions { visibility: hidden; }
.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  transform: translate3d(calc(100% + var(--swipe-x, 0px)), 0, 0);
  transition: transform var(--dur-slow) var(--ease-out);
}
.swipe-host.is-swiping .swipe-actions { transition: none; }
.swipe-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 76px;
  padding: 0 var(--sp-3);
  background: var(--surface-3);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.swipe-action .icon { width: 22px; height: 22px; --dt: .2; }
.swipe-action.is-danger { background: var(--danger); color: #FFFFFF; }
[data-theme="dark"] .swipe-action.is-danger { color: var(--bg); }
.swipe-action.is-primary { background: var(--primary); color: var(--on-primary); }
.swipe-action.is-teal { background: var(--teal); color: var(--on-teal); }
.swipe-action:active, .swipe-action.is-pressed { opacity: .82; }
/* longPress(el): visual hold state */
.is-holding { transform: scale(0.98); transition: transform var(--dur-slow) var(--ease-out); }

/* send-button morph (motion.morphButton): two stacked glyphs that rotate/scale between states */
.morph { position: relative; display: inline-flex; width: 20px; height: 20px; }
.morph > .icon { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transition: opacity var(--dur) var(--ease-out), transform var(--dur-slow) var(--ease-spring); }
.morph > .morph-b { opacity: 0; transform: scale(.4) rotate(-90deg); }
.is-morphed .morph > .morph-a { opacity: 0; transform: scale(.4) rotate(90deg); }
.is-morphed .morph > .morph-b { opacity: 1; transform: none; }

/* ================================================================ prose (assistant answers, debate, documents) */
.prose { font-size: var(--fs-base); line-height: var(--lh-prose); color: var(--text); overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 .8em; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  margin: 1.25em 0 .5em;
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
}
.prose h1 { font-size: var(--fs-xl); }
.prose h2 { font-size: var(--fs-lg); }
.prose h3, .prose h4, .prose h5, .prose h6 { font-size: var(--fs-base); }
.prose ul, .prose ol { margin: 0 0 .8em; padding-left: 1.4em; }
.prose li { margin: .25em 0; }
.prose li > p { margin: 0; }
.prose li > ul, .prose li > ol { margin: .2em 0 0; }
.prose li::marker { color: var(--text-3); }
.prose strong { font-weight: var(--fw-semibold); }
.prose a { color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.prose blockquote { margin: 0 0 .8em; padding-left: var(--sp-3); border-left: 3px solid var(--primary-soft-press); color: var(--text-2); }
.prose hr { height: 1px; margin: 1.4em 0; border: 0; background: var(--line); }
.prose :not(pre) > code {
  padding: .12em .4em;
  border-radius: var(--r-xs);
  background: var(--code-inline-bg);
  color: var(--code-inline-text);
  font-family: var(--font-mono);
  font-size: .88em;
  overflow-wrap: anywhere;
}
.code-block { margin: .9em 0; border-radius: var(--r-md); background: var(--code-bg); overflow: hidden; }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 var(--sp-1) 0 var(--sp-3);
  background: var(--code-head);
  color: var(--code-dim);
  font-size: var(--fs-xs);
  line-height: 1;
}
.code-copy {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  color: var(--code-dim);
  font-size: var(--fs-xs);
}
.code-copy::after { content: ""; position: absolute; top: -6px; bottom: -6px; left: 0; right: 0; }
.code-copy .icon { width: 16px; height: 16px; }
.code-copy:active, .code-copy.is-pressed { background: rgba(255, 255, 255, 0.08); }
.code-copy.is-done { color: var(--code-func); }
.code-block pre {
  margin: 0;
  padding: var(--sp-3);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: var(--fs-sm);
  line-height: var(--lh-prose);
}
.code-block code {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: var(--lh-prose);
  color: var(--code-text);
  white-space: pre;
  tab-size: 4;
  overflow-wrap: normal;
}
.tk-kw { color: var(--code-keyword); }
.tk-str { color: var(--code-string); }
.tk-num { color: var(--code-number); }
.tk-com { color: var(--code-comment); font-style: italic; }
.tk-fn { color: var(--code-func); }
.table-wrap { margin: .9em 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.prose table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: var(--fs-sm); line-height: var(--lh-wrap); }
.prose th, .prose td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { color: var(--text-2); font-weight: var(--fw-semibold); white-space: nowrap; border-bottom-color: var(--line-strong); }
.prose td { min-width: 64px; max-width: 15em; }
.prose td code, .prose th code { white-space: nowrap; font-size: var(--fs-xs); }
.prose tr > :first-child { padding-left: 0; }
.prose tr > :last-child { padding-right: 0; }
.math:not(.is-done), .math.is-error {
  font-family: var(--font-mono);
  font-size: .88em;
  color: var(--text-2);
  overflow-wrap: anywhere;
}
.prose .math-display {
  display: block;
  margin: .8em 0;
  padding: 2px 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.prose .math-display:not(.is-done), .prose .math-display.is-error {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--code-inline-bg);
  white-space: pre-wrap;
}
.prose .math-display.is-pending { color: var(--text-3); }
.prose .katex { font-size: 1.1em; }
.prose .katex-display { margin: 0; }
.prose .math-inline .katex { white-space: normal; }
.caret {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-left: 2px;
  vertical-align: -0.18em;
  background: var(--primary);
  animation: caret-blink 1s steps(1, end) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

/* ================================================================ reduced motion: opacity only */
@media (prefers-reduced-motion: reduce) {
  .press:active, .press.is-pressed, .card.is-tappable:active, .card.is-tappable.is-pressed,
  .btn:active:not(:disabled), .btn.is-pressed:not(:disabled), .btn-primary:active:not(:disabled), .btn-primary.is-pressed:not(:disabled),
  .chip:active:not(:disabled), .chip.is-pressed:not(:disabled), .seg > button:active, .seg > button.is-pressed,
  .is-holding { transform: none; }
  .icon-btn::before { transform: none; }
  .sheet, .sheet.is-open { transform: none; opacity: 0; transition: opacity var(--dur-sheet) linear; }
  .sheet.is-open { opacity: 1; }
  .drawer, .drawer.is-open { transform: none; opacity: 0; transition: opacity var(--dur-sheet) linear; visibility: hidden; }
  .drawer.is-open { opacity: 1; visibility: visible; }
  .dialog { transform: none; }
  .toast, .toast.is-open { transform: translate(-50%, 0); }
  .view.has-subpage .view-root { transform: none; }
  .subpage { transform: none; opacity: 0; transition: opacity var(--dur-page) linear, visibility 0s linear var(--dur-page); }
  .subpage.is-open { opacity: 1; transition: opacity var(--dur-page) linear, visibility 0s; }
  .skeleton { animation: skeleton-pulse 2.4s linear infinite alternate; background-image: none; }
  .morph > .icon { transform: none; }
  .switch::after { transition-timing-function: linear; }
}
@keyframes skeleton-pulse { from { opacity: 1; } to { opacity: .6; } }
