/* ============================================================
   Мобильная адаптация — до 700px.
   Поверх layout.css и components.css, ничего не ломает на десктопе.
   ============================================================ */

@media (max-width: 700px){
  /* --- общие --- */
  html,body{font-size:15px}
  body::before{opacity:.25}

  .shell{padding:14px 12px 48px}

  /* --- шапка --- */
  header.masthead{
    grid-template-columns:1fr;gap:6px;
    padding-bottom:14px;margin-bottom:18px;
  }
  .brand{font-size:30px;line-height:.95}
  .masthead .meta{
    flex-wrap:wrap;gap:10px 16px;justify-content:flex-start;
    font-size:10px;letter-spacing:.14em;
  }
  .issue{text-align:left;font-size:12px}

  /* Компактная шапка на мобильном — вертикально */
  header.masthead.compact{
    grid-template-columns:1fr;gap:10px;
  }
  .masthead.compact .brand{font-size:22px}
  .masthead-right{justify-content:stretch;gap:10px}
  .masthead-right .streak-widget,
  .masthead-right .auth-badge{width:100%}

  /* --- селектор заданий: две строки по 10 для ч.1, 6 для ч.2 --- */
  .task-selector{margin-bottom:22px}
  .selector-caption{
    flex-direction:column;align-items:flex-start;gap:4px;
    font-size:10px;letter-spacing:.14em;
  }
  .selector-caption em{font-size:13px}
  .task-row.part1{grid-template-columns:repeat(10, 1fr)}
  .task-row.part2{grid-template-columns:repeat(6, 1fr);max-width:none}
  .task-btn{min-height:44px;padding:8px 2px 6px}
  .tnum{font-size:15px}
  .tdot{width:3px;height:3px;margin-top:3px}
  .tprog{width:16px;height:2px;margin-top:4px}
  .task-btn .ttip{display:none} /* тултипы бесполезны на тач-экране */

  /* --- основной лэйаут — вертикально --- */
  .layout{grid-template-columns:1fr;gap:18px}

  /* --- сайдбар тем --- */
  aside.themes{
    position:static;padding-top:10px;
    border-top:1px solid var(--ink);border-bottom:1px solid var(--line);
    padding-bottom:14px;
  }
  aside.themes h3{margin-bottom:10px}
  .theme-item{
    font-size:15px;padding:10px 12px 10px 0;
    -webkit-tap-highlight-color:rgba(192,57,43,.15);
  }
  .theme-item.active::before{left:-10px;top:11px}
  .mode-switch{margin-top:18px;padding-top:12px}
  .mode-switch button{font-size:14px;padding:12px 0}

  /* --- заголовок темы --- */
  .theme-header{
    grid-template-columns:1fr;gap:10px;
    padding-bottom:14px;margin-bottom:20px;
  }
  .kicker{font-size:10px;letter-spacing:.14em;margin-bottom:6px}
  .theme-title{font-size:28px;line-height:1.02}
  .theme-subtitle{font-size:15px;margin-top:6px}
  .theme-meta{text-align:left;font-size:10px}

  /* --- блок теории --- */
  .theory{padding:18px 16px;margin-bottom:24px}
  .theory::before{left:14px;font-size:13px}
  .theory h4{font-size:17px;margin:14px 0 6px}
  .theory p, .theory ul, .theory ol{max-width:none;font-size:14.5px}
  .theory ul, .theory ol{margin-left:18px}
  .theory .formula{
    padding:10px 12px;margin:10px 0;
    flex-direction:column;align-items:flex-start;gap:4px;
    overflow-x:auto; /* не даём формуле рвать ширину экрана */
  }
  .theory .formula .desc{font-size:12px}
  .theory .note{font-size:13px;padding-left:12px}

  /* --- шапка блока задач --- */
  .tasks-header{
    flex-direction:column;align-items:flex-start;gap:6px;
    margin-bottom:14px;padding-bottom:8px;
  }
  .tasks-header h3{font-size:22px}
  .progress{font-size:11px;width:100%;min-width:0}
  .progress-bar{height:16px}
  .progress-bar-label{font-size:10px}

  /* --- карточка задачи --- */
  .task{margin-bottom:14px}
  .task-head{padding:10px 14px;gap:10px}
  .task-num{font-size:18px;width:28px}
  .task-kicker{font-size:9px;letter-spacing:.1em;line-height:1.4}

  /* КРИТИЧНО: убираем огромный левый отступ 76px */
  .task-body{padding:14px 14px 16px}
  .task-text{font-size:15px;line-height:1.6;max-width:none}

  /* SVG и картинки не вылезают за экран */
  .task-text .fig{
    margin:12px -4px;padding:10px;
    max-width:100%;overflow-x:auto;
    width:auto;
  }
  .task-text .fig svg{max-width:100%;height:auto;display:block;margin:0 auto}

  /* таблицы — горизонтальный скролл */
  .task-text{overflow-x:hidden}
  .task-text table{
    display:block;max-width:100%;overflow-x:auto;
    white-space:nowrap;font-size:12px;
  }
  .task-text table td, .task-text table th{padding:4px 7px}

  /* --- ответ --- */
  .answer-row{gap:8px;margin-top:14px}
  .answer-label{font-size:15px;width:100%;margin-bottom:-4px}
  .answer-input{
    width:100%;min-width:0;flex:1 1 120px;
    font-size:16px; /* 16px = iOS не зумит при фокусе */
    padding:8px 10px;
  }
  .answer-unit{font-size:13px;flex:0 0 auto}

  /* --- кнопки: крупнее под палец --- */
  .btn{
    padding:12px 18px;font-size:12px;
    min-height:44px;
    -webkit-tap-highlight-color:rgba(26,34,56,.2);
  }
  .answer-row .btn{flex:1 1 auto;text-align:center}

  .feedback{padding:12px 14px;font-size:13.5px}

  /* --- решение --- */
  .solution summary{padding:12px 14px;font-size:11px}
  .solution .sol-body{padding:0 14px 14px;font-size:13.5px;line-height:1.65}
  .solution .sol-body .step{padding:10px 12px;gap:10px}
  .solution .sol-body .step-num{font-size:16px}

  /* --- критерии (часть 2) --- */
  .criteria{padding:12px 14px;font-size:12.5px}

  /* --- режим варианта --- */
  .variant-banner{
    grid-template-columns:1fr;gap:12px;padding:16px 18px;
  }
  .variant-banner h2{font-size:22px}
  .timer{font-size:22px;padding:4px 12px;justify-self:start}

  .score-card{padding:18px 20px}
  .score-card h3{font-size:20px}
  .score-grid{gap:14px;grid-template-columns:repeat(3,1fr)}
  .score-num{font-size:30px}
  .score-label{font-size:9px;letter-spacing:.14em}

  /* --- пейволл / админка --- */
  .paywall{padding:18px 16px}
  .paywall h4{font-size:18px}
  .paywall p{font-size:13px}
  .admin-panel{padding:18px 16px}
  .admin-panel h2{font-size:20px}

  /* --- футер --- */
  footer.colophon{
    margin-top:40px;padding-top:16px;
    grid-template-columns:1fr;gap:6px;font-size:10px;
  }
}

