/* ==========================================================================
   Phrasal Verb Access — English Access brand tokens
   Shared palette with Grammar Access / Vocabulary Access:
   deep purple #2E1A47, gold #F3D03E, slate #6E7C7D.
   ========================================================================== */
:root {
  --plum-950: #1E1030;
  --purple-800: #2E1A47;
  --purple-700: #4A2C6F;
  --purple-100: #EFEBF6;
  --gold-600: #8A6D12;
  --gold-300: #FBF4DA;
  --lavender-400: #B4A8C6;
  --gray-500: #6E7C7D;
  --gray-200: #E3E6E6;
  --gold-xp: #F3D03E;
  --purple-soft: #E7E0F1;
  --purple-ink: #3B2359;
  --blue-ink: #4A3168;
  --toast-bg: #2E1A47;
  --brand-solid: #2E1A47;
  --brand-solid-hover: #4A2C6F;
  --medal-from: #4A2C6F;
  --medal-to: #2E1A47;

  --accent-solid: #F3D03E;
  --accent-solid-hover: #E0BC22;
  --accent-ink: #2E1A47;

  --paper: #F8F7FA;
  --paper-raised: #FFFFFF;
  --ink: #2E1A47;
  --ink-soft: #4A4750;

  --correct: #1F7A45;
  --correct-bg: #E8F3EC;
  --incorrect: #E6392E;
  --incorrect-bg: #FBEAE8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-1: 0 1px 2px rgba(46, 26, 71, 0.06), 0 2px 8px rgba(46, 26, 71, 0.06);
  --shadow-2: 0 4px 16px rgba(46, 26, 71, 0.12);

  --serif: 'Poppins', 'Frutiger', 'Segoe UI', Helvetica, Arial, sans-serif;
  --sans: 'Frutiger', 'Inter', 'Segoe UI', Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --paper: #1B1224;
  --paper-raised: #241733;
  --ink: #F1EBF7;
  --ink-soft: #C9BEDA;
  --gray-200: #3A2E4A;
  --purple-100: #2E2140;
  --purple-soft: #33254A;
  --gold-300: #3A2E17;
  --correct-bg: #163B29;
  --incorrect-bg: #3B1A18;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.3), 0 2px 8px rgba(0,0,0,0.24);
  --shadow-2: 0 4px 20px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

a { color: var(--purple-700); }
[data-theme="dark"] a { color: var(--lavender-400); }

button { font-family: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--paper-raised);
  border-bottom: 1px solid var(--gray-200);
  position: sticky; top: var(--ea-nav-height, 0px); z-index: 20;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .brand img { height: 30px; display: block; }
.topbar .brand-title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; color: var(--plum-950); }
.topbar .brand-title span { color: var(--gold-600); }
[data-theme="dark"] .topbar .brand-title span { color: var(--gold-xp); }
.topbar .controls { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-md);
  border: 1px solid var(--gray-200); background: var(--paper-raised);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-size: 1rem;
}
.icon-btn:hover { background: var(--purple-100); }
.score-pill {
  font-family: var(--serif); font-weight: 600; font-size: .82rem;
  background: var(--purple-soft); color: var(--purple-ink);
  padding: 6px 12px; border-radius: 999px;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 0 20px; }

.search-bar-row {
  background: var(--paper-raised); border-bottom: 1px solid var(--gray-200);
  padding: 12px 24px; position: relative;
}
.search-bar-inner {
  max-width: 900px; margin: 0 auto; position: relative;
  display: flex; align-items: center; gap: 10px;
  background: var(--paper); border: 1px solid var(--gray-200); border-radius: var(--radius-md);
  padding: 9px 14px;
}
.search-bar-inner:focus-within { border-color: var(--purple-700); }
.search-icon { font-size: .9rem; opacity: .6; flex-shrink: 0; }
#phrasal-verb-search {
  flex: 1; border: none; background: none; outline: none;
  font-family: var(--sans); font-size: .88rem; color: var(--ink);
}
#phrasal-verb-search::placeholder { color: var(--ink-soft); }
.search-clear {
  border: none; background: none; color: var(--ink-soft); cursor: pointer;
  font-size: .8rem; padding: 2px 6px; flex-shrink: 0;
}
.search-results {
  max-width: 900px; margin: 8px auto 0; max-height: 420px; overflow-y: auto;
  background: var(--paper-raised); border: 1px solid var(--gray-200); border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(46,26,71,.12);
}
.search-result-item {
  display: block; width: 100%; text-align: left; padding: 12px 16px;
  border: none; border-bottom: 1px solid var(--gray-200); background: var(--paper-raised);
  cursor: pointer;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--purple-100); }
