/* ============================================================
   LexiRoots - Main Design System
   Dark-mode, mobile-first PWA
   ============================================================ */

/* ----- Custom Properties / Design Tokens ----- */
:root {
  /* Colors */
  --color-bg:               #0f0f1a;
  --color-surface:          #1a1a2e;
  --color-surface-light:    #252540;
  --color-surface-lighter:  #30305a;
  --color-primary:          #6c5ce7;
  --color-primary-light:    #a29bfe;
  --color-primary-dark:     #5a4bd1;
  --color-accent:           #00cec9;
  --color-accent-secondary: #fd79a8;
  --color-success:          #00b894;
  --color-success-light:    #55efc4;
  --color-warning:          #fdcb6e;
  --color-warning-dark:     #e1b04c;
  --color-danger:           #d63031;
  --color-danger-light:     #ff7675;
  --color-text:             #eeeeee;
  --color-text-muted:       #888888;
  --color-text-dim:         #555566;
  --color-border:           rgba(255, 255, 255, 0.06);
  --color-border-light:     rgba(255, 255, 255, 0.1);
  --color-overlay:          rgba(0, 0, 0, 0.6);
  --color-glass:            rgba(26, 26, 46, 0.85);
  --color-glass-strong:     rgba(15, 15, 26, 0.92);

  /* Shadows */
  --shadow-sm:   0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md:   0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg:   0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-xl:   0 16px 48px rgba(0, 0, 0, 0.5);
  --shadow-glow-primary: 0 0 20px rgba(108, 92, 231, 0.3);
  --shadow-glow-accent:  0 0 20px rgba(0, 206, 201, 0.3);

  /* Border Radius */
  --radius-xs:  4px;
  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-2xl: 32px;
  --radius-full: 9999px;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  --font-mono:   'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  --text-xs:   0.75rem;    /* 12px */
  --text-sm:   0.8125rem;  /* 13px */
  --text-base: 0.9375rem;  /* 15px */
  --text-md:   1rem;       /* 16px */
  --text-lg:   1.125rem;   /* 18px */
  --text-xl:   1.25rem;    /* 20px */
  --text-2xl:  1.5rem;     /* 24px */
  --text-3xl:  1.875rem;   /* 30px */
  --text-4xl:  2.25rem;    /* 36px */
  --text-5xl:  3rem;       /* 48px */

  --font-normal:   400;
  --font-medium:   500;
  --font-semibold: 600;
  --font-bold:     700;
  --font-black:    900;

  --leading-tight:  1.2;
  --leading-normal: 1.5;
  --leading-loose:  1.75;

  /* Spacing Scale */
  --space-0:  0;
  --space-1:  0.25rem;  /* 4px */
  --space-2:  0.5rem;   /* 8px */
  --space-3:  0.75rem;  /* 12px */
  --space-4:  1rem;     /* 16px */
  --space-5:  1.25rem;  /* 20px */
  --space-6:  1.5rem;   /* 24px */
  --space-8:  2rem;     /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-20: 5rem;     /* 80px */
  --space-24: 6rem;     /* 96px */

  /* Layout */
  --top-bar-height:   56px;
  --bottom-nav-height: 64px;
  --max-content-width: 480px;
  --safe-area-top:    env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left:   env(safe-area-inset-left, 0px);
  --safe-area-right:  env(safe-area-inset-right, 0px);

  /* Transitions */
  --ease-out:       cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out:    cubic-bezier(0.65, 0, 0.35, 1);
  --ease-bounce:    cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-spring:    cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --duration-fast:  150ms;
  --duration-base:  250ms;
  --duration-slow:  400ms;
  --duration-slower: 600ms;

  /* Z-Index Scale */
  --z-base:     1;
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-top-bar:  300;
  --z-nav:      300;
  --z-overlay:  400;
  --z-modal:    500;
  --z-toast:    600;
  --z-max:      9999;
}


/* ----- Reset / Normalize ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

button {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

a {
  color: var(--color-primary-light);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul,
ol {
  list-style: none;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  color: var(--color-text);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-md); }

p {
  color: var(--color-text);
  line-height: var(--leading-normal);
}


/* ----- App Shell ----- */
#app {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}


/* ----- Top Bar ----- */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--top-bar-height) + var(--safe-area-top));
  padding-top: var(--safe-area-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  background: var(--color-glass-strong);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--color-border);
  z-index: var(--z-top-bar);
  transition: transform var(--duration-base) var(--ease-out);
}

.top-bar.hidden-bar {
  transform: translateY(-100%);
}

/* Top bar sections — flat-hyphenated names matching index.html */
.top-bar-left,
.top-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 48px;
}

.top-bar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Brand title in top bar header */
.app-title {
  font-size: var(--text-xl);
  font-weight: var(--font-black);
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

/* Streak badge in top bar */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-warning);
}

.streak-icon {
  font-size: var(--text-md);
  line-height: 1;
}

/* Hearts badge in top bar */
.hearts-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* XP badge in top bar */
.xp-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-primary-light);
}

.xp-icon {
  font-size: var(--text-md);
  line-height: 1;
}


