/* Shared components: sheets, segmented controls, switches, steppers, the crisis hint,
   the one celebration, line fields and small status lines. */

/* ---------- Extra button variants ---------- */
.btn--danger { --btn-bg: var(--danger); --btn-fg: #fff; min-height: 56px; font-weight: 600; }
html[data-theme='night'] .btn--danger { --btn-fg: #1a1210; }
.btn--danger:hover { box-shadow: none; transform: none; filter: brightness(1.06); }
.btn--danger-ghost { --btn-bg: transparent; --btn-fg: var(--danger); --btn-bd: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn--danger-ghost:hover { --btn-bg: color-mix(in srgb, var(--danger) 8%, transparent); box-shadow: none; }
.btn[aria-busy='true'] { opacity: .7; }

.chip--small { min-height: 44px; padding: 8px 15px; font-size: var(--text-small); gap: 8px; }
.chip--quiet { min-height: 44px; padding: 8px 16px; background: transparent; font-size: var(--text-small); }
.chips-row { display: flex; flex-wrap: wrap; gap: 8px; }
.optional { font-weight: 400; color: var(--faint); font-size: var(--text-micro); margin-left: 6px; }

/* Line fields: no boxes, only a baseline — the letter, the notebook. */
.input--line, .textarea--line { border: 0; border-bottom: 1px solid var(--line-strong); border-radius: 0; background: transparent; padding-inline: 2px; }
.input--line:focus, .textarea--line:focus { box-shadow: 0 1px 0 var(--green); border-color: var(--green); }
.textarea--line { min-height: 64px; }
fieldset.field { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.field legend { padding: 0; margin-bottom: 8px; }

/* Tiny JS autosize fallback hook (field-sizing not supported) */
.is-autosize { overflow: hidden; }

/* Ripple hosts: the soft circle stays inside the control (motion.css draws it). */
:is(.seg button, .weather__tile, .bubble-chip, .icon-btn, .step, .door__frame, .book__toc [role='tab']) { position: relative; isolation: isolate; overflow: hidden; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  min-height: 44px; padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: var(--text-small); line-height: 1.3;
  transition: background-color .25s var(--ease-out), border-color .25s var(--ease-out), color .25s var(--ease-out), transform .3s var(--ease-settle);
}
.seg button:hover { border-color: var(--sage-500); transform: translateY(calc(var(--lift) * .5)); }
.seg button:active { transform: scale(var(--press)); transition-duration: .09s; }
.seg button[aria-pressed='true'] { background: var(--green); border-color: var(--green); color: var(--on-green); animation: pop .45s var(--ease-settle); }
.seg--dark button { background: transparent; color: var(--on-band); border-color: color-mix(in srgb, var(--on-band) 28%, transparent); }
.seg--dark button:hover { border-color: color-mix(in srgb, var(--on-band) 60%, transparent); }
.seg--dark button[aria-pressed='true'] { background: var(--on-band); color: var(--band); border-color: var(--on-band); }

/* ---------- Switch rows (role=switch) ---------- */
.toggle-row {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 10px 4px;
  text-align: left; color: inherit; font-size: var(--control); line-height: 1.35;
  border-bottom: 1px solid var(--line);
}
.toggle-row > .icon { width: 22px; height: 22px; color: var(--sage-500); }
.toggle-row > span { flex: 1; display: grid; gap: 2px; }
.toggle-row small { font-size: var(--text-micro); color: var(--muted); line-height: 1.45; }
.toggle-row[role='switch']::after {
  content: ''; flex-shrink: 0; width: 44px; height: 26px; border-radius: 999px;
  background: var(--line-strong) radial-gradient(circle at 13px 50%, var(--surface-raised) 0 9px, transparent 9.5px) no-repeat;
  transition: background-color var(--t-fast), background-position var(--t-fast) var(--ease-settle);
  background-position: 0 0;
}
.toggle-row[aria-checked='true']::after { background-color: var(--green); background-position: 18px 0; }
.toggle-row[role='switch']::after { transition: background-color .3s var(--ease-out), background-position .45s var(--ease-settle); }
.toggle-row:hover > span { color: var(--ink); }
.toggle-row--small { min-height: 48px; font-size: var(--text-small); border-bottom: 0; }
.band .toggle-row { border-bottom-color: color-mix(in srgb, var(--on-band) 14%, transparent); }
.band .toggle-row > .icon { color: var(--on-band-muted); }
.band .toggle-row[role='switch']::after { background-color: color-mix(in srgb, var(--on-band) 25%, transparent); background-image: radial-gradient(circle at 13px 50%, var(--on-band) 0 9px, transparent 9.5px); }
.band .toggle-row[aria-checked='true']::after { background-color: #c98d70; }

/* ---------- Stepper ---------- */
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper__label { min-width: 4.2em; font-size: var(--text-small); }
.stepper button { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid currentColor; opacity: .8; }
.stepper button:hover { opacity: 1; }
.stepper button .icon { width: 18px; height: 18px; }
.stepper output { min-width: 3.2em; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- Sheets (<dialog class="sheet">) ---------- */
dialog.sheet {
  --sheet-bg: var(--paper);
  padding: 0; border: 0; margin: auto;
  width: min(640px, calc(100vw - 32px)); max-width: none; max-height: min(88vh, 900px);
  border-radius: var(--radius-lg); background: var(--sheet-bg); color: var(--ink);
  box-shadow: var(--shadow-lg); overflow: hidden;
  opacity: 1; transform: none;
  transition: opacity .32s var(--ease-out), transform .42s var(--ease-settle), overlay .42s allow-discrete, display .42s allow-discrete;
}
dialog.sheet:not([open]) { opacity: 0; transform: translateY(18px); }
@starting-style { dialog.sheet[open] { opacity: 0; transform: translateY(24px); } }
dialog.sheet::backdrop { background: rgba(28, 40, 33, .46); background: var(--scrim); opacity: 1; transition: opacity .3s var(--ease-out), overlay .3s allow-discrete, display .3s allow-discrete; }
@starting-style { dialog.sheet[open]::backdrop { opacity: 0; } }
dialog.sheet[open] { display: flex; flex-direction: column; }
.sheet__scroll { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px clamp(22px, 4vw, 44px) clamp(28px, 4vw, 44px); -webkit-overflow-scrolling: touch; }
.sheet__bar { position: sticky; top: 0; z-index: 2; display: flex; justify-content: flex-end; margin: 0 calc(-1 * clamp(22px, 4vw, 44px)) 4px; padding: 10px 12px 0; background: linear-gradient(var(--sheet-bg) 70%, transparent); }
.sheet__close { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); transition: background-color var(--t-fast); }
.sheet__close:hover { background: var(--sage-100); }
.sheet__close--dark { color: var(--on-band); }
.sheet__close--dark:hover { background: color-mix(in srgb, var(--on-band) 12%, transparent); }
.sheet__title { font-size: clamp(34px, 3.4vw, 48px); line-height: 1.04; margin-bottom: 18px; outline: none; }
.sheet__status { min-height: 1.6em; margin-top: 14px; font-size: var(--text-small); color: var(--muted); }
.sheet__status--dark { color: var(--on-band-muted); }

/* Side panel on desktop */
@media (min-width: 768px) {
  dialog.sheet--side { margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(540px, 100vw); border-radius: var(--radius-lg) 0 0 var(--radius-lg); }
  dialog.sheet--side:not([open]) { transform: translateX(32px); }
  @starting-style { dialog.sheet--side[open] { transform: translateX(40px); } }
}
/* Full screen (rooms, emergency stop) */
dialog.sheet--full { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }

/* Bottom sheet on phones */
@media (max-width: 767px) {
  dialog.sheet:not(.sheet--full) { margin: auto 0 0; width: 100vw; max-height: 92dvh; border-radius: 24px 24px 0 0; }
  dialog.sheet:not(.sheet--full):not([open]) { transform: translateY(40px); }
  @starting-style { dialog.sheet:not(.sheet--full)[open] { transform: translateY(60px); } }
  dialog.sheet:not(.sheet--full) .sheet__scroll { padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }
}
html.is-quiet dialog.sheet, html.motion-reduced dialog.sheet { transition-duration: .001ms; }

/* Prose inside sheets */
.prose { display: grid; gap: 14px; max-width: 38em; }
.prose p { color: var(--ink-soft); }

/* ---------- Crisis hint (safety.js) ---------- */
.crisis-hint {
  display: flex; gap: 14px; align-items: flex-start; margin: 14px 0;
  padding: 16px 18px; border-radius: var(--radius); background: var(--terracotta-soft); color: var(--ink);
  font-size: var(--text-small); line-height: 1.55;
}
.crisis-hint__icon { width: 26px; height: 26px; color: var(--terracotta-ink); margin-top: 2px; }
.crisis-hint > div { display: grid; gap: 8px; justify-items: start; }
.crisis-hint__title { font-weight: 600; }
.band .crisis-hint, .room .crisis-hint { color: var(--ink); }

/* ---------- The one celebration: sprout or petals ---------- */
.celebration { position: fixed; z-index: 80; width: 0; height: 0; pointer-events: none; }
.celebration__sprout { position: absolute; left: -32px; top: -64px; width: 64px; height: 64px; color: var(--sage-500); }
.celebration__sprout svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.celebration__sprout path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: sprout-draw 1.2s var(--ease-settle) forwards, sprout-fade .6s 1.9s ease forwards; }
.celebration__sprout path:nth-child(2) { animation-delay: .35s, 1.9s; }
.celebration__sprout path:nth-child(3) { animation-delay: .55s, 1.9s; }
.celebration__petal { position: absolute; left: -8px; top: -12px; width: 16px; height: 22px; color: var(--terracotta); opacity: 0; animation: petal-fall 2.2s var(--ease-out) var(--delay, 0ms) forwards; }
.celebration__petal svg { width: 100%; height: 100%; fill: currentColor; opacity: .7; }
.celebration__petal:nth-child(even) { color: var(--sage-300); }
@keyframes sprout-draw { to { stroke-dashoffset: 0; } }
@keyframes sprout-fade { to { opacity: 0; } }
@keyframes petal-fall {
  0% { opacity: 0; transform: translate(0, 0) rotate(0); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx, 0), 120px) rotate(var(--rot, 40deg)); }
}

/* ---------- Data list (what the site knows) ---------- */
.data-list { display: grid; margin: 14px 0; }
.data-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: var(--text-small); }
.data-list li b { font-weight: 600; }
.data-list .is-empty { color: var(--muted); }
.data-list button { flex-shrink: 0; }

.forget-confirm { display: grid; gap: 10px; margin-top: 10px; padding: 14px 16px; border-radius: var(--radius-sm); background: rgba(255, 255, 255, .06); font-size: var(--text-small); }
.forget-confirm__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Shared «copy / share» action bar ---------- */
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.icon-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px; border-radius: 999px; font-size: var(--text-small); color: var(--ink-soft); transition: background-color .25s var(--ease-out), color .25s var(--ease-out), transform .3s var(--ease-settle); }
.icon-btn .icon { width: 18px; height: 18px; transition: transform .45s var(--ease-settle); }
.icon-btn:hover { background: var(--sage-100); color: var(--ink); }
.icon-btn:hover .icon { transform: scale(1.12); }
.icon-btn:active { transform: scale(var(--press)); transition-duration: .09s; }
.status-line { min-height: 1.5em; font-size: var(--text-small); color: var(--muted); }

/* Phrase quote — words, help sheet, deck back */
.quote-mark { width: 40px; height: 40px; color: var(--terracotta); opacity: .6; }

/* ---------- Mini breathing circle 3–6 (emergency stop, «очень тяжело») ---------- */
.mini-breath { display: flex; align-items: center; gap: 20px; margin-top: 22px; }
.mini-breath__circle {
  position: relative; flex-shrink: 0; width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--lamp) 55%, transparent) 0 38%, color-mix(in srgb, var(--lamp) 18%, transparent) 39% 100%);
  transform: scale(.55); transition: transform 3s var(--ease-breath);
}
.mini-breath__circle.is-in { transform: scale(1); transition-duration: 3s; }
.mini-breath__circle.is-out { transform: scale(.55); transition-duration: 6s; }
.mini-breath.is-static .mini-breath__circle { transform: scale(.8); transition: none; }
.mini-breath__text { font-family: var(--serif); font-size: clamp(26px, 2vw + 16px, 34px); font-variant-numeric: tabular-nums; line-height: 1.1; }
.mini-breath__cap { font-size: var(--text-small); color: var(--muted); margin-bottom: 2px; }
