:root {
  --blue-950: #123853;
  --blue-900: #174b6a;
  --blue-800: #236f8f;
  --blue-700: #2f8fab;
  --blue-500: #54abc3;
  --blue-200: #ccebf2;
  --pink-700: #d77da0;
  --pink-500: #eda9c2;
  --pink-200: #f9dbe6;
  --cream: #fff8e9;
  --gold: #f5bd4e;
  --success: #2ea57b;
  --danger: #d85b78;
  --ink: #173f62;
  --muted: #6d8292;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(255, 255, 255, 0.93);
  --shadow: 0 18px 52px rgba(20, 68, 92, 0.17);
  --shadow-small: 0 10px 28px rgba(20, 68, 92, 0.13);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --grid-size: 12;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: var(--viewport-height, 100dvh);
  color: var(--ink);
  font-family: "Cairo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #dceff4;
  overflow-x: hidden;
}

button,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

button:focus-visible,
a:focus-visible {
  outline: 4px solid rgba(47, 143, 171, 0.28);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

/* =========================================================
   Background image + animation
   ========================================================= */

.scene-background {
  position: fixed;
  inset: 0;
  z-index: -4;
  overflow: hidden;
  pointer-events: none;

  /*
   * The illustration remains vertical and is never enlarged with cover.
   * The side gradient fills wide monitors without cropping the artwork.
   */
  background:
    linear-gradient(180deg, #d8eef4 0%, #edf4ed 48%, #fff0d2 100%);
}

.scene-background::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("images/al-aqsa-background.jpeg");
  background-repeat: no-repeat;
  background-size: auto 100%;
  background-position: center bottom;
  filter: saturate(0.94) contrast(0.99) brightness(1.03);
  animation: backgroundGlow 12s ease-in-out infinite alternate;
}

.scene-background::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(226, 246, 250, 0.1), rgba(255, 246, 222, 0.08)),
    radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.52), transparent 29%),
    radial-gradient(circle at 80% 12%, rgba(255, 255, 255, 0.4), transparent 25%);
}

.sky-wash {
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(90deg, rgba(248, 188, 211, 0.16), transparent 32%, rgba(84, 171, 195, 0.13)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 248, 233, 0.12));
  mix-blend-mode: soft-light;
  animation: washBreathe 9s ease-in-out infinite alternate;
}

.spark,
.light-orb {
  position: absolute;
  z-index: 2;
  display: block;
  border-radius: 50%;
}

.spark {
  width: var(--size, 8px);
  height: var(--size, 8px);
  left: var(--left);
  top: var(--top);
  background: rgba(255, 230, 137, 0.92);
  box-shadow: 0 0 12px 4px rgba(255, 220, 112, 0.32);
  animation: sparkleFloat var(--duration, 6s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.spark-1 { --left: 11%; --top: 17%; --size: 7px; --duration: 6.8s; }
.spark-2 { --left: 26%; --top: 32%; --size: 5px; --duration: 5.7s; --delay: -2s; }
.spark-3 { --left: 42%; --top: 13%; --size: 10px; --duration: 7.3s; --delay: -3s; }
.spark-4 { --left: 58%; --top: 29%; --size: 6px; --duration: 5.9s; --delay: -1s; }
.spark-5 { --left: 73%; --top: 17%; --size: 8px; --duration: 7.9s; --delay: -4s; }
.spark-6 { --left: 88%; --top: 38%; --size: 5px; --duration: 6.3s; --delay: -2.5s; }
.spark-7 { --left: 35%; --top: 52%; --size: 5px; --duration: 8.2s; --delay: -5s; }
.spark-8 { --left: 67%; --top: 49%; --size: 7px; --duration: 7s; --delay: -1.8s; }

.light-orb {
  width: 190px;
  height: 190px;
  filter: blur(5px);
  opacity: 0.34;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.92), transparent 68%);
  animation: orbFloat 13s ease-in-out infinite alternate;
}

.orb-1 { left: -60px; top: 10%; }
.orb-2 { right: -80px; top: 30%; animation-delay: -4s; }
.orb-3 { left: 38%; bottom: 4%; width: 240px; height: 240px; animation-delay: -7s; }

@keyframes backgroundGlow {
  from { filter: saturate(0.91) contrast(0.99) brightness(1.01); }
  to { filter: saturate(1) contrast(1) brightness(1.055); }
}

@keyframes washBreathe {
  from { opacity: 0.56; }
  to { opacity: 0.94; }
}

