:root {
  --ink: #16323f;
  --paper: #f4ecd8;
  --paper-shadow: #d8c9a3;
  --bg-light: #17495c;
  --bg: #103241;
  --bg-deep: #0b2530;
  --accent: #e2a13d;
  --accent-dark: #b97b22;
  --correct: #5f9b7c;
  --correct-dark: #3f7a5c;
  --wrong: #c2564a;
  --muted: #7fa3ac;
}

/* تم «جنگلی» */
:root[data-theme="forest"] {
  --ink: #1b3a22;
  --paper: #f1f0dd;
  --paper-shadow: #d4d1b0;
  --bg-light: #2a5c38;
  --bg: #16331e;
  --bg-deep: #0d2013;
  --accent: #c9a227;
  --accent-dark: #a07d16;
  --correct: #4c8c5a;
  --correct-dark: #336b43;
  --wrong: #c2564a;
  --muted: #7fae8a;
}

/* تم «غروب» */
:root[data-theme="sunset"] {
  --ink: #3a1f3d;
  --paper: #fdece0;
  --paper-shadow: #e6c9a8;
  --bg-light: #5a2d54;
  --bg: #2d1b3d;
  --bg-deep: #1a0f24;
  --accent: #ef8354;
  --accent-dark: #c6612f;
  --correct: #6fae8f;
  --correct-dark: #477a63;
  --wrong: #d1495b;
  --muted: #c99bb5;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 20% 10%, var(--bg-light) 0%, var(--bg) 45%, var(--bg-deep) 100%);
  color: var(--paper);
  font-family: 'Vazirmatn', sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  /* نواحی امن (ناچ و خط پایینِ آیفون): محتوا زیر آن‌ها نمی‌رود */
  padding: calc(14px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  text-align: center;
}

.title {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 4px 0 0;
  letter-spacing: 0.5px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.chip {
  background: rgba(244, 236, 216, 0.1);
  border: 1px solid rgba(244, 236, 216, 0.25);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.9rem;
  display: flex;
  gap: 6px;
}

.chip-label { color: var(--muted); }

.lives {
  display: flex;
  gap: 6px;
  font-size: 1.15rem;
}

.board-wrap {
  display: flex;
  justify-content: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 440px;
}

.cell {
  aspect-ratio: 1 / 1;
  background: var(--paper);
  color: var(--ink);
  border: none;
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--paper-shadow);
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  text-align: center;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
  direction: ltr;
}

.cell-label {
  display: inline-block;
  white-space: nowrap;
  line-height: 1.2;
}

.cell:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--paper-shadow); }

.cell.selected {
  background: var(--accent);
  box-shadow: 0 4px 0 var(--accent-dark);
  transform: translateY(-2px);
}

.cell.matched {
  background: var(--correct);
  color: #eef6f0;
  box-shadow: 0 4px 0 var(--correct-dark);
  cursor: default;
  pointer-events: none;
}

.cell.wrong {
  background: var(--wrong);
  color: #fdf0ee;
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

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

.btn-help {
  background: var(--accent);
  color: var(--ink);
}

.btn-help:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  background: rgba(244, 236, 216, 0.12);
  color: var(--paper);
  border: 1px solid rgba(244, 236, 216, 0.3);
}

.btn-speak {
  background: #2f6478;
  color: var(--paper);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(244, 236, 216, 0.25);
}

.help-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--paper);
  color: var(--ink);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.35);
  padding: 18px;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.help-panel-inner {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.help-word {
  font-weight: 800;
  font-size: 1.1rem;
  margin: 0;
  direction: ltr;
  text-align: center;
}

.help-sentence {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--bg);
}

