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

:root {
  --bg: #0a0f1a;
  --surface: #131a2e;
  --gold: #c9a227;
  --gold-dim: #8a6f1a;
  --text: #e8e0d0;
  --text-dim: #7a7568;
  --red: #c0392b;
  --green: #27ae60;
  --radius: 12px;
}

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

.screen {
  display: none;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  gap: 20px;
  text-align: center;
}

/* Buttons */
.btn {
  font-family: 'Tajawal', sans-serif;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  padding: 14px 40px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--gold);
  color: var(--bg);
}
.btn-primary:hover { background: #d4af37; }
.btn-primary:disabled { background: var(--gold-dim); cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--gold-dim);
}
.btn-ghost:hover { background: rgba(201, 162, 39, 0.1); }

/* Start Screen */
.game-title {
  font-size: 72px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 40px rgba(201, 162, 39, 0.3);
  letter-spacing: 4px;
}
.subtitle {
  font-size: 20px;
  color: var(--text-dim);
  line-height: 1.8;
}

/* Game Screen */
#screen-game {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid rgba(201, 162, 39, 0.15);
}
#level-indicator {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
}
#timer {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.puzzle-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 20px;
}

.puzzle-hint {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.puzzle-img {
  max-width: 90%;
  max-height: 50vh;
  border-radius: var(--radius);
  border: 2px solid rgba(201, 162, 39, 0.2);
}

.answer-section {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  background: var(--surface);
  border-top: 1px solid rgba(201, 162, 39, 0.15);
}
.answer-section input {
  flex: 1;
  font-family: 'Tajawal', sans-serif;
  font-size: 18px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(201, 162, 39, 0.2);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.answer-section input:focus {
  border-color: var(--gold);
}

/* Toast popup */
.toast-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(192, 57, 43, 0.95);
  color: white;
  font-family: 'Tajawal', sans-serif;
  font-size: 18px;
  font-weight: 700;
  padding: 16px 32px;
  border-radius: var(--radius);
  z-index: 100;
  transition: opacity 0.4s;
}
.toast-popup.fade-out { opacity: 0; }

.wrong-msg { display: none; }

/* Level 3 — T9 */
.t9-code {
  direction: ltr;
  font-size: 36px;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: 4px;
  text-align: center;
  line-height: 1.8;
}
.t9-hint {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 12px;
}
.t9-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 260px;
  margin-top: 16px;
  direction: ltr;
}
.t9-key {
  background: var(--surface);
  border: 1px solid rgba(201, 162, 39, 0.15);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
}
.t9-key .num {
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
}
.t9-key .letters {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Level 4 — Emoji */
.emoji-puzzle {
  font-size: 42px;
  text-align: center;
  direction: ltr;
  line-height: 1.6;
}

/* Level 5 — Scrambled */
.scrambled {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.scrambled span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--surface);
  border: 2px solid var(--gold-dim);
  border-radius: 10px;
  font-size: 28px;
  font-weight: 700;
  color: var(--gold);
}

/* Level 7 — Morse */
.morse-code {
  direction: ltr;
  font-size: 24px;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: 4px;
  text-align: center;
  word-spacing: 14px;
  font-family: 'Courier New', monospace;
  white-space: nowrap;
}
.morse-ref {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  max-width: 360px;
  margin-top: 20px;
  direction: ltr;
  font-size: 11px;
  color: var(--text-dim);
}
.morse-ref span {
  background: var(--surface);
  padding: 4px;
  border-radius: 4px;
  text-align: center;
}

/* Level 3 — Phone */
.phone-img {
  max-height: 35vh;
  margin-top: 12px;
}

/* Level 8 — Coordinates */
.coordinates {
  direction: ltr;
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
  font-family: 'Courier New', monospace;
  background: var(--surface);
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 1px solid rgba(201, 162, 39, 0.2);
  letter-spacing: 1px;
  text-align: center;
  margin-top: 16px;
}

/* Level 6 — Flag hint */
.flag-hint {
  width: 32px;
  height: auto;
  margin-top: 12px;
  opacity: 0.7;
  border-radius: 4px;
}

/* Level 9 — Silhouette */
.silhouette {
  filter: brightness(0);
}