@keyframes sparkleFloat {
  0%, 100% { opacity: 0.25; transform: translateY(0) scale(0.7); }
  45% { opacity: 1; transform: translateY(-20px) scale(1.25); }
  70% { opacity: 0.55; transform: translateY(-32px) scale(0.85); }
}

@keyframes orbFloat {
  from { transform: translate3d(0, 0, 0) scale(0.9); }
  to { transform: translate3d(45px, -25px, 0) scale(1.12); }
}

/* =========================================================
   Shared layout and controls
   ========================================================= */

.app-shell {
  width: min(1180px, 100%);
  min-height: var(--viewport-height, 100dvh);
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(clamp(10px, 2vw, 24px), env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(clamp(10px, 2vw, 24px), env(safe-area-inset-left));
}

.primary-button,
.secondary-button,
.language-button,
.icon-button,
.hint-button {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease, background 0.2s ease;
}

.primary-button {
  min-height: 50px;
  padding: 11px 23px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--blue-800), var(--blue-500) 56%, var(--pink-700));
  box-shadow: 0 10px 0 rgba(18, 56, 83, 0.12), 0 18px 32px rgba(47, 143, 171, 0.23);
  font-weight: 900;
}

.primary-button:hover,
.secondary-button:hover,
.language-button:hover,
.icon-button:hover,
.hint-button:hover {
  transform: translateY(-2px);
  filter: saturate(1.08);
}

.primary-button:active,
.secondary-button:active,
.language-button:active,
.icon-button:active,
.hint-button:active {
  transform: translateY(1px);
}

.secondary-button,
.language-button,
.hint-button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid rgba(47, 143, 171, 0.19);
  border-radius: 13px;
  color: var(--blue-900);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-small);
  font-size: 13px;
  font-weight: 900;
}

.language-button {
  white-space: nowrap;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(47, 143, 171, 0.16);
  border-radius: 13px;
  color: var(--blue-900);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-small);
  font-size: 19px;
}

.glass-panel {
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: var(--radius-xl);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.67));
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

/* =========================================================
   Intro
   ========================================================= */

.intro-screen {
  position: relative;
  min-height: calc(var(--viewport-height, 100dvh) - 24px);
  display: grid;
  place-items: center;
  padding: 20px 0;
}

.intro-language {
  position: absolute;
  top: 4px;
  inset-inline-end: 0;
  z-index: 5;
}

.intro-card {
  position: relative;
  width: min(650px, 100%);
  padding: clamp(24px, 4vw, 40px);
  overflow: hidden;
  isolation: isolate;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.94);
  border-radius: 38px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.6));
  box-shadow: 0 26px 80px rgba(25, 74, 95, 0.2);
  backdrop-filter: blur(24px);
  animation: introRise 0.75s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.intro-card::before,
.intro-card::after {
  content: "";
  position: absolute;
  z-index: -1;
  border-radius: 50%;
}

.intro-card::before {
  width: 260px;
  height: 260px;
  top: -145px;
  inset-inline-start: -75px;
  background: radial-gradient(circle, rgba(237, 169, 194, 0.7), transparent 68%);
}

.intro-card::after {
  width: 280px;
  height: 280px;
  bottom: -170px;
  inset-inline-end: -85px;
  background: radial-gradient(circle, rgba(84, 171, 195, 0.52), transparent 68%);
}

.logo-halo {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 20px 42px rgba(47, 143, 171, 0.2), inset 0 0 0 9px rgba(237, 169, 194, 0.13);
  animation: logoFloat 4.8s ease-in-out infinite;
}

.logo-halo::before,
.logo-halo::after {
  content: "";
  position: absolute;
  inset: -10px;
  border: 2px dashed rgba(47, 143, 171, 0.28);
  border-radius: 50%;
  animation: slowSpin 18s linear infinite;
}

.logo-halo::after {
  inset: -20px;
  border-color: rgba(215, 125, 160, 0.24);
  animation-duration: 24s;
  animation-direction: reverse;
}

.main-logo {
  width: 82%;
  height: 82%;
  object-fit: contain;
  filter: drop-shadow(0 10px 16px rgba(23, 63, 98, 0.11));
}

.intro-eyebrow,
.game-kicker,
.win-eyebrow {
  margin: 0 0 6px;
  color: var(--pink-700);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.intro-card h1 {
  margin: 0;
  color: var(--blue-950);
  font-size: clamp(40px, 7vw, 68px);
  line-height: 1.08;
  font-weight: 900;
  text-shadow: 0 7px 0 rgba(255, 255, 255, 0.5);
}

.intro-card h1::after {
  content: "";
  display: block;
  width: min(280px, 68%);
  height: 8px;
  margin: 9px auto 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue-500), var(--pink-500));
}

