/* =====================================================================
   SmartQoldau — стиль главной страницы
   Шрифты подключены в <head> через Google Fonts (Baloo 2 + Nunito)
   ===================================================================== */

:root {
    /* --- Цвета --- */
    --color-bg: #FFF8E9;
    --color-bg-card: #FFFFFF;
    --color-text: #1B3A4B;
    --color-text-soft: #4A6572;

    --color-math:     #E85D9C;   /* розово-малиновый — Математика */
    --color-writing:  #7ED6C1;   /* мятный — Письмо / слоги */
    --color-alphabet: #2EC4B6;   /* бирюзовый — Учим алфавит */
    --color-reading:  #FFB100;   /* жёлтый — Учимся читать */
    --color-pictures: #FF6B6B;   /* коралловый — Расскажи, что видишь */
    --color-weather:  #4FB6E8;   /* голубой — Погода */
    --color-seasons:  #6BCB77;   /* зелёный — Времена года */
    --color-ai:       #9B7EDE;   /* фиолетовый — AI-помощник */
    --color-progress: #FF9F45;   /* оранжевый — Мои достижения */
    --color-teacher:  #6C7A89;   /* серо-синий — Для учителя */

    --color-star: #FFC93C;

    /* --- Форма и тень («пухлая» кнопка) --- */
    --radius-lg: 28px;
    --radius-md: 18px;
    --pop-depth: 6px;            /* высота "подушки" под плиткой */

    /* --- Шрифты --- */
    --font-heading: 'Baloo 2', 'Arial Rounded MT Bold', sans-serif;
    --font-body: 'Nunito', 'Segoe UI', sans-serif;

    /* --- Масштаб текста для кнопок A+ / A- --- */
    --font-scale: 1;
}

/* =====================================================================
   Базовые настройки
   ===================================================================== */

* {
    box-sizing: border-box;
}

html {
    /* Масштаб меняется через JS (кнопки A+ / A-) */
    font-size: calc(16px * var(--font-scale));
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

h1, h2, h3, .heading {
    font-family: var(--font-heading);
    font-weight: 600;
    margin: 0 0 0.5em 0;
    line-height: 1.2;
}

img {
    max-width: 100%;
    display: block;
}

button {
    font-family: inherit;
    cursor: pointer;
}

/* Видимый фокус для клавиатуры — обязательно для доступности */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
    outline: 4px solid var(--color-ai);
    outline-offset: 3px;
    border-radius: 8px;
}

/* Уважаем настройку "уменьшить анимацию" в ОС пользователя */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* =====================================================================
   Панель доступности (закреплена сверху)
   ===================================================================== */

.a11y-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.6rem 1.5rem;
    background: var(--color-text);
}

.a11y-bar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0 0.9rem;
    border: none;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    transition: transform 0.15s ease, background 0.15s ease;
}

.a11y-bar__btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.a11y-bar__btn:active {
    transform: scale(0.94);
}

.a11y-bar__btn[aria-pressed="true"] {
    background: var(--color-star);
    color: var(--color-text);
}

/* =====================================================================
   Шапка и приветствие
   ===================================================================== */

.hero {
    max-width: 900px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 1.5rem;
    text-align: center;
}

.hero__logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-heading);
    font-size: 1.6rem;
    color: var(--color-alphabet);
    margin-bottom: 1rem;
}

.hero__mascot {
    width: 96px;
    height: 96px;
    margin: 0 auto 1rem;
}

.hero__greeting {
    font-size: 2rem;
    color: var(--color-text);
}

.hero__greeting span {
    color: var(--color-pictures);
}

.hero__subtitle {
    font-size: 1.15rem;
    color: var(--color-text-soft);
    max-width: 480px;
    margin: 0.4rem auto 0;
}

/* =====================================================================
   Сетка разделов (главная навигация)
   ===================================================================== */

.sections {
    max-width: 1000px;
    margin: 0 auto;
    padding: 1rem 1.5rem 3rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.5rem;
}

