/* ==========================================================================
   Leaf API demo kit: shared styles
   ========================================================================== */

:root {
  --bg: #faf8f6;
  --fg: #1a4d2e;
  --fg-soft: rgba(26, 77, 46, 0.72);
  --fg-mute: rgba(26, 77, 46, 0.5);
  --card: #ffffff;
  --primary: #2d7a4f;
  --primary-hover: #256842;
  --primary-fg: #ffffff;
  --secondary: #f0ebe3;
  --muted: #e8ddf5;
  --border: #e0d5ca;
  --input: #ffffff;
  --danger: #c41e3a;
  --dark: #0f2818;
  --dark-2: #1a3a2a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(26, 77, 46, 0.06), 0 1px 3px rgba(26, 77, 46, 0.08);
  --shadow-lg: 0 10px 30px rgba(15, 40, 24, 0.12);
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--fg);
  background: linear-gradient(180deg, var(--secondary) 0%, var(--bg) 280px);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--primary); }

/* ---------- Shell ---------- */
.leaf-shell { max-width: 1240px; margin: 0 auto; padding: 16px; }
.leaf-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 4px 14px; flex-wrap: wrap; }
.leaf-brand { display: flex; align-items: center; gap: 10px; }
.leaf-logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: var(--primary-fg);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800;
}
.leaf-brand-title { font-weight: 700; font-size: 16px; }
.leaf-brand-sub { font-size: 12px; color: var(--fg-mute); display: flex; align-items: center; gap: 6px; }
.leaf-status { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.status-chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--card);
  border-radius: 999px; padding: 5px 10px; color: var(--fg-soft);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.status-dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }

.leaf-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.leaf-app {
  background: var(--card); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 22px; min-height: 520px; min-width: 0;
}
.leaf-stage { min-width: 0; }
/* The demo's own layouts respond to the space the demo really has (page, tablet or phone), not the window. */
.leaf-screen { container: site / inline-size; }
@media (max-width: 960px) { .leaf-layout { grid-template-columns: minmax(0, 1fr); } }
@container site (max-width: 960px) { .leaf-app { padding: 16px; } }

