:root {
  --green: #007a3d;
  --green-dark: #005c2e;
  --green-light: #1a9d55;
  --red: #ce1126;
  --red-dark: #9b0d1c;
  --gold: #c9a227;
  --gold-light: #e8c547;
  --black: #1a1a1a;
  --white: #fafafa;
  --cream: #f5f0e6;
  --blue-arrow: #2563eb;
  --yellow-arrow: #eab308;
  --barrier: #64748b;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  --radius: 14px;
}

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

html, body {
  min-height: 100%;
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--black);
  color: var(--black);
}

#app {
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: block;
}

/* ===== Main Menu ===== */
#screen-menu {
  position: relative;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: max(2rem, calc(env(safe-area-inset-top, 0px) + 1.25rem)) 1rem 3rem;
  overflow-x: hidden;
  overflow-y: auto;
}

#screen-menu.active {
  display: flex;
}

.menu-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(0, 122, 61, 0.92), rgba(0, 92, 46, 0.88)),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 20px,
      rgba(255, 255, 255, 0.03) 20px,
      rgba(255, 255, 255, 0.03) 40px
    );
  z-index: 0;
}

.menu-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 80%, rgba(206, 17, 38, 0.25), transparent 50%),
              radial-gradient(circle at 80% 20%, rgba(201, 162, 39, 0.2), transparent 45%);
}

.menu-header,
.menu-intro,
.menu-cards,
.menu-footer {
  position: relative;
  z-index: 1;
}

.menu-intro {
  max-width: min(720px, 100%);
  margin: 0 auto 1.75rem;
  padding: 1.25rem 1.5rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  color: var(--white);
  text-align: right;
  line-height: 1.7;
}

.menu-intro h2 {
  font-size: 1.2rem;
  color: var(--gold-light);
  margin-bottom: 0.75rem;
}

.menu-intro h3 {
  font-size: 1.05rem;
  color: var(--gold);
  margin: 1.25rem 0 0.5rem;
}

.menu-intro p {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.88);
  margin-bottom: 0.65rem;
}

.menu-intro a {
  color: var(--gold-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.menu-intro a:hover {
  color: #fff;
}

.menu-edu-more {
  margin-top: 1.5rem;
}

.menu-game-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.menu-game-links,
.in-game-edu-links {
  font-size: 0.82rem;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.82);
  text-align: right;
  margin: 0;
  padding: 0.35rem 0.15rem 0.15rem;
}

.menu-game-links a,
.in-game-edu-links a {
  color: var(--gold-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.menu-game-links a:hover,
.in-game-edu-links a:hover {
  color: #fff;
}

.in-game-edu-links {
  position: relative;
  z-index: 2;
  max-width: 1100px;
  margin: 0.35rem auto 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.35);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.game-learn-panel {
  margin-top: 0.75rem;
}

.game-learn-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.game-learn-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.game-learn-links a {
  color: var(--gold-light);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.game-learn-links a:hover {
  color: #fff;
}

.game-learn-panel--memory {
  margin-top: 1.25rem;
  padding: 1rem;
  background: rgba(0, 92, 46, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  text-align: right;
}

.menu-footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 0;
  margin-bottom: 1rem;
}

.menu-header {
  text-align: center;
  color: var(--white);
  margin-bottom: 2rem;
  max-width: min(720px, 100%);
  padding-top: max(1.25rem, calc(env(safe-area-inset-top, 0px) + 0.75rem));
  overflow: visible;
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
  margin-inline: auto;
  padding-top: 0.5rem;
  overflow: visible;
  background: transparent !important;
  border: none;
  box-shadow: none;
}

.brand-logo,
.game-header-logo,
.about-logo,
.question-card-emblem {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: center center;
  overflow: visible;
  background: transparent !important;
  border: none !important;
  box-shadow: none;
  border-radius: 0;
}

.brand-logo {
  padding-top: 0.4rem;
  clip-path: none;
  -webkit-clip-path: none;
  overflow: visible;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.35));
}

.brand-logo--emblem {
  width: clamp(88px, 22vw, 108px);
  height: auto;
  max-width: 108px;
  max-height: none;
  aspect-ratio: auto;
}

.about-logo {
  width: clamp(80px, 20vw, 96px);
  height: auto;
  margin: 0 auto 1rem;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35));
}

.org-name-ar {
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
  font-weight: 700;
  color: #fff;
  line-height: 1.55;
  max-width: 22em;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}

.org-name-en {
  font-size: clamp(0.72rem, 2vw, 0.85rem);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.45;
  max-width: 26em;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.game-title {
  font-size: clamp(1.35rem, 4.2vw, 2rem);
  font-weight: 800;
  line-height: 1.35;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  color: var(--gold-light);
  margin-top: 0.5rem;
}

.tagline {
  font-size: 1.1rem;
  color: var(--gold-light);
  margin-top: 0.75rem;
  font-weight: 600;
}

.menu-cards {
  display: grid;
  gap: 1.25rem;
  width: min(520px, 100%);
}

.menu-cards .menu-card {
  width: 100%;
}

.menu-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 1.5rem 1.75rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: right;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
}

.menu-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.28);
}

.menu-card.primary {
  background: linear-gradient(135deg, var(--cream), #fff);
  border-right: 6px solid var(--red);
}

.menu-card.secondary {
  background: linear-gradient(135deg, #fff, var(--cream));
  border-right: 6px solid var(--gold);
}

.card-icon {
  font-size: 2rem;
}

.card-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--green-dark);
}

.card-desc {
  font-size: 0.95rem;
  color: #555;
  line-height: 1.5;
}

.menu-footer {
  margin-top: 2rem;
}

.menu-footer a {
  color: var(--gold-light);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px dashed rgba(255,255,255,0.4);
}

.menu-footer a:hover {
  color: #fff;
}

.menu-footer .footer-sep {
  color: rgba(255, 255, 255, 0.35);
  margin: 0 0.35rem;
}

.menu-contact {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  width: 100%;
}

.menu-contact-org {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gold-light, #e6c866);
  margin: 0 0 0.35rem;
}

.menu-contact-links {
  font-size: 0.78rem;
  line-height: 1.7;
  margin: 0;
  color: rgba(245, 240, 232, 0.85);
}

