/* =====================================================================
   Puu- ja pensasvisa – Rifpelit (luontoteemainen vihreä variantti)
   ===================================================================== */
:root {
  --brand: #2f9e56;
  --brand-bright: #45c06e;
  --brand-deep: #1f7a41;
  --brand-glow: rgba(47, 158, 86, 0.35);
  --brand-tint: rgba(47, 158, 86, 0.12);
  --accent: #ff1919;            /* Rifpelit-punainen korostus */
  --bg: #0b0f0c;
  --surface-1: #121712;
  --surface-2: #182018;
  --surface-3: #202a20;
  --border: #2a352a;
  --text: #f2f6f2;
  --text-muted: #b3c1b3;
  --text-dim: #7d8c7d;
  --green: #45c06e;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow-md: 0 12px 34px rgba(0, 0, 0, 0.5);
  --transition: 0.26s 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;
}
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(820px 520px at 12% -5%, rgba(47, 158, 86, 0.10), transparent 60%),
    radial-gradient(720px 520px at 88% 12%, rgba(69, 192, 110, 0.06), transparent 60%);
}
::selection { background: var(--brand); color: #fff; }

.container {
  width: 92%;
  max-width: 640px;
  margin: 26px auto;
  padding: 26px 22px;
  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: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 0 0 8px;
  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);
}
.tagline { color: var(--text-muted); font-size: 0.98rem; margin: 0 0 18px; }

/* Tila-palkki */
#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.95rem; font-weight: 600; }
#status p span { color: var(--brand-bright); }
#playerInfo { width: 100%; margin-top: 8px; }

.streak { font-weight: 700; color: var(--brand-bright); transition: transform var(--transition); display: inline-block; }
.streak.bump { transform: scale(1.35); }

label {
  display: block; margin: 14px 0 6px;
  font-size: 0.9rem; 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: 12px; 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);
}
#modeSelect, #groupSelect { border: 1.5px solid var(--brand); font-weight: 600; }
select option { background: var(--surface-3); color: var(--text); }

button {
  background: linear-gradient(135deg, var(--brand), var(--brand-bright));
  color: #fff; cursor: pointer; font-weight: 600; border: none;
  box-shadow: 0 6px 16px var(--brand-glow);
  transition: transform var(--transition), box-shadow var(--transition);
}
button:hover { transform: translateY(-2px); box-shadow: 0 10px 26px var(--brand-glow); }
button:active { transform: translateY(0); }

#startGame { font-size: 1.1rem; font-weight: 700; padding: 14px; margin-top: 6px; }
button.secondary {
  background: var(--surface-3); border: 1px solid var(--border);
  color: var(--text); box-shadow: none;
}
button.secondary:hover { border-color: var(--brand); background: var(--surface-2); }

#playerInfo button {
  background: var(--surface-3); border: 1px solid var(--border);
  box-shadow: none; font-weight: 600; width: auto; margin-bottom: 0;
}
#playerInfo button:hover { border-color: var(--brand); background: var(--surface-2); }

