/* Utilities + components. Pages use these classes; page-specific CSS goes in /css/pages/<module>.css. */

/* ── layout utilities ── */
.stack { display: flex; flex-direction: column; gap: var(--gap, var(--s4)); }
.stack-sm { --gap: var(--s2); }
.stack-lg { --gap: var(--s6); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--s3)); }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: var(--gap, var(--s4)); grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--min, 260px)), 1fr)); }
.grid-2 { display: grid; gap: var(--gap, var(--s4)); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--gap, var(--s4)); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--gap, var(--s4)); grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.center { text-align: center; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.big { font-size: var(--fs-lg); }
.bold { font-weight: 800; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0 !important; }
.mt-2 { margin-top: var(--s2); } .mt-4 { margin-top: var(--s4); } .mt-6 { margin-top: var(--s6); }
.mb-2 { margin-bottom: var(--s2); } .mb-4 { margin-bottom: var(--s4); } .mb-6 { margin-bottom: var(--s6); }
.text-success { color: var(--success); } .text-danger { color: var(--danger); } .text-warning { color: var(--warning); } .text-accent { color: var(--accent); } .text-xp { color: var(--xp); }
.emoji { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; line-height: 1; }

/* ── page header ── */
.page { max-width: var(--content-max); margin: 0 auto; display: flex; flex-direction: column; gap: var(--s5); }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); }
.page-title { font-size: var(--fs-2xl); margin: 0; display: flex; align-items: center; gap: var(--s3); }
.page-subtitle { margin: var(--s1) 0 0; color: var(--text-muted); }
.section-title { font-size: var(--fs-lg); margin: 0 0 var(--s3); display: flex; align-items: center; gap: var(--s2); }
.eyebrow { font-size: var(--fs-xs); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }

/* ── cards ── */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s5);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-title { font-size: var(--fs-lg); font-weight: 800; margin: 0; display: flex; align-items: center; gap: var(--s2); }
.card-subtitle { color: var(--text-muted); font-size: var(--fs-sm); margin: var(--s1) 0 0; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.card-icon { font-size: 1.6rem; width: 48px; height: 48px; flex: none; display: grid; place-items: center; border-radius: 14px; background: var(--accent-soft); }
.card-footer { margin-top: var(--s4); display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.card--accent { border-top: 5px solid var(--accent); }
.card--glow { box-shadow: var(--shadow), var(--glow); }
.card--soft { background: var(--surface-2); box-shadow: none; }
.card--flat { box-shadow: none; }
.card--compact { padding: var(--s4); border-radius: var(--radius); }
.card--hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 30%, var(--surface)) 0%, var(--surface) 70%);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  overflow: hidden;
}
.card--hero::after { content: ""; position: absolute; inset: auto -40px -60px auto; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--accent) 35%, transparent), transparent 70%); pointer-events: none; }
.card--click { cursor: pointer; transition: transform var(--dur) var(--ease-bounce), border-color var(--dur), box-shadow var(--dur); text-decoration: none; color: inherit; display: block; }
.card--click:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); box-shadow: var(--shadow-lg); }
.card--click:active { transform: translateY(0) scale(.99); }
.card--locked { opacity: .55; filter: saturate(.4); }