.menu-contact-links a {
  color: var(--gold, #c9a227);
  text-decoration: none;
}

.menu-contact-links a:hover {
  text-decoration: underline;
}

.players-panel-hint {
  font-size: 0.82rem;
  color: #555;
  margin: 0 0 0.65rem;
  line-height: 1.45;
}

.player-count-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}

.player-count-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #444;
}

.player-count-picker {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.player-count-btn {
  font-family: inherit;
  min-width: 2.1rem;
  height: 2.1rem;
  padding: 0 0.55rem;
  border-radius: 8px;
  border: 2px solid rgba(0, 122, 61, 0.35);
  background: #fff;
  color: var(--green-dark);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.player-count-btn.is-active {
  background: var(--green);
  border-color: var(--green-dark);
  color: #fff;
}

.player-count-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.player-chip .player-name-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  padding: 0.3rem 0.45rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  background: #fafafa;
  color: #222;
}

.player-chip .player-name-input:focus {
  outline: 2px solid rgba(201, 162, 39, 0.45);
  border-color: var(--gold);
  background: #fff;
}

.player-chip .player-name-input:disabled {
  background: transparent;
  border-color: transparent;
  color: inherit;
  padding-left: 0;
  padding-right: 0;
}

/* ===== Game Header ===== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(90deg, var(--green-dark), var(--green));
  color: var(--white);
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  overflow: visible;
}

.game-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.game-header-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  flex: 1;
  min-width: 0;
  background: none;
}

.game-header-logo {
  width: clamp(36px, 8vw, 44px);
  height: auto;
  max-width: 44px;
  max-height: none;
  flex-shrink: 0;
  padding: 0;
  clip-path: none;
  -webkit-clip-path: none;
  overflow: visible;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.25));
}

.game-header-brand h2 {
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-back,
.btn-help {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--white);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-back:hover,
.btn-help:hover {
  background: rgba(255,255,255,0.25);
}

/* ===== Train Game Layout ===== */
.train-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  min-height: calc(100vh - 56px);
  background: var(--cream);
}

.train-sidebar {
  background: #fff;
  border-left: 1px solid #ddd;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.panel {
  background: var(--cream);
  border-radius: 10px;
  padding: 0.85rem;
  border: 1px solid #e5dcc8;
}

.panel h3 {
  font-size: 0.95rem;
  color: var(--green-dark);
  margin-bottom: 0.6rem;
  font-weight: 700;
}

.highlight {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--red);
}

.panel-current-turn {
  border: 2px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.current-turn-display {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  background: #fff;
  border: 2px solid #e5dcc8;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.current-turn-display.is-live {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.25);
}

.current-turn-display.turn-bump {
  animation: turn-bump 0.55s ease;
}

@keyframes turn-bump {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.04); box-shadow: 0 0 16px rgba(201, 162, 39, 0.45); }
}

.current-player-dot {
  width: auto;
  height: auto;
  flex-shrink: 0;
  font-size: 1.4rem;
  line-height: 1;
  border: none;
  border-radius: 0;
  background: none !important;
  transition: transform 0.3s, filter 0.3s;
}

.current-turn-display:not(.is-live) .current-player-dot {
  display: none;
}

.current-turn-display.is-live .current-player-dot {
  display: block;
}

.current-player-name {
  font-size: clamp(1.15rem, 3.5vw, 1.45rem);
  font-weight: 800;
  line-height: 1.2;
  margin: 0;
}

.current-player-name.is-waiting {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--green-dark);
}

.status-text {
  font-size: 0.9rem;
  color: #444;
  line-height: 1.55;
  margin-top: 0.35rem;
  font-weight: 600;
}

#players-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  background: #fff;
  border-radius: 8px;
  font-size: 0.85rem;
  border: 2px solid transparent;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.player-chip.active {
  border-color: var(--gold);
  background: #fffbeb;
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.35), 0 4px 14px rgba(201, 162, 39, 0.25);
  transform: scale(1.04);
  animation: active-player-pulse 1.6s ease-in-out infinite;
}

.player-chip.active .player-key {
  transform: scale(1.15);
  filter: drop-shadow(0 0 4px var(--key-color));
}

.player-chip.turn-flash {
  animation: turn-flash 0.85s ease;
}

@keyframes active-player-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.35), 0 4px 14px rgba(201, 162, 39, 0.2); }
  50% { box-shadow: 0 0 0 4px rgba(201, 162, 39, 0.5), 0 6px 20px rgba(201, 162, 39, 0.35); }
}

@keyframes turn-flash {
  0%, 100% { background: #fffbeb; }
  25%, 75% { background: #fef08a; transform: scale(1.06); }
  50% { background: #fde047; transform: scale(1.08); }
}

.player-chip .player-name {
  font-weight: 700;
}

.player-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(0,0,0,0.15);
}

.player-pos {
  margin-right: auto;
  font-weight: 800;
  font-size: 0.88rem;
  color: var(--green-dark);
  background: rgba(0, 122, 61, 0.12);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  min-width: 2.4rem;
  text-align: center;
  letter-spacing: 0.02em;
}

.player-chip.active .player-pos {
  background: rgba(201, 162, 39, 0.2);
  color: #92400e;
}

.player-remove-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  margin-right: -0.15rem;
  border: none;
  border-radius: 50%;
  background: rgba(185, 28, 28, 0.1);
  color: #b91c1c;
  font-size: 1rem;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}

.player-remove-btn:hover {
  background: #b91c1c;
  color: #fff;
  transform: scale(1.08);
}

.player-remove-btn:focus-visible {
  outline: 2px solid #b91c1c;
  outline-offset: 2px;
}

.btn-small,
.btn-primary,
.btn-gold,
.btn-outline {
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  width: 100%;
  margin-top: 0.35rem;
  transition: opacity 0.2s, transform 0.15s;
}

.btn-small {
  background: var(--green-light);
  color: #fff;
  width: auto;
}

.btn-primary {
  background: var(--green);
  color: #fff;
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--black);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--green);
  color: var(--green-dark);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Train sidebar — solid opaque controls (no washed-out transparent buttons) */
