/* Buttons, cards, inputs, chips, sheets, toasts, rings and meters. */

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
a.card, button.card { transition: transform 0.14s ease, filter 0.14s ease; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: var(--r-md);
  font-weight: 700; font-size: 1rem; text-align: center; transition: transform 0.12s ease, filter 0.12s ease, background 0.15s; user-select: none; -webkit-user-select: none; }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: var(--tap); padding: 0 14px; font-size: 0.92rem; border-radius: 14px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.soft { background: var(--accent-soft); color: var(--accent-strong); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost.danger-text { color: var(--danger); }
.btn.danger { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn.danger { color: #1a0d0a; }
.btn:disabled { opacity: 0.5; }
.btn.busy { opacity: 0.7; pointer-events: none; }
.btn.apple { background: #000; color: #fff; width: 100%; }
:root[data-theme="dark"] .btn.apple { background: #fff; color: #000; }
.btn.google { background: var(--raised); color: var(--text); border: 1px solid var(--line-strong); width: 100%; }
.link { color: var(--accent); font-weight: 700; min-height: var(--tap); display: inline-flex; align-items: center; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn { width: var(--tap); height: var(--tap); border-radius: 50%; display: inline-grid; place-items: center; color: var(--text-2); flex-shrink: 0; transition: background 0.15s, transform 0.12s; }
.icon-btn.small { width: 36px; height: 36px; position: relative; }
.icon-btn.small::after { content: ""; position: absolute; inset: -4px; }
.icon-btn:disabled { opacity: 0.3; }
.round-btn { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; flex-shrink: 0; transition: transform 0.12s; }
@media (hover: hover) {
  .btn.primary:hover { background: var(--accent-strong); }
  .icon-btn:hover:not(:disabled) { background: var(--sunken); }
  a.card:hover { border-color: var(--line-strong); }
}

/* ---------- inputs ---------- */
.input { width: 100%; min-height: 50px; padding: 12px 14px; font-size: 16px; border-radius: var(--r-md); border: 1.5px solid var(--line-strong); background: var(--raised); color: var(--text); appearance: none; -webkit-appearance: none; }
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea.input { resize: vertical; min-height: 64px; line-height: 1.4; }
input[type="date"].input { min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 0.86rem; font-weight: 700; color: var(--text-2); }
.field-hint { font-size: 0.82rem; color: var(--text-3); }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: var(--r-sm); padding: 10px 12px; font-size: 0.92rem; font-weight: 600; }
.check-row { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 4px 0; cursor: pointer; }
.check-row > span { flex: 1; }
input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); flex-shrink: 0; margin: 0; }
input[type="checkbox"].switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--sunken); border: 1px solid var(--line-strong); position: relative; transition: background 0.18s; cursor: pointer; }
input[type="checkbox"].switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform 0.2s cubic-bezier(.3,1.5,.5,1); }
input[type="checkbox"].switch:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"].switch:checked::after { transform: translateX(20px); }
.code-input { text-transform: uppercase; letter-spacing: 0.22em; font-weight: 700; font-variant-numeric: tabular-nums; }
.code-big { font-size: 1.5rem; font-weight: 800; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; color: var(--accent); }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { flex: 1; min-width: 0; }
.big-number { font-size: 1.7rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; min-height: 60px; }
.weight-entry { display: flex; align-items: center; gap: 10px; }
.weight-entry .input { flex: 1; min-width: 0; }
.unit-toggle { display: inline-flex; background: var(--sunken); border-radius: 12px; padding: 3px; flex-shrink: 0; }
.unit-toggle button { min-width: 46px; min-height: 38px; border-radius: 9px; font-weight: 700; color: var(--text-2); text-align: center; position: relative; }
.unit-toggle button::after { content: ""; position: absolute; inset: -4px 0; }
.unit-toggle button.on { background: var(--paper); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px; scrollbar-width: none; }
.chips.scroll-x::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: var(--r-pill); font-size: 0.82rem; font-weight: 700; white-space: nowrap; background: var(--sunken); color: var(--text-2); line-height: 1.2; }
.chip.soft, .chip.good { background: var(--accent-soft); color: var(--accent-strong); }
.chip.ember { background: var(--ember-soft); color: var(--ember-strong); }
.chip.quiet { background: var(--sunken); color: var(--text-2); }
.chip.level { background: var(--accent-soft); color: var(--accent-strong); padding-left: 4px; }
.chip .lv { background: var(--accent); color: var(--on-accent); border-radius: var(--r-pill); padding: 2px 8px; font-size: 0.74rem; }
.chip.tap { min-height: var(--tap); padding: 0 14px; font-size: 0.9rem; background: var(--accent-soft); color: var(--accent-strong); flex-shrink: 0; transition: transform 0.12s; }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--ember); color: #fff; font-size: 0.72rem; font-weight: 800; margin-left: 6px; }
.xp-pill { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: var(--r-pill); background: var(--ember); color: #fff; font-weight: 800; font-size: 0.8rem; white-space: nowrap; }
:root[data-theme="dark"] .xp-pill, :root[data-theme="dark"] .badge { color: #2a1408; }

/* ---------- segmented control ---------- */
.segmented { display: flex; background: var(--sunken); border-radius: 14px; padding: 4px; gap: 2px; }
.seg { flex: 1; min-height: 40px; border-radius: 11px; font-weight: 700; font-size: 0.92rem; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; white-space: nowrap; transition: background 0.15s, color 0.15s; position: relative; }
.seg::after { content: ""; position: absolute; inset: -4px 0; }
.seg.on { background: var(--paper); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.between > .segmented { flex: 0 1 auto; }

/* ---------- avatars ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 800; font-size: 0.9rem; flex-shrink: 0; letter-spacing: 0.02em; }
.avatar.sm { width: 28px; height: 28px; font-size: 0.68rem; }
.avatar.lg { width: 60px; height: 60px; font-size: 1.3rem; }
.avatar-stack { display: flex; align-items: center; }
.avatar-stack .avatar { margin-right: -8px; border: 2px solid var(--paper); box-sizing: content-box; }
.avatar-stack .muted { margin-left: 16px; }

/* ---------- lists ---------- */
.card.list { padding: 4px 16px; gap: 0; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 0; border-bottom: 1px solid var(--line); width: 100%; }
.list-row:last-child { border-bottom: 0; }
.list-row.tap { transition: opacity 0.12s; }
.list-row.tap:active { opacity: 0.6; }
.list-row .segmented { flex: 0 0 auto; }
.list-row .seg { min-height: 36px; padding: 0 10px; font-size: 0.86rem; }

/* ---------- rings, bars, meters ---------- */
.ring { position: relative; flex-shrink: 0; }
.ring svg { position: absolute; inset: 0; }
.ring-track { stroke: var(--accent-soft); }
.ring-fill { stroke: var(--accent); transition: stroke-dashoffset 0.9s cubic-bezier(.34, 1.4, .5, 1); }
.ring.complete .ring-fill { stroke: var(--ember); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ring-num { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ring-cap { font-size: 0.72rem; color: var(--text-2); font-weight: 650; }
.xpbar, .meter, .habit-bar { display: block; height: 8px; border-radius: 99px; background: var(--accent-soft); overflow: hidden; }
.xpbar i, .meter i, .habit-bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.8s cubic-bezier(.3, 1.2, .5, 1); }
.xpbar i { background: linear-gradient(90deg, var(--ember), #EEB333); }
.xpbar { background: var(--ember-soft); height: 7px; }
.xpbar.big { height: 12px; }
.meter { height: 12px; }
.meter.thin { height: 5px; }
.meter i.done { background: var(--ember); }
.habit-bar { height: 5px; margin-top: 6px; background: color-mix(in srgb, var(--habit, var(--accent)) 18%, transparent); }
.habit-bar i { background: var(--habit, var(--accent)); }
.habit-bar.big { height: 10px; margin-top: 0; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: var(--sunken); border-radius: var(--r-md); padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile-label { font-size: 0.76rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.tile-value { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-value small { font-size: 0.85rem; font-weight: 700; color: var(--text-2); }
.tile-sub { font-size: 0.8rem; color: var(--text-2); }

/* ---------- empty + loading ---------- */
.empty-state { align-items: center; text-align: center; padding: 28px 20px; gap: 8px; border-style: dashed; box-shadow: none; background: transparent; }
.empty-emoji { font-size: 44px; line-height: 1; }
.empty-state p { color: var(--text-2); max-width: 300px; }
.empty-state .btn { margin-top: 8px; }
.loading-block { display: flex; flex-direction: column; gap: 10px; padding: 6px 0; }
.skeleton { display: block; height: 76px; border-radius: var(--r-lg); background: linear-gradient(90deg, var(--sunken) 25%, var(--paper) 50%, var(--sunken) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skeleton.short { width: 60%; height: 20px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity 0.22s ease; }
.sheet-backdrop.open { opacity: 1; }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; background: var(--paper); border-radius: 26px 26px 0 0; box-shadow: var(--shadow-up); display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(.2, .9, .3, 1); }
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 8px auto 0; flex-shrink: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px 6px 20px; flex-shrink: 0; }
.sheet-title { font-size: 1.2rem; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 4px max(20px, env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: 26px; max-height: 86dvh; transform: translateY(24px) scale(0.97); }
  .sheet.wide { max-width: 620px; }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 14px; }
}

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + 18px + env(safe-area-inset-bottom)); z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--canvas); padding: 11px 16px; border-radius: 14px; font-weight: 650; font-size: 0.92rem; box-shadow: var(--shadow); max-width: 440px; text-align: center; animation: toast-in 0.3s cubic-bezier(.3, 1.4, .5, 1); }
.toast.error { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast.error { color: #1a0d0a; }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity 0.22s, transform 0.22s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.94); } }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 120; }

/* ---------- legend ---------- */
.legend { display: flex; gap: 10px; font-size: 0.78rem; color: var(--text-2); font-weight: 650; }
.key { display: inline-flex; align-items: center; gap: 5px; }
.key::before { content: ""; width: 14px; height: 3px; border-radius: 2px; background: var(--accent); }
.key.pace::before { background: none; border-top: 2px dashed var(--ember); height: 0; }
.key.other::before { background: var(--text-3); opacity: 0.6; }

/* Compact links keep a full-size touch target. */
a.chip { position: relative; }
a.chip::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }
