/* Stream Evolution base: reset, typography and the shared component set.
   Requires tokens.css. Page stylesheets only add layout for their page —
   never redefine these components there. */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}
img, video, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); text-underline-offset: 3px; }
a:hover { color: var(--fg); }
h1, h2, h3, h4 { margin: 0; line-height: var(--leading-tight); font-weight: 750; letter-spacing: -.01em; }
h1 { font-size: var(--text-3xl); font-weight: 800; }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
p { margin: 0; }
code, kbd { font-family: var(--font-mono); font-size: .92em; }
hr { border: 0; border-top: var(--line-w) dashed var(--border); margin: var(--s-6) 0; }
::selection { background: var(--pop); color: var(--on-pop); }

:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: var(--s-4); top: -60px; z-index: 100; }
.skip-link:focus { top: var(--s-4); }

.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.small { font-size: var(--text-sm); }
.mono { font-family: var(--font-mono); }

/* ---------- Layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s-2); }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.container { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 0 var(--s-4); }

/* ---------- Buttons: sticker style, press down on click ---------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--fg);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5);
  border: var(--line-w) solid var(--ink); border-radius: var(--r-md);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 700; font-size: var(--text-md); line-height: 1; text-decoration: none; white-space: nowrap;
  box-shadow: var(--e-1);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), background var(--dur-fast);
}
.btn:hover { background: var(--surface-3); color: var(--btn-fg); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: var(--e-1); }
.btn svg { width: 18px; height: 18px; flex: none; }

.btn-primary { --btn-bg: var(--brand); --btn-fg: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-pop { --btn-bg: var(--pop); --btn-fg: var(--on-pop); }
.btn-pop:hover { background: var(--pop); filter: brightness(1.08); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
:root:not([data-theme="light"]) .btn-danger { --btn-fg: #1a1033; }
.btn-ghost {
  --btn-bg: transparent; border-color: transparent; box-shadow: none;
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost:active { transform: none; }
.btn-sm { min-height: 36px; padding: 0 var(--s-3); font-size: var(--text-sm); border-radius: 10px; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn-block { width: 100%; }
.btn[aria-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--btn-fg); border-right-color: transparent;
  animation: se-spin .7s linear infinite;
}

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 650; font-size: var(--text-sm); color: var(--fg); }
.hint { font-size: var(--text-sm); color: var(--fg-muted); }
.field-error { font-size: var(--text-sm); color: var(--danger); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px var(--s-3);
  background: var(--surface-1); color: var(--fg);
  border: var(--line-w) solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 96px; resize: vertical; line-height: var(--leading); }
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--fg-subtle); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: none; border-color: var(--focus-ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 35%, transparent);
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.select {
  appearance: none; padding-right: 40px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-muted) 50%), linear-gradient(135deg, var(--fg-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
}
input[type="range"] { accent-color: var(--pop); width: 100%; }
input[type="color"] { width: 44px; height: 44px; padding: 2px; border: var(--line-w) solid var(--ink); border-radius: var(--r-md); background: var(--surface-1); cursor: pointer; }

/* Checkbox + switch */
.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; font-weight: 600; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--pop); margin: 0; }
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; font-weight: 600; min-height: 44px; }
.switch input {
  appearance: none; margin: 0; flex: none; cursor: pointer;
  width: 46px; height: 28px; border-radius: var(--r-full);
  background: var(--surface-3); border: var(--line-w) solid var(--ink);
  position: relative; transition: background var(--dur) var(--ease-out);
}
.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--fg); border: var(--line-w) solid var(--ink);
  transition: transform var(--dur) var(--ease-bounce);
}
.switch input:checked { background: var(--success); }
.switch input:checked::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface-1);
  border: var(--line-w) solid var(--ink);
  border-radius: var(--r-lg);
  box-shadow: var(--e-2);
  padding: var(--s-5);
}
.card-flat { box-shadow: none; border-color: var(--border); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: var(--text-xl); }