.help-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 37, 48, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.overlay[hidden] {
  display: none;
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

.overlay-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: 28px 24px;
  text-align: center;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.overlay-card h2 { margin: 0; font-size: 1.4rem; }
.overlay-card p { margin: 0; color: #46626c; line-height: 1.6; }

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== صفحات (شروع / بازی / آمار) ===== */

.screen {
  display: none;
}

.screen.active {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.screen .title {
  text-align: center;
  margin: 4px 0 0;
}

/* ===== صفحه شروع ===== */

.diamond-chip-standalone {
  align-self: center;
  background: rgba(226, 161, 61, 0.15);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.panel {
  background: rgba(244, 236, 216, 0.06);
  border: 1px solid rgba(244, 236, 216, 0.15);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.section-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.level-options {
  display: flex;
  gap: 10px;
}

.level-btn {
  background: rgba(244, 236, 216, 0.08);
  border: 1px solid rgba(244, 236, 216, 0.25);
  color: var(--paper);
  border-radius: 10px;
  padding: 10px 16px;
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 600;
  cursor: pointer;
}

.level-btn.selected {
  background: var(--accent);
  color: var(--ink);
  border-color: var(--accent-dark);
}

.btn-wide {
  width: 100%;
}

.music-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.music-filename {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
  text-align: center;
}

.start-footer {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.start-footer .btn {
  flex: 1;
  min-width: 130px;
}

/* ===== نوار بالای بازی ===== */

.topbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.icon-btn {
  background: transparent;
  border: 1px solid rgba(244, 236, 216, 0.3);
  color: var(--paper);
  border-radius: 10px;
  padding: 6px 14px;
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 600;
  cursor: pointer;
}

/* ===== مودال‌های عمومی (راهنما، تبلیغ) ===== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(11, 37, 48, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: 24px;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-card h2 { margin: 0; font-size: 1.3rem; }
.modal-text { margin: 0; color: #46626c; line-height: 1.7; white-space: pre-line; }

#infoModalText {
  max-height: 280px;
  overflow-y: auto;
}

#infoModalText[dir="rtl"] {
  text-align: right;
}

#gameHelpText {
  height: 320px;
  overflow-y: auto;
  text-align: right;
}

.ad-countdown {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent-dark);
  margin: 0;
}

/* ===== صفحه آمار ===== */

.stats-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
  overflow: hidden;
}

.stats-table th,
.stats-table td {
  padding: 12px 8px;
  font-size: 0.9rem;
  text-align: center;
}

.stats-table th.stats-game {
  text-align: left;
  white-space: nowrap;
  background: rgba(244, 236, 216, 0.08);
}

.stats-table th {
  background: rgba(226, 161, 61, 0.3);
  font-weight: 700;
}

.stats-table tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.04);
}

/* ===== امضای پایین صفحات ===== */

.credit {
  margin-top: auto;
  padding-top: 8px;
  text-align: center;
}

.credit a {
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: none;
  opacity: 0.85;
}

.credit a:hover,
.credit a:active {
  text-decoration: underline;
  opacity: 1;
}

/* ===== سربرگ صفحه شروع: نام برنامه (چپ) + الماس (راست) ===== */

.start-header {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  direction: ltr;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.2px;
  margin: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* سقف ارتفاع جدول فقط در حالت عمودی؛ در حالت افقی ارتفاع صفحه کم است و جدول نباید ریز شود */
@media (orientation: portrait) {
  .grid {
    max-width: min(440px, calc(100dvh - 290px));
  }
}

.help-meaning {
  margin: 0;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-dark);
}

/* ===== چهار دکمه‌ی انتخاب بازی، دوتا دوتا در هر ردیف ===== */

.mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

/* ===== صفحه‌ی جای خالی ===== */

.blank-wrap {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 0 8px;
}

.blank-progress {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.blank-sentence {
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  font-size: 1.15rem;
  line-height: 1.7;
  font-weight: 600;
  max-width: 440px;
}

.blank-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 440px;
}

.blank-option {
  background: rgba(244, 236, 216, 0.1);
  border: 1px solid rgba(244, 236, 216, 0.25);
  color: var(--paper);
  border-radius: 12px;
  padding: 14px 10px;
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.blank-option:active {
  transform: translateY(2px);
}

.blank-option.selected {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: var(--ink);
}

.blank-option.correct {
  background: var(--correct);
  border-color: var(--correct-dark);
  color: #eef6f0;
}

.blank-option.wrong {
  background: var(--wrong);
  border-color: var(--wrong);
  color: #fdf0ee;
}

/* ===== مرور اشتباهات در پایان بازی «جای خالی» ===== */

.overlay-mistakes {
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: right;
}

.mistake-item {
  background: rgba(11, 37, 48, 0.06);
  border-radius: 12px;
  padding: 10px 12px;
}

.mistake-sentence {
  margin: 0 0 4px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink);
  direction: ltr;
  text-align: left;
}

.mistake-word {
  color: var(--wrong);
  font-weight: 800;
}

.mistake-meaning {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-dark);
}

/* ===== دکمه‌های کوچک گرید انتخاب بازی ===== */

.mode-btn {
  padding: 8px 6px;
  font-size: 0.74rem;
  min-width: 0;
  white-space: normal;
  line-height: 1.3;
}

.mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== ردیف «آمار و رکوردها» + «راهنما» ===== */

.secondary-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.secondary-row .btn {
  flex: 1;
  font-size: 0.85rem;
}

/* ===== صفحه‌بندی مودال راهنما ===== */

.modal-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.page-indicator {
  color: #6c8a93;
  font-size: 0.85rem;
}

.modal-pagination .btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ===== آیکون برنامه + دکمه‌های هدر (موزیک/تنظیمات) ===== */

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-shrink: 1;
}

.app-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: block;
  flex-shrink: 0;
}