.train-sidebar .actions-panel {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.train-sidebar .actions-panel .btn-primary {
  background: var(--green);
  color: #fff;
  border: 2px solid var(--green-dark);
  opacity: 1;
}

.train-sidebar .actions-panel .btn-primary:disabled {
  background: var(--green);
  color: #fff;
  opacity: 0.5;
}

.train-sidebar .actions-panel .btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--black);
  border: 2px solid #b8860b;
  opacity: 1;
}

.train-sidebar .actions-panel .btn-gold:disabled {
  opacity: 0.5;
}

.train-sidebar .actions-panel .btn-outline {
  background: #fff;
  border: 2px solid var(--green);
  color: var(--green-dark);
  opacity: 1;
}

.train-sidebar .actions-panel .btn-outline:disabled {
  background: #fff;
  color: var(--green-dark);
  opacity: 0.5;
}

.train-sidebar .actions-panel .btn-rewarded {
  background: linear-gradient(135deg, #fde68a, #fef3c7);
  border: 2px solid var(--gold);
  color: var(--green-dark);
  opacity: 1;
}

.train-sidebar .actions-panel .btn-rewarded:disabled {
  background: linear-gradient(135deg, #fde68a, #fef3c7);
  opacity: 0.5;
}

button:not(:disabled):hover {
  transform: scale(1.02);
}

.legend {
  list-style: none;
  font-size: 0.78rem;
  line-height: 1.8;
  color: #444;
}

.legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

.dot.city { background: var(--green); }
.dot.blue { background: var(--blue-arrow); }
.dot.yellow { background: var(--yellow-arrow); }
.dot.barrier { background: var(--barrier); }
.dot.event { background: var(--red); }

.board-wrap {
  padding: 0.75rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: linear-gradient(180deg, #e8f4ec 0%, #d4e8dc 100%);
  min-height: 320px;
}

.board {
  width: 100%;
  max-width: 900px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 3px solid var(--gold);
  overflow: hidden;
  background: #1a472a;
}

.board-map {
  position: relative;
  width: 100%;
  line-height: 0;
  aspect-ratio: 999 / 1400;
  background: #1a472a;
}

.board-map-img {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  pointer-events: none;
  object-fit: contain;
}

.board-tokens-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.map-token {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
}

.map-highlight {
  position: absolute;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 0 12px rgba(201, 162, 39, 0.85);
  animation: map-pulse 0.6s ease infinite alternate;
  z-index: 1;
  pointer-events: none;
}

@keyframes map-pulse {
  from { transform: translate(-50%, -50%) scale(0.85); opacity: 0.7; }
  to { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
}

.key-token {
  display: inline-block;
  font-size: 1.35rem;
  line-height: 1;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8)) drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
  text-shadow: 0 0 6px var(--key-color, #fff);
}

.key-token-active {
  animation: key-glow 1.2s ease-in-out infinite;
  transform: scale(1.2);
}

@keyframes key-glow {
  0%, 100% { filter: drop-shadow(0 0 4px var(--key-color)) drop-shadow(0 0 8px var(--key-color)); }
  50% { filter: drop-shadow(0 0 8px var(--key-color)) drop-shadow(0 0 14px var(--key-color)); }
}

.player-key {
  font-size: 1.1rem;
  line-height: 1;
  filter: drop-shadow(0 0 3px var(--key-color));
}

.level-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.55rem 0.35rem;
  border: 2px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.level-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}

.level-btn.is-active {
  border-color: var(--level-hex);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--level-hex) 35%, transparent);
}

.level-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-btn-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--level-hex);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.level-btn-name {
  color: var(--green-dark);
}

.level-btn-count {
  font-size: 0.65rem;
  color: #888;
  font-weight: 600;
}

.level-btn--low .level-btn-count {
  color: #b45309;
  font-weight: 800;
}

.level-btn--low.is-active {
  box-shadow: 0 0 0 2px rgba(180, 83, 9, 0.35);
}

.train-pool-warning {
  margin-top: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  font-size: 0.82rem;
  line-height: 1.45;
  font-weight: 600;
}

.pool-warn-inline {
  margin-top: 0.75rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 0.9rem;
}

.btn-pulse-ready {
  animation: btn-pulse-ready 1.4s ease-in-out infinite;
}

@keyframes btn-pulse-ready {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201, 162, 39, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(201, 162, 39, 0.12); }
}

.panel-level h3 {
  margin-bottom: 0.65rem;
}

/* Legacy grid cells — kept for reference, unused */
.cell-hidden { display: none; }

.cell {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 0.65rem;
  font-weight: 700;
  text-align: center;
  padding: 2px 2px 13px;
  line-height: 1.1;
  border: 1px solid rgba(0, 0, 0, 0.12);
  min-height: 52px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(2px);
}

.cell-num {
  font-size: 0.7rem;
  color: #888;
  position: absolute;
  top: 2px;
  left: 4px;
}

.cell-label {
  font-size: 0.58rem;
  color: var(--green-dark);
  font-weight: 800;
  padding-top: 8px;
}