.tile {
    --tile-color: var(--color-alphabet);

    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.6rem;
    padding: 1.8rem 1.2rem 1.5rem;
    background: var(--color-bg-card);
    border: 3px solid var(--tile-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 var(--pop-depth) 0 var(--tile-color);
    text-decoration: none;
    color: var(--color-text);
    transform: translateY(0);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.tile:hover {
    transform: translateY(-2px);
}

.tile:active,
.tile.is-pressed {
    transform: translateY(var(--pop-depth));
    box-shadow: 0 0 0 var(--tile-color);
}

.tile__icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--tile-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
}

.tile__title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
}

.tile__desc {
    font-size: 0.95rem;
    color: var(--color-text-soft);
    margin: 0;
}

/* Цветовая привязка каждого раздела */
.tile--math      { --tile-color: var(--color-math); }
.tile--writing   { --tile-color: var(--color-writing); }
.tile--alphabet  { --tile-color: var(--color-alphabet); }
.tile--reading   { --tile-color: var(--color-reading); }
.tile--pictures  { --tile-color: var(--color-pictures); }
.tile--weather   { --tile-color: var(--color-weather); }
.tile--seasons   { --tile-color: var(--color-seasons); }
.tile--ai        { --tile-color: var(--color-ai); }
.tile--progress  { --tile-color: var(--color-progress); }
.tile--teacher   { --tile-color: var(--color-teacher); }

/* Звёздочка-бейдж прогресса на плитке (необязательный элемент) */
.tile__stars {
    position: absolute;
    top: -12px;
    right: -8px;
    background: var(--color-star);
    color: var(--color-text);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

/* =====================================================================
   Подвал
   ===================================================================== */

.site-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--color-text-soft);
    font-size: 0.9rem;
}

.site-footer a {
    color: var(--color-teacher);
}

/* =====================================================================
   Режим высокого контраста — переключается атрибутом
   <body data-contrast="high"> через JS (кнопка ◐)
   ===================================================================== */

body[data-contrast="high"] {
    background: #000000;
    color: #FFFFFF;
}

body[data-contrast="high"] .hero__subtitle,
body[data-contrast="high"] .tile__desc,
body[data-contrast="high"] .site-footer {
    color: #E8E8E8;
}

body[data-contrast="high"] .tile {
    background: #000000;
    border-width: 4px;
    box-shadow: 0 var(--pop-depth) 0 var(--tile-color);
}

body[data-contrast="high"] .tile__title {
    color: #FFFFFF;
}

body[data-contrast="high"] .a11y-bar {
    background: #000000;
    border-bottom: 2px solid #FFFFFF;
}

/* =====================================================================
   Адаптивность — мобильная версия
   Три уровня: планшет (≤900px), телефон (≤600px), маленький телефон (≤360px)
   ===================================================================== */

/* --- Планшеты и телефоны в альбомной ориентации --- */
@media (max-width: 900px) {
    .hero {
        padding: 1.8rem 1.2rem 1rem;
    }

    .sections {
        padding: 1rem 1.2rem 2.5rem;
        gap: 1.2rem;
    }
}

/* --- Телефоны --- */
@media (max-width: 600px) {
    .a11y-bar {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.5rem 1rem;
        /* учитываем чёлку / индикатор жестов на телефоне */
        padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    }

    .a11y-bar__btn {
        min-width: 42px;
        min-height: 42px;
        padding: 0 0.7rem;
        font-size: 1rem;
    }

    .hero__logo {
        font-size: 1.3rem;
    }

    .hero__mascot {
        width: 72px;
        height: 72px;
    }

    .hero__greeting {
        font-size: 1.5rem;
    }

    .hero__subtitle {
        font-size: 1rem;
    }

    /* Одна колонка — крупные, удобные для нажатия плитки на весь экран */
    .sections {
        grid-template-columns: 1fr;
        gap: 0.9rem;
        padding: 0.9rem 1rem 2.5rem;
    }

    .tile {
        flex-direction: row;
        text-align: left;
        align-items: center;
        gap: 1rem;
        padding: 0.9rem 1.1rem;
        min-height: 84px;
        /* приподнятая "подушка" под плитку делаем тоньше — на телефоне удобнее плоское нажатие */
        --pop-depth: 4px;
    }

    .tile__icon {
        flex-shrink: 0;
        width: 56px;
        height: 56px;
        font-size: 1.6rem;
    }

    .tile__title {
        font-size: 1.1rem;
    }

    .tile__desc {
        font-size: 0.85rem;
    }

    .tile__stars {
        position: static;
        margin-left: auto;
        flex-shrink: 0;
        box-shadow: none;
        font-size: 0.75rem;
        padding: 0.2rem 0.5rem;
    }

    .site-footer {
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        font-size: 0.8rem;
    }
}

