/* Bibido shell and kit styles. Look: a bright playroom. Warm cream paper,
   indigo for actions, sunny yellow for stars, chunky rounded buttons with a
   bottom edge so they look pressable. Phones and tablets (portrait and
   landscape) are both first-class. Each app adds apps/<id>/style.css, every
   rule under .app-<id>. */
:root {
  --bg: #fff7ec;
  --surface: #ffffff;
  --surface-2: #fdeed6;
  --fg: #2a2140;
  --muted: #6b6280;
  --line: #eadfcb;
  --accent: #5b4bdb;
  --accent-fg: #ffffff;
  --star: #ffb800;
  --good: #1f9d58;
  --bad: #e2475a;
  --edge: rgba(42, 33, 64, 0.16);
  --radius: 22px;
  --radius-sm: 14px;
  --gutter: 16px;
  --tap: 56px;
  --font: "Nunito", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color-scheme: light;
}
:root:lang(zh-Hans) { --font: "Nunito", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17132a; --surface: #221c3a; --surface-2: #2c2549; --fg: #f6f1ff; --muted: #b7aed0;
    --line: #3a3260; --accent: #a99bff; --accent-fg: #17132a; --star: #ffc93d; --good: #4bd48a;
    --bad: #ff7a84; --edge: rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17132a; --surface: #221c3a; --surface-2: #2c2549; --fg: #f6f1ff; --muted: #b7aed0;
  --line: #3a3260; --accent: #a99bff; --accent-fg: #17132a; --star: #ffc93d; --good: #4bd48a;
  --bad: #ff7a84; --edge: rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-weight: 700;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
h1, h2, h3 { font-weight: 900; line-height: 1.2; margin: 0; text-wrap: balance; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.5rem; font-weight: 900; }
.brand img { border-radius: 10px; }
.title { flex: 1; font-size: 1.3rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.brand:not([hidden]) + .title { flex: 1; }
.icon-btn {
  position: relative; flex: none;
  width: 48px; height: 48px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--surface); color: var(--fg);
  box-shadow: 0 3px 0 var(--edge);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.icon-btn svg { width: 26px; height: 26px; }
/* Hold feedback (src/kit/hold.js): a ring fills while the button is held. */
.hold::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p, 0) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  opacity: 0;
}
@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }
.hold.holding::after { opacity: 1; animation: hold-fill var(--hold-ms, 600ms) linear forwards; }
@keyframes hold-fill { from { --p: 0; } to { --p: 1; } }

.page { max-width: 1040px; margin: 0 auto; padding: 8px var(--gutter) calc(32px + env(safe-area-inset-bottom)); }

/* Home */
.tagline { color: var(--muted); font-size: 1.05rem; margin: 4px 0 18px; }
.who h2 { font-size: 1.2rem; margin-bottom: 10px; }
.who-row { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.kid {
  flex: none; width: 88px; display: grid; justify-items: center; gap: 4px;
  padding: 10px 4px; border: 3px solid transparent; border-radius: var(--radius);
  background: var(--surface); box-shadow: 0 4px 0 var(--edge);
}
.kid[aria-pressed="true"] { border-color: var(--accent); }
.kid-avatar { font-size: 2.4rem; line-height: 1; }
.kid-name { font-size: 0.9rem; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.kid-add .kid-avatar { color: var(--accent); font-weight: 900; }
.kid-add .kid-name { color: var(--muted); }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 16px; margin-top: 18px; }
.app-card {
  display: grid; gap: 4px; padding: 18px;
  border-radius: var(--radius); background: var(--surface);
  border-top: 10px solid var(--app-color, var(--accent));
  box-shadow: 0 6px 0 var(--edge);
  transition: transform 0.1s;
}
.app-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--edge); }
.app-icon { font-size: 3.4rem; line-height: 1.1; }
.app-name { font-size: 1.5rem; font-weight: 900; }
.app-hook { color: var(--muted); }
.app-ages { font-size: 0.85rem; color: var(--muted); }

/* Buttons and chips shared by every app */
.btn, .big-btn {
  min-height: 48px; padding: 8px 18px;
  border: 0; border-radius: 999px;
  background: var(--surface-2); color: var(--fg); font-weight: 800;
  box-shadow: 0 4px 0 var(--edge);
  -webkit-user-select: none; user-select: none;
}
.btn:active, .big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.btn.primary, .big-btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { color: var(--bad); }
.big-btn { min-height: var(--tap); min-width: var(--tap); font-size: 1.3rem; padding: 10px 24px; }
.big-btn:disabled { opacity: 0.35; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; min-width: 44px; padding: 6px 14px;
  border: 2px solid var(--line); border-radius: 999px; background: var(--surface);
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.input {
  width: 100%; min-height: 52px; padding: 8px 14px;
  border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  font-size: 1.2rem;
}

/* Settings sheet (<dialog>) */
.sheet {
  width: min(560px, calc(100vw - 2 * var(--gutter))); max-height: calc(100dvh - 32px);
  padding: 20px; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--fg); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.sheet::backdrop { background: rgba(10, 8, 20, 0.6); }
.sheet .chip[data-avatar] { font-size: 1.7rem; padding: 2px 8px; }
.sheet section { margin-top: 18px; display: grid; gap: 10px; }
.sheet h3 { font-size: 1rem; color: var(--muted); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.sheet-foot .danger { margin-right: auto; }
.kid-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.kid-list li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border-radius: var(--radius-sm); background: var(--surface); }
.kid-list li > span:nth-child(2) { flex: 1; }
.kid-list .kid-avatar { font-size: 1.8rem; }

/* Toast (src/kit/toast.js) */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px; background: var(--fg); color: var(--bg);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Confetti (src/kit/confetti.js) */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px;
  animation: confetti-fall 2.2s ease-in forwards;
}
@keyframes confetti-fall { to { transform: translate(var(--drift), 105vh) rotate(var(--spin)); } }

/* Apps: no text selection or callouts while a child taps around. */
.app { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.stars { color: var(--star); letter-spacing: 2px; }
.stars .off { color: var(--line); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