.search-result-phrasal-verb { font-family: var(--serif); font-weight: 600; font-size: .92rem; color: var(--purple-800); }
.search-result-cat {
  font-family: var(--serif); font-weight: 600; font-size: .66rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--gold-600); margin-left: 8px;
}
.search-result-meaning { font-size: .82rem; color: var(--ink-soft); margin-top: 2px; }
.search-empty { padding: 16px; text-align: center; color: var(--ink-soft); font-size: .85rem; }
[data-theme="dark"] .search-result-cat { color: var(--gold-xp); }

/* ---------- home / category grid ---------- */
.hero { text-align: center; padding: 40px 0 8px; }
.hero .eyebrow {
  font-family: var(--serif); font-weight: 600; font-size: .72rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--gold-600);
  margin: 0 0 10px;
}
[data-theme="dark"] .hero .eyebrow { color: var(--gold-xp); }
.hero h1 { font-family: var(--serif); font-weight: 700; font-size: clamp(1.8rem, 4.5vw, 2.6rem); color: var(--plum-950); margin: 0 0 12px; }
[data-theme="dark"] .hero h1 { color: var(--ink); }
.hero p { color: var(--ink-soft); max-width: 480px; margin: 0 auto; line-height: 1.55; }

.progress-summary {
  display: flex; justify-content: center; gap: 28px; margin: 26px 0 6px; flex-wrap: wrap;
}
.progress-stat { text-align: center; }
.progress-stat .num { font-family: var(--serif); font-weight: 700; font-size: 1.5rem; color: var(--purple-800); }
[data-theme="dark"] .progress-stat .num { color: var(--lavender-400); }
.progress-stat .label { font-size: .78rem; color: var(--ink-soft); }

.category-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  margin: 30px 0 60px;
}
@media (max-width: 720px) { .category-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .category-grid { grid-template-columns: 1fr; } }

.category-card {
  background: var(--paper-raised); border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg); padding: 18px 16px;
  box-shadow: var(--shadow-1); text-align: left;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.category-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.category-card .cat-name { font-family: var(--serif); font-weight: 600; font-size: .98rem; color: var(--plum-950); }
[data-theme="dark"] .category-card .cat-name { color: var(--ink); }
.category-card .cat-meta { font-size: .8rem; color: var(--ink-soft); display: flex; justify-content: space-between; }
.cat-bar { height: 6px; border-radius: 4px; background: var(--gray-200); overflow: hidden; }
.cat-bar-fill { height: 100%; background: var(--gold-xp); border-radius: 4px; }
.cat-chunk { margin-top: 8px; font-family: var(--serif); font-size: .72rem; font-weight: 600; color: var(--purple-700); }
[data-theme="dark"] .cat-chunk { color: var(--lavender-400); }

/* ---------- practice screen ---------- */
.practice-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 0 18px; gap: 12px; flex-wrap: wrap;
}
.practice-header h2 { font-family: var(--serif); font-weight: 600; font-size: 1.2rem; margin: 0; color: var(--plum-950); }
[data-theme="dark"] .practice-header h2 { color: var(--ink); }
.mode-toggle {
  display: inline-flex; border: 1px solid var(--gray-200); border-radius: 999px; overflow: hidden;
}
.mode-toggle button {
  border: none; background: transparent; padding: 7px 16px; font-size: .82rem;
  font-family: var(--serif); font-weight: 600; color: var(--ink-soft);
}
.mode-toggle button.active { background: var(--purple-800); color: #fff; }

.progress-track { height: 8px; border-radius: 4px; background: var(--gray-200); margin-bottom: 26px; overflow: hidden; }
.progress-track-fill { height: 100%; background: var(--purple-700); border-radius: 4px; transition: width .25s ease; }

.card-stage { min-height: 260px; }

.q-card {
  background: var(--paper-raised); border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg); padding: 28px 26px; box-shadow: var(--shadow-1);
}
.q-prompt { font-size: .85rem; color: var(--ink-soft); margin: 0 0 10px; }
.q-example { font-family: var(--serif); font-size: 1.15rem; line-height: 1.6; color: var(--ink); margin: 0 0 22px; }
.q-blank {
  display: inline-block; min-width: 90px; border-bottom: 2px solid var(--purple-700);
  color: var(--purple-700); font-weight: 600;
}

