/* =====================================================================
   Car Model Quiz – Rifpelit-brändin mukainen tyyli
   ===================================================================== */
:root {
  --brand: #ff1919;
  --brand-bright: #ff3b3b;
  --brand-deep: #cc1414;
  --brand-glow: rgba(255, 25, 25, 0.35);
  --brand-tint: rgba(255, 25, 25, 0.12);
  --bg: #0a0a0a;
  --surface-1: #141414;
  --surface-2: #1b1b1b;
  --surface-3: #232323;
  --border: #2a2a2a;
  --text: #f5f5f5;
  --text-muted: #b4b4b4;
  --text-dim: #7c7c7c;
  --green: #36c25a;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 34px rgba(0, 0, 0, 0.45);
  --transition: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', 'Inter', Arial, sans-serif;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

/* Hienovarainen tunnelmavalo taustalle */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(820px 520px at 12% -5%, rgba(255, 25, 25, 0.07), transparent 60%),
    radial-gradient(720px 520px at 88% 12%, rgba(255, 25, 25, 0.05), transparent 60%);
}

::selection { background: var(--brand); color: #fff; }

.container {
  width: 92%;
  max-width: 620px;
  margin: 28px auto;
  padding: 28px 24px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}

h1 {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 0 0 18px;
  color: #fff;
}
h1::after {
  content: '';
  display: block;
  width: 60px;
  height: 4px;
  margin: 12px auto 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--brand-bright));
  box-shadow: 0 2px 10px var(--brand-glow);
}

/* Tila-palkki (pisteet / taso / putki) */
#status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
#status p { margin: 0; font-size: 0.98rem; font-weight: 600; }
#status p span { color: var(--brand-bright); }

#playerInfo { width: 100%; margin-top: 8px; }

/* Putkilaskuri */
.streak {
  font-weight: 700;
  color: var(--brand-bright);
  white-space: nowrap;
  transition: transform var(--transition);
}
.streak.bump { transform: scale(1.25); }

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
}

input, select, button {
  font-size: 0.95rem;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  margin-bottom: 14px;
  width: 100%;
  font-family: inherit;
}

input, select {
  background: var(--surface-3);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}

#difficultySelect {
  border: 1.5px solid var(--brand);
  font-weight: 600;
}
#difficultySelect option, #brandSelect option {
  background: var(--surface-3);
  color: var(--text);
}

/* Napit – brändigradientti + hehku */
button {
  background: linear-gradient(135deg, var(--brand), var(--brand-bright));
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  border: none;
  box-shadow: 0 6px 16px rgba(255, 25, 25, 0.28);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}
button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(255, 25, 25, 0.45);
}
button:active { transform: translateY(0); }

#startGame {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 14px;
  margin-top: 6px;
}

/* Pienemmät toissijaiset napit (Analytics / Challenge / Leaderboard / player) */
#playerInfo button,
#setup div button {
  background: var(--surface-3);
  border: 1px solid var(--border);
  box-shadow: none;
  font-weight: 600;
  width: auto;
}
#playerInfo button:hover,
#setup div button:hover {
  border-color: var(--brand);
  background: var(--surface-2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--brand-glow);
}

/* Edistymispalkki */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 14px;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--brand), var(--brand-bright));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.question-counter {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0 0 6px;
}

/* Kysymyksen kuva */
.quiz-image, img.quiz-image {
  width: 100%;
  max-width: 420px;
  height: 220px;
  object-fit: cover;
  background: var(--surface-3);
  border-radius: var(--r-md);
  border: 3px solid var(--brand);
  box-shadow: 0 8px 24px rgba(255, 25, 25, 0.22);
  margin: 4px auto 18px;
  display: block;
  cursor: zoom-in;
  transition: transform var(--transition);
}
.quiz-image:hover { transform: scale(1.02); }

