:root {
  --deep-purple: #3D2169;
  --zaka-purple: #5E3A9A;
  --mid-purple: #7B5BB8;
  --soft-lilac: #E8DEF7;
  --white: #FFFFFF;
  --body: #1F1F2E;
  --border: rgba(255,255,255,0.28);
  --shadow: 0 22px 70px rgba(44, 19, 87, 0.22);
  --radius-xl: 34px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --font: "Montserrat", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--white);
  background: linear-gradient(135deg, #4B2B7F 0%, #6E47B2 52%, #8F5FE0 100%);
  overflow-x: hidden;
  text-shadow: 0 2px 10px rgba(39, 18, 74, .18);
}

h1, h2, h3, strong, .primary-btn, .secondary-btn, .ghost-btn, .option-btn, .drag-item, .puzzle-tile {
  text-shadow: 0 3px 12px rgba(40, 16, 76, .28);
}

body[dir="rtl"] { font-family: "Segoe UI", Tahoma, Arial, sans-serif; }

.page-bg,
.noise,
.circuit { position: fixed; inset: 0; pointer-events: none; }
.page-bg {
  background: radial-gradient(circle at top center, rgba(255,255,255,0.22), transparent 35%),
              linear-gradient(135deg, #4B2B7F 0%, #6E47B2 52%, #8F5FE0 100%);
}
.noise {
  opacity: .08;
  background-image: radial-gradient(rgba(255,255,255,.55) 0.5px, transparent 0.5px);
  background-size: 12px 12px;
  mask-image: linear-gradient(to bottom, transparent, black 20%, black 80%, transparent);
}
.circuit::before,
.circuit::after {
  content: "";
  position: absolute;
  width: 210px;
  height: 360px;
  border: 2px solid rgba(255,255,255,.24);
  border-radius: 28px;
}
.circuit-left::before { top: 120px; left: -90px; border-right: none; }
.circuit-right::before { bottom: 120px; right: -90px; border-left: none; }
.circuit-left::after,
.circuit-right::after {
  width: 200px;
  height: 0;
  border: none;
  background:
    linear-gradient(rgba(255,255,255,.72), rgba(255,255,255,.72)) left 0 top 0/160px 2px no-repeat,
    radial-gradient(circle, rgba(255,255,255,.95) 0 8px, transparent 9px) right 0 top -7px/16px 16px no-repeat,
    linear-gradient(rgba(255,255,255,.72), rgba(255,255,255,.72)) left 28px top 56px/144px 2px no-repeat,
    radial-gradient(circle, rgba(255,255,255,.95) 0 8px, transparent 9px) left 136px top 49px/16px 16px no-repeat,
    linear-gradient(rgba(255,255,255,.72), rgba(255,255,255,.72)) left 12px top 112px/120px 2px no-repeat,
    radial-gradient(circle, rgba(255,255,255,.95) 0 8px, transparent 9px) left 4px top 105px/16px 16px no-repeat,
    linear-gradient(rgba(255,255,255,.72), rgba(255,255,255,.72)) left 24px top 168px/160px 2px no-repeat,
    radial-gradient(circle, rgba(255,255,255,.95) 0 8px, transparent 9px) right 12px top 161px/16px 16px no-repeat;
  opacity: .9;
}
.circuit-left::after { top: 96px; left: 0; }
.circuit-right::after { right: 0; bottom: 88px; transform: scaleX(-1); }

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 18px auto 32px;
  position: relative;
  z-index: 2;
}
.glass {
  background: rgba(61,33,105,0.32);
  border: 1.6px solid rgba(255,255,255,0.22);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  border-radius: 28px;
  padding: 16px 18px;
}
.brand-wrap { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo { width: 168px; height: auto; object-fit: contain; background: #fff; padding: 9px 14px; border-radius: 14px; box-shadow: 0 8px 22px rgba(44,19,87,.22); }
.eyebrow {
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: rgba(255,255,255,.88);
  margin-bottom: 6px;
}
.main-title {
  margin: 0;
  font-size: clamp(1.4rem, 2vw, 1.9rem);
  line-height: 1;
  font-weight: 800;
}
.header-actions { display: flex; gap: 10px; }
button, input, a { font: inherit; }
button { cursor: pointer; border: none; }
.ghost-btn, .secondary-btn, .primary-btn, .name-input, .link-btn {
  border-radius: 999px;
  transition: .22s ease;
}
.ghost-btn {
  background: rgba(255,255,255,.1);
  color: var(--white);
  border: 1px solid rgba(255,255,255,.26);
  padding: 11px 16px;
}
.ghost-btn:hover, .secondary-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.16); }
.primary-btn {
  background: linear-gradient(90deg, var(--deep-purple), var(--zaka-purple));
  color: var(--white);
  padding: 14px 24px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(61, 33, 105, .3);
}
.primary-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.secondary-btn {
  background: rgba(255,255,255,.14);
  color: var(--white);
  border: 1px solid rgba(255,255,255,.28);
  padding: 14px 24px;
}
.link-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.screen { display: none; }
.screen.active { display: block; }
.layout-home {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(270px, .68fr);
  gap: 22px;
  margin-top: 22px;
}
.hero-card, .about-card, .puzzle-layout, .result-card {
  border-radius: var(--radius-xl);
  padding: 30px;
}
.hero-card { min-height: 650px; display: flex; flex-direction: column; justify-content: center; }
.pill {
  width: fit-content;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(61, 33, 105, .35);
  color: var(--white);
  border: 1px solid rgba(255,255,255,.18);
  font-size: .92rem;
  font-weight: 800;
}
.hero-title {
  font-size: clamp(2.3rem, 5vw, 4rem);
  line-height: .96;
  margin: 16px 0 14px;
  font-weight: 800;
}
.hero-copy, .mini-card p, .result-summary, .puzzle-copy, .about-slide p { color: rgba(255,255,255,.93); line-height: 1.7; }
.feature-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 22px 0;
}
.feature-box {
  padding: 18px 14px;
  border-radius: 22px;
  background: rgba(61,33,105,.34);
  border: 1px solid rgba(255,255,255,.18);
  text-align: center;
}
.feature-box strong { display: block; font-size: 1.6rem; margin-bottom: 6px; }
.input-label { font-size: .95rem; font-weight: 600; margin-bottom: 10px; display: inline-block; }
.name-input {
  width: 100%;
  padding: 16px 18px;
  border: 1px solid rgba(255,255,255,.30);
  background: rgba(255,255,255,.94);
  color: var(--body);
  outline: none;
}
.action-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.action-row.center { justify-content: center; }
.action-row.end { justify-content: flex-end; }
.side-stack { display: flex; flex-direction: column; gap: 18px; }
.mini-card { border-radius: 28px; padding: 24px; }
.mini-card h3, .leaderboard-head h3 { margin-top: 0; margin-bottom: 10px; font-size: 1.15rem; }
.inline-link { color: var(--white); font-weight: 800; text-decoration: none; border-bottom: 1px dashed rgba(255,255,255,.7); width: fit-content; }