/* Kysymys */
.question-counter { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); margin: 0 0 6px; }
.mode-hint { font-size: 0.82rem; color: var(--text-dim); margin: 2px 0 10px; text-align: left; min-height: 1em; }
/* Aikahaaste / sinnittely -palkki kysymyksen yllä */
.qa-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; margin-bottom: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 0.95rem; font-weight: 600;
}
.qa-bar b { color: var(--brand-bright); }
#timerDisplay { font-size: 1.15rem; }
#timerDisplay.low { color: var(--accent); animation: pulse 0.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.progress-bar {
  width: 100%; height: 8px; background: var(--surface-3);
  border-radius: 999px; overflow: hidden; margin: 4px 0 16px;
}
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--brand), var(--brand-bright));
  border-radius: 999px; transition: width 0.4s ease;
}
.prompt { font-size: 1.1rem; font-weight: 600; margin: 6px 0 14px; color: #fff; }
.prompt .clue {
  display: block; margin-top: 8px; font-style: italic; font-weight: 500;
  color: var(--brand-bright); font-size: 0.98rem;
}

/* Media (valokuva) */
.media {
  width: 100%; max-width: 420px; height: 260px; margin: 0 auto 6px;
  border: 3px solid var(--brand); border-radius: var(--r-md); overflow: hidden;
  box-shadow: 0 8px 24px var(--brand-glow); background: var(--surface-3);
}
.media.small { max-width: 100%; height: 190px; margin: 4px 0 6px; }
.quiz-photo { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Kysymyskuvan karuselli (nuolet + pyyhkäisy) */
.media.carousel { position: relative; }
.car-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.45); color: #fff; border: none;
  font-size: 1.7rem; line-height: 1; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.15s; z-index: 3;
  -webkit-tap-highlight-color: transparent;
}
.car-arrow:hover { background: rgba(0, 0, 0, 0.72); }
.car-arrow:active { transform: translateY(-50%) scale(0.9); }
.car-arrow.prev { left: 8px; }
.car-arrow.next { right: 8px; }
.car-count {
  position: absolute; top: 8px; right: 10px; z-index: 3;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 0.72rem; font-weight: 600; padding: 2px 9px; border-radius: 999px;
}
.car-dots {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; z-index: 3;
}
.car-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.5); transition: background 0.2s;
}
.car-dots span.active { background: #fff; }

/* Pelimuoto: Yhdistä latina */
.match-board { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; position: relative; }
.match-lines { position: absolute; inset: 0; pointer-events: none; z-index: 2; overflow: visible; }
.match-lines line { stroke: var(--green); stroke-width: 3; stroke-linecap: round; opacity: 0.9; stroke-dasharray: 1000; animation: dash 0.4s ease-out forwards; }
.match-lines circle { fill: var(--green); }
@keyframes dash { from { stroke-dashoffset: 1000; } to { stroke-dashoffset: 0; } }
.match-col { display: flex; flex-direction: column; gap: 10px; }
.match-item, .match-latin {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-3); color: var(--text); cursor: pointer;
  font-weight: 600; font-size: 0.9rem; text-align: left; box-shadow: none;
  transition: border-color 0.18s, background 0.18s, transform 0.12s; min-height: 52px;
}
.match-item img {
  width: 42px; height: 42px; object-fit: cover; border-radius: 6px; flex-shrink: 0;
}
.match-latin { justify-content: center; text-align: center; font-style: italic; }
.match-item:hover:not(:disabled), .match-latin:hover:not(:disabled) {
  border-color: var(--brand); background: var(--surface-2); transform: translateY(-1px);
}
.match-item.sel, .match-latin.sel {
  border-color: var(--brand-bright); background: var(--brand-tint);
  box-shadow: 0 0 0 2px var(--brand-tint);
}
.match-item.matched, .match-latin.matched {
  border-color: var(--green); background: rgba(69, 192, 110, 0.18);
  color: var(--green); cursor: default; opacity: 0.85;
}
.match-item.mismatch, .match-latin.mismatch {
  border-color: var(--accent); background: rgba(255, 25, 25, 0.18);
  animation: shake 0.3s ease;
}
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (max-width: 380px) {
  .match-item, .match-latin { font-size: 0.82rem; padding: 6px 8px; min-height: 46px; }
  .match-item img { width: 36px; height: 36px; }
}

/* Ennätykset-modaali */
.records-content { max-width: 460px; }
.records-body { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 16px; }
.record-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.rec-ico { font-size: 1.3rem; width: 28px; text-align: center; }
.rec-label { flex: 1; font-size: 0.9rem; color: var(--text-muted); }
.rec-val { font-weight: 700; color: var(--brand-bright); white-space: nowrap; }
.reset-records { width: 100%; font-size: 0.85rem; }
.leaf-svg { width: 100%; height: auto; display: block; max-height: 260px; }
.credit {
  font-size: 0.72rem; color: var(--text-dim); text-align: center;
  margin: 0 auto 16px; max-width: 420px; line-height: 1.4;
}
.credit a { color: var(--brand-bright); text-decoration: none; }
.credit a:hover { text-decoration: underline; }
.reveal-card .credit, .study-card .credit { text-align: left; margin: 4px 0 10px; }

