/* =========================================================
   Simple Past — polished quiz UI
========================================================= */

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

:root {
  --sp-green: #079d73;
  --sp-green-dark: #068a64;
  --sp-green-soft: #eaf8f4;
  --sp-green-border: #d5ebe3;
  --sp-bg: #eef5f2;
  --sp-card: #ffffff;
  --sp-text: #1c2434;
  --sp-muted: #6b7589;
  --sp-ok: #059669;
  --sp-ok-bg: #ecfdf5;
  --sp-bad: #e11d48;
  --sp-bad-bg: #fff1f2;
  --sp-option: #ffffff;
  --sp-option-border: #d7e3dd;
  --sp-option-text: #243041;
  --sp-shadow: 0 18px 50px rgba(16, 48, 38, 0.1);
  --sp-radius: 28px;
}

html[data-theme="dark"] {
  --sp-bg: #0e1311;
  --sp-card: #17201c;
  --sp-text: #eef5f1;
  --sp-muted: #9aaba3;
  --sp-green-soft: #14352c;
  --sp-green-border: #24463b;
  --sp-option: #1e2a25;
  --sp-option-border: #2f453c;
  --sp-option-text: #eef5f1;
  --sp-ok-bg: #10352b;
  --sp-bad-bg: #3a1520;
  --sp-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
}

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(7, 157, 115, 0.12), transparent 60%),
    var(--sp-bg);
  color: var(--sp-text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Hide site header while playing — Topics button is enough */
body.sp-playing .game-header {
  display: none !important;
}

/* ---------- Header (menu / result only) ---------- */
.game-header {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 68px;
  padding: 12px 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--sp-green-border);
}

html[data-theme="dark"] .game-header {
  background: rgba(14, 19, 17, 0.9);
}

.header-left { justify-self: start; }
.header-right { justify-self: end; min-width: 44px; }

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--sp-text);
  background: var(--sp-card);
  border: 1px solid var(--sp-green-border);
  transition: 0.15s ease;
}

.back-button:hover {
  border-color: var(--sp-green);
  box-shadow: 0 6px 16px rgba(7, 157, 115, 0.12);
}

.game-title {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: center;
}

.game-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #12c48f, #079d73);
  color: #fff;
  font-size: 20px;
  box-shadow: 0 10px 20px rgba(7, 157, 115, 0.28);
}

.game-title-text h1 { font-size: 16px; font-weight: 800; }
.game-title-text p { font-size: 12px; color: var(--sp-muted); margin-top: 2px; }

/* ---------- Layout ---------- */
.game-container {
  width: min(900px, 92%);
  margin: 0 auto;
  padding: 28px 0 56px;
  flex: 1;
}

body.sp-playing .game-container {
  padding-top: 20px;
}

.screen { animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.eyebrow {
  display: inline-block;
  color: var(--sp-green);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.3px;
}

.menu-intro { text-align: center; margin-bottom: 28px; }
.menu-intro h2 {
  margin: 10px 0 8px;
  font-size: clamp(28px, 5vw, 36px);
  letter-spacing: -0.6px;
}
.menu-intro p { color: var(--sp-muted); font-size: 15px; }

/* ---------- Topic cards ---------- */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.topic-card {
  background: var(--sp-card);
  border: 1px solid var(--sp-green-border);
  border-radius: 22px;
  padding: 22px 18px;
  box-shadow: var(--sp-shadow);
}

.topic-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #12c48f, #079d73);
  color: #fff;
  font-size: 20px;
  margin-bottom: 12px;
  box-shadow: 0 10px 18px rgba(7, 157, 115, 0.25);
}

.topic-card h3 { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.topic-card > p { color: var(--sp-muted); font-size: 13px; margin-bottom: 14px; }

.level-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.level-list li,
.level-list li.level-link a {
  display: block;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--sp-green-soft);
  border: 1px solid transparent;
  color: var(--sp-green-dark);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
  transition: 0.15s ease;
}

