/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Syne:wght@600;700;800&family=Unbounded:wght@500;700;900&display=swap');

:root {
  --color-bg-light: #F2FAFF;
  --color-blue-100: #D6EEFF;
  --color-blue-200: #A9DBFF;
  --color-blue-300: #6DBEFF;
  --color-blue-400: #3AA6FF;
  --color-accent: #1E6FD9;
  --color-text-head: #0F2F52;
  --color-text-body: #2A4B6E;
  
  --font-head: 'Unbounded', 'Syne', sans-serif;
  --font-body: 'Manrope', sans-serif;
}

/* Reset & Base */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

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

button, a, input, select, textarea {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  min-height: 100dvh;
  background-color: var(--color-bg-light);
  color: var(--color-text-body);
  font-family: var(--font-body), system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-size: clamp(15px, 0.9rem + 0.3vw, 17px);
  line-height: 1.6;
}

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

input, textarea, select {
  font-size: 16px; /* Prevent iOS zoom */
}

h1, h2, h3, h4, .font-head {
  font-family: var(--font-head), system-ui, sans-serif;
  color: var(--color-text-head);
}

h1 { font-size: clamp(28px, 5vw + 8px, 56px); }
h2 { font-size: clamp(24px, 3vw + 10px, 40px); }
h3 { font-size: clamp(18px, 1vw + 14px, 24px); }

/* Prevent tiny text */
.text-\[9px\], .text-\[10px\], .text-xs {
  font-size: max(12px, 0.75rem) !important;
}

/* Handle long names (removed aggressive wrapping as per request) */
h3, h4, p {
  /* Inherit standard wrapping */
}

h1, h2 {
  text-wrap: balance;
}

.font-syne {
  font-family: 'Syne', sans-serif;
}

/* Film Grain Overlay */
.film-grain {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 99;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 300 300' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* STRICT LAYER STRUCTURE */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  overflow: hidden;
}

.content-layer {
  position: relative;
  z-index: 10;
}

.header-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
}

section {
  scroll-margin-top: 80px;
}

/* Background Blobs (Autonomous floating 20-40s loop, pointer-events: none) */
.bg-blob {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  user-select: none;
  filter: blur(90px);
  opacity: 0.3;
  will-change: transform;
}

.blob-1 {
  top: -15%;
  left: -10%;
  width: 55vw;
  height: 55vw;
  background: radial-gradient(circle, var(--color-blue-200), var(--color-blue-400));
  animation: floatBlob1 28s ease-in-out infinite alternate;
}

.blob-2 {
  bottom: -15%;
  right: -10%;
  width: 65vw;
  height: 65vw;
  background: radial-gradient(circle, var(--color-blue-300), var(--color-accent));
  opacity: 0.22;
  animation: floatBlob2 36s ease-in-out infinite alternate;
}

.blob-3 {
  top: 35%;
  left: 30%;
  width: 45vw;
  height: 45vw;
  background: radial-gradient(circle, var(--color-blue-100), var(--color-blue-400));
  opacity: 0.25;
  animation: floatBlob3 24s ease-in-out infinite alternate;
}

.blob-4 {
  top: 70%;
  left: -5%;
  width: 40vw;
  height: 40vw;
  background: radial-gradient(circle, var(--color-accent), var(--color-blue-200));
  opacity: 0.18;
  animation: floatBlob4 32s ease-in-out infinite alternate;
}

@keyframes floatBlob1 {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(80px, -60px, 0) scale(1.15); }
}

@keyframes floatBlob2 {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(-100px, 90px, 0) scale(1.25); }
}

@keyframes floatBlob3 {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(60px, 70px, 0) scale(0.85); }
}

@keyframes floatBlob4 {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(-70px, -80px, 0) scale(1.1); }
}

.god-rays {
  position: absolute;
  top: -20%;
  left: 20%;
  width: 60vw;
  height: 120vh;
  background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(169,219,255,0.1) 40%, transparent 80%);
  transform: rotate(-15deg);
  pointer-events: none;
  filter: blur(40px);
  opacity: 0.5;
}

/* Glassmorphism System */
.glass-panel {
  background: rgba(255, 255, 255, 0.28);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: inset 0 0 25px rgba(255, 255, 255, 0.3), 0 16px 40px rgba(30, 111, 217, 0.1);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

@supports not (backdrop-filter: blur(1px)) {
  .glass-panel {
    background: rgba(255, 255, 255, 0.88);
  }
}

.glass-card-static {
  background: rgba(255, 255, 255, 0.28);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 10px 30px rgba(58, 166, 255, 0.1);
}

@supports not (backdrop-filter: blur(1px)) {
  .glass-card-static {
    background: rgba(255, 255, 255, 0.88);
  }
}

@media (hover: hover) and (pointer: fine) {
  .glass-panel:hover {
    border-color: rgba(255, 255, 255, 0.95);
    box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.45), 0 20px 50px rgba(30, 111, 217, 0.18);
    transform: translateY(-4px);
  }
}