.cell.city { background: #e8f5e9; border-color: var(--green-light); }
.cell.barrier { background: #eceff1; border-color: var(--barrier); }
.cell.event { background: #ffebee; border-color: var(--red); }
.cell.blue-start { box-shadow: inset 0 0 0 2px var(--blue-arrow); background: rgba(219, 234, 254, 0.92); }
.cell.yellow-start { box-shadow: inset 0 0 0 2px var(--yellow-arrow); background: rgba(254, 243, 199, 0.92); }
.cell.yellow-head { box-shadow: inset 0 0 0 2px var(--yellow-arrow); }
.cell.start-cell { background: #fff8e1; }
.cell.end-cell { background: #fce4ec; border: 2px solid var(--red); }

.cell .tokens {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 2px;
  justify-items: center;
  align-items: center;
  max-width: calc(100% - 6px);
  pointer-events: none;
  z-index: 2;
}

.tokens-1 { grid-template-columns: 1fr; }
.tokens-2 { grid-template-columns: repeat(2, auto); }
.tokens-3 { grid-template-columns: repeat(3, auto); }
.tokens-4 { grid-template-columns: repeat(2, auto); }
.tokens-5 { grid-template-columns: repeat(3, auto); }
.tokens-6 { grid-template-columns: repeat(3, auto); }

.token {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.token-active {
  transform: scale(1.35);
  border: 2px solid #fff;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.25),
    0 0 8px 3px rgba(201, 162, 39, 0.85),
    0 0 14px 5px rgba(201, 162, 39, 0.45);
  animation: token-glow 1.4s ease-in-out infinite;
  z-index: 3;
  position: relative;
}

@keyframes token-glow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 0 8px 3px rgba(201, 162, 39, 0.75); }
  50% { box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 0 12px 5px rgba(201, 162, 39, 1); }
}

.cell-move-highlight {
  animation: cell-pulse 0.35s ease;
  box-shadow: inset 0 0 0 3px var(--gold), 0 0 12px rgba(201, 162, 39, 0.55) !important;
  z-index: 1;
}

@keyframes cell-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.tokens-4 .token,
.tokens-5 .token,
.tokens-6 .token {
  width: 8px;
  height: 8px;
}

.cell-move {
  font-size: 0.55rem;
  color: var(--red);
  font-weight: 800;
}

/* ===== Memory Game ===== */
#screen-memory {
  background: linear-gradient(180deg, #0f3460 0%, #16213e 50%, #1a1a2e 100%);
  padding-bottom: 2rem;
}

.memory-stage-picker {
  padding: 1.25rem 1rem 1.5rem;
  max-width: 420px;
  margin: 0 auto;
}

.memory-stage-picker-title {
  margin: 0 0 0.35rem;
  text-align: center;
  color: var(--gold-light);
  font-size: 1.15rem;
}

.memory-stage-picker-hint {
  margin: 0 0 1rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.85rem;
}

.memory-stage-selector {
  margin-bottom: 1rem;
}

.memory-stage-selector .memory-stage-btn {
  background: rgba(255, 255, 255, 0.95);
  border-color: color-mix(in srgb, var(--level-hex) 45%, rgba(0, 0, 0, 0.12));
  min-height: 72px;
}

.memory-stage-selector .memory-stage-btn:hover:not(:disabled) {
  border-color: var(--level-hex);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--level-hex) 30%, transparent);
}

.memory-stage-selector .memory-stage-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.memory-stage-selector .memory-stage-btn .level-btn-name {
  font-size: 0.9rem;
}

.memory-play-all-btn {
  display: block;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  font-size: 0.95rem;
}

.memory-game-area[hidden] {
  display: none !important;
}

.memory-change-stage {
  width: auto;
  min-width: min(320px, 90vw);
  padding: 0.65rem 1.5rem;
}

.memory-game-area {
  display: block;
}

.memory-stage-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.75rem 1.5rem;
  padding: 0.75rem 1rem 0;
  color: var(--gold-light);
  font-size: 0.95rem;
  border-top: 3px solid var(--memory-stage-accent, var(--gold));
  transition: border-color 0.35s ease;
}

.memory-stage-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.5rem;
  padding: 0.25rem 0.85rem;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #1a1a2e;
  background: var(--memory-stage-accent, var(--gold));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.memory-stage-bar[data-stage-color="yellow"] {
  --memory-stage-accent: #e6b422;
}

.memory-stage-bar[data-stage-color="green"] {
  --memory-stage-accent: #3d9b4a;
}

.memory-stage-bar[data-stage-color="brown"] {
  --memory-stage-accent: #8b5a2b;
}

.memory-stage-bar[data-stage-color="red"] {
  --memory-stage-accent: #c62828;
}

.memory-stage-bar[data-stage-color="yellow"] .memory-stage-label {
  color: #f5d76e;
}

.memory-stage-bar[data-stage-color="green"] .memory-stage-label {
  color: #8fd99a;
}

.memory-stage-bar[data-stage-color="brown"] .memory-stage-label {
  color: #d4a574;
}

.memory-stage-bar[data-stage-color="red"] .memory-stage-label {
  color: #ef9a9a;
}

.memory-stage-label {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--white);
}

.memory-global-progress {
  color: rgba(255, 255, 255, 0.85);
}

.memory-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem;
  padding: 1rem;
  color: var(--gold-light);
  font-size: 1rem;
}

.memory-message {
  text-align: center;
  color: rgba(255,255,255,0.85);
  padding: 0 1rem 1rem;
  font-size: 1rem;
  transition: color 0.25s ease;
}

.memory-message--success {
  color: #86efac;
  font-weight: 700;
}

.memory-message--miss {
  color: #fca5a5;
}

.memory-progress-wrap {
  max-width: 520px;
  margin: 0 auto 0.75rem;
  padding: 0 1rem;
}

.memory-progress-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.memory-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), #fde68a);
  transition: width 0.35s ease;
}

.memory-stage-bar--transition {
  animation: memory-stage-swap 0.45s ease;
}

.memory-stage-bar--complete .memory-stage-label {
  color: #86efac;
}

@keyframes memory-stage-swap {
  0% { opacity: 1; transform: translateY(0); }
  45% { opacity: 0.35; transform: translateY(-6px); }
  100% { opacity: 1; transform: translateY(0); }
}

.memory-card.just-matched .memory-card-inner {
  animation: memory-match-pop 0.55s ease;
}

@keyframes memory-match-pop {
  0%, 100% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.06); }
}

.memory-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 1rem;
}

.memory-card {
  aspect-ratio: 3/4;
  perspective: 800px;
  cursor: pointer;
}

.memory-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s;
  transform-style: preserve-3d;
}

.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
  transform: rotateY(180deg);
}

