/* Game-specific tokens (shared tokens from design-tokens.css) */
:root {
  --color-correct: #15803d;
  --color-present: #d97706;
  --color-absent: #3a3a3a;
  --color-empty-border: var(--border-color);
  --color-filled-border: #5a5a5a;
  --tile-size: 62px;
  --tile-gap: 6px;
}

[data-theme="light"] {
  --color-correct: #166534;
  --color-present: #b45309;
  --color-absent: #6a6a76;
  --color-empty-border: #aaaaaa;
  --color-filled-border: #808090;
}


/* ========== Reset & Base ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  background-image: none;
}

body.rtl {
  direction: rtl;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ========== Typography ========== */
h1, h2, h3 {
  color: var(--text-primary);
  font-weight: 700;
}

/* ========== Landing View ========== */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  animation: fadeIn 0.5s ease;
}

.landing-title {
  text-align: center;
}

.landing-title h1 {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--color-primary);
}

.landing-title .arabic-title {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-top: 4px;
  opacity: 0.7;
  -webkit-text-fill-color: initial;
  background: none;
}

.landing-title p {
  color: var(--text-secondary);
  margin-top: 12px;
  font-size: 1.05rem;
}

.landing-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.lang-buttons {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.lang-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 220px;
  padding: 32px 24px;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  color: var(--text-primary);
  font-family: var(--font-main);
}

.lang-btn:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
}

.lang-btn:active {
  transform: translateY(-2px);
}

.lang-btn .lang-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.lang-btn .lang-name {
  font-size: 1.3rem;
  font-weight: 700;
}

.lang-btn .lang-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tile-decoration {
  display: flex;
  gap: 6px;
  margin-top: 20px;
  opacity: 0.5;
}

.tile-decoration .deco-tile {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  animation: decoFloat 3s ease-in-out infinite;
}

.tile-decoration .deco-tile:nth-child(1) {
  background: var(--color-correct);
  animation-delay: 0s;
}
.tile-decoration .deco-tile:nth-child(2) {
  background: var(--color-present);
  animation-delay: 0.3s;
}
.tile-decoration .deco-tile:nth-child(3) {
  background: var(--color-absent);
  animation-delay: 0.6s;
}
.tile-decoration .deco-tile:nth-child(4) {
  background: var(--color-present);
  animation-delay: 0.9s;
}
.tile-decoration .deco-tile:nth-child(5) {
  background: var(--color-correct);
  animation-delay: 1.2s;
}

@keyframes decoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ========== How to Play (inline) ========== */
.how-to-play {
  max-width: 420px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.6;
}

.how-to-play .legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 12px;
}

.how-to-play .legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.how-to-play .legend-swatch {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1;
}

/* ========== Game View ========== */
.game-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 500px;
  animation: fadeIn 0.4s ease;
}

.game-header {
  text-align: center;
}

.game-header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--color-primary);
}

.game-header .game-lang-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 2px;
}

/* ========== Game Board ========== */
.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  gap: var(--tile-gap);
  padding: 10px;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  gap: var(--tile-gap);
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--color-empty-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-primary);
  transition: border-color 0.1s ease;
  user-select: none;
  position: relative;
}

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

.tile.correct {
  background: var(--color-correct);
  border-color: var(--color-correct);
  color: #fff;
  border-width: 3px;
  border-style: solid;
}

.tile.present {
  background: var(--color-present);
  border-color: var(--color-present);
  color: #fff;
  border-width: 3px;
  border-style: dashed;
}

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

/* Colorblind accessibility: symbols on revealed tiles */
.tile.correct::after {
  content: '\2713';
  position: absolute;
  inset-block-end: 2px;
  inset-inline-end: 3px;
  font-size: 0.6rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

.tile.present::after {
  content: '\25C6';
  position: absolute;
  inset-block-end: 2px;
  inset-inline-end: 3px;
  font-size: 0.6rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

.tile.absent::after {
  content: '\2215';
  position: absolute;
  inset-block-end: 2px;
  inset-inline-end: 3px;
  font-size: 0.6rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

/* Flip animation */
.tile.flip {
  animation: tileFlip 0.5s ease forwards;
}

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

/* Pop animation on letter entry */
@keyframes tilePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Shake animation for invalid word */
.board-row.shake {
  animation: rowShake 0.5s ease;
}

@keyframes rowShake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-6px); }
  30%, 70% { transform: translateX(6px); }
}

/* Bounce animation for winning row */
.tile.bounce {
  animation: tileBounce 0.5s ease;
}

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

/* ========== Keyboard ========== */
.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 500px;
  padding: 0 4px;
  user-select: none;
}

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

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  min-width: 32px;
  padding: 0 8px;
  border: none;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  flex: 1;
  max-width: 44px;
  text-transform: uppercase;
  position: relative;
}