html[data-theme="dark"] .level-list li,
html[data-theme="dark"] .level-list li.level-link a { color: #b6f0d8; }

.level-list li:hover,
.level-list li.level-link a:hover {
  border-color: var(--sp-green);
  transform: translateX(2px);
}

.level-list li.level-link { padding: 0; background: transparent; border: none; }

/* ---------- Play top ---------- */
.play-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.mode-label {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.4px;
  color: var(--sp-green);
  text-align: center;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--sp-card);
  border: 1px solid var(--sp-green-border);
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(7, 157, 115, 0.08);
}

.progress-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(7, 157, 115, 0.12);
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #12c48f, #079d73);
  transition: width 0.35s ease;
}

/* =========================================================
   QUIZ CARD
========================================================= */
#playScreen .prompt-card {
  margin: 0;
  border: 1px solid var(--sp-green-border);
  border-bottom: none;
  border-radius: var(--sp-radius) var(--sp-radius) 0 0;
  background: var(--sp-card);
  padding: 40px 28px 28px;
  text-align: center;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

#playScreen .prompt-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(600px 180px at 50% 0%, rgba(7, 157, 115, 0.08), transparent 70%);
  pointer-events: none;
}

#playScreen .prompt-hint {
  position: relative;
  margin: 0 0 14px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--sp-green-soft);
  font-size: 11px;
  font-weight: 900;
  color: var(--sp-green-dark);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

html[data-theme="dark"] #playScreen .prompt-hint { color: #9af0cd; }

#playScreen .prompt-text {
  position: relative;
  margin: 0;
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 800;
  letter-spacing: -0.45px;
  line-height: 1.4;
  max-width: 22ch;
}

#playScreen .choices-area {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin: 0;
  padding: 22px 24px 28px;
  background: var(--sp-card);
  border: 1px solid var(--sp-green-border);
  border-radius: 0 0 var(--sp-radius) var(--sp-radius);
  box-shadow: var(--sp-shadow);
}

/* DEFAULT options — neutral (NOT success green) */
#playScreen .choice-btn {
  appearance: none;
  flex: 1 1 140px;
  max-width: 220px;
  min-width: 120px;
  min-height: 58px;
  padding: 14px 18px;
  border-radius: 18px;
  border: 2px solid var(--sp-option-border);
  background: var(--sp-option);
  color: var(--sp-option-text);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 4px 0 #c8d8d0;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.12s ease, color 0.15s ease;
}

html[data-theme="dark"] #playScreen .choice-btn {
  box-shadow: 0 4px 0 #0f1915;
}

#playScreen .choice-btn:hover:not(:disabled) {
  border-color: var(--sp-green);
  background: var(--sp-green-soft);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #b7cfc4;
}

#playScreen .choice-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #b7cfc4;
}

/* CORRECT — clearly different from default */
#playScreen .choice-btn.correct,
#playScreen .choice-btn.is-correct {
  background: linear-gradient(180deg, #10b981, #059669) !important;
  border-color: transparent !important;
  color: #ffffff !important;
  box-shadow: 0 5px 0 #047857, 0 0 0 4px rgba(16, 185, 129, 0.2) !important;
  transform: translateY(-1px);
}

/* WRONG — clearly different */
#playScreen .choice-btn.wrong,
#playScreen .choice-btn.is-wrong {
  background: linear-gradient(180deg, #fb7185, #e11d48) !important;
  border-color: transparent !important;
  color: #ffffff !important;
  box-shadow: 0 5px 0 #9f1239, 0 0 0 4px rgba(225, 29, 72, 0.15) !important;
}

#playScreen .choice-btn:disabled {
  cursor: default;
}

/* dim non-selected after answer if needed */
#playScreen .choice-btn:disabled:not(.correct):not(.is-correct):not(.wrong):not(.is-wrong) {
  opacity: 0.45;
}