/* ---------- Badges ---------- */
.badge {
  --badge-bg: var(--surface-3); --badge-fg: var(--fg);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  background: var(--badge-bg); color: var(--badge-fg);
  font-size: var(--text-xs); font-weight: 700; line-height: 1.4; white-space: nowrap;
}
.badge-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-success { --badge-bg: var(--success-soft); --badge-fg: var(--success); }
.badge-warning { --badge-bg: var(--warning-soft); --badge-fg: var(--warning); }
.badge-danger  { --badge-bg: var(--danger-soft);  --badge-fg: var(--danger); }
.badge-info    { --badge-bg: var(--info-soft);    --badge-fg: var(--info); }
.badge-brand   { --badge-bg: var(--brand-soft);   --badge-fg: var(--fg); }
.badge-pop     { --badge-bg: var(--pop-soft);     --badge-fg: var(--pop); }
.badge-live::before { animation: se-pulse 1.6s ease-in-out infinite; }

/* ---------- Tabs / segmented control ---------- */
.seg {
  display: inline-flex; gap: 4px; padding: 4px; flex-wrap: wrap;
  background: var(--surface-2); border: var(--line-w) solid var(--ink); border-radius: var(--r-md);
}
.seg button, .seg a {
  min-height: 36px; padding: 0 var(--s-3); border: 0; border-radius: 8px;
  background: transparent; color: var(--fg-muted); font-weight: 700; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button:hover, .seg a:hover { color: var(--fg); }
.seg [aria-selected="true"], .seg [aria-current="page"], .seg [aria-pressed="true"], .seg .is-active {
  background: var(--pop); color: var(--on-pop);
}

/* ---------- Dialog (native <dialog>, driven by UI.openDialog) ---------- */
dialog.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; overflow: hidden;
  background: var(--surface-1); color: var(--fg);
  border: var(--line-w) solid var(--ink); border-radius: var(--r-xl); box-shadow: var(--e-3);
}
dialog.dialog.dialog-lg { width: min(860px, calc(100vw - 32px)); }
dialog.dialog.dialog-sm { width: min(420px, calc(100vw - 32px)); }
dialog.dialog[open] { display: flex; flex-direction: column; animation: se-dialog-in var(--dur-slow) var(--ease-bounce); }
dialog.dialog.is-closing { animation: se-dialog-out var(--dur-fast) var(--ease-out) forwards; }
dialog.dialog::backdrop { background: var(--overlay); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-5) var(--s-6) var(--s-3); }
.dialog-head h2 { font-size: var(--text-2xl); }
.dialog-body { padding: 0 var(--s-6) var(--s-5); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s-3); padding: var(--s-4) var(--s-6); border-top: var(--line-w) dashed var(--border); background: var(--surface-2); flex-wrap: wrap; }

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed; z-index: 1000; right: var(--s-4); bottom: var(--s-4);
  display: flex; flex-direction: column-reverse; gap: var(--s-2);
  width: min(380px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  background: var(--surface-1); color: var(--fg);
  border: var(--line-w) solid var(--ink); box-shadow: var(--e-2);
  animation: se-toast-in var(--dur-slow) var(--ease-bounce);
}
.toast::before { content: ""; flex: none; width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--info); }
.toast-success::before { background: var(--success); }
.toast-error::before { background: var(--danger); }
.toast-warning::before { background: var(--warning); }
.toast-msg { flex: 1; font-weight: 600; }
.toast .btn { min-height: 32px; }
.toast.is-leaving { animation: se-toast-out var(--dur) var(--ease-out) forwards; }

/* ---------- Banner (inline, page-level message) ---------- */
.banner {
  --banner-bg: var(--info-soft); --banner-fg: var(--info);
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  background: var(--banner-bg); border: var(--line-w) solid var(--banner-fg);
}
.banner strong { color: var(--banner-fg); }
.banner .banner-text { flex: 1; min-width: 200px; }
.banner-warning { --banner-bg: var(--warning-soft); --banner-fg: var(--warning); }
.banner-danger { --banner-bg: var(--danger-soft); --banner-fg: var(--danger); }
.banner-success { --banner-bg: var(--success-soft); --banner-fg: var(--success); }

/* ---------- Empty state ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-3);
  padding: var(--s-12) var(--s-6); border: var(--line-w) dashed var(--border-strong); border-radius: var(--r-lg);
}
.empty-art { font-size: 44px; line-height: 1; }
.empty h3 { font-size: var(--text-xl); }
.empty p { color: var(--fg-muted); max-width: 44ch; }

/* ---------- Copy field ---------- */
.copy-field { display: flex; gap: var(--s-2); align-items: stretch; }
.copy-field .input { font-family: var(--font-mono); font-size: var(--text-sm); }