/* Совсем узкие экраны (старые iPhone SE и т.п.) */
@media (max-width: 380px){
  .task-row.part1{grid-template-columns:repeat(5, 1fr)}
  .brand{font-size:26px}
  .theme-title{font-size:24px}
  .tnum{font-size:14px}
}

/* Не даём KaTeX ломать ширину страницы длинной формулой */
.katex-display{overflow-x:auto;overflow-y:hidden;padding:2px 0}
.katex{max-width:100%}

/* Глобально — чтобы никакой элемент не создавал горизонтальный скролл корня */
html,body{overflow-x:hidden}

/* ============ Mobile: onboarding ============ */
@media (max-width: 700px){
  #onboardingPopup{
    left:12px !important;right:12px !important;
    top:auto !important;bottom:16px !important;
    width:auto !important;max-width:none !important;
    padding:16px 18px 12px;
  }
  .onb-title{font-size:19px}
  .onb-text{font-size:14px;margin-bottom:14px}
  .onb-btn{padding:11px 12px;font-size:10px;letter-spacing:.1em}
  .onb-nav{gap:6px}
  .onb-dots{gap:4px}
  .onb-dot{width:5px;height:5px}
}

/* ============ Mobile: landing ============ */
@media (max-width: 700px){
  .landing-hero{padding:56px 12px 40px;margin-bottom:28px}
  .landing-badge{font-size:10px;padding:5px 12px;margin-bottom:20px}
  .landing-title{font-size:42px}
  .landing-title em{font-size:0.55em;margin-top:6px}
  .landing-lead{font-size:15px;margin-bottom:24px}

  .landing-stats{gap:16px;padding:12px 18px;margin-bottom:24px}
  .landing-stat b{font-size:22px}
  .landing-stat span{font-size:8px}
  .landing-stat-sep{height:28px}

  .landing-ctas{flex-direction:column;gap:10px}
  .landing-btn{padding:14px 24px;width:100%;font-size:11px;justify-content:center}
  .landing-note{font-size:12px}
  .landing-scroll{margin-top:28px}

  .landing-grid{grid-template-columns:1fr;gap:16px;margin-bottom:28px;padding:0 12px}
  .landing-card{padding:20px 18px}
  .landing-card h3{font-size:22px;margin-bottom:14px}
  .landing-features li{font-size:14px}
  .landing-subjects{padding:16px 18px;margin:0 12px}
  .landing-subjects ul{gap:14px;font-size:15px}
  .landing-foot{font-size:9px;padding:14px 12px}

  /* Фоновые символы помельче на мобильном */
  .float-sym{font-size:12px !important}
  .landing-glow{width:600px;height:600px}
}