/* Fallback */
.choices-area { display: flex; flex-wrap: wrap; gap: 12px; }
.choice-btn {
  appearance: none;
  min-height: 52px;
  padding: 14px 18px;
  border-radius: 16px;
  border: 2px solid var(--sp-option-border);
  background: var(--sp-option);
  color: var(--sp-option-text);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

/* ---------- Match board ---------- */
.sp-match-rush {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--sp-card);
  border: 1px solid var(--sp-green-border);
  border-radius: var(--sp-radius);
  padding: 18px;
  box-shadow: var(--sp-shadow);
}

.sp-mr-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.sp-mr-stat {
  text-align: center;
  padding: 12px 10px;
  border-radius: 14px;
  background: var(--sp-green-soft);
  border: 1px solid var(--sp-green-border);
}

.sp-mr-stat span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: var(--sp-muted);
  text-transform: uppercase;
}

.sp-mr-stat h2 {
  margin-top: 4px;
  font-size: 22px;
  color: var(--sp-green);
}

.sp-mr-powerups { display: flex; justify-content: center; gap: 10px; }

.sp-mr-power {
  appearance: none;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--sp-green);
  background: transparent;
  color: var(--sp-green-dark);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.sp-mr-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.sp-mr-column {
  background: var(--sp-green-soft);
  border: 1px solid var(--sp-green-border);
  border-radius: 16px;
  padding: 14px;
  min-height: 200px;
}

.sp-mr-column h3 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--sp-green);
  text-align: center;
}

.sp-mr-column > div { display: flex; flex-direction: column; gap: 10px; }

.match-chip,
#matchLeft button,
#matchRight button {
  appearance: none;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--sp-option-border);
  background: var(--sp-option);
  color: var(--sp-option-text);
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 3px 0 #c8d8d0;
  transition: 0.12s ease;
}

.match-chip.selected,
#matchLeft button.selected,
#matchRight button.selected {
  background: linear-gradient(180deg, #10b981, #059669);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 0 #047857;
}

.match-chip.matched,
#matchLeft button.matched,
#matchRight button.matched {
  opacity: 0.35;
  pointer-events: none;
  box-shadow: none;
}

/* ---------- Feedback / buttons ---------- */
.feedback {
  min-height: 32px;
  margin-top: 16px;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
}

.feedback.ok {
  color: var(--sp-ok);
  background: var(--sp-ok-bg);
  border: 1px solid rgba(5, 150, 105, 0.2);
  border-radius: 12px;
  padding: 10px 14px;
}

.feedback.bad {
  color: var(--sp-bad);
  background: var(--sp-bad-bg);
  border: 1px solid rgba(225, 29, 72, 0.18);
  border-radius: 12px;
  padding: 10px 14px;
}

.main-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 28px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(145deg, #12c48f, #079d73);
  color: #fff;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 8px 0 #047857;
  transition: transform 0.12s ease;
}

.main-btn:hover { transform: translateY(-2px); }
.main-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #047857; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--sp-green-border);
  background: var(--sp-card);
  color: var(--sp-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(16, 48, 38, 0.06);
  transition: 0.15s ease;
}

.ghost-btn:hover {
  border-color: var(--sp-green);
  color: var(--sp-green-dark);
  background: var(--sp-green-soft);
}

/* ---------- Result ---------- */
.result-card {
  max-width: 480px;
  margin: 0 auto;
  background: var(--sp-card);
  border: 1px solid var(--sp-green-border);
  border-radius: 24px;
  box-shadow: var(--sp-shadow);
  padding: 36px 28px;
  text-align: center;
}

.result-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--sp-green-soft);
  font-size: 28px;
}

.result-card h2 { margin: 8px 0 18px; font-size: 30px; }

.final-score {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 28px;
  border-radius: 16px;
  background: var(--sp-green-soft);
  margin-bottom: 18px;
}

.final-score span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--sp-green);
}