.memory-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.3;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.memory-front {
  background: linear-gradient(135deg, #5c2d91, #3d1f6e);
  color: var(--white);
  border: 2px solid #8b5e3c;
  padding: 0;
}

.memory-front::before {
  content: '🃏';
  font-size: 1.8rem;
}

.memory-back {
  background: #e9b94d;
  color: var(--green-dark);
  transform: rotateY(180deg);
  border: 2px solid #8b5e3c;
  padding: 0;
  overflow: hidden;
}

.memory-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.memory-card.matched .memory-back {
  border-color: var(--green-light);
  filter: brightness(1.05);
}

/* ===== Question cards — HTML only, level colors ===== */
.question-card-wrap {
  text-align: center;
}

.pt-card {
  position: relative;
  max-width: min(380px, 92vw);
  margin: 0 auto;
  background: var(--level-color, #eab308);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.35);
}

.pt-card--html {
  padding: 1rem 1.1rem 1.25rem;
  min-height: auto;
}

.pt-card--yellow { --level-color: #eab308; background: #eab308; }
.pt-card--green { --level-color: #16a34a; background: #16a34a; }
.pt-card--red { --level-color: #dc2626; background: #dc2626; }
.pt-card--brown { --level-color: #92400e; background: #92400e; }
.pt-card--purple { --level-color: #5c2d91; background: #5c2d91; }

.pt-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.pt-level-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.pt-city-badge {
  display: inline-block;
  margin-inline-start: 0.5rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(22, 163, 74, 0.35);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.pt-city-fact {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  line-height: 1.5;
  opacity: 0.92;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
}

.pt-steps-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.35);
}

.pt-step {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.15);
  color: #fff;
}

.pt-step--correct {
  background: rgba(255, 255, 255, 0.22);
}

.pt-step--wrong {
  background: rgba(0, 0, 0, 0.22);
}

.pt-card--html .pt-card-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: center;
}

.pt-card--red {
  background: #dc2626;
}

.pt-card--purple {
  background: #5c2d91;
}

/* Photo mode — original PDF card image + color-matched overlay */
.pt-card--photo {
  padding: 0;
}

.pt-card--photo .pt-card-content {
  display: none;
}

.pt-card-photo {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: top;
}

.pt-card--photo.pt-card--purple .pt-card-color-cover {
  top: 40%;
  left: 13%;
  right: 13%;
  bottom: 13%;
  background: #5c2d91;
}

.pt-card--photo.pt-card--red .pt-card-color-cover {
  top: 42%;
  left: 13%;
  right: 13%;
  bottom: 13%;
  background: #c41e3a;
}

.pt-card-color-cover {
  position: absolute;
  z-index: 2;
  background: #5c2d91;
  pointer-events: none;
}

.question-card-emblem {
  position: absolute;
  top: 0.5rem;
  inset-inline-end: 0.5rem;
  width: clamp(48px, 15vw, 60px);
  height: auto;
  max-height: 64px;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.35));
}

.pt-section {
  position: relative;
  text-align: center;
}

.pt-label {
  display: inline-block;
  background: #fff;
  color: #5c2d91;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.35rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.pt-question {
  flex: 1;
}

.pt-question-text {
  color: #fff;
  font-size: clamp(0.95rem, 3.8vw, 1.12rem);
  font-weight: 800;
  line-height: 1.55;
  margin: 0;
  padding: 0.35rem 0.25rem 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Answer options — below card, outside purple border */
.question-card-options {
  margin-top: 1rem;
  padding: 0 0.25rem;
}

.question-card-option-btns {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 0.65rem;
}

.question-card-option-btn {
  min-width: 7rem;
  font-size: 1.1rem;
  font-weight: 800;
  padding: 0.75rem 1.5rem;
}

.question-card-option-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.question-card-hint {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0;
  line-height: 1.5;
}

.question-card-hint--error {
  color: var(--red);
  font-weight: 600;
}

.cards-loading-status {
  font-size: 0.85rem;
  color: var(--gold);
  margin-top: 0.35rem;
  font-weight: 600;
}

.cards-loading-status.hidden {
  display: none;
}

.cards-loading-status--error {
  color: var(--red);
}

.step-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.step-btn {
  font-family: inherit;
  font-weight: 700;
  padding: 0.65rem;
  border: 2px solid var(--green);
  border-radius: 8px;
  background: var(--cream);
  cursor: pointer;
  font-size: 0.9rem;
}

.step-btn:hover {
  background: #e8f5e9;
  border-color: var(--green-dark);
}

.memory-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  margin-top: 1.5rem;
}

.memory-actions .btn-gold,
.memory-actions .btn-rewarded,
.memory-actions .btn-outline {
  width: auto;
  min-width: min(320px, 90vw);
  padding: 0.75rem 2rem;
}

.memory-actions .btn-outline {
  border-color: var(--gold-light);
  color: var(--gold-light);
  background: rgba(255, 255, 255, 0.06);
}

.memory-actions .btn-outline:hover {
  background: rgba(255, 255, 255, 0.12);
}

.memory-actions .btn-rewarded {
  padding: 0.55rem 1.5rem;
}

.memory-next-stage {
  font-size: 1.05rem;
  animation: memory-stage-pulse 1.5s ease-in-out infinite;
}

@keyframes memory-stage-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233, 185, 77, 0.45); }
  50% { box-shadow: 0 0 12px 4px rgba(233, 185, 77, 0.35); }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 5000;
  padding: max(1rem, env(safe-area-inset-top, 0px)) 1rem max(1rem, env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  max-height: none;
  overflow: visible;
  padding: 1.5rem;
  position: relative;
  box-shadow: var(--shadow);
  animation: modalIn 0.25s ease;
  margin: auto;
  flex-shrink: 0;
}

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

.modal-close {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #888;
  line-height: 1;
}

#modal-title {
  font-size: 1.2rem;
  color: var(--green-dark);
  margin-bottom: 1rem;
  padding-left: 2rem;
}

#modal-body {
  line-height: 1.7;
  color: #333;
}

#modal-body .question-text {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--black);
}

.option-btn {
  display: block;
  width: 100%;
  text-align: right;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: var(--cream);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, background 0.2s;
}

.option-btn:hover {
  border-color: var(--green);
  background: #e8f5e9;
}

.option-btn.correct {
  border-color: var(--green);
  background: #c8e6c9;
}

.option-btn.wrong {
  border-color: var(--red);
  background: #ffcdd2;
}

.modal-actions.question-card-actions {
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}

.modal-actions.question-card-actions .question-card-option-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}