/* ── buttons ── */
.btn {
  --btn-bg: var(--surface-3);
  --btn-fg: var(--text);
  --btn-edge: rgba(0, 0, 0, .35);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 10px 18px;
  border: 0; border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 800; font-size: var(--fs-md); line-height: 1.1; text-decoration: none;
  box-shadow: 0 4px 0 var(--btn-edge);
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, box-shadow .08s ease, filter var(--dur);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-edge); }
.btn:focus-visible { box-shadow: 0 4px 0 var(--btn-edge), var(--focus); border-radius: var(--radius-sm); }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: not-allowed; transform: none; filter: none; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: #fff; --btn-edge: color-mix(in srgb, var(--primary) 55%, #000); }
.btn-accent { --btn-bg: var(--accent); --btn-fg: var(--accent-ink); --btn-edge: color-mix(in srgb, var(--accent) 55%, #000); }
.btn-success { --btn-bg: #16a34a; --btn-fg: #fff; --btn-edge: #0f6b31; }
.btn-danger { --btn-bg: #e11d48; --btn-fg: #fff; --btn-edge: #8f1230; }
.btn-warning { --btn-bg: #f59e0b; --btn-fg: #1f1300; --btn-edge: #a36404; }
.btn-secondary { --btn-bg: var(--surface-2); --btn-edge: var(--border-strong); border: 1px solid var(--border); }
.btn-ghost { --btn-bg: transparent; --btn-edge: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-ghost:active { transform: none; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: var(--fs-sm); border-radius: 10px; }
.btn-lg { min-height: 56px; padding: 14px 26px; font-size: var(--fs-lg); border-radius: var(--radius); }
.btn-block { display: flex; width: 100%; }
.btn-icon { min-width: 44px; padding: 8px; }
.btn-icon.btn-sm { min-width: 34px; padding: 4px; }
.btn .emoji { font-size: 1.15em; }

/* ── chips & badges ── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--accent-soft); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  font-size: var(--fs-xs); font-weight: 800; line-height: 1.4; white-space: nowrap;
}
.chip-success { --accent: var(--success); } .chip-warning { --accent: var(--warning); } .chip-danger { --accent: var(--danger); } .chip-info { --accent: var(--info); } .chip-muted { --accent: var(--text-faint); }
button.chip { cursor: pointer; }
.chip.is-active { background: var(--accent); color: var(--accent-ink); }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--danger); color: #fff; font-size: 12px; font-weight: 800; }

/* ── forms ── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-weight: 800; font-size: var(--fs-sm); color: var(--text-muted); }
.help { font-size: var(--fs-xs); color: var(--text-faint); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 10px 14px;
  background: var(--bg-2); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); outline: none; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input-lg { min-height: 56px; font-size: var(--fs-lg); }
.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; font-weight: 700; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

/* ── tabs ── */
.tabs { display: flex; gap: var(--s1); padding: var(--s1); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 8px 16px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); font-weight: 800; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); background: var(--surface-3); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 55%, #000); }

/* ── progress ── */
.progress { position: relative; height: var(--h, 12px); border-radius: var(--radius-pill); background: var(--surface-3); overflow: visible; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 70%, #fff), var(--accent)); width: 0; transition: width .6s var(--ease-bounce); }
.progress-target { position: absolute; top: -4px; bottom: -4px; width: 3px; border-radius: 2px; background: var(--text); opacity: .7; }
.progress-label { display: flex; justify-content: space-between; font-size: var(--fs-xs); font-weight: 800; color: var(--text-muted); margin-bottom: 4px; }
.ring { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring svg { display: block; transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-3); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .8s var(--ease-bounce); }
.ring-target { stroke: var(--text); stroke-width: 3; opacity: .8; }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-weight: 900; line-height: 1; }
.ring-label small { display: block; font-size: .6em; font-weight: 700; color: var(--text-muted); margin-top: 2px; }

/* ── KPI tiles ── */
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s4); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-value { font-size: var(--fs-xl); font-weight: 900; line-height: 1.1; }
.kpi-label { font-size: var(--fs-xs); font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }

/* ── lists & tables ── */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.list-item { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
a.list-item, button.list-item { color: inherit; text-decoration: none; cursor: pointer; text-align: left; width: 100%; transition: border-color var(--dur), transform var(--dur); }
a.list-item:hover, button.list-item:hover { border-color: var(--accent); transform: translateX(2px); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface-2); font-weight: 800; color: var(--text-muted); }
.table tr:last-child td { border-bottom: 0; }

/* ── callouts ── */
.callout { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s4); border-radius: var(--radius); background: var(--info-soft); border: 1px solid color-mix(in srgb, var(--info) 35%, transparent); }
.callout-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.callout-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.callout-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.callout > .emoji { font-size: 1.4rem; }

/* ── empty state & skeleton ── */
.empty { text-align: center; padding: var(--s8) var(--s5); color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: var(--s3); }
.empty-icon { font-size: 3.2rem; animation: float 3s ease-in-out infinite; }
.empty-title { color: var(--text); font-size: var(--fs-lg); font-weight: 800; margin: 0; }
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--radius-sm); min-height: 14px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 8%, transparent), transparent); animation: shimmer 1.3s infinite; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 4px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }

