/* =========================================================
   Зал Энигмы · Telegram Mini App (TMA) Design System
   Ancient Roman / Delphic Oracle Wordle Aesthetics
   ========================================================= */

:root {
  --bg-primary: #0a0d13;
  --bg-secondary: #121820;
  --bg-card: rgba(18, 24, 32, 0.92);
  --text-primary: #f0f3f6;
  --text-muted: #8b949e;
  --gold-primary: #d4af37;
  --gold-light: #f5df88;
  --gold-glow: rgba(212, 175, 55, 0.35);
  --gold-border: rgba(212, 175, 55, 0.28);
  
  /* Цвета статусов Wordle (Палитра «5 Букв» Т-Банка) */
  --color-bull: #ffd000;
  --color-bull-glow: rgba(255, 208, 0, 0.4);

  --color-cow: #ffffff;
  --color-cow-glow: rgba(255, 255, 255, 0.25);

  --color-miss: #282f3a;
  --color-empty-border: rgba(255, 255, 255, 0.08);

  --font-serif: 'Cormorant Garamond', 'Cinzel', serif;
  --font-serif-deco: 'Cinzel Decorative', 'Cormorant Garamond', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #161e2a 0%, #0a0d13 75%);
}

/* Subtle Ancient Overlay */
.ancient-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.75) 100%);
  pointer-events: none;
  z-index: 1;
}

/* Main Container: строго помещается в 100dvh */
.app-container {
  width: 100%;
  max-width: 440px;
  height: 100vh;
  height: 100dvh;
  padding: calc(8px + var(--safe-top)) 10px calc(10px + var(--safe-bottom)) 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}

/* =========================================================
   Шапка (App Header)
   ========================================================= */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(18, 24, 32, 0.75);
  border: 1px solid var(--gold-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-crest {
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 0 6px var(--gold-glow));
}

.chamber-title {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: linear-gradient(180deg, #ffffff 0%, var(--gold-light) 65%, var(--gold-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.laurels-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 208, 0, 0.35);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.laurels-badge .laurels-icon {
  font-size: 14px;
  line-height: 1;
}

.laurels-badge .laurels-value {
  color: #ffd000;
  letter-spacing: 0.5px;
}

.header-icon-btn {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(212, 175, 55, 0.2);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.2s ease;
}

.header-icon-btn:active {
  transform: scale(0.92);
  background: rgba(212, 175, 55, 0.2);
}

/* =========================================================
   Игровая доска (Board Section)
   ========================================================= */

.board-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
}

.board-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 310px;
}

.tile-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
}

