/* ==========================================================================
   BQ24 — «Пайдалы нұсқаулықтар» onboarding modal  (css/guide.css)
   Self-contained component. Uses the project's existing theme switch
   (<html data-theme="dark|light">) and scopes its own tokens to .guide-overlay.
   No auth / session / Live Quiz logic lives here.
   ========================================================================== */

/* ---------- Design tokens (dark = project default) ---------- */
.guide-overlay {
  --gd-primary: #2563EB;
  --gd-primary-hover: #1D4ED8;
  --gd-primary-press: #1E40AF;
  --gd-accent: #60A5FA;
  --gd-bg: #0B1220;
  --gd-surface: #111C2E;
  --gd-surface-2: #17243A;
  --gd-text: #F8FAFC;
  --gd-text-2: #A7B4C8;
  --gd-border: #293A53;
  --gd-success: #10B981;
  --gd-info: #3B82F6;
  --gd-violet: #8B5CF6;
  --gd-amber: #F59E0B;
  --gd-focus: #93C5FD;
  --gd-scrim: rgba(5, 10, 20, 0.62);
  --gd-shadow: 0 28px 80px rgba(2, 6, 23, 0.6), 0 2px 8px rgba(2, 6, 23, 0.4);
  --gd-suit: #2B4A7A;
  --gd-hair: #334155;
  --gd-skin: #F2C9A5;

  /* radius scale */
  --gd-r-sm: 10px;
  --gd-r-btn: 12px;
  --gd-r-card: 14px;
  --gd-r-modal: 24px;

  /* 4px spacing scale */
  --gd-s1: 4px;
  --gd-s2: 8px;
  --gd-s3: 12px;
  --gd-s4: 16px;
  --gd-s6: 24px;
  --gd-s8: 32px;
}

[data-theme="light"] .guide-overlay {
  --gd-bg: #F8FAFC;
  --gd-surface: #FFFFFF;
  --gd-surface-2: #F8FAFC;
  --gd-text: #0F172A;
  --gd-text-2: #64748B;
  --gd-border: #E2E8F0;
  --gd-focus: #2563EB;
  --gd-scrim: rgba(15, 23, 42, 0.42);
  --gd-shadow: 0 24px 64px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.06);
  --gd-suit: #0F172A;
  --gd-hair: #1E293B;
}

/* ---------- Overlay (backdrop) ---------- */
.guide-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: var(--gd-scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  overscroll-behavior: contain;
  animation: gdFadeIn 0.18s ease both;
}

.guide-overlay.hidden { display: none !important; }
.guide-overlay.is-closing { animation: gdFadeOut 0.16s ease both; }
.guide-overlay.is-closing .guide-modal { animation: gdPopOut 0.16s ease both; }

/* ---------- Dialog window ---------- */
.guide-modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1100px, 100%);
  height: min(640px, 100%);
  color: var(--gd-text);
  background: var(--gd-surface);
  border: 1px solid var(--gd-border);
  border-radius: var(--gd-r-modal);
  box-shadow: var(--gd-shadow);
  overflow: hidden;
  font-family: inherit;
  animation: gdPopIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.guide-modal:focus { outline: none; }
.guide-overlay :focus-visible { outline: 2px solid var(--gd-focus); outline-offset: 2px; }

/* ---------- Header ---------- */
.guide-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gd-s4);
  padding: var(--gd-s4) var(--gd-s6);
  border-bottom: 1px solid var(--gd-border);
}

.guide-brand { display: flex; align-items: center; gap: var(--gd-s2); min-width: 0; }

.guide-brand-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--gd-r-sm);
  color: var(--gd-primary);
  background: rgba(37, 99, 235, 0.12);
}

.guide-brand-icon svg,
.guide-brand-icon i { width: 20px; height: 20px; }

.guide-brand-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--gd-text);
}

.guide-header-end { display: flex; align-items: center; gap: var(--gd-s3); }

.guide-step-pill {
  min-width: 56px;
  padding: 4px 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--gd-text-2);
  background: var(--gd-surface-2);
  border: 1px solid var(--gd-border);
  border-radius: 999px;
}

