@import url('https://fonts.googleapis.com/css2?family=Heebo:wght@400;700;900&display=swap');

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

:root {
  --wide-key-w: 56px;
  --regular-key-w: min(calc((100vw - 12px - 9 * 5px - 2 * var(--wide-key-w)) / 8), 42px);
  --bg: #121213;
  --text: #ffffff;
  --tile-border-empty: #3a3a3c;
  --tile-border-filled: #565758;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --key-bg: #818384;
  --key-text: #ffffff;
  --modal-bg: #1f1f23;
  --header-border: #3a3a3c;
  --toast-bg: #ffffff;
  --toast-text: #121213;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', 'Assistant', system-ui, Arial, sans-serif;
  direction: rtl;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ─── HOME SCREEN ─── */
#home {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 32px;
  padding: 24px;
}

#home .game-title {
  font-size: clamp(2.5rem, 12vw, 5rem);
  font-weight: 900;
  letter-spacing: 2px;
}

#home .tagline {
  font-size: 1rem;
  color: #aaa;
  text-align: center;
}

#home .play-btn {
  background: var(--correct);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 16px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 1px;
  touch-action: manipulation;
  transition: opacity 0.15s;
}
#home .play-btn:active { opacity: 0.8; }

#home .footer-note {
  font-size: 0.8rem;
  color: #666;
}

/* ─── GAME SCREEN ─── */
#game {
  display: none;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
}

#game.active { display: flex; }

/* Header */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--header-border);
  flex-shrink: 0;
}

.game-header .header-title {
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 1px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  touch-action: manipulation;
  line-height: 1;
}

/* Board */
.board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0 4px;
  overflow: hidden;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.row {
  display: flex;
  flex-direction: row;
  gap: 5px;
}

.tile {
  width: clamp(44px, calc((100dvh - 270px) / 6), 62px);
  height: clamp(44px, calc((100dvh - 270px) / 6), 62px);
  border: 2px solid var(--tile-border-empty);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 4vw, 1.7rem);
  font-weight: 700;
  text-transform: uppercase;
  transition: border-color 0.05s;
  perspective: 250px;
  position: relative;
}

.tile.filled {
  border-color: var(--tile-border-filled);
}

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

/* ─── KEYBOARD ─── */
.keyboard-area {
  flex-shrink: 0;
  padding: 4px 6px calc(6px + env(safe-area-inset-bottom));
}

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

.key {
  height: clamp(36px, calc((100dvh - 270px) * 0.36 / 3), 52px);
  width: var(--regular-key-w);
  flex: none;
  border-radius: 4px;
  border: none;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.key.wide {
  width: var(--wide-key-w);
  font-size: 0.75rem;
  flex: none;
}

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

.key:active { filter: brightness(0.8); }

/* ─── MODALS ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal-card {
  background: var(--modal-bg);
  border-radius: 12px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 12px;
  left: 12px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--header-border);
  padding-bottom: 12px;
}

/* Help modal */
.help-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: #ccc;
  text-align: right;
  margin-bottom: 16px;
}

.help-example {
  display: flex;
  flex-direction: row;
  gap: 6px;
  margin: 12px 0;
  justify-content: center;
}

.help-tile {
  width: 44px;
  height: 44px;
  border: 2px solid var(--tile-border-filled);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
}

.help-tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.help-tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.help-tile.absent  { background: var(--absent);  border-color: var(--absent);  color: #fff; }

.help-legend {
  font-size: 0.82rem;
  color: #aaa;
  margin-top: 6px;
  text-align: right;
}

/* Result modal */
.result-heading {
  font-size: 1.6rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.result-answer {
  font-size: 1rem;
  color: #aaa;
  margin-bottom: 20px;
}

.answer-word {
  display: block;
  font-size: 2.4rem;
  font-weight: 900;
  color: #e5a000;
  letter-spacing: 3px;
  margin-top: 4px;
}

.stats-grid {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.stat-number {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.stat-label {
  font-size: 0.7rem;
  color: #aaa;
  margin-top: 4px;
  text-align: center;
}

.distribution-title {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 10px;
  color: #ccc;
}

.dist-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 20px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  direction: rtl;
}

.dist-label {
  font-size: 0.85rem;
  font-weight: 700;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.dist-bar-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  direction: rtl;
}

.dist-bar {
  background: var(--absent);
  border-radius: 2px;
  min-width: 24px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  transition: width 0.4s ease;
}

.dist-bar.highlight { background: var(--correct); }

.countdown-label {
  font-size: 0.85rem;
  color: #aaa;
  margin-bottom: 4px;
}

.countdown-timer {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 2px;
  direction: ltr;
}

/* ─── TOAST ─── */
#toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}

#toast.show { opacity: 1; }

/* ─── ANIMATIONS ─── */
@keyframes pop {
  0%   { transform: scale(0.85); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

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

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  40%       { transform: translateY(-20px); }
  60%       { transform: translateY(-10px); }
}

.tile.pop     { animation: pop 0.1s ease forwards; }
.row.shake    { animation: shake 0.6s ease forwards; }
.tile.flip    { animation: flip-down 0.5s ease forwards; }
.tile.bounce  { animation: bounce 0.5s ease forwards; }

@media (prefers-reduced-motion: reduce) {
  .tile.pop, .row.shake, .tile.flip, .tile.bounce { animation: none; }
}

/* ─── RESPONSIVE ─── */
@media (min-width: 500px) {
  .key { max-width: 46px; }
}