.about-card { min-height: 680px; display: flex; flex-direction: column; justify-content: center; text-align: center; margin-top: 22px; }
.about-slide { display: none; }
.about-slide.active { display: block; }
.about-slide h2 {
  font-size: clamp(2.2rem, 5vw, 4rem);
  margin: 0 0 20px;
  font-weight: 800;
}
.about-logo { width: min(400px, 82%); margin: 4px auto 20px; display: block; background: #fff; padding: 22px 30px; border-radius: 22px; box-shadow: 0 14px 34px rgba(44,19,87,.24); }
.about-slide p { font-size: 1.28rem; margin: 16px auto; max-width: 760px; }
.about-nav { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 26px; }
.dots { display: flex; gap: 8px; }
.dot { width: 11px; height: 11px; border-radius: 999px; background: rgba(255,255,255,.36); }
.dot.active { background: var(--white); }

.game-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  margin-top: 22px;
}
.status-card, .question-card {
  border-radius: var(--radius-xl);
  padding: 26px;
}
.counter { font-size: 2.2rem; font-weight: 800; margin-bottom: 18px; }
.progress { height: 12px; background: rgba(255,255,255,.12); border-radius: 999px; overflow: hidden; margin-bottom: 22px; }
.progress > div { height: 100%; width: 0%; background: linear-gradient(90deg, var(--soft-lilac), var(--white)); border-radius: inherit; transition: width .25s ease; }
.unlock-card, .tip-card, .stat-box, .question-card, .leaderboard-card, .reminder-card {
  background: rgba(61,33,105,.34);
  border: 1px solid rgba(255,255,255,.18);
}
.unlock-card { border-radius: 22px; padding: 18px; margin-bottom: 18px; }
.letters { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-top: 10px; }
.letters span {
  display: flex; align-items: center; justify-content: center;
  height: 64px; border-radius: 16px; font-size: 1.35rem; font-weight: 800;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  opacity: .45;
}
.letters span.unlocked { opacity: 1; background: rgba(255,255,255,.22); }
.stats-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; margin-bottom: 18px; }
.stat-box { border-radius: 18px; padding: 16px; }
.stat-box span, .metric-box span { display: block; font-size: .9rem; color: rgba(255,255,255,.82); }
.stat-box strong, .metric-box strong { font-size: 1.65rem; display: block; margin-top: 8px; }
.timer-box strong.warning { color: #FFF2A8; }
.timer-box strong.danger { color: #FFD3DC; }
.tip-card { border-radius: 22px; padding: 18px; line-height: 1.65; }
.question-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 18px; }
.question-tag, .question-mode { display: inline-flex; align-items: center; padding: 9px 14px; border-radius: 999px; }
.question-tag { background: rgba(255,255,255,.18); font-weight: 800; }
.question-mode { background: rgba(255,255,255,.08); color: rgba(255,255,255,.86); }
.question-text { font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.4; margin: 0 0 24px; }
.options { display: grid; gap: 12px; }
.option-btn {
  width: 100%;
  text-align: start;
  padding: 18px 18px 18px 64px;
  position: relative;
  border-radius: 22px;
  background: rgba(61,33,105,.34);
  border: 1px solid rgba(255,255,255,.18);
  color: var(--white);
  line-height: 1.6;
}
body[dir="rtl"] .option-btn { padding: 18px 64px 18px 18px; text-align: right; }
.option-btn::before {
  content: attr(data-letter);
  position: absolute; inset-inline-start: 18px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.18); font-weight: 800;
}
.option-btn:hover { background: rgba(255,255,255,.14); transform: translateY(-1px); }
.option-btn.correct { background: rgba(127, 212, 160, .22); border-color: rgba(127,212,160,.62); }
.option-btn.wrong { background: rgba(255, 116, 140, .18); border-color: rgba(255,116,140,.54); }
.option-btn.dimmed { opacity: .6; }
.feedback { min-height: 50px; margin-top: 16px; font-weight: 600; line-height: 1.7; color: rgba(255,255,255,.96); }
.feedback.error { color: #ffe7e7; }
.feedback.success { color: #efffea; }
.center-text { text-align: center; }

.puzzle-layout { margin-top: 22px; }
.puzzle-head { display: flex; justify-content: space-between; gap: 18px; align-items: center; }
.puzzle-head h2 { margin: 12px 0 0; font-size: clamp(1.8rem, 3.6vw, 3rem); }
.puzzle-score { text-align: center; padding: 16px 20px; border-radius: 18px; background: rgba(61,33,105,.34); border: 1px solid rgba(255,255,255,.18); }
.puzzle-score strong { display: block; font-size: 1.8rem; margin-top: 8px; }
.puzzle-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 24px; }
.drag-pool, .drop-zone {
  min-height: 300px; padding: 16px; border-radius: 24px; background: rgba(255,255,255,.08); border: 1px dashed rgba(255,255,255,.36);
  display: flex; flex-direction: column; gap: 12px;
}
.drag-item, .drop-slot {
  border-radius: 18px; padding: 16px 18px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2); color: var(--white);
}
.drag-item { cursor: grab; font-weight: 800; }
.drag-item.selected { outline: 2px solid rgba(255,255,255,.8); background: rgba(255,255,255,.24); }
.drag-item:active { cursor: grabbing; }
.drop-slot { min-height: 62px; display: flex; align-items: center; gap: 12px; }
.drop-slot.over { background: rgba(255,255,255,.18); }
.slot-index {
  width: 34px; height: 34px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.2); font-weight: 800; flex-shrink: 0;
}
.slot-placeholder { color: rgba(255,255,255,.78); }
.drop-content { flex: 1; }
.drag-item.placed { opacity: .45; }