.header-icons {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.icon-toggle-btn {
  background: rgba(244, 236, 216, 0.1);
  border: 1px solid rgba(244, 236, 216, 0.25);
  color: var(--paper);
  border-radius: 9px;
  width: 30px;
  height: 30px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

/* ===== صفحه تنظیمات ===== */

.settings-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.setting-row label {
  font-size: 0.88rem;
  color: var(--paper);
}

.setting-row select {
  background: var(--paper);
  color: var(--ink);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-family: 'Vazirmatn', sans-serif;
  font-size: 0.85rem;
}

.setting-row input[type="range"] {
  width: 120px;
  accent-color: var(--accent);
}

.toggle-switch {
  width: 42px;
  height: 24px;
  appearance: none;
  background: rgba(244, 236, 216, 0.25);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  outline: none;
  transition: background 0.2s ease;
}

.toggle-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--paper);
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle-switch:checked {
  background: var(--accent);
}

.toggle-switch:checked::before {
  transform: translateX(18px);
}

/* ===== صفحه‌ی جدول کلمات ===== */

.ws-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  flex: 1;
}

.ws-grid {
  display: grid;
  position: relative;
  /* صفحه راست‌به‌چپ است و ستون‌های شبکه را هم برعکس می‌چیند، ولی مختصات SVG همیشه از چپ شروع می‌شود؛
     جدول حروف انگلیسی هم باید چپ‌به‌راست خوانده شود */
  direction: ltr;
  gap: 0;
  width: 100%;
  aspect-ratio: 1 / 1;   /* ارتفاع نهایی را جاوااسکریپت هم صریح می‌گذارد (fitWordSearchGrid) */
  max-width: 440px;
  max-width: min(440px, calc(100dvh - 330px));
  touch-action: none;
  user-select: none;
}

.ws-cell {
  min-width: 0;
  min-height: 0;          /* اندازه از ردیف/ستونِ شبکه می‌آید، نه از aspect-ratio */
  background: var(--paper);
  color: var(--ink);
  border: none;
  border-radius: 5px;
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  touch-action: none;
}

/* رنگ‌آمیزی خانه‌ها حالا با خط‌های ماژیکی روی لایه‌ی SVG انجام می‌شود؛ خود خانه‌ها رنگ نمی‌گیرند */
.ws-cell.selecting,
.ws-cell.found {
  color: var(--ink);
}