.learn-card .learn-phrasal-verb {
  font-family: var(--serif); font-weight: 700; font-size: 1.5rem; color: var(--purple-800);
  margin: 4px 0 0;
}
[data-theme="dark"] .learn-card .learn-phrasal-verb { color: var(--lavender-400); }
.learn-card .learn-meaning {
  font-size: 1rem; color: var(--ink); margin: 4px 0 0; line-height: 1.55;
}

.hint-btn {
  border: none; background: none; padding: 0; margin: 14px 0 0;
  font-size: .82rem; color: var(--purple-700); text-decoration: underline;
}
.hint-btn:disabled { color: var(--ink-soft); text-decoration: none; cursor: default; }
.hint-text {
  margin: 8px 0 0; font-size: .88rem; color: var(--ink-soft);
  background: var(--purple-100); border-radius: var(--radius-sm); padding: 8px 12px;
}

.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: block; width: 100%; text-align: left; padding: 12px 16px;
  border: 1px solid var(--gray-200); border-radius: var(--radius-md);
  background: var(--paper-raised); font-size: .95rem; color: var(--ink);
}
.choice:hover { border-color: var(--purple-700); }
.choice.correct { background: var(--correct-bg); border-color: var(--correct); color: var(--correct); font-weight: 600; }
.choice.incorrect { background: var(--incorrect-bg); border-color: var(--incorrect); color: var(--incorrect); font-weight: 600; }
.choice.dim { opacity: .55; }
.choice:disabled { cursor: default; }

.fill-row { display: flex; gap: 10px; margin-top: 4px; }
.fill-input {
  flex: 1; padding: 12px 14px; border: 1px solid var(--gray-200); border-radius: var(--radius-md);
  font-size: .95rem; background: var(--paper); color: var(--ink);
}
.fill-input:focus { outline: none; border-color: var(--purple-700); }
.fill-input.correct { border-color: var(--correct); background: var(--correct-bg); color: var(--correct); }
.fill-input.incorrect { border-color: var(--incorrect); background: var(--incorrect-bg); color: var(--incorrect); }
.btn {
  font-family: var(--serif); font-weight: 600; font-size: .9rem;
  padding: 12px 20px; border-radius: var(--radius-md); border: none;
  background: var(--brand-solid); color: #fff;
}
.btn:hover { background: var(--brand-solid-hover); }
.btn.ghost { background: transparent; color: var(--purple-700); border: 1px solid var(--gray-200); }
.btn.ghost:hover { background: var(--purple-100); }
.btn:disabled { opacity: .5; }

.feedback-banner {
  margin-top: 16px; padding: 12px 16px; border-radius: var(--radius-md);
  font-size: .88rem; display: none;
}
.feedback-banner.show { display: block; }
.feedback-banner.correct { background: var(--correct-bg); color: var(--correct); }
.feedback-banner.incorrect { background: var(--incorrect-bg); color: var(--incorrect); }

.stage-actions { display: flex; justify-content: space-between; margin-top: 22px; }

/* ---------- session summary ---------- */
.summary-card {
  text-align: center; background: var(--paper-raised); border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg); padding: 40px 30px; box-shadow: var(--shadow-1);
}
.summary-card .medal {
  width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--medal-from), var(--medal-to));
  display: flex; align-items: center; justify-content: center;
  color: var(--gold-xp); font-family: var(--serif); font-weight: 700; font-size: 1.4rem;
}
.summary-card h3 { font-family: var(--serif); font-weight: 600; font-size: 1.3rem; margin: 0 0 6px; color: var(--plum-950); }
[data-theme="dark"] .summary-card h3 { color: var(--ink); }
.summary-card p { color: var(--ink-soft); margin: 0 0 20px; }
.summary-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