/* Vaihtoehdot */
.options { display: flex; flex-direction: column; gap: 12px; }
.options button {
  background: var(--surface-3);
  border: 1.5px solid var(--border);
  color: var(--text);
  box-shadow: none;
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0;
  position: relative;
}
.options button .key-hint {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
}
.options button:hover:not(:disabled) {
  border-color: var(--brand);
  background: var(--surface-2);
  transform: translateY(-2px);
}
.options button:disabled { cursor: default; }
button.correct {
  background: linear-gradient(135deg, var(--green), #2ea34d) !important;
  border-color: var(--green) !important;
  color: #fff !important;
  box-shadow: 0 6px 18px rgba(54, 194, 90, 0.4) !important;
}
button.wrong {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep)) !important;
  border-color: var(--brand) !important;
  color: #fff !important;
}

/* Oikein/väärin -välähdys ruudulla */
.feedback-flash {
  position: fixed;
  inset: 0;
  z-index: 900;
  pointer-events: none;
  opacity: 0;
}
.feedback-flash.correct { box-shadow: inset 0 0 120px rgba(54, 194, 90, 0.55); animation: flash 0.6s ease; }
.feedback-flash.wrong { box-shadow: inset 0 0 120px rgba(255, 25, 25, 0.55); animation: flash 0.6s ease; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

#timerDisplay {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--brand-bright);
  margin-top: 14px;
}
#timerDisplay.low { animation: pulse 0.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

.points-info {
  color: var(--green);
  font-weight: 600;
  font-size: 0.92rem;
  margin-top: 10px;
}

.reveal { font-weight: 600; margin-top: 12px; color: var(--text-muted); }
.reveal strong { color: var(--brand-bright); }

#dailyBtn {
  background: linear-gradient(135deg, #f0b000, #ff8a00);
  box-shadow: 0 6px 16px rgba(240, 176, 0, 0.3);
}
#dailyBtn:hover { box-shadow: 0 10px 26px rgba(240, 176, 0, 0.5); }

/* Kuvan zoom-modaali */
.image-modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex; justify-content: center; align-items: center;
  z-index: 1000; cursor: zoom-out;
  backdrop-filter: blur(4px);
}
.modal-image {
  max-width: 92%; max-height: 92%;
  border: 3px solid var(--brand);
  border-radius: var(--r-md);
}

/* Tulokset */
.results { margin-top: 24px; }
.results-summary,
.achievements,
.wrong-answers,
.stats-summary,
.analytics-section {
  background: var(--surface-2);
  padding: 16px 18px;
  border-radius: var(--r-md);
  margin-bottom: 14px;
  border: 1px solid var(--border);
  text-align: left;
}
.results-summary { border-color: var(--brand); }
.achievements { border-color: var(--green); }
.achievement { color: var(--green); font-weight: 700; margin: 6px 0; }
.wrong-answers { border-color: var(--brand); }
.mistake {
  background: var(--surface-3);
  padding: 10px 12px;
  border-radius: var(--r-sm);
  margin: 10px 0;
  border-left: 4px solid var(--brand);
}

/* Modaalit (historia / analytiikka / jako / tulostaulu) */
.history-modal, .analytics-modal, .share-modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex; justify-content: center; align-items: center;
  z-index: 1000; padding: 16px;
  backdrop-filter: blur(4px);
}
.history-content, .analytics-content, .share-content {
  background: var(--surface-1);
  padding: 24px;
  border-radius: var(--r-lg);
  max-width: 540px; width: 100%;
  max-height: 84vh; overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--text);
  text-align: left;
}
.history-content h2, .analytics-content h2, .share-content h3 { color: var(--brand-bright); margin-top: 0; }

.history-list, .leaderboard-list { max-height: 320px; overflow-y: auto; }
.history-item {
  background: var(--surface-3);
  padding: 10px 12px; border-radius: var(--r-sm);
  margin: 10px 0; border-left: 4px solid var(--brand);
}