.ws-strokes {
  position: absolute;
  top: 0;
  left: 0;              /* اندازه‌ی دقیق (به پیکسل) را جاوااسکریپت از روی جدول می‌گذارد */
  pointer-events: none;
}

.ws-strokes path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ماژیک نیمه‌شفاف: با multiply روی کاغذ، حرف‌ها خوانا می‌مانند و خط‌های هم‌پوشان هر دو دیده می‌شوند */
.ws-found {
  opacity: 0.62;
  mix-blend-mode: multiply;
}

/* رد انگشت هنگام کشیدن */
.ws-trail {
  stroke: var(--ink);
  opacity: 0.32;
}

.ws-clues {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 440px;
}

.ws-clue {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(244, 236, 216, 0.1);
  border: 1px solid rgba(244, 236, 216, 0.25);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 700;
}

.ws-clue-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.ws-clue-letter {
  direction: ltr;
}

.ws-clue.solved {
  opacity: 0.6;
  text-decoration: line-through;
}

/* ===== سرنخ جدول کلمات: حرف اول + طول کلمه زیر آن ===== */

.ws-clue-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.ws-clue-len {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
}

.ws-clue.solved .ws-clue-len {
  display: none;
}

/* راهنما: حلقه‌ی هم‌رنگ کلمه (رنگ در JS تنظیم می‌شود) با یک ضربان ملایم */
.ws-cell.hint {
  animation: wsHintPulse 1.2s ease-in-out infinite;
}

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

/* جلوگیری از منوی نگه‌داشتن/انتخاب متن هنگام کشیدن انگشت روی جدول */
.ws-grid,
.ws-cell {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== مرور کلمه‌های «جدول کلمات» در پایان بازی ===== */

.overlay-mistakes.ws-review {
  max-height: 260px;
  gap: 6px;
}

.overlay-mistakes .ws-review-title {
  margin: 0 0 2px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #6c8a93;
  text-align: center;
}

.ws-review-item {
  display: flex;
  align-items: center;
  gap: 8px;
  direction: ltr;
  background: rgba(11, 37, 48, 0.06);
  border-radius: 10px;
  padding: 7px 10px;
}

.ws-review-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ws-review-word {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--ink);
  white-space: nowrap;
}

.ws-review-item.missed .ws-review-word {
  color: var(--wrong);
}

.ws-review-meaning {
  flex: 1;
  direction: rtl;
  text-align: right;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-dark);
}

/* ===== نوار حروف انتخاب‌شده (بالای جدول، تا انگشت نپوشوندش) ===== */

.ws-selection {
  min-height: 2.3rem;
  line-height: 2.3rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--accent);
  text-align: center;
  direction: ltr;
}

/* ===== صفحه‌ی «حدس کلمه» ===== */

.wg-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex: 1;
}

.wg-clue-label {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.wg-clue {
  margin: 0;
  padding: 0 8px;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  color: var(--paper);
}

/* کلمه و کیبورد باید چپ‌به‌راست باشند (صفحه راست‌به‌چپ است و بدون این، حرف‌ها وارونه چیده می‌شوند) */
.wg-word {
  display: flex;
  justify-content: center;
  gap: 6px;
  width: 100%;
  direction: ltr;
  margin: 6px 0 10px;
}

.wg-tile {
  flex: 1 1 0;
  max-width: 42px;
  aspect-ratio: 1 / 1.25;
  border-radius: 8px;
  background: rgba(244, 236, 216, 0.12);
  border-bottom: 3px solid rgba(244, 236, 216, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--ink);
}

.wg-tile.filled {
  background: var(--paper);
  border-bottom-color: var(--accent);
}

.wg-tile.missed {
  background: rgba(194, 86, 74, 0.25);
  border-bottom-color: var(--wrong);
  color: #f6d9d4;
}

.wg-keyboard {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 420px;
  direction: ltr;
}

.wg-key {
  height: 46px;
  border: none;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Vazirmatn', sans-serif;
  font-size: 1.1rem;
  font-weight: 800;
  box-shadow: 0 3px 0 var(--paper-shadow);
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.wg-key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--paper-shadow);
}