/* 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; padding-left: 44px; text-align: left;
}
.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 7px;
}
.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(69, 192, 110, 0.4) !important;
}
button.wrong {
  background: linear-gradient(135deg, var(--accent), #c31212) !important;
  border-color: var(--accent) !important; color: #fff !important;
}
.options button i { font-style: italic; }

/* Palaute-välähdys */
.feedback-flash { position: fixed; inset: 0; z-index: 900; pointer-events: none; opacity: 0; }
.feedback-flash.correct { box-shadow: inset 0 0 120px rgba(69, 192, 110, 0.5); animation: flash 0.6s ease; }
.feedback-flash.wrong { box-shadow: inset 0 0 120px rgba(255, 25, 25, 0.5); animation: flash 0.6s ease; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* Paljastuskortti */
.reveal { margin-top: 16px; }
.reveal-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--r-md); padding: 16px 18px; text-align: left;
}
.reveal-head { font-size: 1.05rem; margin-bottom: 10px; }
.reveal-head strong { color: var(--brand-bright); }
.latin { font-style: italic; color: var(--text-dim); font-weight: 500; }
.reveal-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tag {
  font-size: 0.78rem; font-weight: 600; padding: 3px 10px;
  border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border); color: var(--text-muted);
}
.tag.lehtipuu { background: rgba(90, 166, 74, 0.18); color: #8fd47a; border-color: #4a7a3a; }
.tag.havupuu  { background: rgba(47, 125, 79, 0.20); color: #6ecb9a; border-color: #2f6b4f; }
.tag.pensas   { background: rgba(107, 179, 86, 0.16); color: #a6d98f; border-color: #5a7a3a; }
.tag.varpu    { background: rgba(138, 178, 74, 0.16); color: #c3d98f; border-color: #6b7a3a; }
.tag.koriste  { background: rgba(214, 111, 168, 0.16); color: #e8a8ce; border-color: #8a4a6b; }
.reveal-facts { list-style: none; padding: 0; margin: 6px 0 14px; }
.reveal-facts li { margin: 7px 0; font-size: 0.92rem; color: var(--text-muted); }
.reveal-facts b { color: var(--text); }
.next-btn { font-weight: 700; margin-bottom: 0; }

/* Tulokset */
.results { margin-top: 22px; }
.results-summary, .wrong-answers {
  background: var(--surface-2); padding: 18px; border-radius: var(--r-md);
  margin-bottom: 14px; border: 1px solid var(--border); text-align: left;
}
.results-summary { border-color: var(--brand); text-align: center; }
.results-summary h2 { margin: 0 0 8px; color: var(--brand-bright); }
.big-score { font-size: 1.4rem; font-weight: 800; margin: 8px 0; }
.big-score .pct { color: var(--brand-bright); }
.result-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
.result-buttons button { width: auto; margin-bottom: 0; }
.wrong-answers h3 { color: var(--accent); margin-top: 0; }
.mistake {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface-3); padding: 10px 12px;
  border-radius: var(--r-sm); margin: 10px 0; border-left: 4px solid var(--accent);
}
.mistake-media {
  width: 70px; height: 70px; flex-shrink: 0;
  border-radius: 8px; overflow: hidden; background: var(--surface-2);
}
.mistake-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mistake-info { font-size: 0.9rem; }
.mistake-info small { color: var(--text-dim); display: block; margin-top: 4px; }

/* Opiskelu-modaali */
.study-modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.82);
  display: flex; justify-content: center; align-items: center;
  z-index: 1000; padding: 14px; backdrop-filter: blur(4px);
}
.study-content {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg); width: 100%; max-width: 900px;
  max-height: 88vh; overflow-y: auto; padding: 20px; box-shadow: var(--shadow-md);
}
.study-head { display: flex; justify-content: space-between; align-items: center; }
.study-head h2 { margin: 0; color: var(--brand-bright); }
.close-btn { width: auto; background: var(--surface-3); border: 1px solid var(--border); padding: 8px 14px; margin: 0; box-shadow: none; }
.study-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.study-filter button { width: auto; margin: 0; background: var(--surface-3); border: 1px solid var(--border); color: var(--text); box-shadow: none; font-size: 0.85rem; padding: 8px 14px; }
.study-filter button.active { background: linear-gradient(135deg, var(--brand), var(--brand-bright)); border-color: var(--brand); color: #fff; }
.study-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.study-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 14px; text-align: left;
}
.study-media {
  width: 100%; height: 150px; margin: 0 auto 8px;
  border-radius: var(--r-md); overflow: hidden; border: 2px solid var(--brand);
  background: var(--surface-3);
}
.study-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs { display: flex; gap: 6px; margin: 6px 0 2px; }
.thumb {
  width: 44px; height: 44px; object-fit: cover; border-radius: 6px;
  border: 2px solid var(--border); cursor: pointer; opacity: 0.7;
  transition: opacity var(--transition), border-color var(--transition);
}
.thumb:hover { opacity: 1; }
.thumb.active { border-color: var(--brand); opacity: 1; }
.study-credit { min-height: 14px; }
.study-card h3 { margin: 6px 0; font-size: 1.05rem; color: #fff; }
.study-card h3 .latin { display: block; font-size: 0.82rem; }
.study-card .reveal-facts li { font-size: 0.82rem; }

/* Alaosa */
.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;
  box-shadow: 0 6px 16px var(--brand-glow);
  transition: transform var(--transition), box-shadow var(--transition);
}
#addGamesButton:hover { transform: translateY(-2px); box-shadow: 0 10px 26px var(--brand-glow); }

footer {
  text-align: center; padding: 22px 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 .share-container { margin-bottom: 12px; }
.disclaimer { font-size: 0.78rem; color: var(--text-dim); max-width: 480px; margin: 8px auto 0; }

@media (max-width: 768px) {
  h1 { font-size: 1.6rem; }
  .container { padding: 20px 14px; }
  .study-grid { grid-template-columns: 1fr 1fr; }
  .study-card .reveal-facts { display: none; }
  .result-buttons button { width: 100%; }
}
@media (max-width: 480px) {
  .study-grid { grid-template-columns: 1fr; }
  .study-card .reveal-facts { display: block; }
}