.leaf-boot { min-height: 420px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--fg-mute); font-size: 14px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--secondary); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- API call log ---------- */
.leaf-log {
  background: var(--dark); color: #f0ebe3; border-radius: 18px; overflow: hidden; display: flex; flex-direction: column;
  height: 640px; position: sticky; top: 16px;
}
@media (max-width: 960px) { .leaf-log { position: static; height: 360px; } }
.log-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); font-size: 14px; font-weight: 600; }
.log-head .count { color: rgba(255, 255, 255, 0.5); font-weight: 500; font-size: 12px; }
.log-head .spacer { flex: 1; }
.log-head button { background: none; border: 0; color: rgba(255, 255, 255, 0.55); padding: 4px; display: inline-flex; }
.log-head button:hover { color: #fff; }
.pulse { position: relative; width: 8px; height: 8px; }
.pulse::before, .pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: #4ade80; }
.pulse::before { animation: ping 1.4s cubic-bezier(0, 0, 0.2, 1) infinite; opacity: 0.6; }
@keyframes ping { 75%, 100% { transform: scale(2.4); opacity: 0; } }
.log-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.log-empty { text-align: center; color: rgba(255, 255, 255, 0.5); font-size: 13px; padding: 40px 16px; line-height: 1.5; }
.log-item { background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 10px; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.log-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.log-copy {
  margin-left: auto; flex-shrink: 0; width: 24px; height: 24px; border: 0; border-radius: 6px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.08); color: rgba(255, 255, 255, 0.75); opacity: 0; transition: opacity 0.15s, background 0.15s;
}
.log-copy svg { width: 13px; height: 13px; }
.log-item:hover .log-copy, .log-copy:focus-visible, .log-copy.done { opacity: 1; }
.log-copy:hover { background: #22c55e; color: #052e16; }
.log-copy.done { background: #22c55e; color: #052e16; }
@media (hover: none) { .log-copy { opacity: 1; } }
.log-path { font-family: var(--mono); font-size: 11.5px; color: rgba(255, 255, 255, 0.92); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-body pre { margin: 8px 0 0; max-height: 110px; overflow: auto; background: rgba(0, 0, 0, 0.3); border-radius: 6px; padding: 8px; font-family: var(--mono); font-size: 11px; line-height: 1.5; color: rgba(255, 255, 255, 0.72); }
.log-result { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 11px; }
.log-result.ok { color: #86efac; }
.log-result.err { color: #fca5a5; }
.log-result .ms { margin-left: auto; color: rgba(255, 255, 255, 0.4); }
.log-result svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ---------- Methods ---------- */
.method { flex-shrink: 0; font-size: 10px; font-weight: 700; border-radius: 4px; padding: 2px 6px; letter-spacing: 0.02em; }
.m-GET { background: #dbeafe; color: #1e40af; }
.m-POST { background: #dcfce7; color: #166534; }
.m-PATCH { background: #f3e8ff; color: #6b21a8; }
.m-PUT { background: #fef9c3; color: #854d0e; }
.m-DELETE { background: #fee2e2; color: #991b1b; }

/* ---------- Primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 9px; border: 1px solid transparent;
  padding: 8px 14px; font-size: 14px; font-weight: 600; background: var(--primary); color: var(--primary-fg); white-space: nowrap; text-decoration: none;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:hover:not(:disabled) { background: var(--primary-hover); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn svg { width: 16px; height: 16px; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-outline { background: var(--card); color: var(--fg); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--secondary); border-color: rgba(45, 122, 79, 0.35); }
.btn-ghost { background: transparent; color: var(--fg-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--secondary); color: var(--fg); }
.btn-danger, .btn.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a3182f; border-color: #a3182f; color: #fff; }
.btn-warn, .btn.btn-warn { background: #f59e0b; border-color: #f59e0b; color: #422006; }
.btn-warn:hover:not(:disabled) { background: #d97706; border-color: #d97706; color: #422006; }
/* Armed "click again to confirm" state for destructive buttons. */
.btn.armed { background: var(--danger); border-color: var(--danger); color: #fff; animation: armPulse 1s ease-in-out infinite; }
.btn.armed:hover:not(:disabled) { background: #a3182f; border-color: #a3182f; color: #fff; }
@keyframes armPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(196, 30, 58, 0.35); } 50% { box-shadow: 0 0 0 5px rgba(196, 30, 58, 0); } }
.btn-block { width: 100%; }
.icon-btn { background: none; border: 0; padding: 4px; color: var(--fg-mute); display: inline-flex; border-radius: 6px; }
.icon-btn { transition: color .15s, background .15s; }
.icon-btn:hover { color: var(--fg); background: var(--secondary); }
.icon-btn.danger:hover { color: var(--danger); background: #fee2e2; }
.icon-btn.armed, .icon-btn.armed:hover { background: var(--danger); color: #fff; padding: 4px 8px; font-size: 12px; font-weight: 600; gap: 4px; align-items: center; }
.icon-btn svg { width: 15px; height: 15px; }

.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); background: var(--input); border-radius: 9px; padding: 8px 11px; font-size: 14px;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45, 122, 79, 0.15); }
.textarea { resize: vertical; min-height: 90px; }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600; border: 1px solid transparent; }
.badge-low { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-medium { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-hard { background: #ffe4e6; color: #9f1239; border-color: #fecdd3; }
.badge-expert { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.badge-mobile { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.chip { border: 0; border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 500; background: var(--secondary); color: var(--fg-soft); transition: background .15s, color .15s; }
.chip:hover:not(.active) { background: #e7dfd3; color: var(--fg); }
.chip.active { background: var(--primary); color: var(--primary-fg); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--fg-mute); }
.soft { color: var(--fg-soft); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 8px; }
.grid { display: grid; gap: 12px; }
.title { font-size: 20px; font-weight: 700; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-mute); }
.skeleton { background: var(--secondary); border-radius: 10px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.error-banner { margin-bottom: 14px; border: 1px solid rgba(196, 30, 58, 0.3); background: rgba(196, 30, 58, 0.08); color: var(--danger); padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.hide-sm { }
@media (max-width: 640px) { .hide-sm { display: none !important; } }

/* ---------- Modal ---------- */
.leaf-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 40, 24, 0.45); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.leaf-modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--card); border-radius: 20px;
  box-shadow: 0 25px 60px rgba(15, 40, 24, 0.3); animation: popIn 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
.modal-hero { padding: 22px 22px 0; display: flex; gap: 14px; align-items: flex-start; }
.modal-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: #dcfce7; color: var(--primary); }
.modal-icon.warn { background: #fef3c7; color: #b45309; }
.modal-icon.err { background: #ffe4e6; color: #be123c; }
.modal-icon svg { width: 22px; height: 22px; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-sub { font-size: 13.5px; color: var(--fg-soft); margin-top: 4px; line-height: 1.5; }
.modal-body { padding: 18px 22px 22px; }
.modal-close { margin-left: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--fg-soft); margin-bottom: 6px; }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 8px; }
.key-input { font-family: var(--mono); letter-spacing: 0.02em; }
.hint { font-size: 12px; color: var(--fg-mute); margin-top: 8px; line-height: 1.5; }
.account-note { display: flex; align-items: center; gap: 6px; color: var(--primary); }
.account-note svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-google { width: 100%; gap: 10px; padding: 10px 14px; color: var(--primary); border-color: var(--primary); }
.btn-google svg { width: 18px; height: 18px; }
.or-divider { display: flex; align-items: center; gap: 10px; margin: 16px 0 14px; font-size: 12px; color: var(--fg-mute); }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--secondary); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 19px; }
.stat span { font-size: 11px; color: var(--fg-soft); }
.meter { height: 6px; background: var(--secondary); border-radius: 999px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: var(--primary); transition: width 0.5s ease; }
.meter.warn > i { background: #f59e0b; }
.meter.full > i { background: var(--danger); }
.res-list { display: flex; flex-direction: column; gap: 6px; }
.res-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 11px; padding: 9px 10px; }
.res-item.current { border-color: var(--primary); background: rgba(45, 122, 79, 0.05); }
.res-item .grow { flex: 1; min-width: 0; }
.res-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-meta { font-size: 11.5px; color: var(--fg-mute); }
.tag { font-size: 10px; font-weight: 700; border-radius: 4px; padding: 1px 5px; background: var(--secondary); color: var(--fg-soft); }
.tag.green { background: #dcfce7; color: #166534; }
.tag.red { background: #ffe4e6; color: #9f1239; }
.need-box { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; border: 1px dashed #c4b5fd; background: #f5f3ff; border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.need-box p { flex-basis: 100%; margin: 0; }
.need-facts { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--fg-soft); }
.need-facts b { color: #6d28d9; }
.need-count { display: flex; align-items: baseline; gap: 6px; }
.need-count b { font-size: 30px; font-weight: 800; color: #6d28d9; line-height: 1; transition: transform .2s; }
.need-count span { font-size: 12px; color: var(--fg-soft); }
.need-slots { display: flex; gap: 5px; }
.need-slots i { width: 22px; height: 22px; border-radius: 6px; background: #ddd6fe; border: 2px solid #c4b5fd; }
.need-slots i.used { background: #7c3aed; border-color: #7c3aed; }
.need-slots i.just-freed { animation: popIn .35s ease; background: #dcfce7; border-color: #22c55e; }
.res-item.freed { opacity: .55; border-style: dashed; }
/* Project choice rows: info on the left, the two choices (each with an optional Recommended badge) on the right. */
.res-item.res-choice { flex-wrap: wrap; row-gap: 10px; }
.res-choice-info { display: flex; align-items: center; gap: 10px; flex: 1 1 220px; min-width: 0; }
.res-choice-actions { display: flex; align-items: flex-end; gap: 8px; margin-left: auto; }
.choice { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.choice.recommended .btn-warn { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3); }
.choice.recommended .btn-danger { box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.22); }
.rec-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; border-radius: 999px; padding: 2px 7px; white-space: nowrap; }
.rec-badge svg { width: 10px; height: 10px; fill: currentColor; }
.rec-badge.use { background: #fef3c7; color: #92400e; }
.rec-badge.delete { background: #ffe4e6; color: #9f1239; }
.res-meta.fit-ok { color: #166534; }
.res-meta.fit-short { color: #9f1239; }
.res-meta.fit-tight { color: #92400e; }
.res-item.suggested { border-color: rgba(196, 30, 58, 0.45); background: rgba(196, 30, 58, 0.04); }
.ok-box { border-radius: 12px; background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.warn-box { border-radius: 12px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.progress-line { height: 4px; background: var(--secondary); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress-line > i { display: block; height: 100%; background: var(--primary); transition: width 0.25s; }

/* ---------- Toast ---------- */
.leaf-toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; background: var(--dark); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 13.5px; box-shadow: var(--shadow-lg); animation: popIn 0.25s ease;
}

/* ==========================================================================
   Device preview (website / tablet / mobile): only the demo goes in the frame
   ========================================================================== */
.leaf-statusbar, .leaf-homebar { display: none; }
.leaf-device { position: relative; }
html:not([data-device="desktop"]) .leaf-layout { align-items: stretch; }
html:not([data-device="desktop"]) .leaf-stage {
  display: flex; justify-content: center; align-items: flex-start; padding: 18px 12px; border-radius: 18px; border: 1px solid var(--border);
  background: radial-gradient(circle at 30% 20%, rgba(45,122,79,.12), transparent 50%), radial-gradient(circle at 80% 80%, rgba(139,92,246,.10), transparent 45%), #ece7df;
}
html:not([data-device="desktop"]) .leaf-device {
  display: flex; flex-direction: column; overflow: hidden; background: var(--card); flex-shrink: 0;
  border: 12px solid #121212; box-shadow: 0 0 0 2px #3a3a3a, 0 30px 70px rgba(0,0,0,.28);
}
/* Real device proportions (390×844 phone, 820×1180 tablet). leaf-api.js zooms the whole frame down to fit the
   window instead of squashing its height, so the preview always has the shape of a real device. */
html[data-device="mobile"] .leaf-device { width: 390px; height: 844px; border-radius: 56px; --leaf-screen-r: 44px; }
html[data-device="tablet"] .leaf-device { width: 820px; height: 1180px; border-radius: 38px; border-width: 16px; --leaf-screen-r: 22px; }
html:not([data-device="desktop"]) .leaf-screen { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
/* Chrome (GPU compositing) ignores the frame's rounded overflow clip for backdrop-filter, so a blurred bottom nav or
   sheet backdrop paints square corners over the frame. A solid mask forces a real mask layer that clips to the
   element's own rounded corners (radius = frame radius - border). clip-path: inset() is not enough for sticky navs. */
html:not([data-device="desktop"]) .leaf-screen,
html:not([data-device="desktop"]) .leaf-device > .in-device { -webkit-mask-image: linear-gradient(#000, #000); mask-image: linear-gradient(#000, #000); }
html:not([data-device="desktop"]) .leaf-screen { border-radius: 0 0 var(--leaf-screen-r) var(--leaf-screen-r); }
html:not([data-device="desktop"]) .leaf-device > .in-device { border-radius: var(--leaf-screen-r); overflow: hidden; }
html:not([data-device="desktop"]) .leaf-screen::-webkit-scrollbar { width: 0; }
html:not([data-device="desktop"]) .leaf-app { border: 0; border-radius: 0; box-shadow: none; min-height: 100%; padding: 16px 16px 28px; }
/* Apps drawn edge to edge (chat, full-screen tools): a root with .leaf-bleed fills the whole device screen with no
   white gutter around it, the way a native app does. */
html:not([data-device="desktop"]) .leaf-app:has(> .leaf-bleed) { padding: 0; display: flex; flex-direction: column; }
html:not([data-device="desktop"]) .leaf-app > .leaf-bleed { flex: 1; min-height: 0; border: 0; border-radius: 0; }
/* The API calls panel stays beside the device and matches its height. */
html:not([data-device="desktop"]) .leaf-log { height: auto; contain: size; position: static; }
@media (max-width: 960px) { html:not([data-device="desktop"]) .leaf-log { contain: none; height: 360px; } }
html:not([data-device="desktop"]) .leaf-statusbar {
  display: flex; align-items: center; justify-content: space-between; position: relative; flex-shrink: 0;
  padding: 0 26px; height: 48px; font-size: 15px; font-weight: 600; color: #111; background: var(--card);
}
html[data-device="tablet"] .leaf-statusbar { height: 30px; font-size: 12px; padding: 0 20px; }
.sb-island { position: absolute; left: 50%; top: 11px; width: 122px; height: 34px; transform: translateX(-50%); background: #000; border-radius: 999px; }
html[data-device="tablet"] .sb-island { width: 8px; height: 8px; top: 11px; background: #2a2a2a; }
.sb-icons { display: inline-flex; align-items: center; gap: 6px; }
.sb-icons svg { fill: #111; }
.sb-battery { position: relative; width: 25px; height: 12px; border: 1.5px solid rgba(0,0,0,.45); border-radius: 4px; padding: 1.5px; }
.sb-battery::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2px; height: 4px; background: rgba(0,0,0,.45); border-radius: 0 2px 2px 0; }
.sb-level { display: block; height: 100%; width: 100%; background: #111; border-radius: 1.5px; }
.sb-level.low { background: #ef4444; }
html:not([data-device="desktop"]) .leaf-homebar {
  display: block; position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); width: 134px; height: 5px; border-radius: 999px; background: #111; opacity: .85; z-index: 5; pointer-events: none;
}
html[data-device="tablet"] .leaf-homebar { width: 180px; }
/* The demo's own toasts appear on the device screen. */
.leaf-device > .leaf-toast { position: absolute; }

/* ---------- Top bar controls: preview size + settings ---------- */
.tb-seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); background: var(--card); border-radius: 999px; }
.tb-seg-btn, .tb-btn {
  width: 30px; height: 28px; border: 0; border-radius: 999px; background: transparent; color: var(--fg-mute);
  display: inline-flex; align-items: center; justify-content: center; padding: 0; transition: background .15s, color .15s;
}
.tb-seg-btn svg, .tb-btn svg { width: 16px; height: 16px; }
.tb-seg-btn:hover, .tb-btn:hover { color: var(--fg); background: var(--secondary); }
.tb-seg-btn.on { background: var(--primary); color: var(--primary-fg); }
.tb-btn { width: 36px; height: 36px; border: 1px solid var(--border); background: var(--card); }
.tb-btn:hover svg { animation: spin 2s linear infinite; }
@media (max-width: 600px) { .tb-seg { display: none; } }

/* ---------- Narrow demo widths (mobile preview, small screens) ---------- */
@media (max-width: 480px) {
  .leaf-shell { padding: 12px; }
  .leaf-status .status-chip { font-size: 11px; }
  .stat-grid { gap: 6px; }
}
@container site (max-width: 480px) {
  .leaf-app { padding: 14px; border-radius: 14px; min-height: 0; }
  .title { font-size: 18px; }
}

/* ---------- Game Leaderboard ---------- */
.lb-grid { display: grid; grid-template-columns: 1fr 290px; gap: 18px; }
@container site (max-width: 760px) { .lb-grid { grid-template-columns: 1fr; } }
.lb-game { position: relative; min-height: 380px; border-radius: 18px; overflow: hidden; color: #fff; user-select: none; background: linear-gradient(135deg, #f43f5e, #d946ef 50%, #4f46e5); }
.lb-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px; }
.lb-big { font-size: 54px; animation: float 2.4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(8deg); } }
.lb-h { font-size: 28px; font-weight: 800; }
.lb-btn { background: #fff; color: #e11d48; } .lb-btn:hover:not(:disabled) { background: #ffe4e6; }
.lb-ghost { color: #fff; } .lb-ghost:hover:not(:disabled) { background: rgba(255,255,255,.15); color: #fff; }
.lb-hud { position: absolute; left: 16px; right: 16px; top: 12px; display: flex; justify-content: space-between; font-size: 15px; }
.lb-target { position: absolute; width: 62px; height: 62px; transform: translate(-50%, -50%); border-radius: 50%; border: 0; background: #fff; font-size: 28px; box-shadow: 0 10px 25px rgba(0,0,0,.25); transition: left .08s, top .08s; touch-action: manipulation; }
.lb-target:active { transform: translate(-50%, -50%) scale(.88); }
.lb-final { font-size: 72px; font-weight: 900; line-height: 1; }
.lb-board { padding: 14px; }
.lb-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 4px; }
.lb-list li { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 10px; font-size: 14px; animation: slideIn .25s ease; }
.lb-list li.podium { background: var(--secondary); }
.lb-list li.mine { background: #fef3c7; box-shadow: inset 0 0 0 1.5px #f59e0b; }
.lb-rank { width: 24px; text-align: center; font-weight: 700; color: var(--fg-mute); }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-family: var(--mono); }
