/* ============================================================
   base.css — базовые стили, панель ученика (HUD), модалка, тосты
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Comfortaa', cursive; overflow-x: hidden; background: #1a1a2e; }

/* ===== Экраны ===== */
.screen { display: none; width: 100%; min-height: 100vh; position: relative; opacity: 0; transition: opacity 0.6s ease; }
.screen.active { display: block; opacity: 1; }

/* Атрибут hidden сильнее любых display из классов (иначе кнопки «выпрыгивают») */
[hidden] { display: none !important; }

/* Текст только для скринридеров (визуально скрыт, но озвучивается).
   Названия локаций на карте — в .sr-only: рисованные таблички уже называют их */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* ===== Общие анимации ===== */
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.shake { animation: shake 0.5s; }

/* ===== ПАНЕЛЬ УЧЕНИКА (HUD): имя + очки ===== */
.hud {
  position: fixed; top: 10px; left: 10px; right: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  z-index: 900; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-player {
  background: rgba(255,255,255,0.92);
  border: 2px solid rgba(196,69,105,0.35);
  border-radius: 50px; padding: 8px 16px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.25);
  color: #333; font-weight: bold; font-size: 1em;
  max-width: 60vw; font-family: inherit;
  cursor: pointer; transition: all 0.3s;
}
.hud-player:hover { transform: translateY(-2px); border-color: #ff6b9d; box-shadow: 0 6px 20px rgba(255,107,157,0.4); }
.hud-edit { font-size: 0.75em; opacity: 0.55; }
.hud-avatar { font-size: 1.2em; }
.hud-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Чип «N кл.» рядом с именем */
.hud-grade {
  background: #ede7f6; color: #6a3fa0;
  border-radius: 50px; padding: 2px 9px;
  font-size: 0.72em; font-weight: bold; white-space: nowrap;
}
.hud-right { display: flex; align-items: center; gap: 8px; }
.hud-sound {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255,255,255,0.92); border: 2px solid rgba(196,69,105,0.35);
  font-size: 1.1em; cursor: pointer; transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(0,0,0,0.25);
  display: flex; align-items: center; justify-content: center;
}
.hud-sound:hover { transform: translateY(-2px) scale(1.05); border-color: #ff6b9d; }
/* Кнопка музыки: выключенное состояние — серая с зачёркиванием */
.hud-music.off { filter: grayscale(1); opacity: 0.55; }
.hud-music.off::after { content: '✕'; position: absolute; font-size: 0.85em; color: #c62828; font-weight: bold; }
.hud-music { position: relative; }
.hud-score {
  background: linear-gradient(45deg, #ffd700, #ffed4e);
  border: 2px solid #e6a817;
  border-radius: 50px; padding: 8px 16px;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.25);
  color: #5d4037; font-weight: bold; font-size: 1em;
  position: relative;
}
.hud-score-label { font-size: 0.75em; opacity: 0.8; }
.hud-score.bump { animation: scoreBump 0.4s ease; }
@keyframes scoreBump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* Индикатор серии верных ответов */
.hud-streak {
  background: linear-gradient(45deg, #ff9800, #ffb74d);
  border: 2px solid #e65100;
  border-radius: 50px; padding: 8px 14px;
  color: #fff; font-weight: bold; font-size: 0.95em;
  box-shadow: 0 4px 15px rgba(230,81,0,0.4);
  animation: streakIn 0.4s ease;
  white-space: nowrap;
}
@keyframes streakIn { from { transform: scale(0); } to { transform: scale(1); } }
.hud-streak.bump { animation: scoreBump 0.4s ease; }

/* Всплывающие +10 / −2 рядом с очками */
.score-float {
  position: absolute; right: 8px; top: -6px;
  font-size: 1.05em; font-weight: bold;
  pointer-events: none; white-space: nowrap;
  animation: floatUp 1s ease forwards;
}
.score-float.plus { color: #2e7d32; text-shadow: 0 0 6px rgba(255,255,255,0.9); }
.score-float.minus { color: #c62828; text-shadow: 0 0 6px rgba(255,255,255,0.9); }
@keyframes floatUp { to { transform: translateY(-42px); opacity: 0; } }

/* ===== Панель громкости 🎚 (ползунки музыки и звуков) ===== */
.volume-popup {
  position: fixed; top: 64px; right: 12px; z-index: 950;
  background: rgba(255,255,255,0.97);
  border: 2px solid rgba(196,69,105,0.4);
  border-radius: 18px; padding: 14px 16px 10px;
  box-shadow: 0 10px 30px rgba(60,20,60,0.35);
  width: min(320px, calc(100vw - 24px));
  transform-origin: top right;
  animation: volumeIn 0.22s ease;
}
@keyframes volumeIn { from { opacity: 0; transform: scale(0.85) translateY(-8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.volume-popup::before {
  content: ''; position: absolute; top: -9px; right: 118px;
  width: 16px; height: 16px; background: inherit;
  border-left: 2px solid rgba(196,69,105,0.4);
  border-top: 2px solid rgba(196,69,105,0.4);
  transform: rotate(45deg); border-radius: 3px 0 0 0;
}
.volume-title { font-weight: bold; color: #6a3fa0; font-size: 0.95em; margin-bottom: 10px; text-align: center; }
.volume-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.volume-ico { font-size: 1.15em; width: 26px; text-align: center; flex: none; }
.volume-val {
  font-size: 0.8em; font-weight: bold; color: #6a3fa0;
  background: #f3e8fd; border-radius: 50px; padding: 2px 8px;
  min-width: 46px; text-align: center; flex: none;
}
.volume-hint { font-size: 0.72em; color: #999; text-align: center; margin-bottom: 2px; }

/* Красивый ползунок: цветная дорожка + золотой круглый бегунок */
.volume-slider {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 10px; border-radius: 6px; outline: none;
  background: linear-gradient(90deg, #ba68c8 var(--fill, 100%), #e8d5f0 var(--fill, 100%));
  cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe082, #ffb300);
  border: 2.5px solid #fff;
  box-shadow: 0 2px 8px rgba(183,28,28,0.35), 0 0 0 1.5px rgba(230,168,23,0.8);
  transition: transform 0.15s;
}
.volume-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.volume-slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe082, #ffb300);
  border: 2.5px solid #fff;
  box-shadow: 0 2px 8px rgba(183,28,28,0.35);
  cursor: pointer;
}
.volume-slider::-moz-range-track { height: 10px; border-radius: 6px; background: #e8d5f0; }
.volume-slider::-moz-range-progress { height: 10px; border-radius: 6px; background: #ba68c8; }

/* ===== Конфетти ===== */
.confetti { position: fixed; width: 10px; height: 10px; z-index: 9999; pointer-events: none; animation: confettiFall 3s linear forwards; }
@keyframes confettiFall { to { transform: translateY(100vh) rotate(720deg); opacity: 0; } }

/* ===== Таблица результатов (модалка) ===== */
.lb-table { display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 12px;
  background: #faf7fc; border: 2px solid transparent;
}
.lb-row:nth-child(even) { background: #f4eef9; }
.lb-row.me { border-color: #ff6b9d; background: #fff0f6; box-shadow: 0 2px 10px rgba(255,107,157,0.25); }
.lb-rank { min-width: 34px; text-align: center; font-weight: bold; color: #8b4513; font-size: 1.05em; }
.lb-name { flex: 1; color: #333; font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-name small { color: #ff6b9d; font-weight: normal; }
/* Чип класса в таблице результатов */
.lb-grade {
  background: #ede7f6; color: #6a3fa0;
  border-radius: 50px; padding: 2px 8px;
  font-size: 0.72em; font-weight: bold; white-space: nowrap;
}
.lb-avatar { font-size: 1.15em; }
.lb-stars { font-size: 0.85em; letter-spacing: -2px; white-space: nowrap; }
.lb-time { font-size: 0.8em; color: #7b1fa2; white-space: nowrap; }
.lb-score { font-weight: bold; color: #5d4037; white-space: nowrap; }
.lb-date { color: #aaa; font-size: 0.8em; white-space: nowrap; }
.lb-open-page {
  display: inline-block; color: #c44569; font-weight: bold; font-size: 0.95em;
  text-decoration: none; border-bottom: 2px dashed #ff9ec7; padding-bottom: 2px;
  transition: all 0.3s;
}
.lb-open-page:hover { color: #ff6b9d; border-color: #ff6b9d; }
.lb-empty {
  text-align: center; padding: 30px 15px; color: #777;
  background: #faf7fc; border-radius: 14px; line-height: 1.7;
}
/* Плашка «нет связи — показан офлайн-кэш» */
.lb-offline {
  background: linear-gradient(90deg, #fff8e1, #fff3e0);
  border: 2px solid #ffcc80; border-radius: 12px;
  padding: 9px 13px; margin-bottom: 10px;
  color: #8d5b00; font-size: 0.85em; font-weight: bold; line-height: 1.5;
  animation: lbOfflineIn 0.35s ease;
}
.lb-offline small { font-weight: normal; color: #a67c00; }
@keyframes lbOfflineIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== «Как играть?» — список правил ===== */
.howto-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.howto-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: #faf7fc; border: 2px solid #f0e6f8;
  border-radius: 14px; padding: 12px 14px;
  line-height: 1.55; color: #444; font-size: 0.95em;
  transition: transform 0.2s, border-color 0.2s;
}
.howto-item:hover { transform: translateX(4px); border-color: #e1c9f2; }
.howto-item .howto-ico { font-size: 1.6em; line-height: 1; flex-shrink: 0; }
.howto-item .plus-text { color: #2e7d32; }
.howto-item .minus-text { color: #c62828; }

/* ===== Профиль героя (модалка по клику на имя в HUD) ===== */
.profile-hero {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, #fff0f6, #f3e5f5);
  border: 2px solid #f8bbd0; border-radius: 18px;
  padding: 14px 16px; margin-bottom: 12px;
}
.profile-avatar {
  width: 72px; height: 72px; flex-shrink: 0;
  background: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4em; line-height: 1;
  box-shadow: 0 4px 14px rgba(196,69,105,0.25);
  border: 3px solid #f8bbd0;
}
.profile-name { font-weight: bold; color: #333; font-size: 1.15em; margin-bottom: 6px; }
.profile-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.profile-chip-fire {
  background: #fff3e0; color: #e65100;
  border-radius: 50px; padding: 2px 9px;
  font-size: 0.75em; font-weight: bold; white-space: nowrap;
}
.profile-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-bottom: 14px;
}
.profile-stat {
  background: #faf7fc; border: 2px solid #f0e6f8;
  border-radius: 14px; padding: 10px 4px; text-align: center;
}
.profile-stat .ps-value { font-size: 1.2em; font-weight: bold; color: #6a3fa0; }
.profile-stat .ps-label { font-size: 0.68em; color: #888; margin-top: 2px; line-height: 1.3; }
.profile-section-title {
  color: #8e5aa8; font-weight: bold; font-size: 0.95em;
  margin: 16px 0 8px !important;
}

/* ===== Сетка достижений ===== */
.ach-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px; margin-bottom: 6px;
}
.ach-badge {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-align: center; padding: 10px 6px;
  background: #faf7fc; border: 2px solid #f0e6f8;
  border-radius: 14px; position: relative; overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.ach-badge:hover { transform: translateY(-3px); }
.ach-badge .ach-ico { font-size: 1.7em; line-height: 1; }
.ach-badge .ach-name { font-size: 0.75em; font-weight: bold; color: #555; }
.ach-badge .ach-desc { font-size: 0.66em; color: #999; line-height: 1.35; }
/* Открытая ачивка — золото и блеск */
.ach-badge.unlocked {
  background: linear-gradient(135deg, #fff8e1, #ffecb3);
  border-color: #e6a817;
  box-shadow: 0 3px 12px rgba(230,168,23,0.35);
}
.ach-badge.unlocked .ach-name { color: #8b4513; }
.ach-badge.unlocked .ach-desc { color: #a07840; }
.ach-badge.unlocked .ach-ico { animation: achShine 2.6s ease-in-out infinite; }
@keyframes achShine { 0%,100% { transform: scale(1) rotate(-4deg); } 50% { transform: scale(1.18) rotate(4deg); } }
.ach-badge.unlocked::after {
  content: '✨'; position: absolute; top: 5px; right: 7px; font-size: 0.7em;
  animation: achShine 1.8s ease-in-out infinite;
}
/* Закрытая — серая с замочком */
.ach-badge.locked { filter: grayscale(1); opacity: 0.62; }
.ach-badge.locked::after {
  content: '🔒'; position: absolute; top: 5px; right: 7px; font-size: 0.65em;
}

/* Кнопка «Сменить игрока» (осторожная, красная рамка) */
.btn-ghost.danger { border-color: #f8bbd0; color: #c44569; margin-top: 10px; }
.btn-ghost.danger:hover { border-color: #f44336; color: #d32f2f; }
.btn-ghost.danger.armed {
  background: #ffebee; border-color: #f44336; color: #c62828;
  animation: pulse 0.8s ease infinite;
}

/* ===== Золотой тост «Новое достижение!» ===== */
.toast-ach {
  position: fixed; bottom: 84px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(45deg, #ffd700, #ffed4e);
  color: #5d4037; border: 2px solid #e6a817;
  padding: 12px 22px; border-radius: 20px;
  display: flex; align-items: center; gap: 12px;
  font-size: 0.95em; max-width: 90vw;
  box-shadow: 0 8px 26px rgba(230,168,23,0.55);
  opacity: 0; visibility: hidden; z-index: 2100;
  transition: all 0.35s ease;
}
.toast-ach.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.toast-ach .toast-ach-emoji { font-size: 2em; line-height: 1; animation: scoreBump 0.5s ease; }
.toast-ach .toast-ach-text { text-align: left; line-height: 1.35; font-size: 0.9em; }
.toast-ach .toast-ach-text strong { display: block; font-size: 1.05em; color: #6d4c00; }

/* ===== Красивый скроллбар ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.06); }
::-webkit-scrollbar-thumb { background: linear-gradient(45deg, #ff6b9d, #c44569); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #c44569; }

/* Доступность: видимая фокус-рамка с клавиатуры */
:focus-visible { outline: 3px solid #ffd700; outline-offset: 2px; border-radius: 6px; }

/* ===== Модальное окно ===== */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 1000; justify-content: center; align-items: center; padding: 20px; }
.modal.active { display: flex; }
.modal-content { background: white; padding: 30px; border-radius: 20px; max-width: 600px; width: 100%; max-height: 85vh; overflow-y: auto; position: relative; animation: modalSlideIn 0.3s ease; }
@keyframes modalSlideIn { from { transform: translateY(-50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-close { position: absolute; top: 15px; right: 15px; background: #f44336; color: white; border: none; width: 35px; height: 35px; border-radius: 50%; cursor: pointer; font-size: 1.2em; transition: all 0.3s; }
.modal-close:hover { background: #d32f2f; transform: rotate(90deg); }
.modal h3 { color: #333; margin-bottom: 15px; font-size: 1.3em; padding-right: 40px; }
.modal p { color: #555; line-height: 1.6; margin-bottom: 12px; }
.modal-options { display: flex; flex-direction: column; gap: 10px; margin-top: 15px; }
.modal-option { background: linear-gradient(135deg, #e3f2fd, #bbdefb); border: 2px solid #2196f3; padding: 12px 15px; border-radius: 10px; cursor: pointer; transition: all 0.3s; font-size: 1em; font-family: inherit; text-align: left; }
.modal-option:hover { background: linear-gradient(135deg, #bbdefb, #90caf9); transform: translateX(5px); }
.modal-option.correct { background: linear-gradient(135deg, #c8e6c9, #a5d6a7); border-color: #4caf50; }
.modal-option.wrong { background: linear-gradient(135deg, #ffcdd2, #ef9a9a); border-color: #f44336; }
.hint-step { background: #f5f5f5; padding: 10px 15px; border-radius: 10px; margin: 8px 0; border-left: 4px solid #9c27b0; }

/* ===== Тосты (маленькие уведомления) ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(33,33,33,0.92); color: #fff;
  padding: 12px 22px; border-radius: 50px;
  font-size: 0.95em; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  opacity: 0; visibility: hidden; z-index: 2000;
  transition: all 0.3s ease;
}
.toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

/* ===== Адаптивность общих элементов ===== */
@media (max-width: 600px) {
  .hud-player { padding: 6px 12px; font-size: 0.85em; max-width: 52vw; }
  .hud-grade { display: none; }
  .hud-sound { width: 36px; height: 36px; font-size: 0.95em; }
  .hud-score { padding: 6px 12px; font-size: 0.85em; }
  .modal-content { padding: 22px; }
  .lb-date, .lb-stars, .lb-time { display: none; }
  .lb-row { padding: 8px 10px; }
  .hud-streak { padding: 6px 10px; font-size: 0.85em; }
  .profile-stats { grid-template-columns: repeat(2, 1fr); }
  .ach-grid { grid-template-columns: repeat(2, 1fr); }
  .profile-avatar { width: 58px; height: 58px; font-size: 2em; }
}

/* ===== Печать диплома: на бумагу выходит ТОЛЬКО диплом ===== */
#diplomaPrint { display: none; }
@media print {
  /* Альбомный A4 — диплом широкий, так влезает вся статистика */
  @page { size: A4 landscape; margin: 10mm; }
  body.print-diploma { background: #fff !important; }
  body.print-diploma > *:not(#diplomaPrint) { display: none !important; }
  body.print-diploma #diplomaPrint { display: block !important; }
  body.print-diploma #diplomaPrint .diploma-sheet {
    box-shadow: none; margin: 0 auto; max-width: 260mm;
  }
  body.print-diploma #diplomaPrint .diploma-watermark { font-size: 130mm; }
  body.print-diploma #diplomaPrint .diploma-title { font-size: 2.2em; }
  body.print-diploma #diplomaPrint .diploma-name { font-size: 2.1em; }
  body.print-diploma #diplomaPrint .diploma-stat { font-size: 1.05em; }
  body.print-diploma #diplomaPrint .diploma-seal { width: 30mm; height: 30mm; right: 10mm; bottom: 12mm; }
  body.print-diploma { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ===== Доступность: видимая фокус-рамка с клавиатуры ===== */
a:focus-visible, button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #ffb300;
  outline-offset: 2px;
  border-radius: 8px;
}
.hud-sound:focus-visible, .location-btn:focus-visible, .avatar-option:focus-visible {
  outline: 3px solid #ffb300;
  outline-offset: 3px;
  border-radius: 50%;
}
