/* CyberMath — утасны аппын харагдац (≤768px, апп нээгдсэн үед body.cm-app-on).
   Ширээний дэлгэц, landing, embed (iframe) горимд нөлөөлөхгүй. Замын (learning path) SVG-д огт хүрэхгүй —
   зөвхөн эргэн тойрных нь бүрхүүл: дээд app bar, нягт streak/XP, доод таб навигаци, «Цааш» хуудас. */
#cm-bnav, #cm-sheet { display: none; }

@media (max-width: 768px) {
  html { -webkit-tap-highlight-color: transparent; }

  /* ── Дээд app bar ── */
  body.cm-app-on #cybermath-app .navbar {
    position: sticky; top: 0; z-index: 100;
    min-height: 56px; padding: 6px 12px;
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    background: rgba(255, 255, 255, .88);
    -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid rgba(33, 28, 84, .07);
    box-shadow: 0 6px 18px -14px rgba(33, 28, 84, .35);
  }
  body.cm-app-on #cybermath-app .navbar .logo-bird { height: 30px !important; }
  body.cm-app-on #cybermath-app .nav-stats { gap: 5px; }
  body.cm-app-on #cybermath-app .stat-chip { min-height: 28px; padding: 3px 8px; }

  /* ── Том hero-г нууна (апп шиг: шууд агуулга руу) ── */
  body.cm-app-on #cybermath-app .hero { display: none !important; }

  /* ── Хэвтээ табын мөр → доод навигаци ── */
  body.cm-app-on #cybermath-app .tabs { display: none !important; }

  /* ── Streak / XP — зөвхөн «Зам» дээр, нягт карт ── */
  body.cm-app-on:not(.cm-tab-path) #streak-section,
  body.cm-app-on:not(.cm-tab-path) #cybermath-app .xp-banner { display: none !important; }
  body.cm-app-on #streak-section {
    margin: 12px 12px 8px; padding: 12px 14px; gap: 12px;
    border-radius: 18px; border: 1px solid #eee9fb;
    box-shadow: 0 10px 24px -18px rgba(33, 28, 84, .45);
  }
  body.cm-app-on #streak-fire-icon svg { width: 34px; height: 42px; }
  body.cm-app-on #streak-title { font-size: 1.02rem; margin: 0; line-height: 1.2; }
  body.cm-app-on #streak-subtitle { font-size: .78rem; margin: 2px 0 0; line-height: 1.3; }
  body.cm-app-on #cybermath-app .xp-banner {
    margin: 0 12px 12px; padding: 12px 14px;
    border-radius: 18px; border: 1px solid #eee9fb;
    box-shadow: 0 10px 24px -18px rgba(33, 28, 84, .45);
  }
  body.cm-app-on #cybermath-app .xp-header { margin-bottom: 8px; }
  body.cm-app-on #cybermath-app .xp-label { font-size: .72rem; }
  body.cm-app-on #cybermath-app .xp-value { font-size: .95rem; }

  /* ── Табын агуулга: доод навигацийн доор орохгүй, зөөлөн гарч ирнэ
       (tab-mathlet / tab-classroom / tab-exam нь #cybermath-app-ийн гадна байдаг тул id-аар) ── */
  body.cm-app-on .tab-content[id^="tab-"] { padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }
  body.cm-app-on .tab-content[id^="tab-"].active { animation: cmTabIn .24s ease both; }
  body.cm-app-on .tab-content[id^="tab-"] .section-title { font-size: 1.15rem; margin: 14px 6px 12px; }
  /* «Learning Path» гарчиг — доод навигацид «Зам» гэж байгаа тул нууж, газрын зурагт зай гаргана (зам өөрөө хэвээр) */
  body.cm-app-on #tab-path > .section-title { display: none; }
  /* Тоглоом, тэргүүлэгч г.м. — дэлгэцийн захаас зай (замын газрын зураг өргөнөөрөө хэвээр) */
  body.cm-app-on .tab-content[id^="tab-"]:not(#tab-path) { padding-left: 12px; padding-right: 12px; box-sizing: border-box; }
  /* iPhone-ийн доод зураас (home indicator) цонхны товчийг дарахгүй */
  body.cm-app-on .modal-overlay { padding-bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 8px)); }
  /* Мэдэгдэл (toast): урт бичиг дэлгэцээс халихгүй (мөр шилжинэ), доод навигацийн дээр гарна */
  body.cm-app-on .toast {
    white-space: normal; width: max-content; max-width: calc(100vw - 32px); text-align: center; line-height: 1.3;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px)); padding: 11px 18px; border-radius: 18px;
    opacity: 0; visibility: hidden; transform: translateX(-50%) translateY(16px);
    transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), opacity .2s ease, visibility 0s linear .35s;
  }
  body.cm-app-on .toast.show {
    opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0);
    transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), opacity .2s ease;
  }

  /* ── Доод таб навигаци ── */
  body.cm-app-on #cm-bnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 95;
    display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 6px 4px max(6px, env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, .94);
    -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid rgba(33, 28, 84, .08);
    box-shadow: 0 -10px 28px -18px rgba(33, 28, 84, .35);
  }
  #cm-bnav button {
    appearance: none; -webkit-appearance: none; border: 0; background: none; margin: 0;
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 3px 0 1px;
    font: 800 11px/1.1 'Nunito', 'Baloo 2', sans-serif; letter-spacing: .1px;
    color: #8a83a3; cursor: pointer; min-width: 0;
  }
  #cm-bnav button i {
    display: grid; place-items: center; width: 54px; height: 30px; border-radius: 16px;
    transition: background .2s ease, transform .15s ease;
  }
  #cm-bnav button svg { width: 23px; height: 23px; }
  #cm-bnav button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #cm-bnav button.on { color: #5a32d6; }
  #cm-bnav button.on i { background: linear-gradient(135deg, rgba(123, 82, 238, .16), rgba(192, 132, 252, .24)); }
  #cm-bnav button:active i { transform: scale(.9); }

  /* ── AI чатны товч навигацийн дээр ── */
  body.cm-app-on #app-chat-btn {
    bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important; right: 14px !important;
    width: 48px !important; height: 48px !important;
  }
  body.cm-app-on #app-chatbot {
    bottom: calc(140px + env(safe-area-inset-bottom, 0px)) !important;
    left: 10px !important; right: 10px !important; width: auto !important; max-height: 62vh !important;
  }

  /* ── Даралтын мэдрэмж ── */
  body.cm-app-on #cybermath-app .game-card { transition: transform .15s ease; }
  body.cm-app-on #cybermath-app .game-card:active { transform: scale(.97); }
}

