/**
 * Paril – Layout
 * Base reset, global layout, page shell, navigation.
 */

/* ============================================================
   RESET & BASE
   ============================================================ */

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

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--line-base);
  color: var(--text-primary);
  background-color: var(--bg-base);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: 16px;
  touch-action: manipulation;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol { list-style: none; }

/* ============================================================
   APP SHELL
   ============================================================ */

#app {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ============================================================
   LOADING SCREEN
   ============================================================ */

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: var(--z-loading);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-10);
  background: linear-gradient(135deg, #58CC02 0%, #46A302 100%);
  transition: opacity var(--duration-slow) var(--ease-standard),
              transform var(--duration-slow) var(--ease-accelerate);
}

.loading-screen.hiding {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}

.loading-screen.hidden {
  display: none;
}

.loading-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.logo-icon {
  animation: bounceIn 0.7s var(--ease-bounce) both;
  filter: drop-shadow(0 8px 24px hsla(0, 0%, 0%, 0.25));
}

.logo-text {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: var(--weight-black);
  color: white;
  letter-spacing: -0.02em;
  animation: slideUp 0.5s var(--ease-decelerate) 0.2s both;
}

.logo-tagline {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: hsla(0, 0%, 100%, 0.75);
  font-style: italic;
  animation: fadeIn 0.5s var(--ease-decelerate) 0.5s both;
}

.loading-dots {
  display: flex;
  gap: var(--space-2);
  animation: fadeIn 0.3s 0.8s both;
}

.loading-dots span {
  width: 10px;
  height: 10px;
  border-radius: var(--border-radius-full);
  background: hsla(0, 0%, 100%, 0.7);
}

.loading-dots span:nth-child(1) { animation: loadingDot 1.2s 0s infinite; }
.loading-dots span:nth-child(2) { animation: loadingDot 1.2s 0.2s infinite; }
.loading-dots span:nth-child(3) { animation: loadingDot 1.2s 0.4s infinite; }

/* ============================================================
   BOTTOM NAVIGATION
   ============================================================ */

.main-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-overlay);
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  padding-left: calc(var(--space-2) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--space-2) + env(safe-area-inset-right, 0px));
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 20px hsla(240, 15%, 10%, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.main-nav.hidden { display: none; }

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: var(--space-2) var(--space-1);
  border-radius: var(--border-radius-md);
  color: var(--color-neutral-400);
  transition: color var(--duration-fast) var(--ease-standard),
              background-color var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-spring);
  position: relative;
  min-height: 48px;
}

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

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

.nav-item.active .nav-icon svg {
  stroke-width: 2.5;
}

.nav-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 24px;
  height: 24px;
  transition: transform var(--duration-fast) var(--ease-spring);
}

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

.nav-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
}

/* Center speaking button - special style */
.nav-item.nav-center {
  flex: 1.2;
}

.nav-icon-center {
  width: 52px;
  height: 52px;
  border-radius: var(--border-radius-full);
  background: linear-gradient(135deg, var(--color-speaking), hsl(175, 72%, 32%));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px hsla(175, 72%, 42%, 0.45);
  margin-top: -16px;
  transition: transform var(--duration-fast) var(--ease-spring),
              box-shadow var(--duration-fast) var(--ease-standard);
}

.nav-item.nav-center:active .nav-icon-center {
  transform: scale(0.92);
  box-shadow: 0 2px 8px hsla(175, 72%, 42%, 0.3);
}

.nav-icon-center svg {
  width: 24px;
  height: 24px;
  stroke: white;
  stroke-width: 2.5;
}

.nav-item.nav-center .nav-label {
  color: var(--color-speaking);
}

/* Nav active indicator dot */
.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: var(--border-radius-full);
  background: var(--color-primary);
  animation: scaleIn var(--duration-base) var(--ease-spring);
}

.nav-item.nav-center.active::after {
  background: var(--color-speaking);
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */

.page-content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--space-4));
  position: relative;
  overflow-x: hidden;
}

.page-content.no-nav {
  padding-bottom: 0;
  max-width: 100%;
}

/* Page transitions */
.page-enter {
  animation: slideInRight var(--duration-slow) var(--ease-decelerate) both;
}

.page-exit {
  animation: fadeOut var(--duration-base) var(--ease-accelerate) both;
}

/* ============================================================
   OVERLAYS
   ============================================================ */

#overlay-container {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  pointer-events: none;
}

#overlay-container:not(:empty) {
  pointer-events: auto;
}

.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: var(--z-overlay);
  animation: overlayFade var(--duration-base) var(--ease-standard) both;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ============================================================
   CONFETTI CANVAS
   ============================================================ */

.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: var(--z-confetti);
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ============================================================
   SCROLLBAR STYLING
   ============================================================ */

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-neutral-200);
  border-radius: var(--border-radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-neutral-300); }

/* ============================================================
   UTILITY CLASSES
   ============================================================ */

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

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.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); }

.text-center { text-align: center; }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }

.font-display { font-family: var(--font-display); }
.font-bold { font-weight: var(--weight-bold); }
.font-extrabold { font-weight: var(--weight-extrabold); }

.text-primary-color { color: var(--color-primary); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }
.text-secondary { color: var(--text-secondary); }
.text-white { color: white; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.rounded-full { border-radius: var(--border-radius-full); }

.overflow-hidden { overflow: hidden; }

.relative { position: relative; }
.absolute { position: absolute; }

/* ============================================================
   SAFE AREA SUPPORT (iOS)
   ============================================================ */

.safe-top { padding-top: env(safe-area-inset-top, 0px); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }

/* ============================================================
   DESKTOP LAYOUT (>640px)
   ============================================================ */

@media (min-width: 640px) {
  .main-nav {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    right: auto;
    width: 80px;
    height: 100vh;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border-color);
    padding: var(--space-6) var(--space-2);
    box-shadow: 4px 0 20px hsla(240, 15%, 10%, 0.06);
    justify-content: flex-start;
    gap: var(--space-2);
  }

  .page-content {
    padding-bottom: 0;
    padding-left: 80px;
    max-width: none;
  }

  .page-content > .page-inner {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--space-6) var(--space-4);
  }

  .nav-item {
    width: 100%;
    min-height: 64px;
    border-radius: var(--border-radius-md);
  }

  .nav-item.active::after {
    left: 0;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    width: 4px;
    height: 32px;
    border-radius: 0 var(--border-radius-full) var(--border-radius-full) 0;
  }

  .nav-item.nav-center {
    order: -1;
    margin-bottom: var(--space-4);
  }

  .nav-icon-center {
    width: 48px;
    height: 48px;
    margin-top: 0;
  }
}

@media (min-width: 1024px) {
  .main-nav {
    width: 220px;
  }

  .main-nav .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

  .nav-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    letter-spacing: 0;
    text-transform: none;
  }

  .page-content {
    padding-left: 220px;
  }
}