.guide-close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--gd-text-2);
  background: transparent;
  border: 0;
  border-radius: var(--gd-r-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.guide-close:hover { color: var(--gd-text); background: var(--gd-surface-2); }
.guide-close svg, .guide-close i { width: 20px; height: 20px; }

/* ---------- Body (the only scrolling region) ---------- */
.guide-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--gd-s8);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.guide-body:focus-visible { outline-offset: -3px; }

.guide-slide {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  align-items: center;
  gap: var(--gd-s8);
  width: 100%;
  margin-block: auto;
  animation: gdSlideIn 0.2s ease both;
}

.guide-slide[hidden] { display: none !important; }

.guide-title {
  margin: 0 0 var(--gd-s4);
  font-size: clamp(22px, 2.6vw, 32px);
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--gd-text);
  overflow-wrap: anywhere;
  hyphens: auto;
}

.guide-lead {
  margin: 0;
  font-size: 16px;
  line-height: 1.65;
  color: var(--gd-text-2);
}

/* ---------- Item cards (steps 2–5) ---------- */
.guide-list {
  display: grid;
  gap: var(--gd-s3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-item {
  display: flex;
  align-items: center;
  gap: var(--gd-s3);
  padding: var(--gd-s3) var(--gd-s4);
  background: var(--gd-surface-2);
  border: 1px solid var(--gd-border);
  border-radius: var(--gd-r-card);
}

.guide-item-text { min-width: 0; }

.guide-item-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  font-weight: 600;
  color: var(--gd-text);
  overflow-wrap: anywhere;
}

.guide-item-sub {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--gd-text-2);
  overflow-wrap: anywhere;
}

.gd-tile {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--gd-r-sm);
}

.gd-tile svg, .gd-tile i { width: 20px; height: 20px; }
.gd-tile--blue   { color: var(--gd-info);    background: rgba(59, 130, 246, 0.14); }
.gd-tile--green  { color: var(--gd-success); background: rgba(16, 185, 129, 0.14); }
.gd-tile--violet { color: var(--gd-violet);  background: rgba(139, 92, 246, 0.14); }
.gd-tile--amber  { color: var(--gd-amber);   background: rgba(245, 158, 11, 0.14); }

.gd-num {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--gd-primary);
  border-radius: 50%;
}

.guide-list--steps .guide-item { align-items: flex-start; padding: 10px var(--gd-s4); }
.guide-list--steps .gd-num { margin-top: 1px; }

/* ---------- Illustrations ---------- */
.guide-art {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.gd-svg { display: block; width: 100%; max-width: 400px; height: auto; max-height: 100%; }
.gd-svg .f-card { fill: var(--gd-surface-2); }
.gd-svg .f-surface { fill: var(--gd-surface); }
.gd-svg .f-border { fill: var(--gd-border); }
.gd-svg .f-muted { fill: var(--gd-text-2); }
.gd-svg .f-primary { fill: var(--gd-primary); }
.gd-svg .f-accent { fill: var(--gd-accent); }
.gd-svg .f-green { fill: var(--gd-success); }
.gd-svg .f-violet { fill: var(--gd-violet); }
.gd-svg .f-amber { fill: var(--gd-amber); }
.gd-svg .f-skin { fill: var(--gd-skin); }
.gd-svg .f-hair { fill: var(--gd-hair); }
.gd-svg .f-suit { fill: var(--gd-suit); }
.gd-svg .f-white { fill: #fff; }
.gd-svg .s-border { stroke: var(--gd-border); }
.gd-svg .s-primary { stroke: var(--gd-primary); }
.gd-svg .s-accent { stroke: var(--gd-accent); }
.gd-svg .s-green { stroke: var(--gd-success); }
.gd-svg .s-suit { stroke: var(--gd-suit); }
.gd-svg .s-white { stroke: #fff; }
.gd-svg .none { fill: none; }

/* ---------- Footer ---------- */
.guide-footer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "close dots actions";
  align-items: center;
  gap: var(--gd-s4);
  padding: var(--gd-s4) var(--gd-s6);
  border-top: 1px solid var(--gd-border);
  background: var(--gd-surface);
}

.guide-footer .gd-btn--close { grid-area: close; justify-self: start; }
.guide-dots { grid-area: dots; display: flex; align-items: center; justify-content: center; }
.guide-actions { grid-area: actions; justify-self: end; display: flex; gap: var(--gd-s3); }

/* Progress dots: done / active / upcoming */
.guide-dot {
  display: grid;
  place-items: center;
  width: 20px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.guide-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--gd-border);
  transition: width 0.2s ease, background-color 0.2s ease;
}

.guide-dot:hover::before { background: var(--gd-text-2); }
.guide-dot.is-done::before { background: var(--gd-accent); }
.guide-dot[aria-current="step"] { width: 36px; }
.guide-dot[aria-current="step"]::before { width: 24px; background: var(--gd-primary); }

/* ---------- Buttons ---------- */
.gd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gd-s2);
  min-height: 44px;
  padding: 0 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
  color: var(--gd-text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--gd-r-btn);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.gd-btn[hidden] { display: none !important; }