.wg-key.correct {
  background: var(--correct);
  color: #eef6f0;
  box-shadow: 0 3px 0 var(--correct-dark);
}

.wg-key.wrong {
  background: var(--wrong);
  color: #fdf0ee;
  opacity: 0.7;
  box-shadow: none;
}

.wg-key:disabled {
  cursor: default;
}

/* پاسخ در پایان بازی */
.overlay-mistakes .wg-answer-word {
  margin: 0 0 2px;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  color: var(--ink);
}

.wg-answer-item .mistake-meaning {
  text-align: center;
  margin-bottom: 6px;
}

.wg-solved .mistake-word {
  color: var(--correct-dark);
}

/* ===== منو با تعداد فرد دکمه: دکمه‌ی آخر تمام عرض می‌شود ===== */
.mode-buttons .mode-btn:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

/* ===== صفحه‌ی «رمزگشایی کلمه» ===== */

.wd-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
}

.wd-clue {
  margin: 0;
  padding: 0 8px;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  color: var(--paper);
}

/* جدول و کیبورد باید چپ‌به‌راست باشند (صفحه راست‌به‌چپ است) */
.wd-board {
  display: flex;
  flex-direction: column;
  gap: 5px;
  direction: ltr;
  margin: 4px 0 6px;
}

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

.wd-tile {
  flex: 0 0 auto;
  width: min(46px, calc((100vw - 32px - (var(--wd-cols, 5) - 1) * 5px) / var(--wd-cols, 5)));
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 2px solid rgba(244, 236, 216, 0.28);
  background: rgba(244, 236, 216, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--paper);
}

.wd-tile.typed {
  border-color: rgba(244, 236, 216, 0.75);
  background: rgba(244, 236, 216, 0.14);
}

.wd-tile.hinted {
  border-color: var(--correct);
  background: rgba(95, 155, 124, 0.28);
}