@media (max-width: 767px) {
  .glass-panel, .glass-card-static {
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    backdrop-filter: blur(12px) saturate(120%);
  }
}

/* Avatar Responsive Sizes */
.avatar-card {
  width: clamp(96px, 28vw, 140px);
  height: clamp(96px, 28vw, 140px);
}
.avatar-entity {
  width: clamp(56px, 14vw, 72px);
  height: clamp(56px, 14vw, 72px);
}
.avatar-chairman {
  width: clamp(200px, 60vw, 360px);
  height: clamp(200px, 60vw, 360px);
}
.avatar-drawer {
  width: clamp(96px, 30vw, 160px);
  height: clamp(96px, 30vw, 160px);
}
.avatar-coord-row {
  width: clamp(44px, 12vw, 72px);
  height: clamp(44px, 12vw, 72px);
}

/* Word breaking fix */
.word-break-normal {
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: manual;
  text-wrap: balance;
}

/* Apple Liquid Glass Card */
.glass-card-apple {
  background: linear-gradient(135deg, rgba(255,255,255,0.34), rgba(255,255,255,0.12));
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.55);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.9),
    inset 0 -1px 0 rgba(120,180,255,0.25),
    inset 0 0 24px rgba(255,255,255,0.18),
    0 10px 30px rgba(30,111,217,0.14),
    0 2px 6px rgba(30,111,217,0.08);
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: clamp(16px, 2vw, 24px);
  transition: transform 250ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow: hidden;
}
@supports not (backdrop-filter: blur(1px)) {
  .glass-card-apple {
    background: rgba(255,255,255,0.88);
  }
}
@media (max-width: 767px) {
  .glass-card-apple {
    -webkit-backdrop-filter: blur(14px) saturate(180%);
    backdrop-filter: blur(14px) saturate(180%);
  }
}

.glass-card-apple::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(circle at 10% 10%, rgba(255,255,255,0.5) 0%, transparent 60%);
  pointer-events: none;
  z-index: 1;
  transition: opacity 250ms ease;
}
.glass-card-apple::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 28px;
  padding: 1.5px;
  background: linear-gradient(135deg, rgba(255,255,255,1) 0%, rgba(120,180,255,0.2) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 2;
}
@media (hover: hover) and (pointer: fine) {
  .glass-card-apple:hover {
    transform: translateY(-4px);
    box-shadow:
      inset 0 1px 0 rgba(255,255,255,0.95),
      inset 0 -1px 0 rgba(120,180,255,0.3),
      inset 0 0 24px rgba(255,255,255,0.25),
      0 14px 40px rgba(30,111,217,0.2),
      0 4px 10px rgba(30,111,217,0.1);
  }
  .glass-card-apple:hover::before {
    opacity: 0.8;
  }
}
.glass-card-apple:active {
  transform: scale(0.985);
}
@media (prefers-reduced-motion: reduce) {
  .glass-card-apple, .glass-card-apple::before, .glass-card-apple:hover, .glass-card-apple:active {
    transition: none !important;
    transform: none !important;
  }
}

.inner-glass-apple {
  background: rgba(255,255,255,0.28);
  border: 1px solid rgba(255,255,255,0.6);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
  border-radius: 16px;
}
.logo-box-apple {
  width: clamp(48px, 12vw, 56px);
  height: clamp(48px, 12vw, 56px);
}

.avatar-drawer {
  width: clamp(96px, 30vw, 160px);
  height: clamp(96px, 30vw, 160px);
}
.avatar-coord-row {
  width: clamp(44px, 12vw, 72px);
  height: clamp(44px, 12vw, 72px);
}

/* Duotone Blue Filter for Coordinators */
.duotone-blue-img {
  filter: brightness(0.95) contrast(1.05) saturate(0.9);
  mix-blend-mode: normal;
  transition: filter 0.3s ease, transform 0.4s ease;
}

.duotone-blue-img:hover {
  filter: brightness(1) contrast(1.1) saturate(1.1);
}

/* Preloader */
#preloader {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: linear-gradient(135deg, #F2FAFF 0%, #A9DBFF 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: clip-path 0.8s cubic-bezier(0.77, 0, 0.175, 1);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

#preloader.loaded {
  clip-path: polygon(0 0, 100% 0, 100% 0, 0 0);
}

.preloader-letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(20px) scale(0.8);
  animation: revealLetter 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes revealLetter {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Depth Bar Indicator (Desktop Only, Right 20px, Small & Semi-transparent) */
#depth-meter {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0.75;
}

