/* ==========================================================================
   englishvocabgame — shared game engine styles
   Theme is injected per page via CSS custom properties on :root
   --primary --secondary --accent --accent2 --rgb --bg-grad
   ========================================================================== */

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

body {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-grad));
  background-attachment: fixed;
  font-family: 'Sarabun', 'Segoe UI', system-ui, -apple-system, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: #fff;
}

.game-container {
  width: 100%;
  max-width: 560px;
  animation: pageIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.breadcrumb a { color: rgba(255,255,255,0.72); text-decoration: none; font-size: 0.82rem; transition: color 0.18s; }
.breadcrumb a:hover { color: #fff; }
.breadcrumb-sep { color: rgba(255,255,255,0.4); font-size: 0.82rem; }
.breadcrumb-current { color: rgba(255,255,255,0.85); font-size: 0.82rem; }

/* Headings */
.main-title-th { color: #fff; font-size: 1.7rem; font-weight: 800; text-align: center; margin-bottom: 4px; }
.main-title-en {
  color: var(--accent);
  font-size: 0.88rem; font-weight: 700; text-align: center;
  letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 18px;
}

/* Header row */
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.level-label { color: #fff; font-size: 1rem; font-weight: 700; letter-spacing: 0.02em; }
.sound-toggle {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,0.08); border: 1.5px solid rgba(255,255,255,0.18);
  color: #fff; font-size: 1rem; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.16s, transform 0.12s;
}
.sound-toggle:hover { background: rgba(255,255,255,0.16); }
.sound-toggle:active { transform: scale(0.9); }
.sound-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.score-badge {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; padding: 7px 18px; border-radius: 50px;
  font-size: 0.9rem; font-weight: 700;
  box-shadow: 0 4px 14px rgba(var(--rgb), 0.4);
}

/* Mode selector */
.mode-row { display: flex; gap: 7px; margin-bottom: 16px; justify-content: center; flex-wrap: wrap; }
.mode-chip {
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.78);
  padding: 7px 14px; border-radius: 50px;
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  font-family: inherit;
  transition: background 0.16s, border-color 0.16s, color 0.16s, transform 0.12s;
}
.mode-chip:hover { background: rgba(var(--rgb),0.16); color: #fff; }
.mode-chip:active { transform: scale(0.96); }
.mode-chip[aria-pressed="true"] {
  background: rgba(var(--rgb),0.22);
  border-color: var(--accent);
  color: #fff;
}
.mode-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Progress */
.progress-wrap { background: rgba(255,255,255,0.12); border-radius: 50px; height: 6px; margin-bottom: 6px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 50px; transition: width 0.5s cubic-bezier(0.4,0,0.2,1); }
.progress-meta { display: flex; justify-content: space-between; margin-bottom: 18px; }
.progress-label, .q-counter { color: rgba(255,255,255,0.72); font-size: 0.75rem; font-weight: 600; }

/* Card */
.card {
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 24px; padding: 32px 28px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.prompt { color: rgba(255,255,255,0.7); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 10px; text-align: center; }

/* Word + speaker */
.word-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.word { color: #fff; font-size: 2.6rem; font-weight: 800; text-align: center; letter-spacing: -0.02em; line-height: 1.12; overflow-wrap: break-word; word-break: normal; line-break: normal; }
.word.th-word { font-size: 2.1rem; }
.word.entering { animation: wordIn 0.3s cubic-bezier(0.22,1,0.36,1) both; }
@keyframes wordIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.speak-btn {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%;
  background: rgba(var(--rgb),0.16); border: 1.5px solid rgba(var(--rgb),0.4);
  color: var(--accent); font-size: 1.15rem; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.16s, transform 0.12s;
}
.speak-btn:hover { background: rgba(var(--rgb),0.3); }
.speak-btn:active { transform: scale(0.9); }
.speak-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.speak-btn.speaking { animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 0%,100%{transform:scale(1);} 50%{transform:scale(1.12);} }
.speak-btn[hidden] { display: none; }

.word-hint { color: rgba(255,255,255,0.66); font-size: 0.75rem; text-align: center; margin-bottom: 26px; letter-spacing: 0.06em; }

/* Choices */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices.hidden { display: none; }
.choice-btn {
  position: relative; background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(255,255,255,0.16); color: #f1f5f9;
  padding: 18px 12px 14px; border-radius: 14px;
  font-size: 1.15rem; font-weight: 600; font-family: inherit;
  cursor: pointer; text-align: center; min-height: 68px;
  overflow-wrap: break-word; word-break: normal;
  transition: background 0.16s, border-color 0.16s, transform 0.16s, box-shadow 0.16s;
  animation: choiceIn 0.3s cubic-bezier(0.22,1,0.36,1) var(--delay,0ms) both;
}
@keyframes choiceIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.choice-num { position: absolute; top: 6px; left: 9px; font-size: 0.65rem; font-weight: 700; color: rgba(255,255,255,0.55); line-height: 1; }
.choice-btn:hover:not(:disabled) { background: rgba(var(--rgb),0.18); border-color: rgba(var(--rgb),0.6); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(var(--rgb),0.18); }
.choice-btn:active:not(:disabled) { transform: scale(0.97); }
.choice-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice-btn.correct { background: rgba(52,211,153,0.2); border-color: #34d399; color: #a7f3d0; box-shadow: 0 0 20px rgba(52,211,153,0.25); animation: correctPop 0.3s ease; }
@keyframes correctPop { 0%{transform:scale(1);} 40%{transform:scale(1.04);} 100%{transform:scale(1);} }
.choice-btn.wrong { background: rgba(248,113,113,0.16); border-color: #f87171; color: #fca5a5; animation: shake 0.4s ease; }
@keyframes shake { 0%,100%{transform:translateX(0);} 20%{transform:translateX(-6px);} 45%{transform:translateX(6px);} 65%{transform:translateX(-4px);} 85%{transform:translateX(3px);} }
.choice-btn:disabled { cursor: default; }
.choice-btn:disabled:not(.correct):not(.wrong) { opacity: 0.5; }

/* Typing mode */
.type-wrap { display: none; flex-direction: column; gap: 10px; }
.type-wrap.show { display: flex; }
.type-input {
  width: 100%; padding: 16px 18px; border-radius: 14px;
  background: rgba(255,255,255,0.08); border: 1.5px solid rgba(255,255,255,0.2);
  color: #fff; font-size: 1.2rem; font-weight: 600; font-family: inherit; text-align: center;
}
.type-input::placeholder { color: rgba(255,255,255,0.4); }
.type-input:focus { outline: none; border-color: var(--accent); background: rgba(var(--rgb),0.12); }
.type-input.correct { border-color: #34d399; background: rgba(52,211,153,0.14); }
.type-input.wrong { border-color: #f87171; background: rgba(248,113,113,0.12); }
.type-submit {
  padding: 14px; border: none; border-radius: 14px; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff;
  font-size: 1rem; font-weight: 700; font-family: inherit;
  box-shadow: 0 6px 20px rgba(var(--rgb),0.35); transition: transform 0.2s, box-shadow 0.2s;
}
.type-submit:hover { transform: translateY(-2px); }
.type-submit:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Feedback */
.feedback { margin-top: 18px; padding: 13px 18px; border-radius: 12px; text-align: center; font-weight: 600; font-size: 0.9rem; opacity: 0; transition: opacity 0.25s; min-height: 44px; }
.feedback.show { opacity: 1; }
.feedback.correct-msg { background: rgba(52,211,153,0.16); color: #6ee7b7; border: 1px solid rgba(52,211,153,0.3); }
.feedback.wrong-msg { background: rgba(248,113,113,0.12); color: #fca5a5; border: 1px solid rgba(248,113,113,0.28); }

/* Example sentence (shown after answering) */
.example {
  margin-top: 12px; padding: 14px 16px; border-radius: 14px;
  background: rgba(var(--rgb),0.1); border: 1px solid rgba(var(--rgb),0.28);
  text-align: left; animation: fadeIn 0.25s ease both;
}
.example[hidden] { display: none; }
.example-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.example-label { color: var(--accent); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.example .ex-speak { width: 32px; height: 32px; font-size: 0.9rem; margin-left: auto; }
.example-en { color: #fff; font-size: 1.02rem; font-weight: 500; line-height: 1.5; margin-bottom: 4px; }
.example-en strong { color: var(--accent); font-weight: 800; }
.example-th { color: rgba(255,255,255,0.78); font-size: 0.9rem; line-height: 1.5; }

/* Next button */
.next-btn { width: 100%; margin-top: 12px; padding: 15px; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; border: none; border-radius: 14px; font-size: 1rem; font-weight: 700; font-family: inherit; cursor: pointer; display: none; transition: transform 0.2s, box-shadow 0.2s; letter-spacing: 0.03em; box-shadow: 0 6px 20px rgba(var(--rgb),0.35); }
.next-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(var(--rgb),0.45); }
.next-btn:active { transform: scale(0.98); }
.next-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.next-btn.visible { display: block; animation: fadeIn 0.2s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Streak + kb hint */
.streak-label { color: rgba(255,255,255,0.6); font-size: 0.88rem; text-align: center; margin-top: 16px; }
.streak-val { color: #fbbf24; font-weight: 700; }
.kb-hint { color: rgba(255,255,255,0.62); font-size: 0.7rem; text-align: center; margin-top: 10px; letter-spacing: 0.02em; }

/* Round / result screens */
.round-screen, .result-screen { display: none; text-align: center; padding: 16px 0; }
.round-screen.show, .result-screen.show { display: block; animation: pageIn 0.4s ease both; }
.result-emoji { font-size: 4rem; margin-bottom: 10px; }
.result-title { color: #fff; font-size: 1.6rem; font-weight: 800; margin-bottom: 18px; }
.result-sub { color: rgba(255,255,255,0.72); font-size: 0.92rem; margin-bottom: 18px; }

.result-stats { display: flex; justify-content: center; margin-bottom: 22px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; overflow: hidden; }
.stat-item { flex: 1; padding: 16px 8px; border-right: 1px solid rgba(255,255,255,0.1); }
.stat-item:last-child { border-right: none; }
.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; margin-bottom: 5px; }
.stat-value.accent { color: var(--accent); }
.stat-value.gold { color: #fbbf24; }
.stat-label { color: rgba(255,255,255,0.68); font-size: 0.72rem; font-weight: 600; }

/* Mastery bar on result */
.mastery-wrap { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); border-radius: 14px; padding: 14px 16px; margin-bottom: 20px; }
.mastery-top { display: flex; justify-content: space-between; font-size: 0.82rem; color: rgba(255,255,255,0.8); margin-bottom: 8px; font-weight: 600; }
.mastery-track { background: rgba(255,255,255,0.12); border-radius: 50px; height: 8px; overflow: hidden; }
.mastery-fill { height: 100%; background: linear-gradient(90deg, #fbbf24, #34d399); border-radius: 50px; transition: width 0.6s ease; }

/* Mistakes review list */
.review-block { text-align: left; margin-bottom: 20px; }
.review-title { font-size: 0.9rem; font-weight: 700; color: #fca5a5; margin-bottom: 10px; text-align: center; }
.review-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.review-item { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; padding: 10px 12px; }
.review-en { font-weight: 700; color: #fff; }
.review-th { color: rgba(255,255,255,0.75); font-size: 0.9rem; }
.review-arrow { color: rgba(255,255,255,0.4); }
.review-item .speak-btn { width: 34px; height: 34px; font-size: 0.95rem; margin-left: auto; }

/* Buttons row */
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.restart-btn, .primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; border: none;
  padding: 14px 32px; border-radius: 50px; font-size: 1rem; font-weight: 700; font-family: inherit;
  cursor: pointer; box-shadow: 0 6px 20px rgba(var(--rgb),0.4); transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none; display: inline-block;
}
.restart-btn:hover, .primary-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(var(--rgb),0.5); }
.restart-btn:focus-visible, .primary-btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.menu-btn {
  background: rgba(255,255,255,0.08); color: #fff; border: 1.5px solid rgba(255,255,255,0.22);
  padding: 14px 24px; border-radius: 50px; font-size: 1rem; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background 0.2s; text-decoration: none; display: inline-block;
}
.menu-btn:hover { background: rgba(255,255,255,0.16); }
.menu-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.7); outline-offset: 3px; }
.ghost-btn {
  background: transparent; color: rgba(255,255,255,0.7); border: 1.5px solid rgba(255,255,255,0.18);
  padding: 12px 22px; border-radius: 50px; font-size: 0.9rem; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.ghost-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.ghost-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.next-level-row { margin-bottom: 14px; font-size: 0.85rem; color: rgba(255,255,255,0.6); }
.next-level-link { color: var(--accent); text-decoration: none; font-weight: 700; margin-left: 6px; transition: color 0.15s; }
.next-level-link:hover { color: var(--accent2); text-decoration: underline; }
.share-btn { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.75); border: 1px solid rgba(255,255,255,0.14); padding: 10px 24px; border-radius: 50px; font-size: 0.85rem; font-weight: 600; font-family: inherit; cursor: pointer; transition: background 0.2s, color 0.2s; }
.share-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* Confetti */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 9999; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .game-container, .round-screen, .result-screen, .choice-btn, .word.entering,
  .choice-btn.correct, .choice-btn.wrong, .next-btn.visible, .speak-btn.speaking { animation: none !important; }
  .progress-bar, .mastery-fill, .choice-btn, .next-btn, .restart-btn, .primary-btn { transition: none; }
  .choice-btn:hover:not(:disabled), .next-btn:hover, .restart-btn:hover, .primary-btn:hover { transform: none; }
}

/* Mobile */
@media (max-width: 460px) {
  body { padding: 16px; }
  .choices { grid-template-columns: 1fr; }
  .choice-btn { padding: 15px 12px; min-height: 54px; font-size: 1.1rem; }
  .word { font-size: 2.1rem; } .word.th-word { font-size: 1.85rem; }
  .card { padding: 26px 18px 22px; }
}
@media (max-width: 360px) {
  body { padding: 10px; }
  .main-title-th { font-size: 1.35rem; }
  .main-title-en { font-size: 0.8rem; margin-bottom: 12px; }
  .card { padding: 20px 14px 18px; }
  .word { font-size: 1.85rem; }
  .choice-btn { min-height: 48px; padding: 12px 10px; font-size: 1rem; }
}
