/* ============================================
   CSS Reset / Normalize
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

h1, h2, h3, h4, h5, h6, p {
  overflow-wrap: break-word;
}

/* ============================================
   Custom Properties (Theme)
   ============================================ */
:root {
  --primary: #6c5ce7;
  --primary-dark: #5a4bd6;
  --secondary: #00cec9;
  --secondary-dark: #00b5b0;
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-surface: #16213e;
  --bg-overlay: rgba(0, 0, 0, 0.5);
  --text: #eaeaea;
  --text-muted: #8888aa;
  --accent: #e17055;
  --accent-dark: #c8604a;
  --success: #00b894;
  --danger: #d63031;

  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.2);
  --transition: 0.3s ease;
}

/* ============================================
   Base Styles (Mobile-First)
   ============================================ */
html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-stack);
  background-color: var(--bg);
  color: var(--text);
}

/* ============================================
   #app Container
   ============================================ */
#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ============================================
   Screens
   ============================================ */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.screen.active {
  display: flex;
  opacity: 1;
}

.screen-content {
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* ============================================
   Landing Screen
   ============================================ */
.landing-content {
  gap: 1rem;
}

.landing-title {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.1;
}

.landing-tagline {
  font-size: 1.25rem;
  color: var(--secondary);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.landing-description {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 360px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-decoration: none;
  outline: none;
}

.btn:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 24px rgba(108, 92, 231, 0.45);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--secondary), var(--secondary-dark));
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 206, 201, 0.2);
}

.btn-secondary:hover {
  box-shadow: 0 6px 24px rgba(0, 206, 201, 0.35);
}

.btn-large {
  min-height: 56px;
  padding: 1rem 2.5rem;
  font-size: 1.15rem;
  border-radius: 16px;
  width: 100%;
  max-width: 320px;
}

.btn-option {
  background: var(--bg-card);
  color: var(--text);
  border: 2px solid transparent;
  flex: 1;
  min-height: 52px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
}

.btn-option:hover {
  border-color: var(--primary);
}

.btn-option.selected {
  border-color: var(--primary);
  background: rgba(108, 92, 231, 0.15);
  color: #fff;
  box-shadow: 0 0 12px rgba(108, 92, 231, 0.2);
}

/* ============================================
   Input Fields
   ============================================ */
.input-text {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 2px solid rgba(136, 136, 170, 0.3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  transition: border-color var(--transition);
  outline: none;
}

.input-text::placeholder {
  color: var(--text-muted);
}

.input-text:focus {
  border-color: var(--primary);
}

/* ============================================
   Setup Screen
   ============================================ */
.setup-content {
  gap: 0.75rem;
  max-height: 100vh;
  max-height: 100dvh;
  overflow-y: auto;
  padding-top: 2rem;
  padding-bottom: 2rem;
  justify-content: flex-start;
}

.setup-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.setup-step {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(136, 136, 170, 0.1);
}

.step-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step-label {
  font-weight: 600;
  font-size: 1rem;
  flex: 1;
  text-align: left;
}

.step-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  flex-shrink: 0;
  transition: all var(--transition);
  position: relative;
}

.step-check.completed {
  border-color: var(--success);
  background: var(--success);
}

.step-check.completed::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 7px;
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.step-description {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: left;
  line-height: 1.4;
}

.step-error {
  font-size: 0.85rem;
  color: var(--danger);
  text-align: left;
  min-height: 0;
  line-height: 1.3;
}

.step-error:empty {
  display: none;
}

.option-group {
  display: flex;
  gap: 0.6rem;
  width: 100%;
}

/* ============================================
   Loading Screen
   ============================================ */
.loading-content {
  gap: 2rem;
}

.loading-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
}

.loading-dots span {
  animation: dotPulse 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) {
  animation-delay: 0s;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dotPulse {
  0%, 60%, 100% {
    opacity: 0.2;
  }
  30% {
    opacity: 1;
  }
}

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner-ring {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid rgba(108, 92, 231, 0.2);
  border-top-color: var(--primary);
  animation: spinnerRotate 1s linear infinite;
}

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

.loading-fact {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-style: italic;
  max-width: 320px;
  line-height: 1.5;
  min-height: 3em;
  transition: opacity 0.4s ease;
}

/* ============================================
   Game Screen
   ============================================ */
#screen-game {
  justify-content: flex-start;
}

#game-ui {
  width: 100%;
}

/* ============================================
   Completion Screen
   ============================================ */
.completion-content {
  gap: 1.5rem;
  text-align: center;
}

.completion-title {
  font-size: 2rem;
  color: var(--secondary);
  margin-bottom: 0.5rem;
}

.rating-stars {
  font-size: 2.5rem;
  color: #f1c40f;
  letter-spacing: 4px;
}

.rating-title {
  font-size: 1.3rem;
  color: var(--primary);
  font-weight: bold;
  margin-top: 0.5rem;
}

.completion-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  min-width: 80px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--secondary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 0.3rem;
}

.completion-actions {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1rem;
}

/* ============================================
   Location granted state — hide button, show status
   ============================================ */
.btn-location-granted {
  background: var(--success) !important;
  cursor: default !important;
  pointer-events: none;
}

/* ============================================
   Responsive — larger screens
   ============================================ */