/* --- Маленькие телефоны (iPhone SE и подобные, ~360px и уже) --- */
@media (max-width: 360px) {
    .hero__greeting {
        font-size: 1.3rem;
    }

    .tile {
        padding: 0.75rem 0.9rem;
        min-height: 72px;
    }

    .tile__icon {
        width: 48px;
        height: 48px;
        font-size: 1.4rem;
    }

    .tile__title {
        font-size: 1rem;
    }

    .a11y-bar__btn {
        min-width: 38px;
        min-height: 38px;
        padding: 0 0.55rem;
        font-size: 0.9rem;
    }
}

/* --- Отключаем "залипание" синего выделения и двойной тап-зум на кнопках --- */
.tile, .a11y-bar__btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* =====================================================================
   Страница входа (login.php)
   ===================================================================== */

.auth-wrap {
    display: flex;
    justify-content: center;
    padding: 2rem 1rem 3rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-bg-card);
    border: 3px solid var(--color-alphabet);
    border-radius: var(--radius-lg);
    box-shadow: 0 var(--pop-depth) 0 var(--color-alphabet);
    padding: 2rem 1.6rem;
}

.role-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin: 1.2rem 0;
}

.role-tab {
    min-height: 44px;
    border: 2px solid var(--color-alphabet);
    border-radius: var(--radius-md);
    background: #fff;
    color: var(--color-text);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.95rem;
}

.role-tab.is-active {
    background: var(--color-alphabet);
    color: #fff;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.auth-label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.95rem;
}

.auth-label input {
    min-height: 46px;
    padding: 0 0.9rem;
    border: 2px solid #D9E4EA;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: var(--font-body);
}

.auth-label input:focus-visible {
    outline: 3px solid var(--color-ai);
    border-color: var(--color-ai);
}

.auth-submit {
    min-height: 48px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--color-alphabet);
    color: #fff;
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 700;
    text-align: center;
    line-height: 48px;
}

.auth-submit:active {
    transform: translateY(2px);
}

.auth-error {
    background: #FFE5E5;
    color: #C0392B;
    border-radius: var(--radius-md);
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
    text-align: center;
}

/* =====================================================================
   Режим "без отвлекающих элементов" (п.16 концепции)
   На экране остаётся только само задание — прячем декоративные детали
   ===================================================================== */

body[data-distraction-free="true"] .hero__subtitle,
body[data-distraction-free="true"] .site-footer,
body[data-distraction-free="true"] .hero__mascot {
    display: none;
}

/* =====================================================================
   Страницы заданий (math.php, alphabet.php и т.д.)
   ===================================================================== */

.task-wrap {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 1.2rem 3rem;
}

.task-feedback {
    text-align: center;
    font-family: var(--font-heading);
    font-size: 1.1rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.2rem;
}

.task-feedback.is-correct {
    background: #E4F9E5;
    color: #1E7A2E;
}

.task-feedback.is-wrong {
    background: #FFF1E0;
    color: #A05A00;
}

.task-badge {
    margin-top: 0.4rem;
    font-size: 1rem;
}

.task-card {
    background: var(--color-bg-card);
    border: 3px solid var(--color-math);
    border-radius: var(--radius-lg);
    box-shadow: 0 var(--pop-depth) 0 var(--color-math);
    padding: 1.8rem 1.4rem;
    text-align: center;
}

.task-question {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    margin-bottom: 1rem;
}

.task-image {
    max-width: 220px;
    margin: 0 auto 1rem;
    border-radius: var(--radius-md);
}

.task-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 0.8rem;
    margin-top: 0.5rem;
}

.task-option-btn {
    min-height: 56px;
    border: 3px solid var(--color-math);
    border-radius: var(--radius-md);
    background: #fff;
    color: var(--color-text);
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
}