/* Level 10 — Toggle */
.switch-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}
.toggle-switch {
  width: 100px;
  height: 52px;
  background: #333;
  border-radius: 26px;
  padding: 4px;
  cursor: pointer;
  transition: background 0.3s;
  position: relative;
}
.toggle-switch.on { background: var(--green); }
.toggle-knob {
  width: 44px;
  height: 44px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
}
.toggle-switch.on .toggle-knob { transform: translateX(-48px); }

/* Level 10 — Clue text */
.level-clue {
  font-size: 15px;
  color: var(--text-dim);
  margin-top: 20px;
  font-style: italic;
}

/* Level 11 — Door */
.door-level {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  overflow: hidden;
}

.door-frame {
  width: 160px;
  height: 260px;
  background: #2a1810;
  border-radius: 80px 80px 0 0;
  padding: 12px 12px 0 12px;
  perspective: 800px;
  position: relative;
  z-index: 2;
  direction: ltr;
}
.door {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #6b3a2a, #4a2518);
  border-radius: 68px 68px 0 0;
  transform-origin: left center;
  transform: rotateY(40deg);
  transition: transform 0.8s ease;
  cursor: pointer;
  position: relative;
}
.door.half-closed { transform: rotateY(20deg); }
.door.closed { transform: rotateY(0deg); cursor: default; }
.door-handle {
  position: absolute;
  left: 20px;
  top: 50%;
  width: 14px;
  height: 14px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(201, 162, 39, 0.5);
}

.proverb-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  line-height: 2;
  z-index: 2;
  padding: 0 20px;
}
.sedou-word {
  color: inherit;
  cursor: default;
}
.sedou-word.pressed {
  color: var(--gold);
}

/* Wind particles */
.wind-particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
  pointer-events: none;
}
.particle {
  position: absolute;
  right: -20px;
  top: var(--y);
  width: 8px;
  height: 3px;
  background: rgba(200, 200, 200, 0.25);
  border-radius: 2px;
  animation: wind 2s linear infinite;
  animation-delay: var(--delay);
}
.wind-particles.slow .particle { animation-duration: 5s; opacity: 0.5; }
.wind-particles.stopped .particle { animation-play-state: paused; opacity: 0; }

@keyframes wind {
  from { transform: translateX(0); }
  to { transform: translateX(calc(-100vw - 40px)); }
}

/* Win Screen */
.win-title {
  font-size: 52px;
  font-weight: 900;
  color: var(--gold);
}
.win-sub {
  font-size: 18px;
  color: var(--text-dim);
}
.time-display {
  font-size: 48px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}
.save-section {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}
.save-section input {
  flex: 1;
  font-family: 'Tajawal', sans-serif;
  font-size: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--gold-dim);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.save-section input:focus { border-color: var(--gold); }

/* Leaderboard */
.leaderboard {
  width: 100%;
  max-width: 400px;
  margin-top: 12px;
}
.lb-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.lb-rank {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  background: var(--surface);
  color: var(--text-dim);
  flex-shrink: 0;
}
.lb-entry.top-1 .lb-rank { background: var(--gold); color: var(--bg); }
.lb-entry.top-2 .lb-rank { background: #aaa; color: var(--bg); }
.lb-entry.top-3 .lb-rank { background: #a0522d; color: white; }
.lb-name {
  flex: 1;
  font-weight: 500;
  font-size: 16px;
}
.lb-time {
  font-size: 14px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
}

/* Animations */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.shake { animation: shake 0.4s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.4s ease; }

@keyframes correctPulse {
  0% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.5); }
  100% { box-shadow: 0 0 0 20px rgba(39, 174, 96, 0); }
}

/* Image grid for level 2 */
.image-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 400px;
}
.image-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(201, 162, 39, 0.2);
}

/* Responsive */
@media (max-width: 480px) {
  .game-title { font-size: 52px; }
  .subtitle { font-size: 16px; }
  .t9-code { font-size: 28px; }
  .emoji-puzzle { font-size: 32px; }
  .morse-code { font-size: 22px; letter-spacing: 4px; }
  .scrambled span { width: 46px; height: 46px; font-size: 22px; }
  .door-frame { width: 130px; height: 210px; }
  .time-display { font-size: 36px; }
  .win-title { font-size: 40px; }
  .morse-ref { grid-template-columns: repeat(4, 1fr); }
}
