@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

:root {
  --bg: #0b0b0e;
  --card: #141417;
  --surface: #1a1a1f;
  --surface-2: #212126;
  --border: rgba(255,255,255,0.08);
  --text-primary: #ececee;
  --text-secondary: #98989f;
  --text-muted: #66666e;
  --accent: #5b6df0;
  --accent-soft: rgba(91,109,240,0.12);
  --success: #3fae74;
  --success-soft: rgba(63,174,116,0.12);
  --warning: #c98a2e;
  --warning-soft: rgba(201,138,46,0.12);
  --danger: #d9635f;
  --danger-soft: rgba(217,99,95,0.12);
  --ring-track: #24242a;
  --ring-progress: var(--accent);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --radius-xs: 7px;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.3);
  --font: 'Sora', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Space Grotesk', var(--font);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  --bg: #f6f6f8;
  --card: #ffffff;
  --surface: #f1f1f4;
  --surface-2: #e9e9ee;
  --border: #e3e3e8;
  --text-primary: #17171a;
  --text-secondary: #66666f;
  --text-muted: #97979f;
  --ring-track: #e9e9ee;
  --shadow-card: 0 1px 2px rgba(20,20,30,0.06);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f6f8;
    --card: #ffffff;
    --surface: #f1f1f4;
    --surface-2: #e9e9ee;
    --border: #e3e3e8;
    --text-primary: #17171a;
    --text-secondary: #66666f;
    --text-muted: #97979f;
    --ring-track: #e9e9ee;
    --shadow-card: 0 1px 2px rgba(20,20,30,0.06);
  }
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

.icon { display: inline-flex; vertical-align: middle; flex-shrink: 0; }

/* ── SPLASH ─────────────────────────────────────────────── */
#splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
#splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-icon { color: var(--text-primary); margin-bottom: 4px; animation: splashPulse 1.6s ease-in-out infinite; }
.splash-title { font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -0.2px; color: var(--text-primary); }
.splash-sub { color: var(--text-muted); font-size: 11.5px; letter-spacing: 1.2px; text-transform: uppercase; }

@keyframes splashPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ── OFFLINE RIBBON ─────────────────────────────────────── */
#offlineRibbon {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 900;
  background: var(--surface-2);
  color: var(--text-secondary);
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  padding: calc(var(--safe-top) + 7px) 12px 7px;
  letter-spacing: 0.2px;
  border-bottom: 1px solid var(--border);
}
#offlineRibbon.visible { display: flex; }

/* ── INSTALL BANNER ─────────────────────────────────────── */
#installBanner {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 950;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  padding: calc(var(--safe-top) + 10px) 16px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#installBanner.visible { display: flex; }
.install-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.install-icon {
  width: 34px; height: 34px; background: var(--surface); border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center; color: var(--text-secondary); flex-shrink: 0;
}
.install-text { min-width: 0; }
.install-title { font-weight: 600; font-size: 13px; }
.install-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.install-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-install, .btn-dismiss {
  border-radius: var(--radius-xs); padding: 8px 14px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.btn-install { background: var(--text-primary); color: var(--bg); }
.btn-dismiss { background: transparent; color: var(--text-muted); }

/* ── APP SHELL ──────────────────────────────────────────── */
.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(64px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 16px) 20px 14px;
  position: sticky;
  top: 0;
  z-index: 80;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.brand {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.1px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}
.brand-icon { color: var(--text-primary); }

.header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-secondary);
}
.icon-flip .icon { transform: scaleX(-1); }

.account-indicator {
  position: relative;
  border-radius: 50%;
  overflow: visible;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.account-indicator img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.sync-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg);
}
.sync-dot-off { background: var(--text-muted); }
.sync-dot-syncing { background: var(--warning); animation: syncPulse 1s ease-in-out infinite; }
.sync-dot-ok { background: var(--success); }
.sync-dot-error { background: var(--danger); }

@keyframes syncPulse {
  0%, 100% { opacity: 0.5; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.view-root {
  flex: 1;
  padding: 4px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── BOTTOM NAV ─────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 90;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border-top: 1px solid var(--border);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  padding: 4px 4px calc(4px + var(--safe-bottom));
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0 6px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1px;
  border-top: 2px solid transparent;
  transition: color 0.15s ease;
}
.nav-btn.active { color: var(--text-primary); border-top-color: var(--accent); }

/* ── FATAL ERROR ────────────────────────────────────────── */
.fatal-error {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
}
.fatal-error h2 { display: flex; align-items: center; gap: 8px; color: var(--text-primary); font-size: 16px; font-weight: 600; }
.fatal-error button {
  background: var(--text-primary); color: var(--bg); padding: 9px 18px; border-radius: var(--radius-xs); font-weight: 600; font-size: 13px;
}

@media (min-width: 640px) {
  .app-shell { padding-bottom: 24px; }
  .bottom-nav {
    position: sticky;
    bottom: 0;
    border-radius: 0;
    max-width: 560px;
  }
}