.result-card { margin-top: 22px; }
.result-card h2 { font-size: clamp(2.1rem, 4vw, 3.4rem); margin: 18px 0 10px; }
.result-metrics {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; margin: 24px 0;
}
.metric-box {
  border-radius: 22px; padding: 20px; text-align: center; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18);
}
.reminder-card, .leaderboard-card { border-radius: 24px; padding: 22px; margin-top: 18px; }
.leaderboard-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.leaderboard-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 10px; }
.leaderboard-list li {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center;
  padding: 14px 16px; border-radius: 18px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
}
.rank-badge {
  width: 34px; height: 34px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.18); font-weight: 800;
}
.player-meta small { display: block; color: rgba(255,255,255,.76); margin-top: 4px; }
.score-meta { text-align: end; }
.score-meta strong { display: block; }
.score-meta small { color: rgba(255,255,255,.78); }

@media (max-width: 980px) {
  .layout-home, .game-shell, .puzzle-columns { grid-template-columns: 1fr; }
  .hero-card { min-height: auto; }
  .puzzle-head { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 720px) {
  .app-shell { width: min(100% - 18px, 1000px); }
  .topbar { flex-direction: column; align-items: stretch; }
  .brand-wrap { justify-content: center; }
  .header-actions { justify-content: center; }
  .feature-strip, .result-metrics, .stats-grid { grid-template-columns: 1fr; }
  .hero-card, .about-card, .status-card, .question-card, .puzzle-layout, .result-card { padding: 22px; }
  .about-slide p { font-size: 1.05rem; }
  .question-top { flex-direction: column; align-items: flex-start; }
  .leaderboard-list li { grid-template-columns: 36px 1fr; }
  .score-meta { grid-column: 2; text-align: start; }
}


/* Premium image puzzle */
.image-puzzle-wrap {
  display: grid;
  grid-template-columns: minmax(220px, 0.62fr) minmax(300px, 1fr);
  gap: 22px;
  align-items: start;
  margin-top: 24px;
}

.reference-panel,
.image-puzzle-wrap > div:last-child {
  padding: 18px;
  border-radius: 28px;
  background: rgba(61,33,105,.36);
  border: 1px solid rgba(255,255,255,.22);
}

.reference-panel img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 24px;
  border: 2px solid rgba(255,255,255,.26);
  box-shadow: 0 16px 40px rgba(44, 19, 87, .24);
}