/* Tulostaulu */
.leaderboard-item {
  display: grid;
  grid-template-columns: 40px 1fr 70px 80px 76px;
  gap: 10px; padding: 10px 12px;
  background: var(--surface-3);
  border-radius: var(--r-sm); margin: 6px 0;
  align-items: center; font-size: 0.9rem;
}
.leaderboard-item.top-three {
  background: linear-gradient(45deg, #2a2317, var(--surface-3));
  border: 1px solid #ffd700;
}
.leaderboard-item .rank { font-weight: 700; color: var(--brand-bright); text-align: center; }
.leaderboard-item .name { font-weight: 700; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-item .score { text-align: center; color: var(--green); }
.leaderboard-item .points { text-align: center; color: #ffd700; font-weight: 700; }
.leaderboard-item .difficulty { text-align: center; font-size: 0.78rem; color: var(--text-dim); }

/* Analytiikka */
.difficulty-stat {
  padding: 10px; background: var(--surface-3);
  margin: 6px 0; border-radius: var(--r-sm);
}
.hardest-models { display: flex; flex-direction: column; gap: 8px; }
.model-stat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px; background: var(--brand-tint);
  border-radius: var(--r-sm); border-left: 3px solid var(--brand);
}
.model-stat .rank { font-weight: 700; color: var(--brand-bright); min-width: 28px; }
.model-stat .model-name { flex: 1; text-align: left; margin-left: 10px; }
.model-stat .wrong-count { color: #ff6b6b; font-weight: 700; }
.model-stat .avg-time { color: #ffd700; font-size: 0.9rem; }

.result-buttons, .analytics-buttons, .share-buttons {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin-top: 18px;
}
.result-buttons button, .analytics-buttons button {
  font-size: 0.85rem; padding: 10px 14px; width: auto; white-space: nowrap; margin-bottom: 0;
}

/* Jakomodaali */
.share-text textarea, .share-url input {
  width: 100%; background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px;
  font-family: inherit;
}
.share-text textarea { height: 80px; resize: vertical; }
.share-url { display: flex; gap: 10px; margin: 15px 0; }
.share-url input { flex: 1; margin: 0; }
.share-url button { width: auto; margin: 0; }
.share-btn { padding: 10px 14px; border-radius: var(--r-sm); text-decoration: none; color: #fff; font-size: 0.9rem; font-weight: 600; }
.share-btn.twitter { background: #1da1f2; }
.share-btn.facebook { background: #4267b2; }
.share-btn.whatsapp { background: #25d366; }

/* Haaste-ilmoitus */
.challenge-notification {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--surface-1); border: 1px solid var(--brand);
  border-radius: var(--r-lg); padding: 24px;
  box-shadow: var(--shadow-md); color: var(--text);
  z-index: 1000; max-width: 400px; width: 90%; text-align: center;
}
.challenge-notification h3 { margin-top: 0; color: var(--brand-bright); }
.challenge-notification ul { text-align: left; margin: 15px 0; }
.challenge-notification button { width: auto; }

table {
  width: 100%; color: var(--text);
  border-collapse: collapse; margin-top: 12px;
  border-radius: var(--r-sm); overflow: hidden;
}
th, td { padding: 8px; border-bottom: 1px solid var(--border); }
th { background: var(--brand); color: #fff; }
td { text-align: center; }

/* Footer */
footer {
  text-align: center; padding: 24px 16px;
  background: var(--surface-1); border-top: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.9rem; width: 100%; margin-top: auto;
}
footer a { color: inherit; }
footer .logo { width: 76px; height: auto; margin-top: 8px; border: none; opacity: 0.85; }

.add-games { text-align: center; margin: 22px 0; }
#addGamesButton {
  display: inline-block; font-size: 1rem; font-weight: 700;
  padding: 12px 24px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--brand), var(--brand-bright));
  color: #fff; text-decoration: none; width: auto;
  box-shadow: 0 6px 16px rgba(255, 25, 25, 0.3);
  transition: transform var(--transition), box-shadow var(--transition);
}
#addGamesButton:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(255, 25, 25, 0.5); }

/* Mobiili */
@media (max-width: 768px) {
  h1 { font-size: 1.7rem; }
  .container { padding: 20px 16px; }
  .quiz-image, img.quiz-image { height: 190px; }
  .leaderboard-item { grid-template-columns: 32px 1fr 56px 64px; font-size: 0.82rem; }
  .leaderboard-item .difficulty { display: none; }
  .model-stat { flex-direction: column; align-items: flex-start; gap: 5px; }
  .model-stat .model-name { margin-left: 0; }
  .share-buttons, .analytics-buttons, .result-buttons { flex-direction: column; }
  .result-buttons button { width: 100%; max-width: 240px; }
}