.key:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

.key:active {
  transform: translateY(1px);
}

.key.wide {
  min-width: 56px;
  max-width: 68px;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

.key.correct {
  background: var(--color-correct);
  color: #fff;
}

.key.present {
  background: var(--color-present);
  color: #fff;
}

.key.absent {
  background: var(--color-absent);
  color: var(--text-primary);
}

/* Colorblind accessibility: symbols on keyboard keys */
.key.correct::after {
  content: '\2713';
  position: absolute;
  top: 2px;
  inset-inline-end: 3px;
  font-size: 0.5rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

.key.present::after {
  content: '\25C6';
  position: absolute;
  top: 2px;
  inset-inline-end: 3px;
  font-size: 0.5rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

.key.absent::after {
  content: '\2215';
  position: absolute;
  top: 2px;
  inset-inline-end: 3px;
  font-size: 0.5rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* Arabic keyboard keys */
.keyboard.arabic .key {
  font-size: 1rem;
  max-width: 40px;
}

.keyboard.arabic .key.wide {
  font-size: 0.65rem;
  max-width: 62px;
}

/* ========== Toast Notifications ========== */
#toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: auto;
  animation: toastIn 0.3s ease;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  white-space: nowrap;
}

.toast.removing {
  animation: toastOut 0.3s ease forwards;
}

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

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

/* ========== Results Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
  padding: 20px;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  animation: modalSlideIn 0.4s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal h2 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}

.modal h2.win {
  color: var(--color-correct);
}

.modal h2.lose {
  color: var(--color-accent);
}

.modal .answer-reveal {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.modal .answer-reveal .answer-word {
  color: var(--color-primary);
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-item .stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--color-primary);
}

.stat-item .stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Rank Badge */
.rank-badge {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
  animation: rankReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes rankReveal {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.rank-position {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-correct);
}

.rank-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.guess-distribution {
  margin-bottom: 24px;
}

.guess-distribution h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.dist-row .dist-label {
  font-size: 0.8rem;
  font-weight: 600;
  width: 14px;
  text-align: right;
  flex-shrink: 0;
}

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

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

.daily-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 4px;
  font-style: italic;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ========== Win Celebration ========== */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 600;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Win highlight on board */
.board.win-glow .tile.correct {
  border-color: #fff;
}

/* ========== Animations ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== Responsive ========== */
@media (max-width: 520px) {
  :root {
    --tile-size: 52px;
    --tile-gap: 5px;
  }

  #app {
    padding: 10px;
    padding-top: 50px;
  }

  .landing-title h1 {
    font-size: 2.4rem;
    letter-spacing: 4px;
  }

  .landing-title .arabic-title {
    font-size: 1.6rem;
  }

  .lang-btn {
    width: 180px;
    padding: 24px 18px;
  }

  .game-header h1 {
    font-size: 1.4rem;
  }

  .key {
    height: 48px;
    font-size: 0.8rem;
    min-width: 26px;
    padding: 0 5px;
  }

  .key.wide {
    min-width: 44px;
    max-width: 56px;
    font-size: 0.6rem;
  }

  .keyboard.arabic .key {
    font-size: 0.9rem;
    max-width: 34px;
  }

  .keyboard.arabic .key.wide {
    max-width: 50px;
  }

  .tile {
    font-size: 1.5rem;
  }

  .tile.correct::after,
  .tile.present::after,
  .tile.absent::after {
    font-size: 0.5rem;
  }

  .key.correct::after,
  .key.present::after,
  .key.absent::after {
    font-size: 0.45rem;
  }

  .modal {
    padding: 24px 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 380px) {
  :root {
    --tile-size: 46px;
    --tile-gap: 4px;
  }

  .key {
    height: 44px;
    min-width: 22px;
    gap: 3px;
    font-size: 0.75rem;
  }

  .key.wide {
    min-width: 38px;
    max-width: 50px;
  }

  .keyboard.arabic .key {
    font-size: 0.8rem;
    max-width: 30px;
  }

  .tile {
    font-size: 1.3rem;
  }

  .tile.correct::after,
  .tile.present::after,
  .tile.absent::after {
    font-size: 0.45rem;
  }

  .key.correct::after,
  .key.present::after,
  .key.absent::after {
    font-size: 0.4rem;
  }

  .landing-title h1 {
    font-size: 2rem;
  }

  .lang-buttons {
    gap: 12px;
  }

  .lang-btn {
    width: 150px;
    padding: 20px 14px;
  }
}

/* ========== Utility ========== */
.hidden { display: none !important; }