.intro-subtitle {
  max-width: 520px;
  margin: 16px auto 0;
  color: #526f81;
  font-size: clamp(15px, 2vw, 19px);
  line-height: 1.8;
  font-weight: 650;
}

.intro-features {
  margin: 20px auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.intro-features span {
  padding: 7px 11px;
  border: 1px solid rgba(47, 143, 171, 0.11);
  border-radius: 999px;
  color: var(--blue-900);
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 7px 16px rgba(47, 143, 171, 0.08);
  font-size: 12px;
  font-weight: 800;
}

.start-button {
  min-width: min(260px, 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 19px;
}

.button-icon {
  animation: starPulse 1.5s ease-in-out infinite;
}

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

@keyframes logoFloat {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-9px) rotate(1deg); }
}

@keyframes slowSpin {
  to { transform: rotate(360deg); }
}

@keyframes starPulse {
  0%, 100% { transform: scale(1) rotate(0); }
  50% { transform: scale(1.25) rotate(17deg); }
}

/* =========================================================
   Compact game screen — designed to fit one desktop viewport
   ========================================================= */

.game-screen {
  height: calc(var(--viewport-height, 100dvh) - 24px);
  min-height: 610px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  animation: screenIn 0.5s ease both;
}

.top-header {
  z-index: 20;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.79);
  box-shadow: var(--shadow-small);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}

.brand-lockup img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.brand-lockup span {
  display: grid;
  line-height: 1.25;
}

.brand-lockup strong {
  color: var(--blue-950);
  font-size: 14px;
  font-weight: 900;
}

.brand-lockup small {
  color: var(--pink-700);
  font-size: 11px;
  font-weight: 800;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.compact-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(270px, 0.58fr);
  align-items: center;
  gap: 12px;
}

.hero-copy {
  min-width: 0;
  padding: 2px 4px;
}

.hero-copy h2 {
  margin: 0;
  color: var(--blue-950);
  font-size: clamp(26px, 3.6vw, 42px);
  line-height: 1.05;
  font-weight: 900;
}

.hero-copy > p:last-child {
  margin: 4px 0 0;
  color: #536f82;
  font-size: 13px;
  font-weight: 650;
}

.progress-card {
  padding: 10px 13px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-small);
  backdrop-filter: blur(16px);
}

.progress-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-topline span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.progress-topline strong {
  color: var(--blue-950);
  font-size: 15px;
  font-weight: 900;
}

.progress-track {
  height: 9px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(47, 143, 171, 0.11);
  box-shadow: inset 0 2px 4px rgba(23, 63, 98, 0.08);
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue-500), var(--pink-500));
  box-shadow: 0 0 14px rgba(237, 169, 194, 0.52);
  transition: width 0.42s cubic-bezier(0.2, 0.85, 0.2, 1);
}

.progress-card p {
  margin: 5px 0 0;
  color: #60798b;
  font-size: 10.5px;
  font-weight: 700;
}

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 305px;
  align-items: stretch;
  gap: 12px;
}

.puzzle-panel {
  min-width: 0;
  min-height: 0;
  padding: 13px;
  display: flex;
  flex-direction: column;
}

.side-column {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.words-panel,
.secret-panel,
.mini-fact {
  padding: 13px;
}

.words-panel {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-heading,
.heading-copy,
.secret-topline {
  display: flex;
  align-items: center;
}

.panel-heading {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.heading-copy,
.secret-topline {
  min-width: 0;
  gap: 9px;
}

.panel-icon,
.secret-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(249, 219, 230, 0.8), rgba(204, 235, 242, 0.8));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.68);
  font-size: 17px;
}

.panel-heading h3,
.secret-topline h3 {
  margin: 0;
  color: var(--blue-950);
  font-size: 14px;
  font-weight: 900;
}

.panel-heading p,
.secret-topline p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.hint-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #6d4a08;
  border-color: rgba(245, 189, 78, 0.44);
  background: linear-gradient(145deg, #fff9dd, #ffe9a7);
  box-shadow: 0 9px 20px rgba(197, 139, 25, 0.16);
}

.hint-card {
  margin: 0 0 8px;
  padding: 8px 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border: 1px solid rgba(245, 189, 78, 0.43);
  border-radius: 13px;
  color: #6e4a0b;
  background: linear-gradient(145deg, rgba(255, 249, 221, 0.96), rgba(255, 235, 174, 0.93));
  box-shadow: 0 8px 20px rgba(197, 139, 25, 0.12);
  animation: hintIn 0.3s ease both;
}