.task-option-btn:active {
    background: var(--color-math);
    color: #fff;
}

.task-skip {
    display: block;
    text-align: center;
    margin-top: 1.2rem;
    color: var(--color-text-soft);
    font-weight: 600;
    text-decoration: none;
}

.ai-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.4rem;
    padding-top: 1.2rem;
    border-top: 2px dashed #E3E9EC;
}

.ai-btn {
    min-height: 42px;
    padding: 0 0.9rem;
    border: 2px solid var(--color-ai);
    border-radius: var(--radius-md);
    background: #fff;
    color: var(--color-ai);
    font-size: 0.85rem;
    font-weight: 700;
}

.ai-btn:active {
    background: var(--color-ai);
    color: #fff;
}

.ai-panel {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    background: #F4F0FC;
    border-radius: var(--radius-md);
    color: var(--color-text);
    text-align: left;
    font-size: 0.95rem;
}

/* =====================================================================
   Сетка букв алфавита (alphabet.php)
   ===================================================================== */

.letters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 0.6rem;
    max-width: 640px;
    margin: 0 auto 2rem;
    padding: 0 1.2rem;
}

.letter-btn {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--color-alphabet);
    border-radius: var(--radius-md);
    background: #fff;
    color: var(--color-alphabet);
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-weight: 700;
    text-decoration: none;
}

.letter-btn.is-active {
    background: var(--color-alphabet);
    color: #fff;
}

.letter-detail {
    max-width: 420px;
    margin: 0 auto 2rem;
    text-align: center;
    background: var(--color-bg-card);
    border: 3px solid var(--color-alphabet);
    border-radius: var(--radius-lg);
    box-shadow: 0 var(--pop-depth) 0 var(--color-alphabet);
    padding: 1.8rem 1.4rem;
}

.letter-detail__big {
    font-family: var(--font-heading);
    font-size: 5rem;
    color: var(--color-alphabet);
    line-height: 1;
}

.letter-detail__word {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0.5rem 0 1rem;
}

/* =====================================================================
   Игровой режим — хаб игр, карточки, спокойный режим
   ===================================================================== */

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.9rem;
    max-width: 900px;
    margin: 0 auto 2rem;
    padding: 0 1.2rem;
}

.game-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 1.1rem 0.6rem;
    background: var(--color-bg-card);
    border: 3px solid var(--color-ai);
    border-radius: var(--radius-lg);
    box-shadow: 0 var(--pop-depth) 0 var(--color-ai);
    text-decoration: none;
    color: var(--color-text);
    text-align: center;
    font-weight: 700;
    font-size: 0.9rem;
}

.game-card__icon { font-size: 2.2rem; }

.game-card.is-soon {
    opacity: 0.55;
    border-style: dashed;
    box-shadow: none;
}

/* Мягкая обратная связь — НИКОГДА красного цвета/крестика (п.3, п.26 ТЗ) */
.gentle-feedback {
    text-align: center;
    font-family: var(--font-heading);
    font-size: 1.3rem;
    padding: 1.2rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.2rem;
}
.gentle-feedback.is-good { background: #E4F9E5; color: #1E7A2E; }
.gentle-feedback.is-retry { background: #FFF6DA; color: #8A6D00; }

.big-choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 1rem;
    max-width: 480px;
    margin: 1.2rem auto 0;
}

.big-choice-btn {
    min-height: 110px;
    border: 3px solid var(--color-ai);
    border-radius: var(--radius-lg);
    background: #fff;
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--color-text);
}
.big-choice-btn:active { background: var(--color-ai); color: #fff; }

/* Спокойный режим — сохранённая настройка ребёнка/учителя (п.35 ТЗ) */
body[data-calm-mode="true"] .hero__mascot,
body[data-calm-mode="true"] .hero__subtitle,
body[data-calm-mode="true"] .site-footer,
body[data-calm-mode="true"] .a11y-bar__btn[aria-label="🔊"] + .a11y-bar__btn {
    display: none;
}
body[data-calm-mode="true"] * {
    animation: none !important;
    transition: none !important;
}