@media (min-width: 768px) {
  .landing-title {
    font-size: 4rem;
  }

  .landing-tagline {
    font-size: 1.5rem;
  }

  .landing-description {
    font-size: 1.05rem;
    max-width: 420px;
  }

  .setup-content {
    gap: 1rem;
  }

  .loading-title {
    font-size: 1.6rem;
  }

  .completion-title {
    font-size: 2.5rem;
  }
}

/* ============================================
   Very small screens (320px)
   ============================================ */
@media (max-width: 360px) {
  .landing-title {
    font-size: 2.2rem;
  }

  .landing-tagline {
    font-size: 1rem;
  }

  .btn-large {
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
  }

  .setup-step {
    padding: 0.75rem;
  }

  .btn-option {
    font-size: 0.8rem;
    padding: 0.6rem 0.5rem;
  }
}

/* ============================================
   Narrative Overlay
   ============================================ */
.narrative-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  z-index: 100;
  padding: 1rem;
}

.dialogue-box {
  background: rgba(15, 15, 26, 0.95);
  border: 1px solid var(--primary);
  border-radius: 12px;
  padding: 1.2rem;
  max-height: 40vh;
  overflow-y: auto;
}

.dialogue-character {
  font-weight: bold;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dialogue-text {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.6;
}

.dialogue-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.8rem;
  text-align: center;
  opacity: 0;
  animation: fadeIn 1s 1.5s forwards;
}

.dialogue-text.narration {
  font-style: italic;
  color: var(--secondary);
}

@keyframes fadeIn {
  to { opacity: 1; }
}

/* ============================================
   Map Container (game screen override)
   ============================================ */
#map-container {
  width: 100%;
  height: 60vh;
  border-radius: 12px;
  overflow: hidden;
}

/* ============================================
   Game Info Bar
   ============================================ */
.game-info-bar {
  display: flex;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  background: var(--bg-card);
  border-radius: 8px;
  margin: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ============================================
   Minigame Container
   ============================================ */
#minigame-container {
  padding: 1rem;
}

#minigame-container:empty {
  display: none;
}

/* ============================================
   Dev Mode Badge
   ============================================ */
.dev-mode-badge {
  position: fixed;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  z-index: 999;
  font-weight: bold;
}

/* ============================================
   Minigames
   ============================================ */
.minigame { padding: 1rem; }
.minigame h3 { color: var(--secondary); margin-bottom: 1rem; font-size: 1.2rem; }
.minigame-question { color: var(--text); font-size: 1.1rem; margin-bottom: 1rem; line-height: 1.5; }
.minigame-options { display: flex; flex-direction: column; gap: 0.6rem; }
.minigame-option { background: var(--bg-card); border: 2px solid var(--text-muted); border-radius: 8px; padding: 0.8rem 1rem; color: var(--text); font-size: 1rem; cursor: pointer; transition: all 0.2s; text-align: left; }
.minigame-option:hover { border-color: var(--primary); }
.minigame-option.correct { border-color: var(--success); background: rgba(0, 184, 148, 0.15); }
.minigame-option.wrong { border-color: var(--danger); background: rgba(214, 48, 49, 0.15); }
.minigame-option.selected { border-color: var(--primary); background: rgba(108, 92, 231, 0.15); }
.minigame-result { text-align: center; padding: 2rem; }
.minigame-result h3 { font-size: 1.5rem; }
.minigame-score { color: var(--secondary); font-size: 1.3rem; font-weight: bold; }

/* Photo minigame */
.photo-preview { max-width: 100%; max-height: 40vh; border-radius: 8px; margin: 1rem 0; }

/* Puzzle minigame */
.puzzle-grid { display: grid; gap: 4px; max-width: 300px; margin: 1rem auto; aspect-ratio: 1; }
.puzzle-piece { border-radius: 4px; cursor: pointer; transition: transform 0.2s; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #fff; font-size: 1.2rem; }
.puzzle-piece.selected { transform: scale(0.95); box-shadow: 0 0 0 3px var(--primary); }

/* Fingerprint minigame */
.fingerprint-reveal { width: 200px; height: 200px; margin: 1rem auto; border-radius: 50%; background: var(--bg-card); position: relative; overflow: hidden; cursor: pointer; }
.fingerprint-area { position: absolute; inset: 0; background: var(--text-muted); transition: opacity 0.5s; }
.fingerprint-print { position: absolute; inset: 20%; font-size: 3rem; display: flex; align-items: center; justify-content: center; }

/* Phone call minigame */
.phone-incoming { text-align: center; padding: 3rem 1rem; }
.phone-icon { font-size: 4rem; animation: phonePulse 1.5s infinite; }
.phone-caller { font-size: 1.3rem; color: var(--text); margin: 1rem 0; }
@keyframes phonePulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* Reveal minigame */
.suspect-cards { display: flex; flex-direction: column; gap: 0.8rem; margin: 1rem 0; }
.suspect-card { background: var(--bg-card); border: 2px solid var(--text-muted); border-radius: 10px; padding: 1rem; cursor: pointer; transition: all 0.3s; }
.suspect-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.suspect-card.selected { border-color: var(--primary); }
.suspect-card.correct-reveal { border-color: var(--success); background: rgba(0, 184, 148, 0.2); }
.suspect-card.wrong-reveal { border-color: var(--danger); background: rgba(214, 48, 49, 0.1); }
.reveal-dramatic { text-align: center; font-size: 1.8rem; color: var(--accent); animation: fadeIn 0.5s; font-weight: bold; }