.gd-btn svg, .gd-btn i { width: 18px; height: 18px; flex: 0 0 auto; }

.gd-btn--primary { color: #fff; background: var(--gd-primary); }
.gd-btn--primary:hover { background: var(--gd-primary-hover); }
.gd-btn--primary:active { background: var(--gd-primary-press); transform: translateY(1px); }

.gd-btn--secondary { background: var(--gd-surface); border-color: var(--gd-border); }
.gd-btn--secondary:hover { border-color: var(--gd-accent); color: var(--gd-accent); }
[data-theme="light"] .gd-btn--secondary:hover { color: var(--gd-primary); border-color: var(--gd-primary); }
.gd-btn--secondary:active { transform: translateY(1px); }

.gd-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.gd-btn--primary:disabled:hover { background: var(--gd-primary); }
.gd-btn--secondary:disabled:hover { border-color: var(--gd-border); color: var(--gd-text); }

/* ---------- Animations ---------- */
@keyframes gdFadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes gdFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes gdPopIn   { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes gdPopOut  { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes gdSlideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Tablet / narrow desktop ---------- */
@media (max-width: 900px) {
  .guide-modal { width: min(720px, 100%); height: min(700px, 100%); }
  .guide-slide { grid-template-columns: minmax(0, 1fr); gap: var(--gd-s6); }
  .guide-art .gd-svg { max-width: 300px; max-height: 190px; }
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  .guide-overlay {
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .guide-modal {
    width: min(100%, 520px);
    height: min(100%, 760px);
    border-radius: 20px;
  }

  .guide-header { padding: var(--gd-s3) var(--gd-s4); }
  .guide-brand-name { font-size: 17px; }
  .guide-close { width: 44px; height: 44px; margin-right: -6px; }

  .guide-body { padding: var(--gd-s6) var(--gd-s4); }
  .guide-slide { gap: var(--gd-s4); }
  .guide-title { font-size: 22px; margin-bottom: var(--gd-s3); }
  .guide-lead { font-size: 14.5px; line-height: 1.6; }
  .guide-list { gap: 10px; }
  .guide-item { padding: 10px var(--gd-s3); }
  .guide-item-title { font-size: 14px; }
  .guide-item-sub { font-size: 12.5px; }
  .gd-tile { width: 36px; height: 36px; }
  .guide-art .gd-svg { max-width: 240px; max-height: 150px; }
  .guide-slide[data-art="desktop-only"] .guide-art { display: none; }

  .guide-footer {
    grid-template-columns: 1fr;
    grid-template-areas: "dots" "actions" "close";
    gap: var(--gd-s3);
    padding: var(--gd-s3) var(--gd-s4) var(--gd-s4);
  }

  .guide-footer .gd-btn--close { justify-self: stretch; width: 100%; }
  .guide-actions { display: grid; grid-template-columns: 1fr 1fr; justify-self: stretch; gap: var(--gd-s3); }
  .guide-actions .gd-btn { padding: 0 var(--gd-s3); width: 100%; }
  .guide-dot { height: 24px; }
}

/* ---------- Short viewports (small phones, landscape) ---------- */
@media (max-height: 640px) {
  .guide-body { padding-block: var(--gd-s4); }
}

@media (max-height: 640px) and (max-width: 900px) {
  .guide-slide { gap: var(--gd-s3); }
  .guide-art { display: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .guide-overlay,
  .guide-overlay.is-closing,
  .guide-modal,
  .guide-overlay.is-closing .guide-modal,
  .guide-slide { animation: none !important; }
  .gd-btn, .guide-close, .guide-dot::before { transition: none !important; }
}