.modal-actions.question-card-actions .question-card-option-btn {
  flex: 1 1 auto;
  min-width: min(100%, 9rem);
  max-width: 100%;
  min-height: 44px;
  white-space: normal;
  line-height: 1.4;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  direction: rtl;
  text-align: center;
  unicode-bidi: plaintext;
  overflow-wrap: anywhere;
  word-break: break-word;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  pointer-events: auto;
  background: #fff !important;
  border: 2px solid #94a3b8 !important;
  color: #1e293b !important;
}

@media (max-width: 600px) {
  .modal-overlay.modal--question {
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  }

  .modal-overlay.modal--question .modal {
    padding: 1rem 0.85rem 1.15rem;
  }

  .modal-overlay.modal--question #modal-title {
    font-size: 1.05rem;
    margin-bottom: 0.65rem;
  }

  .modal-actions.question-card-actions .question-card-option-btns {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .modal-actions.question-card-actions .question-card-option-btn {
    width: 100%;
    min-width: 0;
    font-size: clamp(0.88rem, 3.6vw, 1rem);
  }
}

.modal-actions.question-card-actions .question-card-option-btn:not(:disabled):hover {
  background: #f8fafc !important;
  border-color: #64748b !important;
}

.pt-question-text {
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

.modal-actions.question-card-actions .question-card-option-btn.correct {
  border-color: #16a34a !important;
  background: #dcfce7 !important;
  color: #166534 !important;
}

.question-card-option-btn.wrong {
  border-color: #dc2626 !important;
  background: #fee2e2 !important;
  color: #991b1b !important;
}

.btn-tf-correct {
  background: #dcfce7 !important;
  border: 2px solid #16a34a !important;
  color: #166534 !important;
}

.btn-tf-wrong {
  background: #fee2e2 !important;
  border: 2px solid #dc2626 !important;
  color: #991b1b !important;
}

.question-card-option-btns--yellow .question-card-option-btn.btn-primary,
.question-card-option-btns--green .question-card-option-btn.btn-primary,
.question-card-option-btns--red .question-card-option-btn.btn-primary,
.question-card-option-btns--brown .question-card-option-btn.btn-primary {
  border-color: var(--green-dark);
}

.modal-actions.question-card-actions .question-card-option-btn.wrong {
  background: #fee2e2 !important;
  border-color: #dc2626 !important;
  color: #991b1b !important;
}

.modal-actions {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.modal-actions button {
  flex: 1;
  min-width: 120px;
}

.rules-list {
  padding-right: 1.25rem;
  line-height: 1.9;
}

.rules-list li {
  margin-bottom: 0.5rem;
}

.event-box {
  background: #ffebee;
  border-right: 4px solid var(--red);
  padding: 0.75rem;
  border-radius: 8px;
  margin-top: 0.5rem;
}

.turn-change-msg {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

.turn-change-next {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--green-dark);
  margin-bottom: 0.65rem;
}

.turn-change-hint {
  font-size: 0.9rem;
  color: #666;
}

/* ===== Train mobile bottom bar & sidebar sheet ===== */
:root {
  --game-header-height: 3.5rem;
  --train-mobile-bar-height: 7.25rem;
  --train-board-available-height: calc(
    100dvh
    - var(--game-header-height)
    - var(--train-mobile-bar-height)
    - env(safe-area-inset-top, 0px)
    - env(safe-area-inset-bottom, 0px)
    - 0.7rem
  );
}

.train-mobile-bar {
  display: none;
}

.btn-sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.15rem;
  cursor: pointer;
  font-family: inherit;
}

.train-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 190;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.train-sidebar-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 900px) {
  html:has(#screen-train.active),
  html:has(#screen-train.active) body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  #screen-train.active,
  html.native-app #screen-train.active {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    min-height: 0;
    padding-bottom: 0;
  }

  #screen-train.active .train-mobile-bar,
  html.native-app #screen-train.active .train-mobile-bar {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 300;
    padding: 0.45rem 0.55rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, #fffef8 0%, #f5f0e4 100%);
    border-top: 3px solid var(--gold);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.14);
  }

  #screen-train.active .train-mobile-bar-turn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 1.35rem;
    padding: 0 0.15rem;
  }

  #screen-train.active .train-mobile-turn-dot {
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1;
  }

  #screen-train.active .train-mobile-turn-label {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--green-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #screen-train.active .train-mobile-bar-row {
    display: flex;
    align-items: stretch;
    gap: 0.4rem;
    min-height: 2.75rem;
  }

  #screen-train.active .train-mobile-levels {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
  }

  #screen-train.active .train-mobile-levels .level-selector {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.3rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100%;
    grid-template-columns: unset;
  }

  #screen-train.active .train-mobile-levels .level-selector::-webkit-scrollbar {
    display: none;
  }

  #screen-train.active .train-mobile-levels .level-btn {
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    padding: 0.35rem 0.5rem;
    font-size: 0.68rem;
    gap: 0.3rem;
    border-radius: 999px;
    min-height: 2.25rem;
  }

  #screen-train.active .train-mobile-levels .level-btn-dot {
    width: 10px;
    height: 10px;
  }

  #screen-train.active .train-mobile-levels .level-btn-count {
    display: none;
  }

  #screen-train.active .train-mobile-actions {
    display: flex;
    flex-shrink: 0;
    gap: 0.35rem;
    align-items: stretch;
  }

  #screen-train.active .train-mbar-btn {
    font-family: inherit;
    font-weight: 800;
    font-size: 0.72rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    padding: 0.4rem 0.55rem;
    min-height: 2.75rem;
    min-width: 2.75rem;
    transition: transform 0.15s, opacity 0.2s;
    white-space: nowrap;
  }

  #screen-train.active .train-mbar-btn--gold {
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    color: var(--black);
    border: 2px solid #b8860b;
  }

  #screen-train.active .train-mbar-btn--primary {
    background: var(--green);
    color: #fff;
    border: 2px solid var(--green-dark);
  }

  #screen-train.active .train-mbar-btn--primary.btn-pulse-ready {
    animation: btn-pulse-ready 1.2s ease-in-out infinite;
  }

  #screen-train.active .train-mbar-btn--menu {
    background: #fff;
    color: var(--green-dark);
    border: 2px solid var(--green);
    font-size: 1rem;
    padding: 0.4rem 0.65rem;
  }

  #screen-train.active .train-mbar-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }

  #screen-train.active .train-mbar-btn[hidden] {
    display: none;
  }

  #screen-train.active .train-mbar-btn:not(:disabled):active {
    transform: scale(0.96);
  }

  #screen-train.active .game-header {
    flex-shrink: 0;
    min-height: var(--game-header-height);
  }

  #screen-train.active .train-layout {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    max-height: calc(100dvh - var(--game-header-height));
  }

  #screen-train.active .board-wrap {
    flex: 1;
    min-height: 0;
    order: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-height: var(--train-board-available-height);
    height: var(--train-board-available-height);
    padding: 0.35rem;
    overflow: hidden;
  }

  #screen-train.active .board {
    flex: 0 1 auto;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    height: auto;
    aspect-ratio: 999 / 1400;
  }

  #screen-train.active .board-map {
    width: 100%;
    height: 100%;
    max-height: 100%;
    aspect-ratio: 999 / 1400;
  }

  #screen-train.active .board-map-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
  }

  #screen-train.active .train-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--train-mobile-bar-height) + env(safe-area-inset-bottom, 0px));
    z-index: 200;
    max-height: min(72vh, 540px);
    border-left: none;
    border-top: 3px solid var(--gold);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 36px rgba(0, 0, 0, 0.22);
    transform: translateY(110%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: 0.5rem;
  }

  #screen-train.active .train-sidebar.is-open {
    transform: translateY(0);
  }

  #screen-train.active .train-sidebar .panel-level,
  #screen-train.active .train-sidebar .actions-panel {
    display: none;
  }

  #screen-train.active .train-sidebar-backdrop {
    display: block;
  }

  #screen-train.active #ad-banner-train {
    display: none;
  }

  #screen-train.active .online-chat-panel:not(.hidden) {
    position: fixed;
    left: 0.5rem;
    right: 0.5rem;
    bottom: calc(var(--train-mobile-bar-height) + env(safe-area-inset-bottom, 0px) + 0.35rem);
    z-index: 150;
    max-width: none;
  }

  #screen-train.active .online-chat-body {
    max-height: min(28vh, 220px);
  }

  #screen-train.active .map-highlight {
    width: 17px;
    height: 17px;
    border-width: 2px;
  }

  #screen-train.active .key-token {
    font-size: clamp(0.55rem, 2.6vw, 0.72rem);
  }

  #screen-train.active .key-token-active {
    transform: scale(1.12);
  }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .board {
    max-width: 100%;
  }

  .level-selector {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .memory-board {
    grid-template-columns: repeat(4, minmax(60px, 1fr));
    gap: 6px;
  }

  .memory-face {
    font-size: 0.62rem;
  }
}