/* ============ Mobile: теория ============ */
@media (max-width: 700px){
  .view-switch{width:100%;margin-bottom:16px}
  .view-switch-btn{flex:1;justify-content:center;padding:10px 6px;font-size:10px;letter-spacing:.12em}

  .theory-head .theme-title{font-size:26px}
  .theory-head{padding-bottom:14px;margin-bottom:20px}
  .theory-actions{width:100%}
  .theory-actions .btn{flex:1;text-align:center}

  .theory-toc-wrap{padding:10px 14px;margin-bottom:20px}
  .theory-toc a{font-size:14px}

  .theory-content{font-size:15.5px;line-height:1.65}
  .theory-content h2{font-size:22px;margin:26px 0 10px;padding-top:10px}
  .theory-content h3{font-size:18px;margin:20px 0 8px}
  .theory-content h4{font-size:14px}
  .theory-content .katex-display{padding:10px 12px;overflow-x:auto;overflow-y:hidden}
  .theory-content blockquote{padding:10px 14px;font-size:14px}
  .theory-content table{font-size:12px;display:block;overflow-x:auto;white-space:nowrap}
  .theory-content th, .theory-content td{padding:6px 10px}

  .theory-placeholder{padding:24px 16px}
  .theory-placeholder h1{font-size:22px}
  .theory-placeholder-note{font-size:14px}
}

/* ============ Mobile: стрик и режим боя ============ */
@media (max-width: 700px){
  .streak-row{padding:10px 12px;gap:12px;flex-wrap:wrap}
  .streak-flame{font-size:20px}
  .streak-num{font-size:18px}
  .streak-extra{gap:12px}
  .streak-stat b{font-size:15px}
  .streak-calendar{gap:2px;margin-left:0;flex:1 1 100%;order:3;justify-content:space-between}
  .streak-day{width:auto;flex:1;max-width:14px;height:18px}

  .battle-head{flex-direction:column;align-items:stretch;gap:10px}
  .battle-title{font-size:24px}
  .battle-subtitle{font-size:13px}
  .battle-actions{width:100%}
  .battle-actions .btn{flex:1}

  .shortcuts-body{min-width:auto;padding:18px 20px}
  .shortcuts-body dl{font-size:13px;gap:8px 14px}

  .mode-switch .mode-primary{font-size:15px !important;padding:12px 0 !important}
}

/* ============ Mobile: самооценка варианта ============ */
@media (max-width: 700px){
  .part2-self-score{padding:12px 14px}
  .part2-score-btn{width:44px;height:44px;font-size:15px}
  .score-breakdown{font-size:13px}
  .score-part2-note{font-size:12px}
  .score-num-sub{font-size:16px}
}

/* ============ Mobile: переключатель предметов ============ */
@media (max-width: 700px){
  .subject-switch{margin:-2px 0 14px}
  .subject-btn{padding:10px 8px;min-height:48px}
  .subject-btn-title{font-size:14px}
  .subject-btn-meta{font-size:9px;letter-spacing:.1em}
}

/* ============ Mobile: auth-бейдж ============ */
@media (max-width: 700px){
  .auth-badge{margin:-6px 0 16px;justify-content:stretch}
  .auth-anon, .auth-signed{
    width:100%;flex-wrap:wrap;gap:10px;
    padding:10px 12px;
  }
  .auth-anon-label{max-width:none;font-size:12px;flex:1 1 100%}
  .auth-signin{width:100%;text-align:center;padding:12px 14px;min-height:44px}
  .auth-name{max-width:130px;font-size:13px}
  .auth-email{max-width:160px}
  .google-btn-slot{width:100%}
}

/* ============ Mobile: стикер-заметка ============ */
@media (max-width: 700px){
  .sticker-add{right:12px;bottom:12px;width:48px;height:48px}
  .sticker-add-icon{font-size:20px}

  /* Развёрнутый стикер превращается в sheet снизу экрана —
     не зависит от позиции на странице, не перекрывается клавиатурой,
     нет mini-бокса посреди контента. */
  .sticker-note.open{
    position:fixed !important;
    left:0 !important;right:0 !important;top:auto !important;
    bottom:0 !important;
    z-index:80;
  }
  .sticker-note.open .sticker-body{
    width:100%;max-width:100%;
    transform:none;
    border:none;border-top:1px solid #c6a74b;
    box-shadow:0 -8px 28px rgba(40,25,0,.22);
    display:flex;flex-direction:column;
    max-height:70vh;
  }
  .sticker-head{cursor:default;padding:12px 16px} /* drag на телефоне не нужен */
  .sticker-title{font-size:14px}
  .sticker-close, .sticker-min{width:32px;height:32px;font-size:18px}
  .sticker-min{font-size:22px}
  .sticker-text{
    min-height:140px;max-height:52vh;font-size:16px; /* 16px — без зума на iOS */
    padding:14px 16px;
  }
  .sticker-foot{padding:10px 16px}

  /* Свёрнутые чипы остаются на своих местах на странице,
     но без перетаскивания (drag на touch не реализован) */
  .sticker-note.collapsed{z-index:40}
  .sticker-chip{font-size:13px;padding:8px 12px;max-width:180px}
  .sticker-chip-close{width:24px;height:24px;font-size:13px}

  /* Затемнение под sheet, чтобы выделить его из страницы */
  .sticker-note.open::before{
    content:"";position:fixed;inset:0;z-index:-1;
    background:rgba(20,12,0,.25);
    pointer-events:none;
  }
}
