/* ============================================================
   Orbit design system — shared by the hub and every app.
   Dark-mode-first. Each app sets its own --accent on <body>.
   ============================================================ */

:root {
  /* Neutral base (dark) */
  --bg: #0b0d14;
  --bg-elev: #12151f;
  --bg-elev-2: #1a1e2c;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef0f6;
  --text-dim: #9aa1b5;
  --text-faint: #6b7186;

  /* Per-app accent (overridden on <body>) */
  --accent: #8b5cf6;
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
  --accent-text: color-mix(in srgb, var(--accent) 70%, white);
  --on-accent: #0b0d14;

  /* Feedback */
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;

  /* Shape + space */
  --radius: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 14px;
  --space-4: 20px;
  --space-5: 32px;
  --space-6: 48px;

  /* Type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 220ms;

  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --glow: 0 0 24px var(--accent-soft);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f5fa;
  --bg-elev: #ffffff;
  --bg-elev-2: #eceef6;
  --surface: rgba(15, 18, 32, 0.04);
  --border: rgba(15, 18, 32, 0.12);
  --text: #171a26;
  --text-dim: #4c5268;
  --text-faint: #7d8299;
  --accent-text: color-mix(in srgb, var(--accent) 72%, black);
  --on-accent: #ffffff;
  --shadow: 0 8px 30px rgba(20, 24, 48, 0.12);
  color-scheme: light;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
main {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-4);
  flex: 1;
}
h1, h2, h3 { line-height: 1.15; margin: 0 0 var(--space-3); letter-spacing: -0.02em; }
h1 { font-size: clamp(1.7rem, 6vw, 2.6rem); font-weight: 800; }
h2 { font-size: clamp(1.2rem, 4vw, 1.6rem); font-weight: 750; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
img, canvas, svg, video { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: 0.85rem; }
.center { text-align: center; }
.accent { color: var(--accent-text); }
.mono { font-family: var(--font-mono); }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Header / footer ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  max-width: 720px; margin: 0 auto; width: 100%;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 1.05rem; color: var(--text);
  text-decoration: none; letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand .orb {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 32% 30%, var(--accent), #0000 72%), var(--bg-elev-2);
  border: 2px solid var(--accent);
  box-shadow: var(--glow);
}
.header-app { color: var(--text-dim); font-weight: 600; font-size: 0.95rem; }
.header-actions { display: flex; align-items: center; gap: var(--space-2); }

.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-4);
  margin-top: var(--space-5);
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
}
.site-footer .foot-links {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-2);
}
.site-footer button.linklike {
  background: none; border: none; padding: 0; font: inherit;
  color: var(--accent-text); cursor: pointer;
}
.site-footer button.linklike:hover { text-decoration: underline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 700 1rem/1 var(--font);
  padding: 14px 22px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  min-height: 48px;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              background var(--dur) var(--ease), filter var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  user-select: none;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #6366f1));
  color: var(--on-accent);
  border: none;
  box-shadow: var(--glow);
}
.btn-ghost { background: transparent; }
.btn-sm { padding: 9px 15px; min-height: 38px; font-size: 0.88rem; }
.btn-block { width: 100%; }
.icon-btn {
  width: 42px; height: 42px; padding: 0; border-radius: 50%;
  font-size: 1.1rem;
}

/* ---------- Cards / chips / badges ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.85rem; font-weight: 650;
}
.chip-neutral { background: var(--surface); color: var(--text-dim); }
.badge-streak {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #f59e0b33, #ef444433);
  border: 1px solid #f59e0b55;
  font-weight: 800; font-size: 0.95rem;
}

/* ---------- Progress ---------- */
.progress {
  height: 8px; border-radius: 4px;
  background: var(--surface);
  overflow: hidden;
}
.progress > .bar {
  height: 100%; width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #fff));
  transition: width 320ms var(--ease);
}

/* ---------- Inputs ---------- */
.field {
  width: 100%;
  font: 500 1rem var(--font);
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  min-height: 48px;
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label.lbl { display: block; font-size: 0.85rem; font-weight: 650; color: var(--text-dim); margin: 0 0 6px 2px; }

/* Autocomplete dropdown */
.ac-wrap { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 40;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto;
  padding: 4px; margin: 0; list-style: none;
}
.ac-list li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.ac-list li .sub { color: var(--text-faint); font-size: 0.8rem; }
.ac-list li[aria-selected="true"], .ac-list li:hover { background: var(--accent-soft); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 6, 12, 0.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 180ms var(--ease);
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 480px; width: 100%;
  max-height: 85svh; overflow-y: auto;
  padding: var(--space-4);
  animation: popIn 220ms var(--ease);
}
.modal h2 { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Toast ---------- */
.toast-zone {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: 92vw;
}
.toast {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 11px 20px;
  font-weight: 650; font-size: 0.92rem;
  box-shadow: var(--shadow);
  animation: popIn 220ms var(--ease);
}

/* ---------- Ad slot ---------- */
.ad-slot {
  max-width: 720px; width: calc(100% - 2 * var(--space-4));
  margin: var(--space-4) auto;
  min-height: 90px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.ad-placeholder {
  min-height: 90px; height: 100%;
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase;
}

/* ---------- Share grid / emoji rows ---------- */
.emoji-grid { font-size: 1.35rem; line-height: 1.5; letter-spacing: 2px; user-select: all; }

/* ---------- Stats ---------- */
.stat-row { display: flex; gap: var(--space-3); justify-content: center; text-align: center; flex-wrap: wrap; }
.stat { min-width: 72px; }
.stat .num { font-size: 1.6rem; font-weight: 800; }
.stat .lab { font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; }
.dist-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.dist-row .n { width: 14px; text-align: right; color: var(--text-dim); font-size: 0.85rem; }
.dist-row .bar {
  height: 20px; border-radius: 5px; background: var(--accent);
  color: var(--on-accent); font-size: 0.78rem; font-weight: 700;
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0 6px; min-width: 20px;
}

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes floatUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.anim-in { animation: floatUp 380ms var(--ease) both; }
@keyframes pulseGlow { 0%, 100% { box-shadow: 0 0 12px var(--accent-soft); } 50% { box-shadow: 0 0 30px var(--accent-soft); } }

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

/* ---------- Small screens ---------- */
@media (max-width: 420px) {
  main { padding: var(--space-3); }
  .btn { padding: 13px 18px; }
}

/* ---- Cross-app "play the rest" panel (nextUp) ---- */
.nextup { margin-top: 18px; padding: 16px; border-radius: 16px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.09); }
.nextup-head { display: flex; justify-content: space-between; align-items: center; }
.nextup-streak { font-weight: 800; color: #fb923c; }
.nextup-progress { color: var(--text-dim); font-size: 0.85rem; font-weight: 700; }
.nextup-dots { display: flex; gap: 8px; margin: 12px 0 4px; font-size: 1.25rem; }
.nextup-dots .nd { opacity: 0.28; filter: grayscale(1); transition: all .2s; }
.nextup-dots .nd.on { opacity: 1; filter: none; transform: translateY(-1px); }
.nextup-label { color: var(--text-dim); font-size: 0.9rem; margin: 12px 0 8px; }
.nextup-games { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 380px) { .nextup-games { grid-template-columns: 1fr; } }
.nextup-game { display: flex; align-items: center; gap: 8px; padding: 11px 13px; border-radius: 12px; text-decoration: none; font-weight: 700; font-size: 0.9rem; color: var(--text, #e8ecf5); background: color-mix(in srgb, var(--card-accent, var(--accent)) 13%, transparent); border: 1px solid color-mix(in srgb, var(--card-accent, var(--accent)) 32%, transparent); transition: transform .12s; }
.nextup-game:hover { transform: translateY(-2px); }
.nextup-game .ng-go { margin-left: auto; color: var(--card-accent, var(--accent)); }
.nextup-all { display: inline-block; margin-top: 12px; color: var(--accent); font-weight: 700; text-decoration: none; font-size: 0.9rem; }

/* ---- Language switcher ---- */
.lang-switch { display: inline-flex; gap: 2px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.10); border-radius: 999px; padding: 2px; }
.lang-btn { font: inherit; font-size: 0.72rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; border: 0; background: transparent; color: var(--text-dim); cursor: pointer; line-height: 1.1; }
.lang-btn[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 26%, transparent); color: var(--text); }
.lang-btn:hover { color: var(--text); }

/* ---- CJK typography: Simplified and HK use different Noto families ---- */
:root[data-lang="zh-cn"] { --font-cjk: "Noto Sans SC", system-ui, sans-serif; }
:root[data-lang="zh-hk"] { --font-cjk: "Noto Sans HK", system-ui, sans-serif; }
:root[data-lang^="zh"] body { font-family: var(--font-cjk, system-ui, sans-serif); }
:root[data-lang^="zh"] h1, :root[data-lang^="zh"] h2, :root[data-lang^="zh"] h3 { line-break: strict; }