.hint-card-icon {
  flex: 0 0 auto;
  font-size: 18px;
}

.hint-card strong {
  display: block;
  font-size: 12px;
  font-weight: 900;
}

.hint-card p {
  margin: 1px 0 0;
  font-size: 10.5px;
  line-height: 1.55;
  font-weight: 700;
}

.grid-wrap {
  min-height: 0;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 7px;
  overflow: hidden;
  border: 1px solid rgba(47, 143, 171, 0.13);
  border-radius: 20px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.95), transparent 30%),
    linear-gradient(145deg, rgba(204, 235, 242, 0.58), rgba(249, 219, 230, 0.43));
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.35);
}

.letter-grid {
  --available-grid: min(57dvh, 540px);
  width: min(100%, var(--mobile-grid-size, 9999px), var(--available-grid));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
  gap: 4px;
  direction: ltr;
  user-select: none;
  touch-action: none;
}

.letter-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(47, 143, 171, 0.19);
  border-radius: 9px;
  color: var(--blue-950);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 3px 8px rgba(28, 89, 112, 0.09), inset 0 -3px 0 rgba(47, 143, 171, 0.045);
  font-size: clamp(12px, 1.55vw, 18px);
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.letter-cell:hover {
  transform: translateY(-1px);
  background: #fff;
}

.letter-cell.is-selected {
  z-index: 2;
  color: #fff;
  background: linear-gradient(145deg, var(--blue-700), var(--blue-500));
  box-shadow: 0 7px 14px rgba(47, 143, 171, 0.24);
  transform: scale(1.04);
}

.letter-cell.is-found {
  color: var(--blue-950);
  border-color: rgba(46, 165, 123, 0.37);
  background: linear-gradient(145deg, rgba(182, 236, 215, 0.95), rgba(255, 255, 255, 0.94));
  box-shadow: 0 6px 14px rgba(46, 165, 123, 0.15);
  animation: cellFound 0.42s cubic-bezier(0.2, 0.85, 0.2, 1) both;
}

.letter-cell.is-hint-start,
.letter-cell.is-hint-next,
.letter-cell.is-hint-end {
  z-index: 4;
  color: var(--blue-950);
  border-color: rgba(245, 189, 78, 0.8);
  background: #fff2b7;
  box-shadow: 0 0 0 5px rgba(245, 189, 78, 0.22), 0 9px 20px rgba(167, 112, 8, 0.2);
  animation: hintPulse 0.9s ease-in-out infinite;
}

.letter-cell.is-hint-start::after,
.letter-cell.is-hint-next::after,
.letter-cell.is-hint-end::after {
  position: absolute;
  top: -8px;
  inset-inline-end: -7px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: var(--pink-700);
  box-shadow: 0 4px 9px rgba(23, 63, 98, 0.2);
  font-size: 10px;
  font-weight: 900;
}

.letter-cell.is-hint-start::after { content: "1"; }
.letter-cell.is-hint-next::after { content: "2"; background: var(--blue-700); }
.letter-cell.is-hint-end::after { content: "★"; background: var(--gold); color: #5f4107; }

.selection-status {
  min-height: 23px;
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #60798b;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.selection-status.success { color: var(--success); }
.selection-status.error { color: var(--danger); }

.word-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: flex-start;
  gap: 6px;
  padding: 2px 2px 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(47, 143, 171, 0.32) transparent;
}

.word-chip {
  position: relative;
  min-width: 0;
  padding: 6px 7px;
  text-align: center;
  overflow: hidden;
  border: 1px solid rgba(47, 143, 171, 0.12);
  border-radius: 999px;
  color: var(--blue-900);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 6px 14px rgba(47, 143, 171, 0.08);
  font-size: 10.5px;
  font-weight: 850;
  white-space: nowrap;
  transition: opacity 0.25s ease, transform 0.25s ease, background 0.25s ease;
}

.word-chip::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 2px;
  border-radius: 999px;
  background: var(--pink-700);
  transform: scaleX(0);
  transition: transform 0.28s ease;
}

.word-chip.found {
  opacity: 0.55;
  color: #527064;
  background: rgba(214, 242, 231, 0.86);
  transform: scale(0.96);
}

.word-chip.found::after {
  transform: scaleX(1);
}

.secret-panel {
  position: relative;
  overflow: hidden;
}

.secret-phrase {
  position: relative;
  z-index: 1;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  direction: rtl;
}

html[dir="ltr"] .secret-phrase {
  direction: ltr;
}

