/* وش الكلمة — layout, board, keyboard, sheets, pages. RTL, mobile-first. */

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Tajawal', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background 0.25s, color 0.25s;
}

a { color: var(--brand); }
button { font-family: inherit; cursor: pointer; }

.wordmark, h1, h2, .tile { font-family: 'Baloo Bhaijaan 2', 'Tajawal', sans-serif; }

/* ---------- header ---------- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline);
}
.top-group { display: flex; align-items: center; gap: 4px; }
.wordmark {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}
.wordmark span { color: var(--brand); }

/* speech-bubble logo (وش الكلمة؟) */
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand-logo { width: 46px; height: 46px; display: block; }

/* theme toggle: show the icon of the theme you'd switch TO */
.icon-sun, .icon-moon { width: 24px; height: 24px; }
:root[data-theme='light'] .icon-sun { display: none; }
:root[data-theme='dark'] .icon-moon { display: none; }
.streak-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  color: var(--subtext);
  padding: 4px 8px;
}
.icon-btn {
  background: none;
  border: none;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  border-radius: 10px;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:focus-visible, .btn:focus-visible, .kb-key:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; }

.game-date { text-align: center; color: var(--subtext); font-size: 0.85rem; padding-top: 8px; }

.mode-banner {
  margin: 8px auto 0;
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--subtext);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.85rem;
  width: fit-content;
}

/* ---------- board ---------- */
main.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  padding: 12px 0;
  width: min(100%, calc(var(--cols) * 64px + (var(--cols) - 1) * 6px));
  flex: 1;
  max-height: 440px;
  align-content: center;
}
.row {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 6px;
}
.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.4rem, 7vw, 2.1rem);
  font-weight: 700;
  border: 2px solid var(--hairline);
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  user-select: none;
  transition: border-color 0.15s;
}
.tile.filled { border-color: var(--subtext); }
.tile[data-state] { border-color: transparent; color: var(--tile-text); }
.tile[data-state='correct'] { background: var(--correct); }
.tile[data-state='present'] { background: var(--present); }
.tile[data-state='absent'] { background: var(--absent); color: var(--absent-text); }

/* ---------- animations (transform/opacity only) ---------- */
.tile.pop { animation: pop 0.12s ease-out; }
@keyframes pop { 50% { transform: scale(1.08); } }

.tile.flip { animation: flip 0.42s ease-in-out; }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

.row.shake { animation: shake 0.35s ease-in-out; }
@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.tile.bounce { animation: bounce 0.5s ease-out; }
@keyframes bounce {
  30% { transform: translateY(-14px); }
  60% { transform: translateY(3px); }
  100% { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- keyboard ---------- */
.keyboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 6px;
}
.kb-row { display: flex; gap: 4px; justify-content: center; }
.kb-key {
  flex: 1;
  max-width: 44px;
  min-height: 52px;
  border: none;
  border-radius: 6px;
  background: var(--key-bg);
  border: 1px solid var(--hairline);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  touch-action: manipulation;
  transition: transform 0.1s ease-out, background 0.15s;
}
.kb-key:active { transform: scale(0.94); }
.kb-wide { max-width: 64px; flex: 1.5; font-size: 0.8rem; }
.kb-key[data-state='correct'] { background: var(--correct); color: var(--tile-text); border-color: transparent; }
.kb-key[data-state='present'] { background: var(--present); color: var(--tile-text); border-color: transparent; }
.kb-key[data-state='absent'] { background: var(--absent); color: var(--absent-text); border-color: transparent; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  top: 76px;
  right: 50%;
  transform: translateX(50%) translateY(-8px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }

/* ---------- overlay / sheet / modals ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 40;
}
.sheet {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  margin: 0 auto;
  max-width: 520px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--hairline);
  border-bottom: none;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translateY(100%);
  transition: transform 0.25s ease-out;
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--hairline); margin: 0 auto 14px; }
.sheet h2 { text-align: center; margin-bottom: 6px; }
.sheet-word-card {
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  margin: 12px 0;
}
.sheet-word { font-size: 2rem; font-weight: 800; font-family: 'Baloo Bhaijaan 2', sans-serif; color: var(--brand); }
.sheet-region { display: inline-block; font-size: 0.8rem; color: var(--subtext); border: 1px solid var(--hairline); border-radius: 999px; padding: 2px 10px; margin: 6px 0; }
.sheet-meaning { color: var(--ink); line-height: 1.7; }
.sheet-meta { display: flex; justify-content: center; gap: 18px; color: var(--subtext); font-size: 0.9rem; margin-bottom: 14px; }
.sheet-countdown { text-align: center; color: var(--subtext); margin-bottom: 14px; }
.sheet-report { display: block; text-align: center; margin-top: 12px; font-size: 0.8rem; color: var(--subtext); text-decoration: none; }
.sheet-report:hover { color: var(--brand); text-decoration: underline; }
.sheet-countdown strong { font-size: 1.3rem; color: var(--ink); font-variant-numeric: tabular-nums; direction: ltr; display: inline-block; }

.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: var(--brand);
  color: var(--surface);
  font-size: 1.05rem;
  font-weight: 700;
  transition: transform 0.1s ease-out, opacity 0.15s;
}
:root[data-theme='dark'] .btn { color: #0E1116; }
.btn:active { transform: scale(0.98); }
.btn + .btn { margin-top: 8px; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--hairline); }
:root[data-theme='dark'] .btn-ghost { color: var(--ink); }
.btn-small { width: auto; min-height: 40px; padding: 0 18px; display: inline-block; }

.modal {
  position: fixed;
  top: 50%;
  right: 50%;
  transform: translate(50%, -50%);
  width: min(92vw, 420px);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 20px;
  z-index: 50;
}
.modal h2 { text-align: center; margin-bottom: 14px; }
.modal-close, .sheet-close {
  position: absolute;
  top: 10px;
  left: 10px;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--subtext);
  min-width: 44px;
  min-height: 44px;
}

/* stats */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 16px; }
.stat-val { font-size: 1.6rem; font-weight: 800; }
.stat-label { font-size: 0.72rem; color: var(--subtext); }
.dist-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.dist-label { width: 16px; color: var(--subtext); font-weight: 700; }
.dist-bar {
  background: var(--correct);
  color: var(--tile-text);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: left;
  min-width: 24px;
}

/* settings */
.theme-option { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--hairline); cursor: pointer; min-height: 48px; }
.theme-option:last-of-type { border-bottom: none; }
.theme-option input { accent-color: var(--brand); width: 20px; height: 20px; }