.hidden { display: none !important; }

.reset-row { text-align: center; margin: 34px 0 0; }
.reset-link {
  border: none; background: none; font-family: var(--sans); font-size: .78rem;
  color: var(--gray-500); text-decoration: underline; cursor: pointer;
}
.reset-link:hover { color: #E6392E; }

footer.site-footer {
  text-align: center; padding: 30px 0 40px; font-size: .8rem; color: var(--ink-soft);
}
footer.site-footer a { color: var(--ink-soft); font-weight: 600; }
footer.site-footer a:hover { color: var(--purple-700); }

/* fullscreen */
:fullscreen .app-shell, :-webkit-full-screen .app-shell { background: var(--paper); overflow-y: auto; padding-bottom: 20px; }

/* ---------- points pill ---------- */
.points-pill {
  font-family: var(--serif); font-weight: 600; font-size: .82rem;
  background: var(--gold-300); color: var(--gold-600);
  padding: 6px 12px; border-radius: 999px;
}
[data-theme="dark"] .points-pill { background: #3A2E17; color: var(--gold-xp); }

/* ---------- quick actions ---------- */
.quick-actions {
  display: flex; justify-content: center; gap: 12px; flex-wrap: wrap;
  margin: 24px 0 8px;
}
.quick-action { display: inline-flex; align-items: center; gap: 8px; }
.qa-icon { font-size: 1rem; }
.quick-action:disabled { opacity: .5; cursor: default; }

/* ---------- section headings ---------- */
.section-heading {
  font-family: var(--serif); font-weight: 600; font-size: .95rem;
  color: var(--plum-950); text-align: center; margin: 34px 0 14px;
}
[data-theme="dark"] .section-heading { color: var(--ink); }

/* ---------- badges ---------- */
.badges-section { margin-top: 6px; }
.badge-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  max-width: 640px; margin: 0 auto;
}
@media (max-width: 560px) { .badge-grid { grid-template-columns: repeat(2, 1fr); } }
.badge-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 8px; border-radius: var(--radius-md);
  background: var(--paper-raised); border: 1px solid var(--gray-200);
  text-align: center;
}
.badge-item.locked { opacity: .4; }
.badge-item .badge-icon {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  background: linear-gradient(135deg, var(--medal-from), var(--medal-to));
}
.badge-item.locked .badge-icon { background: var(--gray-200); filter: grayscale(1); }
.badge-item .badge-name {
  font-family: var(--serif); font-weight: 600; font-size: .74rem; color: var(--ink);
  line-height: 1.3;
}

/* ---------- category tag (weak-spots mixed mode) ---------- */
.category-tag {
  display: inline-block; font-family: var(--serif); font-weight: 600;
  font-size: .7rem; letter-spacing: .03em; text-transform: uppercase;
  color: var(--purple-700); background: var(--purple-100);
  padding: 3px 10px; border-radius: 999px; margin-bottom: 10px;
}
[data-theme="dark"] .category-tag { color: var(--lavender-400); background: var(--purple-100); }