.final-score strong { font-size: 32px; color: var(--sp-green-dark); }
html[data-theme="dark"] .final-score strong { color: #8ef0c4; }

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.result-stats div {
  padding: 12px 8px;
  border-radius: 12px;
  background: var(--sp-green-soft);
  border: 1px solid var(--sp-green-border);
}

.result-stats span {
  display: block;
  font-size: 11px;
  color: var(--sp-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.result-stats strong { font-size: 18px; }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.site-footer {
  text-align: center;
  padding: 20px;
  color: var(--sp-muted);
  font-size: 12px;
  border-top: 1px solid var(--sp-green-border);
}

body.sp-playing .site-footer { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .topic-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  html, body { height: 100%; height: 100dvh; }
  body { overflow: hidden; }

  .game-header {
    min-height: 60px;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top, 0px));
  }

  .game-icon { width: 36px; height: 36px; font-size: 17px; }
  .game-title-text h1 { font-size: 14px; }
  .game-title-text p { font-size: 10px; }
  .header-right { display: none; }
  .site-footer { display: none; }

  .game-container {
    width: 100%;
    margin: 0;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #menuScreen,
  #resultScreen {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #playScreen.screen:not(.hidden) {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: none;
  }

  .play-top, .progress-track { flex: 0 0 auto; }

  #playScreen .prompt-card {
    flex: 1 1 auto;
    min-height: 120px;
    padding: 28px 16px;
  }

  #playScreen .prompt-text { font-size: 22px; }

  #playScreen .choices-area {
    flex: 0 0 auto;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
  }

  #playScreen .choice-btn {
    flex: 0 0 auto;
    max-width: none;
    width: 100%;
    min-height: 56px;
    font-size: 18px;
  }

  .sp-match-rush {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .sp-mr-column {
    min-height: 0;
    overflow-y: auto;
  }

  .feedback { flex: 0 0 auto; }
  .main-btn { width: 100%; max-width: 320px; min-height: 52px; }
}


/* ========== UNIFIED GRAMMAR BACK BUTTON ========== */
.back-button,
a.back-button,
button.back-button,
.arcade-back-btn.back-button,
.arcade-back-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  height: auto !important;
  min-height: 40px !important;
  padding: 10px 14px !important;
  border-radius: 12px !important;
  border: 1px solid #dcefe9 !important;
  background: #ffffff !important;
  color: #202636 !important;
  text-decoration: none !important;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  letter-spacing: 0 !important;
  white-space: nowrap !important;
  cursor: pointer !important;
  box-shadow: none !important;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease !important;
}

.back-button:hover,
a.back-button:hover,
button.back-button:hover,
.arcade-back-btn:hover {
  border-color: #079d73 !important;
  background: #ffffff !important;
  color: #202636 !important;
  box-shadow: 0 6px 16px rgba(7, 157, 115, 0.12) !important;
  transform: translateY(-1px) !important;
  filter: none !important;
}

.back-button:focus-visible,
.arcade-back-btn:focus-visible {
  outline: 3px solid rgba(7, 157, 115, 0.28) !important;
  outline-offset: 2px !important;
}

html[data-theme="dark"] .back-button,
html[data-theme="dark"] .arcade-back-btn,
body:not(.light-mode) .back-button,
body.dark-mode .back-button {
  background: #17201c !important;
  border-color: #24463b !important;
  color: #eef5f1 !important;
}

html[data-theme="dark"] .back-button:hover,
body:not(.light-mode) .back-button:hover,
body.dark-mode .back-button:hover {
  border-color: #079d73 !important;
  box-shadow: 0 6px 16px rgba(7, 157, 115, 0.2) !important;
}

@media (max-width: 700px) {
  .back-button,
  .arcade-back-btn {
    padding: 8px 12px !important;
    font-size: 12px !important;
    min-height: 36px !important;
    border-radius: 10px !important;
  }
}
/* ========== END UNIFIED BACK BUTTON ========== */
