/* Клуб друзей ФМШ №146.
   Светлая тема - тетрадь в клетку, тёмная - школьная доска с мелом.
   Шрифты: заголовки - академический serif, числа и формулы - mono, текст - sans. */

:root {
  /* тетрадь в клетку */
  --bg: #fbfaf6;
  --bg2: #f3f1ea;
  --panel: #ffffff;
  --line: #dcd9cf;
  --grid: rgba(43, 94, 166, .10);
  --text: #22303d;
  --muted: #5e6b77;
  --ink: #1b4fa0;        /* синяя ручка */
  --accent: #b3261e;     /* красная ручка учителя */
  --ok: #1d7a4f;         /* зелёная ручка */
  --shadow: 0 2px 16px rgba(34, 48, 61, .08);
  --serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;   /* фирменный заголовочный */
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, sans-serif;  /* фирменный текстовый */
  --radius: 12px;
}
[data-theme="dark"] {
  /* школьная доска */
  --bg: #243531;
  --bg2: #1d2b28;
  --panel: #2b3f3a;
  --line: #3c544d;
  --grid: rgba(245, 242, 230, .05);
  --text: #f1eee2;       /* мел */
  --muted: #aebcb2;
  --ink: #ffd866;        /* жёлтый мелок */
  --accent: #ff9d76;     /* розовый мелок */
  --ok: #9fe8c1;
  --shadow: 0 2px 18px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.65 var(--sans);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  transition: background-color .25s, color .25s;
}
h1 { font: 700 clamp(1.7rem, 5.5vw, 2.8rem)/1.18 var(--serif); margin: 0 0 1rem; }
h2 { font: 700 clamp(1.3rem, 4vw, 1.85rem)/1.25 var(--serif); margin: 3.6rem 0 2rem; }
h2::before { content: "§ "; color: var(--ink); }
/* раздел «владеет» отступом сверху; не дублируем в начале блока и сразу после заголовка */
h2:first-child, h1 + h2, h2 + h2 { margin-top: 0; }
h3 { font: 700 1.08rem var(--serif); margin: 0 0 .5rem; }
a { color: var(--ink); }
.num, .formula, .term-body, .counter b, .level-big, .calc output, .calc-cell b { font-family: var(--mono); }
.container { max-width: 1080px; margin: 0 auto; padding: 0 1.1rem; }
.narrow { max-width: 740px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.error { color: var(--accent); }
.accent { color: var(--ok); }

/* Шапка */
.site-header { position: sticky; top: 0; z-index: 60; background: var(--bg); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); transition: transform .28s ease; }
.site-header.bar-hidden { transform: translateY(-100%); }
.header-row { display: flex; align-items: center; gap: .9rem; padding: .6rem 1.1rem; }
.logo { display: inline-flex; align-items: center; gap: .5rem; text-decoration: none; line-height: 1; }
.logo-mark { font: 700 2.3rem/1 var(--serif); color: var(--ink); letter-spacing: -.01em; }  /* «146» как фирменный знак, в цвет фавикона */
.logo-text { font: 700 .92rem/1.12 var(--serif); color: var(--text); }
.main-nav { display: flex; gap: 1rem; margin-left: auto; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a { color: var(--muted); text-decoration: none; font-size: .92rem; white-space: nowrap; padding: .25rem 0; }
.main-nav a:hover { color: var(--ink); }
.header-cta { display: none; }
@media (min-width: 820px) { .header-cta { display: inline-block; } }

/* Кнопка-гамбургер: видна только на узких экранах, на десктопе скрыта */
.nav-toggle { display: none; align-items: center; justify-content: center; width: 44px; height: 44px; flex: none; margin-left: auto; border: 1.5px solid var(--line); background: var(--panel); color: var(--text); border-radius: 10px; cursor: pointer; }
.nav-toggle:hover { border-color: var(--ink); }
.nav-toggle .bars { position: relative; display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; transition: background .2s; }
.nav-toggle .bars::before, .nav-toggle .bars::after { content: ""; position: absolute; left: 0; display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; transition: transform .2s; }
.nav-toggle .bars::before { top: -6px; }
.nav-toggle .bars::after { top: 6px; }
.nav-toggle[aria-expanded="true"] .bars { background: transparent; }
.nav-toggle[aria-expanded="true"] .bars::before { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .bars::after { transform: translateY(-6px) rotate(-45deg); }

/* Узкие экраны: навигация прячется за кнопку и раскрывается списком на всю ширину */
@media (max-width: 819.98px) {
  .header-row { flex-wrap: wrap; }
  .nav-toggle { display: inline-flex; }
  .main-nav { order: 5; flex-basis: 100%; flex-direction: column; gap: 0; margin-left: 0; overflow: visible; }
  .main-nav a { font-size: 1rem; padding: .85rem .2rem; border-top: 1px solid var(--line); }
  /* с JS меню свёрнуто и открывается кнопкой; без JS остаётся раскрытым (доступно) */
  .js .main-nav { display: none; }
  .js .main-nav.open { display: flex; }
  /* кнопка «Поддержать» из шапки на мобильном не нужна: внизу есть липкая кнопка,
     а .btn{display:inline-block} ниже по файлу перебивает базовое скрытие */
  .header-cta { display: none !important; }
}
@media (max-width: 379.98px) { #themeLabel { display: none; } }

/* Переключатель темы - как в VS Code, заметный */
.theme-toggle { display: inline-flex; align-items: center; gap: .4rem; border: 1.5px solid var(--line); background: var(--panel); color: var(--text); border-radius: 999px; padding: .35rem .7rem; font: 600 .8rem var(--mono); cursor: pointer; min-height: 36px; }
.theme-toggle:hover { border-color: var(--ink); }
.theme-toggle .ico { font-size: 1rem; line-height: 1; }

/* Кнопки */
.btn { display: inline-block; border: 0; border-radius: 10px; padding: .7rem 1.5rem; font: 700 .98rem var(--sans); text-decoration: none; cursor: pointer; transition: .15s; min-height: 44px; }
.btn-lg { padding: .95rem 2rem; font-size: 1.05rem; }
.btn-sm { padding: .4rem .9rem; font-size: .82rem; min-height: 0; }
.btn-block { width: 100%; text-align: center; }
.btn-accent { background: var(--ink); color: var(--bg); box-shadow: var(--shadow); }
.btn-accent:hover { filter: brightness(1.12); }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.btn-ghost:hover { background: color-mix(in srgb, var(--ink) 10%, transparent); }

/* Нижняя полоса «Поддержать»: выезжает при прокрутке вниз (когда шапка ушла),
   уезжает при прокрутке вверх (вместе с возвратом шапки). Практика sticky-CTA:
   низкая полоса, мягкий слайд, не мешает чтению. Работает и на мобильном, и на десктопе. */
.scroll-cta { position: fixed; bottom: 0; left: 0; right: 0; z-index: 70; padding: .55rem 0 calc(.55rem + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -2px 16px rgba(34, 48, 61, .10); transform: translateY(110%); transition: transform .32s ease; }
.scroll-cta.bar-shown { transform: none; }
.scroll-cta-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.scroll-cta-mascot { flex: 0 0 auto; height: 40px; width: auto; display: block; }
.scroll-cta-text { color: var(--text); font: 600 .95rem var(--sans); }
.scroll-cta .btn { white-space: nowrap; }
@media (max-width: 819.98px) {
  .scroll-cta-text { display: none; }            /* на телефоне - ФМШонок слева, кнопка занимает остаток */
  .scroll-cta .btn { flex: 1; text-align: center; }
}
body { padding-bottom: 76px; }                   /* запас под полосу, чтобы не прятала низ */
@media (min-width: 820px) { body { padding-bottom: 0; } }

/* Герой */
.hero { padding: clamp(2rem, 6vw, 4rem) 0 1rem; }
.hero-grid { display: grid; grid-template-columns: 1fr; gap: 1.6rem; align-items: center; }
@media (min-width: 860px) { .hero-grid { grid-template-columns: 7fr 5fr; } }
.hero-photo { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
.hero-photo img { display: block; width: 100%; height: 100%; object-fit: cover; aspect-ratio: 4/3; }
.hero-tagline { font-size: clamp(1.02rem, 3.2vw, 1.25rem); color: var(--muted); max-width: 58ch; margin: 1.1rem 0 1.4rem; }
.hero-actions { display: flex; gap: .8rem; flex-wrap: wrap; }

/* Формула на полях */
.formula { font-size: clamp(.95rem, 3.4vw, 1.35rem); text-align: center; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1rem; margin: 1.4rem 0; overflow-x: auto; box-shadow: var(--shadow); }
.formula b { color: var(--ink); }
.formula i { color: var(--ok); font-style: normal; }

/* Счётчики */
.counters { padding: 1.6rem 0; }
.counters-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem; }
@media (min-width: 760px) { .counters-row { grid-template-columns: repeat(4, 1fr); } }
.counter { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.counter b { display: block; font-size: clamp(1.25rem, 4.5vw, 1.65rem); font-weight: 800; color: var(--ink); }
.counter span { color: var(--muted); font-size: .82rem; display: block; }
.counter .src { font-size: .68rem; font-family: var(--mono); opacity: .65; margin-top: .25rem; }
.counter-mascot { display: flex; align-items: center; justify-content: center; }
.counter-mascot img { display: block; width: auto; height: 100%; max-height: 120px; max-width: 100%; object-fit: contain; }

/* Секции, карточки */
.section { padding: clamp(2rem, 5.5vw, 3.4rem) 0; }
body.home .section { padding: clamp(1rem, 2.75vw, 1.7rem) 0; }
.section-sub { color: var(--muted); max-width: 64ch; margin-bottom: 1.6rem; }
.cards { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 700px) { .cards { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem; box-shadow: var(--shadow); }
.card-feature { border: 2px solid var(--ink); }
.card-photo { margin: -1.3rem -1.3rem 1rem; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.card-photo img { display: block; width: 100%; aspect-ratio: 16/9; object-fit: cover; }
.card-link { font-weight: 700; text-decoration: none; }
.tag-row { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .6rem; }
.tag { font: .76rem var(--mono); color: var(--ink); background: color-mix(in srgb, var(--ink) 10%, transparent); border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent); border-radius: 999px; padding: .22rem .65rem; }

/* Прогресс */
.progress-wrap { margin: 1.4rem 0; }
.progress { height: 14px; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; min-width: 4px; background: linear-gradient(90deg, var(--ink), var(--ok)); transition: width 1s ease; }
.progress-labels { display: flex; justify-content: space-between; font: .78rem var(--mono); color: var(--muted); margin-top: .35rem; }

/* Калькулятор */
.calc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem; box-shadow: var(--shadow); }
.calc output { font-size: 1.5rem; font-weight: 800; color: var(--ink); display: block; }
.calc input[type=range] { width: 100%; accent-color: var(--ink); height: 36px; }
.calc-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-top: 1rem; }
@media (min-width: 700px) { .calc-grid { grid-template-columns: 1fr 1fr 1fr; } }
.calc-cell b { font-size: 1.15rem; font-weight: 800; color: var(--ok); display: block; }
.calc-cell span { font-size: .8rem; color: var(--muted); }
.spark { width: 100%; height: 72px; margin-top: 1rem; }
.spark polyline { stroke: var(--ink); }
.spark line { stroke: var(--line); }

/* Формы */
.donate-summary { background: color-mix(in srgb, var(--ink) 7%, var(--panel)); border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent); border-radius: 10px; padding: .7rem 1rem; margin: .2rem 0 1rem; font: 700 .95rem var(--mono); color: var(--ink); text-align: center; }
.donate-summary:empty { display: none; }
.donate-form fieldset { border: 0; padding: 0; margin: 0 0 1.6rem; }
.donate-form legend { font: 700 1.05rem var(--serif); margin-bottom: .7rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.seg-item { display: block; border: 1.5px solid var(--line); border-radius: 12px; padding: .8rem .9rem; cursor: pointer; background: var(--panel); min-height: 44px; }
.seg-item:has(input:checked) { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 7%, var(--panel)); }
.seg-item input { margin-right: .45rem; accent-color: var(--ink); }
.seg-item small { color: var(--muted); }
.amounts { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin-bottom: .9rem; }
@media (min-width: 700px) { .amounts { grid-template-columns: repeat(4, 1fr); } }
.amount { position: relative; display: block; border: 1.5px solid var(--line); border-radius: 12px; padding: .75rem .45rem; text-align: center; cursor: pointer; background: var(--panel); }
.amount:has(input:checked) { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, var(--panel)); }
.amount input { position: absolute; opacity: 0; }
.amount b { display: block; font: 800 1.02rem var(--mono); }
.amount small { color: var(--muted); font-size: .72rem; line-height: 1.25; display: block; }
.field { display: block; margin-bottom: .9rem; font-weight: 600; font-size: .92rem; }
.field input, .field select, .field textarea { display: block; width: 100%; margin-top: .3rem; padding: .72rem .85rem; font: 1rem var(--sans); color: var(--text); background: var(--panel); border: 1.5px solid var(--line); border-radius: 10px; min-height: 44px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 18%, transparent); }
.field select { min-height: 52px; padding-top: .9rem; padding-bottom: .9rem; line-height: 1.3; }
.donate-form .seg + .field { margin-top: 1.3rem; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
@media (min-width: 700px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.check { display: flex; gap: .5rem; align-items: flex-start; margin: .6rem 0; font-size: .88rem; color: var(--muted); font-weight: 400; }
.check input { accent-color: var(--ink); min-width: 18px; height: 18px; margin-top: .2rem; }
.switch { display: flex; align-items: center; gap: .6rem; margin: .7rem 0; font-size: .9rem; color: var(--text); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: relative; width: 44px; height: 26px; flex: none; background: var(--line); border-radius: 999px; transition: background .2s; }
.switch .slider::before { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .slider { background: var(--ink); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Кабинет */
.cabinet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.cabinet-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 2rem; }
@media (min-width: 760px) { .cabinet-grid { grid-template-columns: repeat(3, 1fr); } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); }
.level-big { font-size: 1.5rem; font-weight: 800; color: var(--ink); margin: .2rem 0; }
.sub-row { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .85rem 1rem; margin-bottom: .7rem; }
.sub-actions { display: flex; gap: .5rem; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
.table th { font: .78rem var(--mono); color: var(--muted); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Люди */
.people { display: grid; grid-template-columns: 1fr; gap: .9rem; }
@media (min-width: 700px) { .people { grid-template-columns: 1fr 1fr; } }
.person { display: flex; gap: .9rem; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; box-shadow: var(--shadow); }
.person img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: none; border: 2px solid var(--line); }
.person .ava-init { width: 64px; height: 64px; border-radius: 50%; flex: none; border: 2px solid var(--line); background: var(--bg2); color: var(--ink); display: flex; align-items: center; justify-content: center; font: 700 1.15rem var(--serif); }
.person b { font-family: var(--serif); }
.person span { display: block; color: var(--muted); font-size: .85rem; }

/* Галерея */
.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
@media (min-width: 700px) { .gallery { grid-template-columns: repeat(3, 1fr); } }
.gallery a { display: block; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.gallery img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; transition: transform .25s; }
.gallery a:hover img { transform: scale(1.04); }

/* Прочее */
.steps { padding-left: 1.2rem; } .steps li { margin-bottom: .85rem; }
.callout { background: color-mix(in srgb, var(--ink) 7%, var(--panel)); border-left: 3px solid var(--ink); border-radius: 8px; padding: .9rem 1.1rem; margin: 1.4rem 0; }
details { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; margin-bottom: .6rem; }
summary { font: 700 .98rem var(--serif); cursor: pointer; }
details[open] summary { color: var(--ink); }
.doc-list { padding-left: 1.1rem; } .doc-list li { margin-bottom: .5rem; }
.quote { border-left: 3px solid var(--ink); padding: .2rem 0 .2rem 1.1rem; margin: 1.2rem 0; font-family: var(--serif); font-size: 1.04rem; }
.quote .who { font: .82rem var(--sans); color: var(--muted); margin-top: .5rem; }

.cta-strip { background: var(--bg2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 2rem 0; }
.cta-row { display: flex; align-items: center; justify-content: space-between; gap: 1.2rem; flex-wrap: wrap; }
.cta-row p { font: italic 1rem var(--serif); color: var(--muted); max-width: 48ch; margin: 0; }

.site-footer { padding: 2.2rem 0 2.6rem; border-top: 1px solid var(--line); font-size: .88rem; color: var(--muted); }
.footer-grid { display: grid; grid-template-columns: 1fr; gap: 1.3rem; }
@media (min-width: 700px) { .footer-grid { grid-template-columns: repeat(3, 1fr); } }
.site-footer a { color: var(--text); }
.footer-joke { font: .74rem var(--mono); opacity: .6; margin-top: 1.2rem; }

/* Терминал оставлен для страницы успеха */
.terminal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.term-bar { display: flex; gap: .45rem; padding: .6rem .9rem; background: var(--bg2); border-bottom: 1px solid var(--line); }
.term-dot { width: 11px; height: 11px; border-radius: 50%; }
.term-bar .r { background: #ff5f56; } .term-bar .y { background: #ffbd2e; } .term-bar .g { background: #27c93f; }
.term-body { padding: 1rem 1.1rem 1.2rem; font-size: .9rem; line-height: 1.8; }
.term-body .ps1 { color: var(--ok); }
.term-body .out { color: var(--muted); }
.term-body .ok { color: var(--ok); }

@media print {
  body { background: #fff; color: #000; }
  .site-header, .site-footer, .btn, .scroll-cta, .theme-toggle { display: none !important; }
  .table th, .table td { border-color: #999; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Картинки новостей (импорт из ВКонтакте) */
.news-img { display: block; max-width: 100%; max-height: 70vh; width: auto; height: auto; border-radius: var(--radius); border: 1px solid var(--line); margin: 1rem auto; }
.news-gallery { display: flex; flex-direction: column; align-items: center; gap: .8rem; margin: 1rem 0; }
.news-gallery .news-img { margin: 0; }
.news-thumb { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); margin: .2rem 0 .8rem; }