/* ===== Ads ===== */
.ad-banner {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 90px;
  width: 100%;
  padding: 0.5rem;
  background: #fff;
  border: 2px dashed rgba(201, 162, 39, 0.85);
  border-radius: 10px;
  overflow: visible;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

.ad-banner:empty::before {
  content: 'Banner — جاري التحميل… · 728×90';
  display: block;
  width: 100%;
  padding: 1rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green-dark);
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border-radius: 8px;
}

.ad-banner--menu {
  position: relative;
  z-index: 1;
  margin-top: 1.5rem;
  max-width: min(728px, 100%);
  margin-left: auto;
  margin-right: auto;
}

.ad-banner--game {
  padding: 0.5rem 1rem;
  background: #fff;
  border-top: 2px dashed rgba(201, 162, 39, 0.85);
}

#screen-train {
  background: var(--cream);
}

#ad-banner-train {
  background: #fff;
  border: 2px dashed var(--gold);
  margin: 0.75rem 1rem 1rem;
  border-radius: 10px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.14);
  position: relative;
  z-index: 2;
}

.ad-banner[hidden] {
  display: none !important;
}

#screen-train,
#screen-memory {
  padding-bottom: 1rem;
}

.ad-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 72px;
  padding: 0.65rem 1rem;
  border: 2px dashed #999;
  border-radius: 8px;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  text-align: center;
  gap: 0.2rem;
}

.ad-placeholder--banner .ad-placeholder-size {
  font-size: 0.75rem;
  font-weight: 800;
  color: #666;
  letter-spacing: 0.04em;
}

.ad-placeholder--interstitial {
  min-height: 200px;
  border-color: var(--gold);
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
}

.ad-placeholder-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ad-placeholder-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green-dark);
}

.ad-placeholder-hint {
  font-size: 0.7rem;
  color: #999;
}

.ad-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.ad-overlay-card {
  background: #fff;
  border-radius: var(--radius);
  max-width: 420px;
  width: 100%;
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.ad-overlay-card--rewarded {
  border: 3px solid var(--gold);
}

.ad-overlay-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--green-dark);
  margin-bottom: 0.75rem;
}

.ad-overlay-sub {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.75rem;
}

.ad-slot {
  margin: 0.75rem 0;
  min-height: 120px;
}

.ad-slot--interstitial,
.ad-slot--rewarded {
  min-height: 200px;
}

.ad-skip-btn {
  font-family: inherit;
  font-weight: 700;
  padding: 0.65rem 1.5rem;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  width: 100%;
  margin-top: 0.5rem;
}

.ad-skip-btn:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.btn-rewarded {
  font-family: inherit;
  font-weight: 700;
  border: 2px dashed var(--gold);
  border-radius: 8px;
  cursor: pointer;
  padding: 0.55rem 1rem;
  font-size: 0.82rem;
  width: 100%;
  margin-top: 0.35rem;
  background: linear-gradient(135deg, #fff8e1, #fff);
  color: var(--green-dark);
  transition: opacity 0.2s, transform 0.15s;
}

.btn-rewarded:hover:not(:disabled) {
  transform: scale(1.02);
  border-color: var(--gold-light);
}

.btn-rewarded:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

/* ===== Online multiplayer (Phase 2) ===== */
.panel-mode {
  padding-bottom: 0.65rem;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.mode-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.55rem 0.4rem;
  border-radius: 8px;
  border: 2px solid #d4cbb8;
  background: #fff;
  color: var(--green-dark);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.mode-btn.is-active {
  background: var(--green);
  border-color: var(--green-dark);
  color: #fff;
}

.mode-btn:not(.is-active):hover {
  border-color: var(--gold);
}

.online-panel .online-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--green-dark);
  margin-bottom: 0.35rem;
}

