:root {
  --ink: #17352f;
  --muted: #6c817c;
  --line: #dfeae6;
  --paper: #ffffff;
  --background: #f4faf7;
  --mint: #43b997;
  --mint-dark: #23866d;
  --mint-soft: #e7f7f1;
  --coral: #ff846e;
  --coral-soft: #fff0ed;
  --yellow: #ffd76a;
  --danger: #d95c56;
  --danger-soft: #fff0ef;
  --shadow: 0 24px 70px rgba(29, 75, 64, .10);
  --radius: 26px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--background);
  font-family: "Manrope", system-ui, sans-serif;
  overflow-x: hidden;
}

button, select, textarea { font: inherit; }
button { color: inherit; }
svg { width: 1.35em; height: 1.35em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.page-glow { position: fixed; z-index: -1; border-radius: 50%; filter: blur(3px); opacity: .65; }
.page-glow--one { width: 410px; height: 410px; top: 80px; left: -210px; background: #d9f5eb; }
.page-glow--two { width: 330px; height: 330px; right: -150px; top: 410px; background: #fff0d7; }

.topbar {
  width: min(1180px, calc(100% - 40px));
  min-height: 88px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 20px; font-weight: 800; letter-spacing: -.7px; }
.brand > span:last-child > span { color: var(--mint-dark); }
.brand__mark { width: 40px; height: 40px; display: grid; place-items: center; color: white; background: var(--mint); border-radius: 13px 13px 13px 5px; box-shadow: 0 8px 20px rgba(67, 185, 151, .28); }
.brand__mark svg { width: 23px; height: 23px; stroke-width: 2.6; }

.topbar__actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.source-badge { max-width: 230px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 7px 11px; border: 1px solid #cde7df; border-radius: 999px; background: rgba(255,255,255,.7); color: var(--mint-dark); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .55px; }
.count-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.count-field select { appearance: none; min-width: 55px; padding: 8px 24px 8px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236c817c' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 7px center; outline: none; }

.button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 21px; border: 0; border-radius: 14px; font-weight: 800; cursor: pointer; transition: transform .18s, box-shadow .18s, opacity .18s, background .18s; }
.button:hover:not(:disabled) { transform: translateY(-2px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button--small { min-height: 42px; padding: 0 15px; font-size: 13px; }
.button--soft { border: 1px solid var(--line); background: rgba(255,255,255,.85); }
.button--soft:hover { background: white; box-shadow: 0 8px 20px rgba(29,75,64,.08); }
.button--primary { color: white; background: var(--mint-dark); box-shadow: 0 10px 24px rgba(35,134,109,.24); }
.button--primary:hover:not(:disabled) { background: #1c755f; box-shadow: 0 13px 28px rgba(35,134,109,.3); }

.app-shell { width: min(1080px, calc(100% - 40px)); margin: 22px auto 80px; display: grid; gap: 22px; }
.setup-card, .exercise-card { background: rgba(255,255,255,.94); border: 1px solid rgba(216,232,226,.9); border-radius: var(--radius); box-shadow: var(--shadow); }
.setup-card { position: relative; padding: 28px 31px; display: grid; grid-template-columns: 1fr auto; gap: 24px 34px; align-items: center; }
.setup-card__intro h1 { margin: 3px 0 7px; font-size: clamp(26px, 3.3vw, 38px); letter-spacing: -1.4px; line-height: 1.12; }
.setup-card__intro > p:last-child { margin: 0; color: var(--muted); font-size: 14px; }
.eyebrow { margin: 0; color: var(--mint-dark); font-size: 11px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; }

.mode-switch { position: relative; width: 320px; padding: 5px; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 15px; background: #f0f6f3; }
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch label { position: relative; z-index: 2; min-height: 45px; display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 800; cursor: pointer; transition: color .2s; }
.mode-switch label svg { width: 18px; height: 18px; }
.mode-switch input:checked + label { color: var(--ink); }
.mode-switch__thumb { position: absolute; z-index: 1; width: calc(50% - 5px); height: calc(100% - 10px); top: 5px; left: 5px; border: 1px solid #e0ebe7; border-radius: 11px; background: white; box-shadow: 0 4px 12px rgba(29,75,64,.08); transition: transform .25s cubic-bezier(.2,.8,.2,1); }
#modeManual:checked ~ .mode-switch__thumb { transform: translateX(100%); }

.manual-panel { grid-column: 1 / -1; padding-top: 24px; border-top: 1px solid var(--line); }
.manual-panel__heading { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.manual-panel__heading h2 { margin: 0 0 4px; font-size: 16px; letter-spacing: -.2px; }
.manual-panel__heading p { margin: 0; color: var(--muted); font-size: 12px; }
.text-button { display: inline-flex; align-items: center; gap: 7px; padding: 6px 2px; border: 0; background: transparent; color: var(--mint-dark); font-size: 12px; font-weight: 800; cursor: pointer; }
.text-button svg { width: 17px; height: 17px; }
.textarea-wrap { position: relative; }
.textarea-wrap textarea { width: 100%; min-height: 210px; resize: vertical; padding: 15px 18px 35px; border: 1px solid var(--line); border-radius: 16px; outline: none; color: var(--ink); background: #fbfdfc; font-size: 13px; line-height: 1.75; transition: border .18s, box-shadow .18s; }
.textarea-wrap textarea:focus { border-color: var(--mint); box-shadow: 0 0 0 4px var(--mint-soft); }
.line-count { position: absolute; right: 12px; bottom: 12px; padding: 4px 8px; border-radius: 7px; color: var(--muted); background: #edf4f1; font-size: 10px; font-weight: 800; }
.hidden-notice { min-height: 108px; padding: 20px; display: flex; align-items: center; justify-content: center; gap: 14px; border: 1px dashed #bdd8cf; border-radius: 16px; color: var(--muted); background: #f5faf8; text-align: left; }
.hidden-notice > svg { width: 27px; height: 27px; color: var(--mint-dark); }
.hidden-notice div { display: grid; gap: 3px; }
.hidden-notice strong { color: var(--ink); font-size: 13px; }
.hidden-notice span { font-size: 11px; }
.manual-panel__load { margin-top: 13px; margin-left: auto; display: flex; }

.exercise-card { overflow: hidden; }
.exercise-card__top { padding: 22px 32px 18px; border-bottom: 1px solid var(--line); }
.progress-meta { margin-bottom: 9px; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; }
.progress-track { height: 8px; overflow: hidden; border-radius: 99px; background: #e8f0ed; }
.progress-track span { display: block; width: 10%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--mint), #76d0b5); transition: width .4s ease; }
.exercise-card__body { padding: 34px 44px 31px; }
.question-copy { display: flex; align-items: flex-start; gap: 15px; }
.question-number { flex: 0 0 44px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 13px; color: var(--mint-dark); background: var(--mint-soft); font-size: 13px; font-weight: 800; }
.question-copy h2 { margin: 5px 0 5px; font-size: clamp(20px, 3vw, 28px); letter-spacing: -.8px; }
.question-copy > div > p:last-child { margin: 0; color: var(--muted); font-size: 12px; }

.audio-actions { margin: 27px 0 31px; display: flex; gap: 12px; }
.audio-button { min-width: 145px; display: flex; align-items: center; gap: 10px; padding: 9px 16px 9px 9px; border: 1px solid var(--line); border-radius: 15px; background: white; cursor: pointer; transition: transform .18s, border-color .18s, box-shadow .18s; }
.audio-button:hover { transform: translateY(-2px); border-color: #b8d8ce; box-shadow: 0 8px 20px rgba(29,75,64,.08); }
.audio-button span { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 11px; color: var(--mint-dark); background: var(--mint-soft); }
.audio-button strong { font-size: 12px; }
.audio-button--main { color: white; border-color: var(--mint-dark); background: var(--mint-dark); }
.audio-button--main span { color: var(--ink); background: var(--yellow); }
.audio-button.is-playing span svg { animation: pulse .7s ease infinite alternate; }
@keyframes pulse { to { transform: scale(1.2); } }

.section-label { margin-bottom: 9px; display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .7px; }
.answer-zone { min-height: 93px; padding: 15px; display: flex; flex-wrap: wrap; align-content: center; align-items: center; gap: 9px; border: 1.5px dashed #bfd4cd; border-radius: 17px; background: #f8fbfa; transition: border .2s, background .2s; }
.answer-zone.has-items { border-style: solid; border-color: #bddfd4; background: var(--mint-soft); }
.answer-zone.is-correct { border-color: var(--mint); background: #ecfaf5; }
.answer-zone.is-wrong { border-color: #ef9d97; background: var(--danger-soft); }
.answer-placeholder { width: 100%; color: #8aa09a; font-size: 12px; text-align: center; }
.token { min-height: 40px; padding: 0 14px; border: 1px solid #d5e4df; border-bottom-width: 3px; border-radius: 11px; color: var(--ink); background: white; font-weight: 700; font-size: 13px; cursor: pointer; box-shadow: 0 3px 6px rgba(29,75,64,.05); transition: transform .15s, border-color .15s; }
.token:hover:not(:disabled) { transform: translateY(-2px); border-color: #80c7b2; }
.token:disabled { cursor: default; }
.answer-zone .token { border-color: #9fd6c6; }
.edit-actions { min-height: 37px; display: flex; justify-content: flex-end; gap: 13px; }
.edit-actions button { display: flex; align-items: center; gap: 5px; padding: 10px 0 0; border: 0; color: var(--muted); background: transparent; font-size: 10px; font-weight: 800; cursor: pointer; }
.edit-actions button:disabled { opacity: .36; cursor: default; }
.edit-actions svg { width: 14px; height: 14px; }
.word-section { margin-top: 14px; }
.word-bank { min-height: 84px; padding: 15px; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 10px; border: 1px solid var(--line); border-radius: 17px; background: white; }
.word-bank:empty::after { content: "Tất cả thẻ đã được sử dụng"; color: #9bada8; font-size: 11px; }

.feedback { margin-top: 22px; padding: 17px 19px; display: flex; gap: 13px; border-radius: 15px; background: var(--mint-soft); }
.feedback.is-wrong { background: var(--danger-soft); }
.feedback__icon { flex: 0 0 34px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--mint); font-weight: 800; }
.feedback.is-wrong .feedback__icon { background: var(--danger); }
.feedback strong { font-size: 13px; }
.feedback p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.feedback .correct-answer { margin-top: 7px; color: var(--danger); font-weight: 800; }

.exercise-card__footer { min-height: 88px; padding: 18px 32px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); background: #fbfdfc; }
.keyboard-hint { color: #8ba09a; font-size: 10px; }
kbd { padding: 3px 5px; border: 1px solid #d5e2de; border-bottom-width: 2px; border-radius: 5px; color: var(--muted); background: white; font: 700 9px "Manrope", sans-serif; }
.button--check, .button--next { min-width: 160px; }

.loading-overlay { position: fixed; z-index: 20; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(244,250,247,.9); backdrop-filter: blur(7px); }
.loading-overlay strong { margin-top: 18px; font-size: 16px; }
.loading-overlay p { margin: 5px 0; color: var(--muted); font-size: 12px; }
.loader { height: 45px; display: flex; align-items: flex-end; gap: 6px; }
.loader span { width: 10px; height: 22px; border-radius: 8px; background: var(--mint); animation: wave .75s ease-in-out infinite alternate; }
.loader span:nth-child(2) { height: 39px; animation-delay: .15s; }
.loader span:nth-child(3) { height: 29px; animation-delay: .3s; }
@keyframes wave { to { height: 10px; opacity: .45; } }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 24px; transform: translate(-50%, 100px); max-width: calc(100% - 30px); padding: 12px 17px; border-radius: 12px; color: white; background: var(--ink); font-size: 12px; font-weight: 700; box-shadow: 0 12px 28px rgba(23,53,47,.25); opacity: 0; pointer-events: none; transition: .25s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.modal { position: fixed; z-index: 25; inset: 0; display: grid; place-items: center; padding: 20px; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(16,39,34,.54); backdrop-filter: blur(5px); }
.modal__card { position: relative; width: min(430px, 100%); padding: 35px; border-radius: 25px; background: white; box-shadow: 0 35px 90px rgba(16,39,34,.3); text-align: center; animation: pop .28s ease-out; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.result-illustration { height: 78px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.result-illustration span { display: grid; place-items: center; color: var(--coral); font-size: 18px; }
.result-illustration span:nth-child(2) { width: 68px; height: 68px; border-radius: 22px 22px 22px 8px; color: white; background: var(--mint); font-size: 31px; box-shadow: 0 12px 30px rgba(67,185,151,.3); }
.modal__card .eyebrow { margin-top: 15px; }
.modal__card h2 { margin: 5px 0; font-size: 27px; letter-spacing: -1px; }
.modal__card > p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 12px; }
.result-score { margin: 22px 0; padding: 18px; display: flex; flex-direction: column; border-radius: 16px; background: var(--mint-soft); }
.result-score strong { color: var(--mint-dark); font-size: 30px; }
.result-score span { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px; }
.modal__actions { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; }

@media (max-width: 760px) {
  .topbar { width: min(100% - 24px, 1080px); min-height: 74px; }
  .topbar__actions .source-badge, .count-field span { display: none; }
  .button--small span { display: none; }
  .button--small { width: 42px; padding: 0; }
  .app-shell { width: min(100% - 24px, 1080px); margin-top: 10px; }
  .setup-card { padding: 23px 20px; grid-template-columns: 1fr; }
  .mode-switch { width: 100%; }
  .exercise-card__top { padding: 18px 20px 15px; }
  .exercise-card__body { padding: 27px 20px 24px; }
  .exercise-card__footer { padding: 15px 20px; }
  .keyboard-hint { display: none; }
  .button--check, .button--next { width: 100%; }
}

@media (max-width: 470px) {
  .brand > span:last-child { display: none; }
  .setup-card__intro h1 { font-size: 27px; }
  .manual-panel__heading { align-items: center; }
  .manual-panel__heading p { display: none; }
  .question-number { flex-basis: 38px; width: 38px; height: 38px; }
  .audio-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .audio-button { min-width: 0; padding-right: 8px; }
  .audio-button span { width: 34px; height: 34px; }
  .token { min-height: 38px; padding: 0 11px; font-size: 12px; }
  .modal__actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}