/* ── markdown / content ── */
.md { overflow-wrap: break-word; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .75em; }
.md ul, .md ol { margin: 0 0 .75em; padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md table { border-collapse: collapse; margin: .5em 0 1em; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }
.md th { background: var(--surface-2); }
.md blockquote { margin: 0 0 .75em; padding: .5em 1em; border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: 0 var(--radius-xs) var(--radius-xs) 0; }
.md pre { background: var(--bg-2); padding: var(--s3); border-radius: var(--radius-sm); overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: .9em; white-space: pre; tab-size: 4; display: block; }
.md pre { border: 1px solid var(--border); line-height: 1.45; margin: 0 0 .75em; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.1em; margin: 1em 0 .5em; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.md-inline p { display: inline; margin: 0; }
.katex { font-size: 1.08em; }
.figure { margin: var(--s3) 0; padding: var(--s3); background: var(--surface-2); border-radius: var(--radius); color: var(--text); display: flex; flex-direction: column; align-items: center; gap: var(--s2); }
.figure svg { width: 100%; max-width: 420px; height: auto; max-height: 340px; }
.figure figcaption { font-size: var(--fs-xs); color: var(--text-muted); text-align: center; }

/* ── toasts ── */
.toast-stack { position: fixed; z-index: 900; right: var(--s4); bottom: var(--s4); display: flex; flex-direction: column; gap: var(--s2); max-width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); border-left: 6px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow-lg); font-weight: 700; animation: toast-in .35s var(--ease-bounce); }
.toast .emoji { font-size: 1.5rem; }
.toast-success { --accent: var(--success); } .toast-error { --accent: var(--danger); } .toast-warning { --accent: var(--warning); } .toast-reward { --accent: var(--xp); background: linear-gradient(135deg, color-mix(in srgb, var(--xp) 25%, var(--surface-3)), var(--surface-3)); }
.toast.is-leaving { animation: toast-out .25s ease forwards; }
@media (max-width: 900px) { .toast-stack { bottom: calc(76px + env(safe-area-inset-bottom)); left: var(--s4); right: var(--s4); max-width: none; } }

/* ── modal ── */
.modal-backdrop { position: fixed; inset: 0; z-index: 800; background: rgba(4, 7, 22, .66); backdrop-filter: blur(3px); display: grid; place-items: center; padding: var(--s4); animation: fade-in .2s ease; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--s6); animation: pop-in .3s var(--ease-bounce); }
.modal-title { margin: 0 0 var(--s3); font-size: var(--fs-xl); display: flex; align-items: center; gap: var(--s2); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }

/* ── confetti ── */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 950; overflow: hidden; }
.confetti-bit { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: confetti-fall var(--dur-fall, 2.4s) cubic-bezier(.2, .6, .4, 1) forwards; }

/* ── animations ── */
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.92) translateY(10px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes confetti-fall { to { transform: translate(var(--dx, 0), 105vh) rotate(var(--rot, 720deg)); opacity: .9; } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
@keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
.anim-rise { animation: rise-in .4s var(--ease-bounce) both; }
.anim-shake { animation: shake .45s ease; }
.anim-pulse { animation: pulse-ring 1.4s ease-out infinite; }