.secret-letter {
  width: 27px;
  height: 33px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(47, 143, 171, 0.13);
  border-radius: 9px;
  color: transparent;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: inset 0 -3px 0 rgba(47, 143, 171, 0.05);
  font-size: 16px;
  font-weight: 900;
  transition: all 0.34s ease;
}

.secret-letter.space {
  width: 8px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.secret-letter.revealed {
  color: var(--blue-950);
  border-color: rgba(215, 125, 160, 0.42);
  background: linear-gradient(145deg, rgba(249, 219, 230, 0.74), rgba(255, 255, 255, 0.94));
  box-shadow: 0 7px 14px rgba(215, 125, 160, 0.13);
  animation: revealLetter 0.46s cubic-bezier(0.2, 0.85, 0.2, 1) both;
}

.mini-fact {
  display: flex;
  align-items: center;
  gap: 9px;
}

.mini-fact > span {
  flex: 0 0 auto;
  font-size: 21px;
}

.mini-fact p {
  margin: 0;
  color: #5d7688;
  font-size: 10.5px;
  line-height: 1.65;
  font-weight: 700;
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cellFound {
  0% { transform: scale(0.82) rotate(-5deg); }
  65% { transform: scale(1.12) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes hintPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.07); }
}

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

@keyframes revealLetter {
  from { opacity: 0; transform: translateY(8px) rotate(6deg) scale(0.76); }
  to { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}

/* =========================================================
   Toast
   ========================================================= */

.toast {
  position: fixed;
  z-index: 120;
  left: 50%;
  bottom: 18px;
  min-width: min(320px, calc(100vw - 24px));
  max-width: min(520px, calc(100vw - 24px));
  padding: 11px 15px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 15px;
  color: #fff;
  background: rgba(18, 56, 83, 0.93);
  box-shadow: 0 18px 38px rgba(18, 56, 83, 0.27);
  backdrop-filter: blur(14px);
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 13px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.toast.success { background: rgba(32, 130, 97, 0.94); }
.toast.error { background: rgba(190, 69, 95, 0.95); }
.toast.hint { background: rgba(129, 87, 10, 0.94); }

/* =========================================================
   Win modal
   ========================================================= */

.win-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 49, 68, 0.64);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.win-card {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  max-height: min(92dvh, 820px);
  padding: 24px 26px;
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.95);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.97), rgba(255, 246, 222, 0.94));
  box-shadow: 0 30px 85px rgba(14, 48, 67, 0.3);
  transform: translateY(24px) scale(0.92);
  opacity: 0;
  transition: transform 0.34s cubic-bezier(0.2, 0.85, 0.2, 1), opacity 0.3s ease;
}

.win-modal.open .modal-backdrop { opacity: 1; }
.win-modal.open .win-card { opacity: 1; transform: translateY(0) scale(1); }

.modal-close {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--blue-950);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-small);
  cursor: pointer;
  font-size: 25px;
}

.win-logo {
  width: 78px;
  height: 92px;
  object-fit: contain;
}

.trophy {
  margin-top: -8px;
  font-size: 58px;
  animation: trophyBounce 1.6s ease-in-out infinite;
}

.win-card h2 {
  margin: 2px 0 6px;
  color: var(--blue-950);
  font-size: 32px;
  font-weight: 900;
}

.win-card > p:not(.win-eyebrow) {
  margin: 0;
  color: #617a8a;
  font-size: 14px;
  font-weight: 650;
}

.revealed-answer {
  margin: 16px auto;
  padding: 11px 16px;
  border: 1px solid rgba(47, 143, 171, 0.16);
  border-radius: 16px;
  color: var(--blue-950);
  background: linear-gradient(145deg, rgba(204, 235, 242, 0.72), rgba(249, 219, 230, 0.72));
  font-size: 22px;
  font-weight: 900;
}

.win-keyword-block {
  margin: 15px auto 12px;
}

.win-keyword-label {
  display: block;
  margin-bottom: 5px;
  color: var(--pink-700);
  font-size: 12px;
  font-weight: 900;
}

.win-keyword-block .revealed-answer {
  margin: 0;
}

.win-story {
  margin: 12px 0 18px;
  padding: 15px 17px;
  border: 1px solid rgba(47, 143, 171, 0.14);
  border-radius: 18px;
  color: #38596c;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 24px rgba(84, 171, 195, 0.06);
  text-align: start;
  font-size: 13px;
  line-height: 1.85;
  font-weight: 650;
}

.win-story p {
  margin: 0 0 9px;
}

.win-story p:last-child {
  margin-bottom: 0;
}