.puzzle-board {
  width: min(100%, 540px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
  border-radius: 28px;
  background: rgba(255,255,255,.14);
  border: 2px solid rgba(255,255,255,.30);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 18px 50px rgba(44, 19, 87, .26);
}

.puzzle-tile {
  border: 1px solid rgba(255,255,255,.42);
  border-radius: 16px;
  background-size: 300% 300%;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06), 0 8px 18px rgba(44,19,87,.18);
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.puzzle-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.18), transparent 42%, rgba(0,0,0,.12));
  pointer-events: none;
}

.puzzle-tile:hover,
.puzzle-tile.selected {
  transform: translateY(-2px) scale(1.015);
  border-color: rgba(255,255,255,.90);
  box-shadow: 0 0 0 3px rgba(255,255,255,.24), 0 14px 30px rgba(44,19,87,.28);
}

.puzzle-tile.selected::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 12px;
  border: 3px solid rgba(255,255,255,.88);
  z-index: 2;
  pointer-events: none;
}

@media (max-width: 980px) {
  .image-puzzle-wrap { grid-template-columns: 1fr; }
  .reference-panel img { max-width: 260px; margin: 0 auto; }
  .puzzle-board { margin: 0 auto; }
}


/* ================= Tiered game additions ================= */
:root { --tier-accent: #8F5FE0; }

/* Tint the progress bar with the active tier color */
.progress > div { background: linear-gradient(90deg, var(--tier-accent), var(--white)); }

/* Status header: label + tier badge */
.status-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.tier-badge {
  display: inline-flex; align-items: center;
  padding: 6px 12px; border-radius: 999px;
  font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--tier-accent);
  background: rgba(255,255,255,.08);
  border: 1.5px solid var(--tier-accent);
}
.streak-badge {
  margin: -6px 0 18px;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(255, 93, 143, .16); border: 1px solid rgba(255,180,120,.5);
  color: #FFE1B0; font-weight: 800; text-align: center; letter-spacing: .04em;
}