.wd-tile.correct { background: var(--correct); border-color: var(--correct); color: #f3faf5; }
.wd-tile.present { background: #c9a227; border-color: #c9a227; color: #2b2208; }
.wd-tile.absent  { background: #3f5560; border-color: #3f5560; color: #b9cad1; }

.wd-tile.reveal {
  animation: wdReveal 0.45s ease both;
}

@keyframes wdReveal {
  0%   { transform: scale(0.82); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

.wd-row.shake {
  animation: wdShake 0.4s ease;
}

@keyframes wdShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* کیبورد این صفحه (همان کلیدهای «حدس کلمه») کمی کوتاه‌تر تا جدول و کیبورد با هم جا شوند */
.wd-keyboard .wg-key {
  height: 42px;
}

.wd-keyboard .wg-key.present { background: #c9a227; color: #2b2208; box-shadow: 0 3px 0 #9c7d12; }
.wd-keyboard .wg-key.absent  { background: #3f5560; color: #8ea3ac; box-shadow: none; }
.wd-keyboard .wg-key.correct { background: var(--correct); color: #eef6f0; box-shadow: 0 3px 0 var(--correct-dark); }

.wd-keyboard .wd-action {
  background: rgba(244, 236, 216, 0.22);
  color: var(--paper);
  box-shadow: 0 3px 0 rgba(244, 236, 216, 0.12);
}

.wd-keyboard .wd-enter {
  background: var(--accent);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--accent-dark);
}

/* ===== صفحه‌ی اول: ارتفاع یکسان و حالت سه‌بعدی برای همه‌ی دکمه‌ها ===== */

#startScreen { --btn-h: 50px; }

#startScreen .level-btn,
#startScreen .mode-btn,
#startScreen .secondary-row .btn,
#startScreen .start-footer .btn {
  height: var(--btn-h);
  min-height: var(--btn-h);
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

#startScreen .level-btn { flex: 1; }

#startScreen .mode-btn {
  font-size: 0.8rem;
  white-space: nowrap;
  line-height: 1.2;
}

/* سه‌بعدی: «لبه»ی تیره‌ی زیر دکمه + سایه‌ی نرم + براقیِ بالا؛ با لمس، دکمه به اندازه‌ی لبه فرو می‌رود */
#startScreen .btn,
#startScreen .level-btn {
  --edge: rgba(0, 0, 0, 0.38);
  background-image: linear-gradient(rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 55%);
  box-shadow: 0 4px 0 var(--edge), 0 8px 12px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.15s ease;
}

#startScreen .btn-help,
#startScreen .level-btn.selected { --edge: var(--accent-dark); }

#startScreen .btn:active:not(:disabled),
#startScreen .level-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--edge), 0 2px 4px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* ریزه‌کاری صفحه‌ی اول: ردیف سطح‌ها هم‌عرض شبکه‌ی بازی‌ها، و دکمه‌های About تک‌خطی */
#startScreen .level-options { width: 100%; }
#startScreen .start-footer .btn { font-size: 0.85rem; white-space: nowrap; }

/* ===== چیدمان QWERTY (کیبورد حدس کلمه و رمزگشایی): کلیدها باریک‌ترند، پس کمی بلندتر ===== */
.kb-qwerty .wg-key { height: 50px; font-size: 1rem; border-radius: 8px; }
.wd-keyboard.kb-qwerty .wg-key { height: 46px; }
.kb-qwerty .wg-key.wd-action { font-size: 1.15rem; }

/* ===== گوشی‌های کوتاه (ارتفاع کمتر از ۷۰۰ پیکسل): فشرده‌تر تا همه‌چیز بدون اسکرول جا شود ===== */
@media (max-height: 700px) {
  .wd-tile { width: min(38px, calc((100vw - 32px - (var(--wd-cols, 5) - 1) * 5px) / var(--wd-cols, 5))); font-size: 1.2rem; }
  .wd-board, .wd-row { gap: 4px; }
  .wd-clue { font-size: 1.15rem; line-height: 1.35; }
  .wd-wrap { gap: 6px; }
  .wg-keyboard .wg-key { height: 38px; }
  .wg-keyboard.kb-qwerty .wg-key { height: 40px; }
  .wd-keyboard.kb-qwerty .wg-key { height: 38px; }
  .wg-clue { font-size: 1.2rem; }
  .wg-tile { max-width: 36px; }
  .wg-word { margin: 2px 0 4px; }
  .wg-wrap { gap: 8px; }
  .ws-grid { max-width: min(440px, calc(100dvh - 370px)); }
}

/* گوشی‌های کوتاه: جدول کلمات هم بدون اسکرول جا شود (فاصله‌ها و نوار حروف کمی فشرده‌تر؛ اندازه‌ی خانه‌ها دست‌نخورده) */
@media (max-height: 700px) {
  .ws-wrap { gap: 8px; }
  .ws-selection { min-height: 1.8rem; line-height: 1.8rem; font-size: 1.25rem; }
  .ws-clues { gap: 5px; }
  .ws-clue { padding: 2px 10px; }
}

/* ===== برنامه فقط عمودی است: روی گوشی‌های لمسی که افقی شدند، یک پوشش «گوشی را عمودی کن» ===== */
/* (Safari روی آیفون اجازه‌ی قفل کردن جهت را به صفحه‌ی وب نمی‌دهد؛ در برنامه‌ی نصبی این قفل بومی است) */
.rotate-notice {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #0b2530;
  color: var(--paper);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  padding: 24px;
}

.rotate-notice .rotate-icon { font-size: 3rem; }
.rotate-notice p { margin: 0; font-size: 1.1rem; font-weight: 700; }
.rotate-notice .rotate-sub { font-size: 0.85rem; font-weight: 400; opacity: 0.7; direction: ltr; }

@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  .rotate-notice { display: flex; }
}

/* ===== پخش‌کننده‌ی تبلیغ ویدئویی ===== */
.ad-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-overlay[hidden] { display: none; }

.ad-overlay video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.ad-top {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  direction: ltr;
}

.ad-badge {
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
}

.ad-skip {
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.ad-skip:disabled { opacity: 0.6; cursor: default; }

.ad-reward-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  margin: 0;
  padding: 8px 12px;
  text-align: center;
  color: #fff;
  font-size: 0.95rem;
  background: rgba(0, 0, 0, 0.5);
}

/* خط توضیح دلیلِ برگشت به تبلیغ شبیه‌سازی‌شده، و شماره‌ی نسخه در تنظیمات */
.ad-note {
  margin: 10px 0 0;
  font-size: 0.72rem;
  line-height: 1.5;
  color: #6c8a93;
  word-break: break-word;
}

.build-line {
  margin: 4px 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  direction: ltr;
}

/* ===== صفحه‌ی «چیدن جمله» ===== */

.sb-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  justify-content: center;
}

.sb-target {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--paper);
}

.sb-target-word {
  color: var(--accent);
  font-weight: 800;
  font-size: 1.15rem;
}

/* خط پاسخ و بانک تکه‌ها چپ‌به‌راست‌اند (جمله‌ی انگلیسی)؛ صفحه راست‌به‌چپ است */
.sb-answer {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: flex-start;
  gap: 8px;
  direction: ltr;
  min-height: 108px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(244, 236, 216, 0.07);
  border: 1px dashed rgba(244, 236, 216, 0.3);
}

.sb-bank {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  direction: ltr;
}

.sb-tile {
  min-height: 44px;
  padding: 8px 14px;
  border: none;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: 0 3px 0 var(--paper-shadow);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sb-tile:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--paper-shadow); }

/* کلمه‌ی هدف: خط رنگی زیر تکه */
.sb-tile.target { box-shadow: inset 0 -4px 0 var(--accent), 0 3px 0 var(--paper-shadow); }

.sb-tile.ghost {
  background: transparent;
  box-shadow: none;
  color: transparent;
  border: 1px dashed rgba(244, 236, 216, 0.25);
  cursor: default;
}

.sb-tile.locked {
  background: #cfe3d6;
  cursor: default;
}

.sb-tile.ok {
  background: var(--correct);
  color: #f3faf5;
  box-shadow: 0 3px 0 var(--correct-dark);
}

.sb-tile.fix {
  background: #dff0e4;
  box-shadow: 0 3px 0 var(--correct-dark);
  cursor: default;
}

.sb-tile.fix.target { box-shadow: inset 0 -4px 0 var(--accent), 0 3px 0 var(--correct-dark); }

.sb-slot {
  min-width: 48px;
  height: 44px;
  border-radius: 12px;
  border: 2px dashed rgba(244, 236, 216, 0.22);
}

/* مرور پایان بازی */
.overlay-mistakes.sb-review { max-height: 270px; gap: 6px; }

.sb-review-item {
  background: rgba(11, 37, 48, 0.06);
  border-radius: 10px;
  padding: 7px 10px;
}

.sb-review-sentence { margin: 0; font-size: 0.92rem; font-weight: 700; color: var(--ink); text-align: left; }
.sb-review-meaning { margin: 2px 0 0; font-size: 0.8rem; font-weight: 700; color: var(--accent-dark); text-align: left; direction: ltr; }
.sb-review-item.bad .sb-review-sentence { color: var(--wrong); }
.sb-review .mistake-word { color: var(--accent-dark); text-decoration: underline; }

@media (max-height: 700px) {
  .sb-wrap { gap: 8px; }
  .sb-answer { min-height: 90px; padding: 8px; gap: 6px; }
  .sb-bank { gap: 6px; }
  .sb-tile { min-height: 40px; padding: 6px 11px; font-size: 1rem; }
  .sb-slot { height: 40px; min-width: 40px; }
}