.win-actions {
  display: flex;
  justify-content: center;
  gap: 9px;
}

.confetti-piece {
  position: fixed;
  z-index: 130;
  top: -18px;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  pointer-events: none;
  animation: confettiFall var(--duration) linear forwards;
}

@keyframes trophyBounce {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-7px) rotate(2deg); }
}

@keyframes confettiFall {
  from { opacity: 1; transform: translate3d(0, -20px, 0) rotate(0); }
  to { opacity: 0.86; transform: translate3d(var(--drift), 110vh, 0) rotate(var(--rotation)); }
}

/* =========================================================
   English / LTR adjustments
   ========================================================= */

html[dir="ltr"] .progress-card p,
html[dir="ltr"] .panel-heading,
html[dir="ltr"] .secret-topline,
html[dir="ltr"] .mini-fact {
  text-align: left;
}

html[dir="ltr"] .letter-cell {
  font-family: "Cairo", system-ui, sans-serif;
}

/* =========================================================
   Responsive — phone-first rewrite
   ========================================================= */

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

body {
  overscroll-behavior-x: none;
}

body.is-selecting {
  overscroll-behavior: none;
}

img,
svg,
canvas {
  max-width: 100%;
}

button,
a {
  touch-action: manipulation;
}

.letter-grid,
.letter-cell {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.word-list,
.win-card {
  overscroll-behavior: contain;
}

@media (hover: none) {
  .primary-button:hover,
  .secondary-button:hover,
  .language-button:hover,
  .icon-button:hover,
  .hint-button:hover,
  .letter-cell:hover {
    transform: none;
    filter: none;
  }
}

@media (max-width: 920px) {
  :root {
    --radius-xl: 22px;
    --radius-lg: 18px;
    --radius-md: 14px;
  }

  body {
    min-width: 0;
    overflow-y: auto;
  }

  .scene-background::before {
    background-size: auto 100%;
    background-position: center bottom;
  }

  .app-shell {
    width: 100%;
    min-height: var(--viewport-height, 100dvh);
    padding:
      max(7px, env(safe-area-inset-top))
      max(7px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(7px, env(safe-area-inset-left));
  }

  .game-screen {
    width: 100%;
    height: auto;
    min-height: calc(var(--viewport-height, 100dvh) - 17px);
    grid-template-rows: auto auto auto;
    gap: 8px;
  }

  .top-header {
    position: sticky;
    top: max(5px, env(safe-area-inset-top));
    z-index: 40;
    width: 100%;
    min-width: 0;
  }

  .brand-lockup {
    min-width: 0;
    flex: 1 1 auto;
  }

  .brand-lockup span {
    min-width: 0;
  }

  .brand-lockup strong,
  .brand-lockup small {
    max-width: 32vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-actions {
    flex: 0 0 auto;
  }

  .compact-hero {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .hero-copy {
    padding: 2px 6px;
    text-align: center;
  }

  .progress-card {
    width: 100%;
  }

  .game-layout {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .puzzle-panel {
    order: 0;
    width: 100%;
  }

  .side-column {
    display: contents;
  }

  .words-panel {
    order: 1;
    width: 100%;
    overflow: visible;
  }

  .secret-panel {
    order: 2;
    width: 100%;
  }

  .mini-fact {
    order: 3;
    width: 100%;
  }

  .grid-wrap {
    width: 100%;
    min-width: 0;
  }

  .letter-grid {
    --available-grid: min(620px, calc(100vw - 34px));
    max-width: 100%;
    margin-inline: auto;
  }

  .word-list {
    overflow: visible;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .word-chip {
    width: 100%;
    white-space: normal;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 620px) {
  .intro-screen {
    min-height: calc(var(--viewport-height, 100dvh) - 17px);
    padding: 52px 0 12px;
  }

  .intro-language {
    top: 3px;
  }

  .intro-card {
    width: 100%;
    padding: clamp(20px, 6vw, 28px) 14px 24px;
    border-radius: 26px;
  }

  .logo-halo {
    width: clamp(102px, 32vw, 124px);
    height: clamp(102px, 32vw, 124px);
    margin-bottom: 7px;
  }

  .logo-halo::before {
    inset: -7px;
  }

  .logo-halo::after {
    inset: -14px;
  }

  .intro-card h1 {
    font-size: clamp(34px, 12vw, 50px);
  }

  .intro-card h1::after {
    height: 6px;
  }

  .intro-subtitle {
    margin-top: 12px;
    font-size: clamp(13px, 4vw, 16px);
    line-height: 1.7;
  }

  .intro-features {
    margin: 15px auto;
    gap: 5px;
  }

  .intro-features span {
    padding: 5px 7px;
    font-size: 10px;
  }

  .start-button {
    width: min(100%, 310px);
    min-width: 0;
    min-height: 48px;
    font-size: 17px;
  }

  .top-header {
    min-height: 50px;
    gap: 5px;
    padding: 5px 6px;
    border-radius: 16px;
  }

  .brand-lockup {
    gap: 5px;
  }

  .brand-lockup img {
    width: 39px;
    height: 39px;
  }

  .brand-lockup strong {
    max-width: 26vw;
    font-size: 11px;
  }

  .brand-lockup small {
    max-width: 26vw;
    font-size: 8.5px;
  }

  .header-actions {
    gap: 3px;
  }

  .language-button {
    min-height: 38px;
    max-width: 88px;
    padding: 6px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10.5px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 16px;
  }

  .compact-hero {
    gap: 6px;
  }

  .game-kicker {
    margin-bottom: 2px;
    font-size: 10.5px;
  }

  .hero-copy h2 {
    font-size: clamp(25px, 8.5vw, 32px);
  }

  .hero-copy > p:last-child {
    margin-top: 3px;
    font-size: 10px;
    line-height: 1.55;
  }

  .progress-card {
    padding: 8px 10px;
    border-radius: 15px;
  }

  .progress-card p {
    font-size: 9.5px;
    line-height: 1.5;
  }

  .progress-track {
    height: 8px;
    margin-top: 5px;
  }

  .puzzle-panel {
    padding: 8px;
    border-radius: 20px;
  }

  .panel-heading {
    align-items: center;
    gap: 6px;
    margin-bottom: 7px;
  }

  .heading-copy,
  .secret-topline {
    gap: 6px;
  }

  .panel-icon,
  .secret-icon {
    width: 31px;
    height: 31px;
    border-radius: 9px;
    font-size: 14px;
  }

  .panel-heading h3,
  .secret-topline h3 {
    font-size: 12px;
  }

  .panel-heading p,
  .secret-topline p {
    font-size: 8.7px;
  }

  .hint-button {
    min-height: 36px;
    flex: 0 0 auto;
    padding: 6px 8px;
    border-radius: 11px;
    font-size: 10px;
  }

  .hint-card {
    padding: 7px 8px;
  }

  .hint-card p {
    font-size: 9.5px;
  }

  .grid-wrap {
    padding: 4px;
    border-radius: 15px;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32);
  }

  .letter-grid {
    --available-grid: min(100%, calc(100vw - 30px));
    gap: clamp(1px, 0.55vw, 2.5px);
  }

  .letter-cell {
    min-width: 0;
    min-height: 0;
    padding: 0;
    border-radius: clamp(4px, 1.5vw, 6px);
    font-size: clamp(9px, 3.1vw, 14px);
    line-height: 1;
    box-shadow: 0 1px 4px rgba(28, 89, 112, 0.08);
  }

  .letter-cell.is-selected {
    transform: scale(1.02);
  }

  .letter-cell.is-hint-start,
  .letter-cell.is-hint-next,
  .letter-cell.is-hint-end {
    box-shadow: 0 0 0 3px rgba(245, 189, 78, 0.22), 0 5px 10px rgba(167, 112, 8, 0.17);
  }

  .letter-cell.is-hint-start::after,
  .letter-cell.is-hint-next::after,
  .letter-cell.is-hint-end::after {
    top: -5px;
    inset-inline-end: -3px;
    width: 15px;
    height: 15px;
    border-width: 1px;
    font-size: 7px;
  }

  .selection-status {
    min-height: 20px;
    margin-top: 5px;
    padding-inline: 4px;
    font-size: 9.5px;
    line-height: 1.45;
  }

  .words-panel,
  .secret-panel,
  .mini-fact {
    padding: 9px;
    border-radius: 19px;
  }

  .words-panel .panel-heading p {
    display: none;
  }

  .word-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .word-chip {
    min-height: 30px;
    display: grid;
    place-items: center;
    padding: 5px 4px;
    border-radius: 10px;
    font-size: 9.5px;
  }

  .secret-phrase {
    gap: 4px;
  }

  .secret-letter {
    width: clamp(22px, 7vw, 27px);
    height: clamp(29px, 9vw, 33px);
    border-radius: 7px;
    font-size: clamp(13px, 4.4vw, 16px);
  }

  .mini-fact {
    align-items: flex-start;
  }

  .mini-fact p {
    font-size: 9.5px;
    line-height: 1.6;
  }

  .toast {
    bottom: max(10px, env(safe-area-inset-bottom));
    min-width: min(280px, calc(100vw - 18px));
    max-width: calc(100vw - 18px);
    padding: 10px 12px;
    font-size: 10.5px;
  }

  .win-modal {
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .win-card {
    width: 100%;
    max-height: calc(var(--viewport-height, 100dvh) - 16px);
    padding: 18px 12px 14px;
    border-radius: 23px;
  }

  .modal-close {
    top: 8px;
    inset-inline-end: 8px;
    width: 36px;
    height: 36px;
  }

  .win-logo {
    width: 54px;
    height: 64px;
  }

  .trophy {
    font-size: 42px;
  }

  .win-card h2 {
    font-size: clamp(23px, 7vw, 28px);
  }

  .revealed-answer {
    margin: 11px auto;
    padding: 9px 11px;
    font-size: 18px;
  }

  .win-story {
    margin: 9px 0 12px;
    padding: 10px;
    font-size: 10.5px;
    line-height: 1.7;
  }

  .win-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .win-actions button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .brand-lockup span {
    display: none;
  }

  .brand-lockup {
    flex: 0 0 auto;
  }

  .header-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  .language-button {
    max-width: none;
  }

  .game-kicker {
    display: none;
  }

  .hero-copy > p:last-child {
    margin-top: 2px;
  }

  .word-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 350px) {
  .app-shell {
    padding-inline: max(4px, env(safe-area-inset-left));
  }

  .top-header {
    padding-inline: 4px;
  }

  .language-button {
    padding-inline: 6px;
    font-size: 9.5px;
  }

  .icon-button {
    width: 35px;
    height: 35px;
  }

  .puzzle-panel {
    padding: 6px;
  }

  .hint-button span:last-child {
    display: none;
  }

  .hint-button {
    width: 36px;
    padding: 0;
  }

  .letter-grid {
    --available-grid: min(100%, calc(100vw - 20px));
  }
}

/* Phone landscape: keep the board and the word list side-by-side. */
@media (max-width: 920px) and (orientation: landscape) and (max-height: 560px) {
  .app-shell {
    padding:
      max(4px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  .game-screen {
    gap: 5px;
  }

  .top-header {
    position: static;
    min-height: 43px;
    padding-block: 3px;
  }

  .brand-lockup img {
    width: 34px;
    height: 34px;
  }

  .icon-button,
  .language-button {
    min-height: 34px;
    height: 34px;
  }

  .icon-button {
    width: 34px;
  }

  .compact-hero {
    display: none;
  }

  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(210px, 34vw);
    align-items: start;
    gap: 7px;
  }

  .side-column {
    min-width: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    gap: 7px;
  }

  .puzzle-panel,
  .words-panel,
  .secret-panel {
    order: initial;
  }

  .puzzle-panel {
    padding: 6px;
  }

  .panel-heading {
    margin-bottom: 4px;
  }

  .puzzle-panel .panel-heading p,
  .words-panel .panel-heading p,
  .selection-status,
  .mini-fact {
    display: none;
  }

  .hint-card {
    max-height: 55px;
    overflow: auto;
    margin-bottom: 4px;
  }

  .grid-wrap {
    padding: 3px;
  }

  .letter-grid {
    --available-grid: min(100%, calc(var(--viewport-height, 100dvh) - 112px));
  }

  .words-panel {
    min-height: 0;
    max-height: calc(var(--viewport-height, 100dvh) - 58px);
    overflow: hidden;
    padding: 7px;
  }

  .word-list {
    min-height: 0;
    overflow-y: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .word-chip {
    min-height: 25px;
    padding: 3px;
    font-size: 8.5px;
  }

  .secret-panel {
    display: none;
  }
}

@media (max-height: 700px) and (min-width: 921px) {
  .app-shell {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .game-screen {
    height: calc(var(--viewport-height, 100dvh) - 14px);
    min-height: 560px;
    gap: 7px;
  }

  .top-header {
    min-height: 50px;
  }

  .brand-lockup img {
    width: 42px;
    height: 42px;
  }

  .hero-copy h2 {
    font-size: 31px;
  }

  .game-kicker,
  .hero-copy > p:last-child {
    display: none;
  }

  .progress-card {
    padding: 7px 11px;
  }

  .letter-grid {
    --available-grid: min(54dvh, 450px);
  }

  .panel-heading {
    margin-bottom: 6px;
  }

  .mini-fact {
    display: none;
  }

  .side-column {
    grid-template-rows: minmax(0, 1fr) auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
