*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #0a3d3d;
  --primary-light: #1a6b6b;
  --primary-dark: #062929;
  --accent: #d4a017;
  --accent-light: #f0c84a;
  --bg: #eef6f6;
  --card-bg: #ffffff;
  --text: #1a2e2e;
  --text-muted: #5a7a7a;
  --shadow: 0 4px 20px rgba(10, 61, 61, 0.1);
  --shadow-hover: 0 10px 36px rgba(10, 61, 61, 0.18);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Vazirmatn', 'Tahoma', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  min-height: 100dvh;
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
}

/* ── Header ── */
.site-header {
  background: linear-gradient(145deg, var(--primary-dark) 0%, var(--primary) 45%, #1f8a7a 100%);
  color: #fff;
  padding: calc(1.5rem + var(--safe-top)) 1.25rem 2rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 80%, rgba(240, 200, 74, 0.12) 0%, transparent 50%),
              radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.06) 0%, transparent 40%);
  pointer-events: none;
}

.header-inner {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
}

.header-logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.school-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border-radius: 50%;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  border: 3px solid var(--accent-light);
}

.school-name-block {
  text-align: center;
}

.school-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.school-subtitle {
  font-size: 0.82rem;
  opacity: 0.85;
  margin-top: 0.15rem;
}

.site-header h1 {
  font-size: clamp(1.25rem, 4.5vw, 2rem);
  font-weight: 800;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.site-header .header-desc {
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  opacity: 0.92;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.8;
}

.header-tag {
  display: inline-block;
  margin-top: 1rem;
  background: rgba(212, 160, 23, 0.25);
  border: 1px solid rgba(240, 200, 74, 0.4);
  color: var(--accent-light);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.9rem;
  border-radius: 50px;
}

/* ── Layout ── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.85rem;
  padding-right: 0.75rem;
  border-right: 4px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-block {
  margin-bottom: 2rem;
}

/* ── Cards ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.85rem;
}

.model-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: 1px solid rgba(10, 61, 61, 0.07);
  -webkit-tap-highlight-color: transparent;
}

.model-card:hover,
.model-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  outline: none;
}

.model-card:active {
  transform: scale(0.98);
}

.card-icon {
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-light) 100%);
  padding: 1.25rem 0.75rem;
  text-align: center;
  font-size: 2.4rem;
  line-height: 1;
}

.card-body {
  padding: 0.85rem 0.9rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-body h3 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.25rem;
  line-height: 1.4;
}

.card-body p {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex: 1;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-cta {
  margin-top: 0.65rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-light);
  background: rgba(26, 107, 107, 0.08);
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  width: fit-content;
}

.card-cta::after {
  content: '←';
}

/* ── Help box ── */
.help-box {
  background: #fff;
  border: 1px solid rgba(10, 61, 61, 0.1);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.help-box h2 {
  font-size: 0.95rem;
  color: var(--primary);
  margin-bottom: 1rem;
}

.help-steps {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  list-style: none;
}

.help-steps li {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
}

.step-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
}

.warning-box {
  border-color: #f0c84a;
  background: linear-gradient(135deg, #fffbeb, #fff);
}

/* ── Footer ── */
.site-footer {
  background: var(--primary-dark);
  color: rgba(255, 255, 255, 0.85);
  padding: 1.75rem 1.25rem calc(1.5rem + var(--safe-bottom));
  margin-top: auto;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

.footer-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border-radius: 50%;
  padding: 4px;
  border: 2px solid var(--accent);
}

.footer-school-name {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
}

.footer-subtitle {
  font-size: 0.8rem;
  color: var(--accent-light);
  margin-top: 0.15rem;
}

.footer-info {
  font-size: 0.8rem;
  line-height: 1.9;
  color: rgba(255, 255, 255, 0.75);
}

.footer-phones {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  justify-content: center;
  margin-top: 0.25rem;
}

.footer-phones a {
  color: var(--accent-light);
  text-decoration: none;
  font-weight: 600;
  direction: ltr;
  display: inline-block;
}

.footer-phones a:hover {
  text-decoration: underline;
}

.footer-copy {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.45);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  width: 100%;
}

/* ── Viewer page ── */
.viewer-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}

#viewer-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100dvh;
}

.viewer-topbar {
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: calc(0.7rem + var(--safe-top)) 0.85rem 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  z-index: 20;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  text-decoration: none;
  padding: 0.55rem 0.9rem;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  -webkit-tap-highlight-color: transparent;
}

.back-btn:hover,
.back-btn:active {
  background: rgba(255, 255, 255, 0.28);
}

.viewer-title-wrap {
  flex: 1;
  min-width: 0;
}

.viewer-title-wrap h1 {
  font-size: clamp(0.9rem, 3.5vw, 1.1rem);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-title-wrap p {
  font-size: 0.72rem;
  opacity: 0.75;
}

.viewer-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: linear-gradient(180deg, #dceeee 0%, #c8e4e4 100%);
  min-height: 0;
}

model-viewer {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: 100%;
  --poster-color: transparent;
}

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(238, 246, 246, 0.92);
  z-index: 10;
  transition: opacity 0.4s, visibility 0.4s;
}

.viewer-loading.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(10, 61, 61, 0.12);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.viewer-tips {
  background: #fff;
  padding: 0.75rem 1rem calc(0.75rem + var(--safe-bottom));
  border-top: 1px solid rgba(10, 61, 61, 0.08);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  flex-shrink: 0;
}

.tip {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.15rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0.35rem 0.2rem;
}

.tip-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.tip strong {
  color: var(--primary);
  font-size: 0.75rem;
}

.tip-desktop {
  display: none;
}

/* ── Error state ── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  text-align: center;
  padding: 2rem 1.5rem;
  gap: 1rem;
  background: var(--bg);
}

.error-page h2 {
  color: var(--primary);
  font-size: 1.2rem;
}

.error-page p {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 360px;
  line-height: 1.8;
}

.error-page a {
  color: #fff;
  background: var(--primary);
  font-weight: 600;
  text-decoration: none;
  padding: 0.65rem 1.5rem;
  border-radius: 50px;
  margin-top: 0.5rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* ── Responsive ── */
@media (min-width: 480px) {
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.1rem;
  }

  .card-icon {
    font-size: 2.8rem;
    padding: 1.5rem;
  }

  .card-body h3 {
    font-size: 1rem;
  }

  .help-steps {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .container {
    padding: 2rem 1.5rem 3rem;
  }

  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
  }

  .help-steps {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer-inner {
    flex-direction: row;
    text-align: right;
    align-items: flex-start;
    gap: 2rem;
  }

  .footer-text-block {
    flex: 1;
    text-align: right;
  }

  .footer-copy {
    text-align: center;
  }

  .tip-desktop {
    display: flex;
  }

  .viewer-tips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem 1.5rem;
  }

  .tip {
    flex-direction: row;
    font-size: 0.82rem;
  }
}

@media (max-width: 767px) {
  .tip-mobile-only .tip-icon::after {
    content: '';
  }
}

@media (max-width: 380px) {
  .viewer-tips {
    grid-template-columns: 1fr;
  }

  .tip {
    flex-direction: row;
    justify-content: center;
  }
}