/* ---------- Avatar ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; overflow: hidden;
  display: inline-grid; place-items: center; background: var(--pop); color: var(--on-pop);
  border: var(--line-w) solid var(--ink); font-weight: 800;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- KPI tile ---------- */
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi-value { font-size: var(--text-3xl); font-weight: 800; line-height: 1.1; }
.kpi-label { color: var(--fg-muted); font-size: var(--text-sm); font-weight: 600; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: var(--text-sm); color: var(--fg-muted); font-weight: 650; padding: var(--s-2) var(--s-3); }
.table td { padding: var(--s-3); border-top: var(--line-w) dashed var(--border); vertical-align: middle; }

/* ---------- Loading ---------- */
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--pop); border-right-color: transparent; animation: se-spin .7s linear infinite; }
.skeleton { border-radius: var(--r-md); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: se-shimmer 1.2s linear infinite; min-height: 16px; }

/* ---------- Public site shell (home, legal, library, auth, mobile…) ---------- */
.site-header { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: var(--line-w) solid var(--ink); }
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: 68px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: var(--s-2); color: var(--fg); text-decoration: none; font-weight: 800; font-size: var(--text-lg); }
.brand img { width: 36px; height: 36px; border-radius: 10px; border: var(--line-w) solid var(--ink); }
.site-nav { display: flex; align-items: center; gap: var(--s-1); flex-wrap: wrap; }
.site-nav a:not(.btn) { color: var(--fg-muted); text-decoration: none; font-weight: 650; padding: 10px var(--s-3); border-radius: 10px; min-height: 44px; display: inline-flex; align-items: center; }
.site-nav a:not(.btn):hover, .site-nav a[aria-current="page"] { color: var(--fg); background: var(--surface-2); }
.site-footer { border-top: var(--line-w) solid var(--ink); margin-top: var(--s-16); padding: var(--s-8) 0; color: var(--fg-muted); font-size: var(--text-sm); }
.site-footer .container { display: flex; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.site-footer a { color: var(--fg-muted); min-height: 44px; display: inline-flex; align-items: center; padding: 0 var(--s-2); }
.site-main { padding: var(--s-8) 0; }

/* Theme toggle icon swap */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ---------- Keyframes ---------- */
@keyframes se-spin { to { transform: rotate(360deg); } }
@keyframes se-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes se-shimmer { to { background-position: -200% 0; } }
@keyframes se-dialog-in { from { opacity: 0; transform: translateY(12px) scale(.96); } }
@keyframes se-dialog-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes se-toast-in { from { opacity: 0; transform: translateY(16px) rotate(-2deg); } }
@keyframes se-toast-out { to { opacity: 0; transform: translateX(24px); } }
@keyframes se-confetti { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* Gift-name combobox (public/js/gift-picker.js): dashboard editor + library import */
.combo-wrap { position: relative; }
.gift-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; max-height: 280px; overflow-y: auto;
  list-style: none; margin: 0; padding: var(--s-1);
  background: var(--surface-1); border: var(--line-w) solid var(--ink); border-radius: var(--r-md); box-shadow: var(--e-2);
}
.gift-list li { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; padding: 0 var(--s-2); border-radius: var(--r-sm); cursor: pointer; }
.gift-list li:hover, .gift-list li[aria-selected="true"] { background: var(--pop-soft); }
.gift-list img { width: 28px; height: 28px; object-fit: contain; }
.gift-noimg { width: 28px; text-align: center; }
.gift-list .grow { flex: 1 1 auto; min-width: 0; }

/* Alert caption look in previews (alert editor, position editor, library),
   matching the overlay's .prompt-text in src/routes/browsersource.js. Inline
   styles from the alert's own font/color/weight still win. */
.alert-caption {
  --o: #0b0619;
  font-family: 'Bricolage Grotesque', 'Arial Black', Gadget, sans-serif; font-weight: 800;
  color: #fff7fb;
  -webkit-text-stroke: .13em var(--o); paint-order: stroke fill;
  filter: drop-shadow(.045em .065em 0 var(--o));
}
.alert-caption strong, .alert-caption b { color: #ffd23f; font-weight: inherit; }
