/* ---------- Темы и токены ---------- */

:root {
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-right, 0px));

  --color-correct: #2fa46e;
  --color-present: #e0a832;
  --status-text: #ffffff;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f26;
  --text-muted: #7a8090;
  --tile-border: #d3d7de;
  --tile-border-filled: #9aa1af;
  --color-absent: #9aa1af;
  --key-bg: #e2e5ea;
  --key-text: #1c1f26;
  --accent: #5865f2;
  --accent-text: #ffffff;
  --overlay: rgba(28, 31, 38, 0.55);
  --shadow: 0 12px 40px rgba(28, 31, 38, 0.18);
}

[data-theme="dark"] {
  --bg: #15171c;
  --surface: #22252d;
  --text: #eceef2;
  --text-muted: #8b91a0;
  --tile-border: #3a3e49;
  --tile-border-filled: #5a6072;
  --color-absent: #3a3e49;
  --key-bg: #3c4150;
  --key-text: #eceef2;
  --accent: #6b78ff;
  --accent-text: #ffffff;
  --overlay: rgba(8, 9, 12, 0.65);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .key.absent {
//  color: var(--text-muted);
  opacity: 0.5
}

/* ---------- База ---------- */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 10px) calc(var(--safe-left) + 12px);
}

/* ---------- Шапка ---------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 10px;
}

.title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.lang-toggle {
  display: flex;
  background: var(--key-bg);
  border-radius: 10px;
  padding: 3px;
}

.lang-option {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.lang-option.active {
  background: var(--accent);
  color: var(--accent-text);
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--key-bg);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.icon-button:active {
  transform: scale(0.92);
}

/* ---------- Игровое поле ---------- */

.board-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0 14px;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: clamp(4px, 1.2vw, 7px);
  height: 100%;
  max-height: min(100%, 480px);
  aspect-ratio: 5 / 6;
  max-width: 100%;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(4px, 1.2vw, 7px);
  min-height: 0;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--tile-border);
  border-radius: 12px;
  font-size: clamp(20px, 6vw, 32px);
  font-weight: 800;
  text-transform: uppercase;
  background: transparent;
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.tile.filled {
  border-color: var(--tile-border-filled);
  animation: tile-pop 0.12s ease;
}

.tile.flip-out {
  transform: rotateX(90deg);
  transition: transform 0.24s ease-in;
}

.tile.flip-in {
  transform: rotateX(0);
  transition: transform 0.24s ease-out;
}

.tile.correct,
.tile.present,
.tile.absent {
  border-color: transparent;
  color: var(--status-text);
}

.tile.correct { background: var(--color-correct); }
.tile.present { background: var(--color-present); }
.tile.absent  { background: var(--color-absent); }

.board-row.shake {
  animation: row-shake 0.45s ease;
}

@keyframes tile-pop {
  50% { transform: scale(1.08); }
}

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

/* ---------- Клавиатура ---------- */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  flex: 1;
  max-width: 46px;
  height: clamp(44px, 6.5dvh, 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: var(--key-bg);
  color: var(--key-text);
  font: inherit;
  font-size: clamp(13px, 3.4vw, 17px);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
  touch-action: manipulation;
}

.key:active {
  transform: scale(0.94);
}

.key.wide {
  flex: 1.6;
  max-width: 76px;
}

.key.correct { background: var(--color-correct); color: var(--status-text); }
.key.present { background: var(--color-present); color: var(--status-text); }
.key.absent  { background: var(--color-absent); color: var(--status-text); }

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  top: calc(var(--safe-top) + 64px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
  max-width: 90vw;
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Модальное окно результата ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 26px 24px;
  width: min(360px, 100%);
  text-align: center;
  transform: translateY(0) scale(1);
  transition: transform 0.25s ease;
}

.modal-overlay.hidden .modal-card {
  transform: translateY(14px) scale(0.96);
}

.modal-emoji {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 10px;
}

.modal-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 14px;
}

.modal-word {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-correct);
}

.modal-translation {
  margin-top: 6px;
  font-size: 15px;
  color: var(--text-muted);
  min-height: 1em;
}

.modal-translation:empty {
  display: none;
}

.primary-button {
  margin-top: 20px;
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.primary-button:active {
  transform: scale(0.97);
}

/* ---------- Партиклы ---------- */

.particles-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 25;
}

/* ---------- Адаптивность ---------- */

@media (min-width: 768px) {
  .app {
    padding-top: calc(var(--safe-top) + 20px);
    padding-bottom: calc(var(--safe-bottom) + 24px);
  }

  .title {
    font-size: 26px;
  }

  .key {
    max-width: 52px;
    height: 58px;
  }

  .key.wide {
    max-width: 86px;
  }
}

@media (max-height: 560px) {
  .header {
    padding-bottom: 4px;
  }

  .key {
    height: 38px;
  }
}