.depth-bar-bg {
  width: 3px;
  height: 140px;
  background: rgba(30, 111, 217, 0.15);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.depth-bar-fill {
  width: 100%;
  height: 0%;
  background: linear-gradient(to bottom, #3AA6FF, #1E6FD9);
  border-radius: 999px;
  transition: height 0.1s linear;
}

/* Water Canvas */
#water-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* Watermark Text */
.bg-watermark {
  position: absolute;
  pointer-events: none;
  user-select: none;
  font-family: var(--font-head);
  font-weight: 900;
  color: rgba(169, 219, 255, 0.2);
  mix-blend-mode: overlay;
  z-index: 1;
}

/* SVG Wave Divider */
.svg-wave-divider {
  width: 100%;
  height: auto;
  display: block;
}

/* Drag Slider Container */
.drag-slider-wrapper {
  cursor: grab;
  user-select: none;
}
.drag-slider-wrapper:active {
  cursor: grabbing;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: #F2FAFF;
}
::-webkit-scrollbar-thumb {
  background: #3AA6FF;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #1E6FD9;
}

/* Modal / Drawer Backdrop */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 47, 82, 0.45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: flex-end; /* Bottom sheet on mobile */
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Modal Content Base (Mobile First - Bottom Sheet) */
.modal-content {
  width: 100%;
  max-width: 100%;
  max-height: 85dvh;
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border-top-left-radius: 32px;
  border-top-right-radius: 32px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-bottom: none;
  box-shadow: 0 -10px 40px rgba(15, 47, 82, 0.2);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  padding: 24px 20px env(safe-area-inset-bottom) 20px;
}

/* Pull Indicator for Mobile */
.modal-content::before {
  content: '';
  display: block;
  width: 48px;
  height: 5px;
  background: rgba(42, 75, 110, 0.3);
  border-radius: 10px;
  margin: 0 auto 20px auto;
}

.modal-backdrop.open .modal-content {
  transform: translateY(0);
}

/* Desktop Side Drawer (Right Panel) */
@media (min-width: 768px) {
  .modal-backdrop {
    align-items: center;
    justify-content: flex-end;
  }
  .modal-content {
    width: 440px;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.8);
    border-top: none;
    padding: 32px;
    transform: translateX(100%);
  }
  .modal-content::before {
    display: none;
  }
  .modal-backdrop.open .modal-content {
    transform: translateX(0);
  }
}

/* ─── Avatar Image Crispness & Filter Cleanup ─────────────────────────────── */

/*
 * Muammo: glass-panel → backdrop-blur-md → .avatar ichma-ich GPU compositing
 * qatlamini hosil qilardi, bu esa rasm sub-pixel antialiasing tufayli
 * xira ko'rinishiga olib kelardi.
 *
 * Yechim:
 *  1. Avatar container o'z ajratilgan stacking context (isolation: isolate) va
 *     compositing qatlamida turadi — backdrop-filter ta'sirini cheklab qo'yadi.
 *  2. img elementida hech qanday transform / will-change / backdrop-filter yo'q.
 *  3. .yuklanmoqda holati: blur(4px) → 0.3s da silliq o'chadi.
 *  4. .foto-tiniq holati: filter:none !important — inline style ham saqlanadi.
 *  5. Kartochka hover faqat translateY(-4px) — rasm masshtablanmaydi.
 */

.avatar-container {
  position: relative !important;
  isolation: isolate !important;        /* yangi stacking context — backdrop-filter izolatsiyasi */
  z-index: 1 !important;
  filter: none !important;
  -webkit-filter: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  transform: none !important;
  -webkit-transform: none !important;
  will-change: auto !important;
  contain: layout !important;           /* compositing qatlam hisoblashini cheklaydi */
}

.avatar-img {
  display: block;
  image-rendering: auto;               /* brauzer optimal interpolatsiya tanlaydi */
  object-fit: cover;
  object-position: center top;
  transform: none !important;
  -webkit-transform: none !important;
  will-change: auto !important;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* Faqat filter va opacity animatsiyasi; transform yo'q */
  transition: filter 0.3s ease-out, opacity 0.3s ease-out;
}

/* Yuklanish holatida: yengil blur placeholder */
.avatar-img.yuklanmoqda {
  filter: blur(4px);
  -webkit-filter: blur(4px);
  opacity: 0.7;
}

/* Yuklangan holat: har qanday filter'ni majburiy o'chirish */
.avatar-img.foto-tiniq {
  filter: none !important;
  -webkit-filter: none !important;
  opacity: 1 !important;
  /* blur-sm Tailwind klassini ham bekor qilish uchun */
  -webkit-text-stroke: 0;
}

/* Photo overlay tint — backdrop-filter, filter, blur YO'Q */
.avatar-tint {
  position: absolute;
  inset: 0;
  background-color: rgba(58, 166, 255, 0.08);
  pointer-events: none;
  border-radius: 9999px;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  filter: none !important;
  z-index: 2;
}
}

@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;
  }
}

@media print {
  body, html {
    background: white !important;
    color: black !important;
  }
  .header-layer, #mobile-menu, #preloader, .bg-layer, .film-grain, .modal-backdrop {
    display: none !important;
  }
  .glass-panel, .glass-card-static {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: transparent !important;
  }
}