/* ---------- streak / new-badge banner in summary ---------- */
.new-badges {
  margin-top: 16px; padding: 12px 16px; border-radius: var(--radius-md);
  background: var(--gold-300); color: var(--gold-600);
  font-family: var(--serif); font-weight: 600; font-size: .85rem;
}
[data-theme="dark"] .new-badges { background: #3A2E17; color: var(--gold-xp); }

/* ---------- share modal ---------- */
.modal-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(30,16,48,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-card {
  background: var(--paper-raised); border-radius: var(--radius-lg);
  padding: 26px; max-width: 480px; width: 100%; position: relative;
  box-shadow: var(--shadow-2); text-align: center;
}
.modal-card h3 { font-family: var(--serif); font-weight: 600; margin: 0 0 14px; color: var(--plum-950); }
[data-theme="dark"] .modal-card h3 { color: var(--ink); }
.modal-close {
  position: absolute; top: 14px; right: 14px; border: none; background: none;
  font-size: 1rem; color: var(--ink-soft); cursor: pointer;
}
#share-preview {
  width: 100%; aspect-ratio: 1200 / 630; min-height: 180px; border-radius: var(--radius-md);
  border: 1px solid var(--gray-200); margin-bottom: 16px; display: block; background: var(--paper);
  background-image: linear-gradient(90deg, var(--paper) 0%, var(--purple-100) 50%, var(--paper) 100%);
  background-size: 200% 100%; animation: share-preview-loading 1.4s ease-in-out infinite;
}
#share-preview[src] { animation: none; background-image: none; }
#share-preview.error { animation: none; background-image: none; background: var(--gray-200); }
@keyframes share-preview-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.share-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.share-hint { font-size: .78rem; color: var(--ink-soft); margin: 10px 0 0; }
.link-btn { background: none; border: none; padding: 0; color: var(--purple-700); font-weight: 600; text-decoration: underline; cursor: pointer; font-size: inherit; }
[data-theme="dark"] .link-btn { color: var(--lavender-400); }

/* ---------- leaderboard ---------- */
.lb-setup {
  background: var(--paper-raised); border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg); padding: 26px; text-align: center;
}
.lb-setup p { color: var(--ink-soft); font-size: .9rem; line-height: 1.6; max-width: 480px; margin: 0 auto 8px; }
.lb-setup code {
  background: var(--purple-100); color: var(--purple-ink); padding: 2px 6px;
  border-radius: 4px; font-size: .85em;
}
.lb-name-row { display: flex; gap: 10px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }
.lb-name-row input {
  padding: 10px 14px; border: 1px solid var(--gray-200); border-radius: var(--radius-md);
  font-size: .9rem; background: var(--paper); color: var(--ink); min-width: 220px;
}
.lb-list { max-width: 520px; margin: 0 auto; }
.lb-note { max-width: 520px; margin: 0 auto 14px; font-size: .85rem; color: var(--ink-soft); text-align: center; }
.lb-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  background: var(--paper-raised); border: 1px solid var(--gray-200);
  border-radius: var(--radius-md); margin-bottom: 8px;
}
.lb-row.me { border-color: var(--gold-xp); background: var(--gold-300); }
.lb-rank {
  font-family: var(--serif); font-weight: 700; font-size: 1rem; color: var(--purple-700);
  width: 28px; text-align: center; flex-shrink: 0;
}
.lb-row:nth-child(1) .lb-rank { color: var(--gold-600); }
.lb-name { font-family: var(--serif); font-weight: 600; font-size: .92rem; color: var(--ink); flex: 1; }
.lb-points { font-family: var(--serif); font-weight: 700; font-size: .9rem; color: var(--purple-800); }
[data-theme="dark"] .lb-points { color: var(--lavender-400); }

/* ---------- Toasts & Confetti ----------
   Ported directly from the proven, working implementation used across the
   English Access suite (Grammar Access / Vocabulary Access): static
   persistent containers inside #app-shell, plain CSS transitions/keyframes
   — no canvas, no Web Animations API. */

.toast-stack {
  position: fixed;
  top: calc(76px + var(--ea-nav-height, 0px));
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  pointer-events: none;
  background: var(--toast-bg);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-md, 10px);
  font-family: var(--sans, inherit);
  font-size: .85rem;
  font-weight: 600;
  box-shadow: var(--shadow-2, 0 6px 18px rgba(0,0,0,.18));
  opacity: 0;
  transform: translateX(24px);
  transition: opacity .3s ease, transform .3s ease;
  max-width: 320px;
}
.toast.in { opacity: 1; transform: none; }
.toast.points { background: var(--gold-xp); color: var(--accent-ink); }
.toast.combo { background: var(--purple-700); }

.confetti-layer { position: fixed; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; z-index: 95; overflow: hidden; }
.confetti-piece {
  /* Positioned entirely by JS via requestAnimationFrame, writing
     transform/opacity directly on each frame — deliberately no CSS
     @keyframes or animation property here. The piece's on-screen
     position is never delegated to the browser's CSS animation engine;
     it is set explicitly, every frame, by app.js. */
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 2px;
  pointer-events: none;
}

/* Matches the reference implementation exactly: a global rule disabling
   CSS transitions under prefers-reduced-motion. This has no effect on
   confetti (which is positioned via JS/transform, not CSS transitions),
   but keeps other UI motion — toast fades, theme changes, etc. —
   consistent with the accessibility preference. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