.tile {
  aspect-ratio: 1 / 1;
  background: #18202a;
  border: 2px solid var(--color-empty-border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
  position: relative;
  perspective: 1000px;
}

/* Плитка с активным вводом буквы */
.tile.filled {
  border-color: rgba(255, 255, 255, 0.45);
  background: #222b38;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.15);
  animation: tilePop 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Статусы после переворота (Палитра «5 Букв») */
.tile.bull {
  background: #ffd000 !important;
  border-color: #ffd000 !important;
  color: #12161f !important;
  font-weight: 800;
  box-shadow: 0 0 16px rgba(255, 208, 0, 0.4);
}

.tile.cow {
  background: #ffffff !important;
  border-color: #ffffff !important;
  color: #12161f !important;
  font-weight: 800;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.25);
}

.tile.miss {
  background: #282f3a !important;
  border-color: #282f3a !important;
  color: #6b7280 !important;
}

/* 3D Flip анимация переворота */
.tile.flip {
  animation: tileFlip 0.5s ease forwards;
}

@keyframes tilePop {
  0% { transform: scale(0.85); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes tileFlip {
  0% {
    transform: rotateX(0deg);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

/* Тряска ряда при ошибке словаря (Shake) */
.tile-row.shake {
  animation: rowShake 0.45s ease-in-out;
}

@keyframes rowShake {
  0%, 100% { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-6px); }
  30%, 60%, 90% { transform: translateX(6px); }
}

/* =========================================================
   Экранная виртуальная клавиатура (Keyboard Section)
   ========================================================= */

.keyboard-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  padding-bottom: 2px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

.key-btn {
  flex: 1;
  height: 48px;
  background: #182230;
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: 7px;
  color: #f0f3f6;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
}

.key-btn:active {
  transform: translateY(2px) scale(0.96);
  background: #253347;
}

/* Специальные широкие кнопки */
.key-action {
  flex: 1.45;
  font-size: 13px;
  background: #1e2838;
}

.key-enter {
  flex: 1.6;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-light);
  border-color: var(--gold-border);
}

.key-backspace {
  font-size: 17px;
}

/* Подсветка статусов на клавиатуре (Wordle Memory - Палитра «5 Букв») */
.key-btn.key-bull {
  background: #ffd000 !important;
  border-color: #ffd000 !important;
  color: #12161f !important;
  font-weight: 700;
  box-shadow: 0 0 8px rgba(255, 208, 0, 0.3);
}

.key-btn.key-cow {
  background: #ffffff !important;
  border-color: #ffffff !important;
  color: #12161f !important;
  font-weight: 700;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
}

.key-btn.key-miss {
  background: #14181f !important;
  border-color: #1c222b !important;
  color: #4b5563 !important;
  opacity: 0.45;
}

/* =========================================================
   Toast уведомления (Античные свитки)
   ========================================================= */

.toast-container {
  position: fixed;
  top: calc(65px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 380px;
}

.toast {
  background: rgba(18, 24, 32, 0.95);
  border: 1px solid var(--gold-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 16px var(--gold-glow);
  color: var(--gold-light);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  animation: toastIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), toastOut 0.3s ease 2.7s forwards;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-12px) scale(0.95); }
}

/* =========================================================
   Модальные окна (Modals)
   ========================================================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--gold-primary);
  border-radius: 18px;
  padding: 22px 20px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.8), 0 0 24px var(--gold-glow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateY(16px) scale(0.96);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-backdrop.open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(212, 175, 55, 0.2);
  padding-bottom: 10px;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 18px;
  color: var(--gold-light);
  letter-spacing: 0.5px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  font-size: 13px;
  line-height: 1.5;
  color: #cfd8dc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rule-example {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 12px;
  border-radius: 10px;
}

.rule-tile-sample {
  width: 36px;
  height: 36px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.rule-tile-sample.bull {
  background: #ffd000;
  color: #12161f;
  box-shadow: 0 0 8px rgba(255, 208, 0, 0.35);
}

.rule-tile-sample.cow {
  background: #ffffff;
  color: #12161f;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
}

.rule-tile-sample.miss {
  background: #282f3a;
  color: #6b7280;
}

.rule-note {
  font-size: 12px;
  color: var(--gold-light);
  background: rgba(212, 175, 55, 0.1);
  padding: 8px 10px;
  border-radius: 8px;
  border-left: 3px solid var(--gold-primary);
}

.antique-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--gold-primary);
  background: linear-gradient(180deg, #d4af37, #997b1a);
  color: #0a0d13;
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.antique-btn:active {
  transform: scale(0.97);
  filter: brightness(0.9);
}

.primary-btn {
  background: linear-gradient(180deg, #d4af37, #997b1a);
  color: #0a0d13;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f0f3f6;
}

.danger-btn {
  background: linear-gradient(180deg, #d32f2f, #8e0000);
  border-color: #ef5350;
  color: #ffffff;
}

/* Карточка завершения игры (GameOver) */
.gameover-card {
  text-align: center;
  align-items: center;
}

.gameover-emblem {
  font-size: 48px;
  line-height: 1;
}

.gameover-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.gameover-secret-box {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--gold-border);
  padding: 10px 18px;
  border-radius: 10px;
  width: 100%;
}

.secret-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
  display: block;
  margin-bottom: 4px;
}

.secret-word {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 900;
  color: var(--gold-light);
  letter-spacing: 3px;
}

.gameover-reward-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(46, 125, 50, 0.2);
  border: 1px solid rgba(76, 175, 80, 0.35);
  padding: 8px 16px;
  border-radius: 10px;
  width: 100%;
  font-size: 15px;
  font-weight: 700;
  color: #a5d6a7;
}

.stacked-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