.online-input {
  width: 100%;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.65rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  margin-bottom: 0.55rem;
  background: #fff;
}

.online-input:focus {
  outline: none;
  border-color: var(--green);
}

.online-create-btn {
  width: 100%;
  margin-bottom: 0.65rem;
}

.online-join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
  align-items: start;
}

.online-code-input {
  margin-bottom: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.online-notice {
  background: #fff8e6;
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 0.65rem;
  margin-bottom: 0.65rem;
  font-size: 0.82rem;
  line-height: 1.5;
}

.online-notice code {
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

.online-room-code-display {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.65rem;
  background: #fff;
  border: 2px dashed var(--gold);
  border-radius: 8px;
  margin-bottom: 0.55rem;
  font-size: 0.88rem;
}

.online-room-code-display strong {
  font-size: 1.35rem;
  letter-spacing: 0.12em;
  color: var(--green-dark);
}

.online-status-text {
  font-size: 0.82rem;
  color: #555;
  margin-bottom: 0.5rem;
  line-height: 1.45;
}

.online-lobby-list {
  list-style: none;
  margin: 0 0 0.65rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.online-lobby-list li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.55rem;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #e5dcc8;
  font-size: 0.85rem;
}

.online-lobby-list li.is-me {
  border-color: var(--green);
  background: rgba(0, 122, 61, 0.06);
}

.online-lobby-list li.is-host::after {
  content: 'مضيف';
  margin-right: auto;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(201, 162, 39, 0.15);
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
}

.online-lobby-list li.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.2);
}

.online-leave-btn {
  width: 100%;
  margin-top: 0.35rem;
}

#online-start-btn {
  width: 100%;
  margin-bottom: 0.35rem;
}

.online-waiting-hint {
  font-size: 0.8rem;
  color: #666;
  font-style: italic;
}

/* ── Online chat (Phase 3–4) ── */
.online-chat-panel {
  width: 100%;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid var(--green);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.online-chat-panel.hidden {
  display: none !important;
}

.online-chat-panel.is-collapsed .online-chat-body {
  display: none;
}

.online-chat-header {
  display: flex;
  align-items: center;
  padding: 0.35rem 0.5rem;
  background: linear-gradient(180deg, rgba(0, 122, 61, 0.08), rgba(0, 122, 61, 0.02));
  border-bottom: 1px solid rgba(0, 122, 61, 0.15);
}

.online-chat-toggle {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--green-dark);
  background: transparent;
  border: none;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  border-radius: 8px;
  width: 100%;
  text-align: right;
}

.online-chat-toggle:hover {
  background: rgba(0, 122, 61, 0.08);
}

.online-chat-body {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.5rem;
  max-height: min(42vh, 320px);
}

.online-chat-toasts {
  position: relative;
  min-height: 0;
  pointer-events: none;
}

.online-chat-toast {
  position: absolute;
  right: 0;
  bottom: 0;
  max-width: 90%;
  padding: 0.4rem 0.65rem;
  background: rgba(0, 122, 61, 0.92);
  color: #fff;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  animation: chat-toast-in 0.25s ease, chat-toast-out 0.35s ease 2.6s forwards;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.online-chat-toast.is-me {
  background: rgba(201, 162, 39, 0.95);
}

@keyframes chat-toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes chat-toast-out {
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.online-chat-messages {
  flex: 1;
  min-height: 72px;
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.35rem;
  background: #faf8f3;
  border: 1px solid #e5dcc8;
  border-radius: 8px;
  scroll-behavior: smooth;
}

.online-chat-messages:empty::before {
  content: 'لا رسائل بعد — استخدم الاختصارات أو اكتب رسالة';
  color: #888;
  font-size: 0.78rem;
  text-align: center;
  padding: 0.75rem 0.35rem;
}

.online-chat-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 92%;
  animation: chat-msg-in 0.2s ease;
}

.online-chat-msg.is-me {
  align-self: flex-end;
  align-items: flex-end;
}

.online-chat-msg-name {
  font-size: 0.68rem;
  font-weight: 700;
  margin-bottom: 0.1rem;
  opacity: 0.85;
}

.online-chat-msg-bubble {
  padding: 0.35rem 0.6rem;
  border-radius: 12px 12px 12px 4px;
  background: #fff;
  border: 1px solid #ddd;
  font-size: 0.84rem;
  line-height: 1.4;
  word-break: break-word;
}

.online-chat-msg.is-me .online-chat-msg-bubble {
  border-radius: 12px 12px 4px 12px;
  background: rgba(0, 122, 61, 0.1);
  border-color: var(--green);
}

.online-chat-msg.is-preset .online-chat-msg-bubble {
  font-weight: 600;
}

.online-chat-msg-time {
  font-size: 0.62rem;
  color: #999;
  margin-top: 0.1rem;
}

@keyframes chat-msg-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.online-chat-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.online-chat-preset-btn {
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: rgba(201, 162, 39, 0.12);
  color: var(--green-dark);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.online-chat-preset-btn:hover:not(:disabled) {
  background: rgba(201, 162, 39, 0.25);
}

.online-chat-preset-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.online-chat-preset-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.online-chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: center;
}

.online-chat-input {
  font-family: inherit;
  font-size: 0.88rem;
  padding: 0.45rem 0.6rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: #fff;
  min-width: 0;
}

.online-chat-input:focus {
  outline: none;
  border-color: var(--green);
}

.online-chat-send-btn {
  font-size: 0.82rem;
  padding: 0.45rem 0.75rem;
  white-space: nowrap;
  min-height: 38px;
}

@media (max-width: 640px) {
  .online-chat-body {
    max-height: min(38vh, 280px);
  }

  .online-chat-messages {
    max-height: 100px;
  }

  .online-chat-preset-btn {
    font-size: 0.72rem;
    padding: 0.28rem 0.45rem;
  }

  .online-chat-panel.is-collapsed .online-chat-header {
    border-bottom: none;
  }
}