/* Two-option (True/False) layout */
.options.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .options.two-col { grid-template-columns: 1fr; } }

/* Tier intro interstitial */
.tier-intro-card {
  border-radius: var(--radius-xl);
  padding: 48px 34px;
  margin-top: 22px;
  min-height: 460px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  position: relative; overflow: hidden;
}
.tier-intro-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 8px;
  background: linear-gradient(90deg, transparent, var(--tier-accent), transparent);
}
.tier-intro-round {
  text-transform: uppercase; letter-spacing: .28em; font-size: .82rem; font-weight: 700;
  color: rgba(255,255,255,.82); margin-bottom: 16px;
}
.tier-intro-name {
  font-size: clamp(2.6rem, 7vw, 5rem); font-weight: 800; line-height: .95;
  margin: 0 0 18px; letter-spacing: .02em;
  text-shadow: 0 6px 30px rgba(0,0,0,.35);
}
.tier-intro-desc { font-size: 1.2rem; max-width: 560px; color: rgba(255,255,255,.92); line-height: 1.6; }
.tier-intro-meta {
  margin-top: 22px; padding: 10px 20px; border-radius: 999px;
  background: rgba(255,255,255,.1); border: 1px solid var(--tier-accent);
  font-weight: 800; letter-spacing: .06em;
}

/* Trace the Workflow bonus */
.workflow-list { display: grid; gap: 12px; margin-top: 24px; }
.workflow-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: start;
  padding: 18px 18px; border-radius: 20px;
  background: rgba(61,33,105,.34); border: 1px solid rgba(255,255,255,.2);
  color: var(--white); cursor: grab; line-height: 1.5;
}
body[dir="rtl"] .workflow-item { text-align: right; }
.workflow-item:hover { background: rgba(255,255,255,.14); transform: translateY(-1px); }
.workflow-item:active { cursor: grabbing; }
.workflow-item.selected { outline: 2px solid rgba(255,255,255,.85); background: rgba(255,255,255,.22); }
.workflow-num {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--tier-accent); color: #241245; font-weight: 800;
}
.workflow-text { flex: 1; font-weight: 600; }
.workflow-grip { opacity: .5; font-weight: 800; letter-spacing: -2px; }

/* Results: rank title + tier breakdown */
.rank-title {
  width: fit-content; margin: 4px auto 6px;
  padding: 8px 20px; border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,255,255,.16), rgba(255,255,255,.06));
  border: 1px solid rgba(255,255,255,.3);
  font-weight: 800; letter-spacing: .06em; text-transform: uppercase; font-size: .95rem;
}
.result-card { text-align: center; }
.result-card .result-summary, .result-card .reminder-card, .result-card .leaderboard-card { text-align: start; }
.result-metrics { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.tier-breakdown-wrap { margin: 6px 0 20px; }
.tier-breakdown-wrap .eyebrow { text-align: center; margin-bottom: 10px; }
.tier-breakdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tier-chip {
  border-radius: 18px; padding: 14px 10px; text-align: center;
  background: rgba(255,255,255,.08); border: 1.5px solid rgba(255,255,255,.2);
}
.tier-chip span { display: block; font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.tier-chip strong { font-size: 1.3rem; }
@media (max-width: 720px) {
  .tier-breakdown { grid-template-columns: repeat(2, 1fr); }
  .tier-intro-card { min-height: 360px; padding: 34px 22px; }
}