/* ----- Main Content Area ----- */
.main-content {
  flex: 1;
  padding-top: calc(var(--top-bar-height) + var(--safe-area-top) + var(--space-4));
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + var(--space-4));
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  max-width: var(--max-content-width);
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.main-content--no-nav {
  padding-bottom: calc(var(--safe-area-bottom) + var(--space-4));
}

.main-content--no-top {
  padding-top: calc(var(--safe-area-top) + var(--space-4));
}

.main-content--full {
  max-width: 100%;
  padding-left: 0;
  padding-right: 0;
}


/* ----- Screen/Page Wrappers ----- */
.screen {
  display: none;
  animation: screenFadeIn var(--duration-base) var(--ease-out);
}

.screen.active {
  display: block;
}

@keyframes screenFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}


/* ----- Home Screen ----- */
.home-screen {
  padding: var(--space-2) 0;
}


/* ----- Generic Screen Title ----- */
.screen-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  margin-bottom: var(--space-4);
}


/* ----- Loading Screen ----- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  min-height: 200px;
  color: var(--color-text-muted);
}

.loading-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}


/* ----- Empty State ----- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
}

.empty-icon {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-4);
}

.empty-state p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 280px;
  line-height: var(--leading-normal);
}


/* ----- Bottom Navigation ----- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
  padding-bottom: var(--safe-area-bottom);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--color-glass-strong);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--color-border);
  z-index: var(--z-nav);
  transition: transform var(--duration-base) var(--ease-out);
}

.bottom-nav.hidden-nav {
  transform: translateY(100%);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  transition: all var(--duration-fast) ease;
  position: relative;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  min-width: 56px;
  text-decoration: none;
}

/* Nav icon — flat class matching index.html */
.nav-icon {
  width: 24px;
  height: 24px;
  transition: transform var(--duration-fast) var(--ease-bounce);
}

.nav-item:hover {
  color: var(--color-text);
  text-decoration: none;
}

.nav-item:active .nav-icon {
  transform: scale(0.9);
}

.nav-item.active {
  color: var(--color-primary-light);
}

.nav-item.active .nav-icon {
  filter: drop-shadow(0 0 6px rgba(108, 92, 231, 0.4));
}

.nav-item.active::after {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--color-primary);
  border-radius: 0 0 var(--radius-full) var(--radius-full);
}


/* ----- Utility Classes ----- */
.hidden { display: none !important; }
.invisible { visibility: hidden; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Flex */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-row { display: flex; flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.items-end    { align-items: flex-end; }
.justify-center  { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around  { justify-content: space-around; }
.justify-end     { justify-content: flex-end; }

/* Grid */
.grid { display: grid; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); }

/* Gap */
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* Padding */
.p-0  { padding: 0; }
.p-2  { padding: var(--space-2); }
.p-3  { padding: var(--space-3); }
.p-4  { padding: var(--space-4); }
.p-6  { padding: var(--space-6); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* Margin */
.m-0  { margin: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Text */
.text-center { text-align: center; }
.text-left   { text-align: left; }
.text-right  { text-align: right; }
.text-muted  { color: var(--color-text-muted); }
.text-dim    { color: var(--color-text-dim); }
.text-primary { color: var(--color-primary-light); }
.text-accent  { color: var(--color-accent); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger  { color: var(--color-danger); }
.text-xs  { font-size: var(--text-xs); }
.text-sm  { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg  { font-size: var(--text-lg); }
.text-xl  { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.font-medium   { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold     { font-weight: var(--font-bold); }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Width/Height */
.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; min-height: 100dvh; }

/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.sticky   { position: sticky; }

/* Border */
.rounded-sm   { border-radius: var(--radius-sm); }
.rounded-md   { border-radius: var(--radius-md); }
.rounded-lg   { border-radius: var(--radius-lg); }
.rounded-xl   { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Opacity */
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }

/* Transitions */
.transition-all {
  transition: all var(--duration-base) var(--ease-out);
}
.transition-fast {
  transition: all var(--duration-fast) ease;
}


/* ----- Scrollbar Styling ----- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-surface-lighter);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-dim);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-surface-lighter) transparent;
}


/* ----- Selection ----- */
::selection {
  background: rgba(108, 92, 231, 0.3);
  color: var(--color-text);
}


/* ----- Focus Visible ----- */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}


/* ----- Responsive Breakpoints ----- */

/* Tablet: 640px+ */
@media (min-width: 640px) {
  :root {
    --max-content-width: 560px;
  }

  .top-bar {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }

  .main-content {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }

  .bottom-nav {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
  }

  .bottom-nav.hidden-nav {
    transform: translateX(-50%) translateY(100%);
  }

  .grid-2 { gap: var(--space-4); }
  .grid-3 { gap: var(--space-4); }
}

/* Desktop: 1024px+ */
@media (min-width: 1024px) {
  :root {
    --max-content-width: 640px;
  }

  .top-bar {
    padding-left: var(--space-8);
    padding-right: var(--space-8);
  }
}

/* Tall phones */
@media (min-height: 800px) {
  .main-content {
    padding-top: calc(var(--top-bar-height) + var(--safe-area-top) + var(--space-6));
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + var(--space-6));
  }
}


/* ----- Reduced Motion ----- */
@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;
  }
}


/* ----- Landscape Lock Hint ----- */
@media (orientation: landscape) and (max-height: 500px) {
  .landscape-hint {
    display: flex;
  }
}