/* ── Угтах дэлгэц (нэвтрээгүй үеийн landing, утсан дээр body.cm-land-on):
      апп шиг нэг дэлгэц — лого, шувуу, гарчиг, 3 том товч. Маркетингийн хэсгүүд «Дэлгэрэнгүй»-гээр нээгдэнэ. ── */
#cm-land-more, #cm-land-install, #cm-land-switch { display: none; }
@media (max-width: 768px) {
  body.cm-land-on #landing-nav {
    height: calc(56px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 16px 0; justify-content: center;
  }
  body.cm-land-on #landing-nav .nav-links,
  body.cm-land-on #landing-nav .nav-actions { display: none !important; }
  body.cm-land-on #landing-nav .nav-logo svg { height: 30px; }
  body.cm-land-on #hero {
    min-height: 100vh; min-height: 100svh; height: auto;
    display: flex !important; flex-direction: column; align-items: stretch; justify-content: flex-end; gap: 0;
    padding: calc(72px + env(safe-area-inset-top, 0px)) 20px calc(18px + env(safe-area-inset-bottom, 0px)) !important; box-sizing: border-box;
  }
  /* Шувуу: гарчиг/товчны дээрх үлдсэн зайд багтана (сайтын floatIn шилжилтийг унтраана) */
  body.cm-land-on #hero .hero-visual {
    display: flex !important; order: 0; flex: 1 1 0; width: auto !important; height: auto !important; min-height: 96px;
    align-items: center; justify-content: center; margin: 0 0 8px; animation: none !important; transform: none !important;
  }
  body.cm-land-on #hero .hero-phone-wrap { display: none !important; }
  body.cm-land-on #hero .hero-bird-big {
    display: block !important; position: static !important; height: 100%; max-height: 210px; width: auto !important;
    aspect-ratio: 259 / 299; margin: 0 auto !important; padding: 0 !important; animation: cmBird 3.4s ease-in-out infinite;
  }
  body.cm-land-on #hero .hero-bird-big svg { width: 100% !important; height: 100% !important; }
  body.cm-land-on #hero .hero-content { order: 1; max-width: none !important; text-align: center !important; }
  body.cm-land-on #hero .hero-title { font-size: clamp(26px, 7.6vw, 34px) !important; margin-bottom: 22px !important; text-align: center; }
  body.cm-land-on #hero .hero-content > div { flex-direction: column !important; gap: 10px !important; }
  body.cm-land-on #hero .btn-hero-primary,
  body.cm-land-on #hero .btn-hero-secondary {
    width: 100% !important; max-width: none !important; min-height: 54px; padding: 14px 20px !important;
    justify-content: center; border-radius: 16px; font-size: 17px;
  }
  body.cm-land-on #hero .btn-hero-secondary:last-child { background: transparent; border-color: transparent; min-height: 44px; font-size: 15px; }
  body.cm-land-on #cm-land-more, body.cm-land-on #cm-land-install {
    display: block; width: 100%; margin: 4px 0 0; padding: 8px; border: 0; background: none; cursor: pointer;
    font: 800 13.5px/1.2 'Nunito', 'Baloo 2', sans-serif; color: rgba(255, 255, 255, .82);
  }
  body.cm-land-on #cm-land-install { color: #FFD84D; }
  body.cm-land-on #cm-land-switch { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; margin: 4px 0 0; padding: 8px; border: 0;
    background: none; cursor: pointer; font: 800 13.5px/1.2 'Nunito', 'Baloo 2', sans-serif; color: rgba(255, 255, 255, .82); }
  body.cm-land-on #cm-land-switch svg { width: 15px; height: 15px; flex: none; }
  /* Маркетингийн хэсгүүд — «Дэлгэрэнгүй» дарахаас өмнө нуугдана */
  body.cm-land-on:not(.cm-land-more) #landing-page > section:not(#hero),
  body.cm-land-on:not(.cm-land-more) #landing-page > footer,
  body.cm-land-on:not(.cm-land-more) #cm-chat-btn { display: none !important; }
  body.cm-land-on.cm-land-more #cm-land-more { display: none; }
}
/* Намхан дэлгэц (iPhone SE г.м.) — нягт */
@media (max-width: 768px) and (max-height: 720px) {
  body.cm-land-on #hero { padding-top: calc(64px + env(safe-area-inset-top, 0px)) !important; }
  body.cm-land-on #hero .hero-title { font-size: clamp(22px, 6.6vw, 28px) !important; margin-bottom: 14px !important; }
  body.cm-land-on #hero .hero-content > div { gap: 8px !important; }
  body.cm-land-on #hero .btn-hero-primary,
  body.cm-land-on #hero .btn-hero-secondary { min-height: 48px; padding: 10px 18px !important; font-size: 16px; }
  body.cm-land-on #hero .btn-hero-secondary:last-child { min-height: 38px; }
  body.cm-land-on #cm-land-more, body.cm-land-on #cm-land-install, body.cm-land-on #cm-land-switch { padding: 5px; margin: 0; }
}
@keyframes cmBird { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ── «Цааш» хуудас (bottom sheet) ── */
#cm-sheet { position: fixed; inset: 0; z-index: 1200; }
#cm-sheet.on { display: block; }
#cm-sheet .bd { position: absolute; inset: 0; background: rgba(20, 14, 48, .45); opacity: 0; transition: opacity .25s ease; }
#cm-sheet.show .bd { opacity: 1; }
#cm-sheet .pn {
  position: absolute; left: 0; right: 0; bottom: 0; background: #fff;
  border-radius: 24px 24px 0 0; padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2, .9, .3, 1);
  box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, .4);
}
#cm-sheet.show .pn { transform: none; }
#cm-sheet .hd { width: 40px; height: 5px; border-radius: 3px; background: #e2ddf0; margin: 0 auto 14px; }
#cm-sheet h4 { margin: 0 4px 12px; font: 900 1.05rem/1.2 'Baloo 2', sans-serif; color: #211C54; }
#cm-sheet .gr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#cm-sheet .gr button {
  appearance: none; -webkit-appearance: none; position: relative; cursor: pointer;
  border: 1px solid #efeaf9; background: #faf8ff; border-radius: 18px; padding: 14px 6px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font: 800 12.5px/1.2 'Nunito', 'Baloo 2', sans-serif; color: #2a2150; transition: transform .15s ease;
}
#cm-sheet .gr button:active { transform: scale(.96); }
#cm-sheet .gr button i {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #7B52EE, #C084FC); box-shadow: 0 10px 20px -10px rgba(123, 82, 238, .8);
}
#cm-sheet .gr button svg { width: 22px; height: 22px; }
#cm-sheet .tx { margin: 0 4px 12px; font: 700 14px/1.5 'Nunito', 'Baloo 2', sans-serif; color: #4b4468; }
#cm-sheet ol { margin: 0 4px 4px; padding-left: 22px; font: 700 14.5px/1.65 'Nunito', 'Baloo 2', sans-serif; color: #2a2150; }
#cm-sheet ol b { color: #5a32d6; }
#cm-sheet ol svg { width: 17px; height: 17px; vertical-align: -3px; color: #5a32d6; }
#cm-sheet .ok {
  display: block; width: 100%; margin-top: 14px; min-height: 50px; border: 0; border-radius: 14px; cursor: pointer;
  background: linear-gradient(135deg, #7B52EE, #A855F7); color: #fff; font: 900 16px/1 'Baloo 2', sans-serif;
}
#cm-sheet .nomore {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin: 12px 0 2px; cursor: pointer;
  font: 700 14px/1.2 'Nunito', 'Baloo 2', sans-serif; color: #6c6486; -webkit-user-select: none; user-select: none;
}
#cm-sheet .nomore input { width: 19px; height: 19px; margin: 0; accent-color: #7B52EE; }
/* iPhone Safari: доод мөрөн дэх «Хуваалцах» товч руу заасан сум */
#cm-sheet .arw { display: flex; justify-content: center; margin-top: 6px; color: #7B52EE; animation: cmArw 1.2s ease-in-out infinite; }
#cm-sheet .arw svg { width: 28px; height: 28px; }
@keyframes cmArw { 0%, 100% { transform: translateY(0); opacity: 1; } 50% { transform: translateY(7px); opacity: .55; } }
#cm-sheet .gr button em {
  position: absolute; top: 7px; right: 7px; font-style: normal; font-size: 9.5px; font-weight: 900;
  background: #FFC800; color: #5a3a00; border-radius: 8px; padding: 1px 6px;
}

@keyframes cmTabIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  body.cm-app-on .tab-content[id^="tab-"].active { animation: none; }
  #cm-sheet .pn, #cm-sheet .bd { transition: none; }
}