/* ---------- ads + sponsor ---------- */
.ad-slot { margin: 16px auto; max-width: 468px; width: 100%; }
.ad-slot:empty { display: none; margin: 0; }
.banner-img { display: block; width: 100%; height: auto; border-radius: 10px; }

.sponsor-line { text-align: center; margin-bottom: 12px; font-size: 0.85rem; }
.sponsor-inner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--subtext);
  text-decoration: none;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 6px 14px;
  min-height: 36px;
}
a.sponsor-inner:hover { border-color: var(--brand); }
.sponsor-logo { height: 20px; width: auto; border-radius: 4px; }

/* ---------- consent ---------- */
.consent-bar {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  z-index: 70;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
}
.consent-bar p { color: var(--subtext); line-height: 1.5; }

/* ---------- content pages ---------- */
.page {
  flex: 1;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  line-height: 1.9;
}
.page h1 { margin-bottom: 16px; }
.page h2 { margin: 24px 0 8px; font-size: 1.15rem; }
.page p, .page li { color: var(--ink); margin-bottom: 10px; }
.page ul, .page ol { padding-right: 22px; }
.page .muted { color: var(--subtext); }

.site-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 10px 14px; border-bottom: 1px solid var(--hairline); font-size: 0.9rem; }
.site-nav[hidden] { display: none; }
.site-nav a { text-decoration: none; padding: 6px 2px; min-height: 44px; display: inline-flex; align-items: center; }
.site-nav a[aria-current='page'] { font-weight: 700; border-bottom: 2px solid var(--brand); }

.site-footer {
  border-top: 1px solid var(--hairline);
  padding: 16px;
  text-align: center;
  color: var(--subtext);
  font-size: 0.8rem;
}
.site-footer a { color: var(--subtext); }

/* archive list */
.archive-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--hairline);
  text-decoration: none;
  color: var(--ink);
  min-height: 48px;
}
.archive-num { font-weight: 700; }
.archive-date { color: var(--subtext); font-size: 0.85rem; margin-inline-start: auto; }
.archive-badge { background: var(--brand); color: var(--surface); border-radius: 999px; font-size: 0.7rem; padding: 2px 10px; }
:root[data-theme='dark'] .archive-badge { color: #0E1116; }

/* how-to-play example tiles */
.example-row { display: flex; gap: 5px; margin: 8px 0 4px; }
.example-row .tile { width: 48px; height: 48px; aspect-ratio: auto; font-size: 1.3rem; }

@media (min-width: 768px) {
  .kb-key { max-width: 48px; min-height: 56px; }
  .board { max-height: 480px; }
}
