* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background-color: #f6f2e8;
  background-image:
    linear-gradient(#e9e2d0 1px, transparent 1px),
    linear-gradient(90deg, #e9e2d0 1px, transparent 1px);
  background-size: 28px 28px;
  color: #3d3a34;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

.hidden { display: none !important; }
.screen { width: 100%; display: flex; flex-direction: column; align-items: center; }

/* ---------- Màn hình chọn bộ từ ---------- */
.sets-wrap { width: min(920px, 94vw); padding: 40px 0 60px; text-align: center; }
.app-title { font-size: clamp(28px, 5vw, 44px); font-weight: 800; margin-bottom: 6px; }
.app-sub { color: #8a8474; font-size: 17px; margin-bottom: 30px; }
.loading { color: #8a8474; }

.sets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
}
.set-card {
  background: #fffdf7;
  border: 3px solid #e7dfc9;
  border-radius: 22px;
  padding: 26px 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 #d9d0b8;
  transition: transform .12s, box-shadow .12s;
}
.set-card:hover { transform: translateY(-3px); box-shadow: 0 7px 0 #d9d0b8; }
.set-card:active { transform: translateY(1px); box-shadow: 0 2px 0 #d9d0b8; }
.set-card .icon { font-size: 44px; }
.set-card h3 { font-size: 20px; margin: 10px 0 2px; }
.set-card .en { color: #8a8474; font-size: 14px; font-weight: 700; }
.set-card .count {
  display: inline-block; margin-top: 10px; font-size: 13px; font-weight: 700;
  background: #f0e9d6; border-radius: 999px; padding: 4px 12px; color: #7a7261;
}
.set-card.random { background: #f3efff; border-color: #cfc6f2; box-shadow: 0 4px 0 #b9aee6; }
.set-card.random:hover { box-shadow: 0 7px 0 #b9aee6; }

/* ---------- Màn hình chơi ---------- */
.game-topbar {
  width: min(920px, 94vw);
  display: flex; align-items: center; gap: 12px;
  padding: 18px 0 10px;
}
.progress-info { flex: 1; text-align: center; }
.set-name { font-weight: 800; font-size: 18px; }
.progress-text { color: #8a8474; font-size: 14px; font-weight: 700; }

.nav-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid #e7dfc9; background: #fffdf7;
  font-size: 24px; font-weight: 800; color: #6b6555;
  cursor: pointer; box-shadow: 0 3px 0 #d9d0b8;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.nav-btn:active { transform: translateY(2px); box-shadow: none; }

.part-tabs { display: flex; gap: 10px; margin: 6px 0 14px; }
.part-tab {
  font-size: 13px; font-weight: 800; padding: 6px 16px; border-radius: 999px;
  background: #efe8d3; color: #a09a86;
}
.part-tab.active { background: #4a6cf7; color: #fff; }
.part-tab.done { background: #bfe6c8; color: #2e7d43; }

.card {
  width: min(920px, 94vw);
  min-height: min(52vh, 420px);
  background: #fffdf7;
  border: 4px solid #e7dfc9;
  border-radius: 30px;
  box-shadow: 8px 8px 0 #cfc6f2;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 40px;
  cursor: text;
  position: relative;
}

.vi-meaning {
  font-size: clamp(24px, 4.5vw, 40px);
  font-weight: 700; text-align: center; color: #45423c;
  margin-bottom: 34px; line-height: 1.4;
}

.slots {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 10px 16px; max-width: 100%;
}
.slot {
  min-width: 54px;
  cursor: pointer;
  border-bottom: 4px solid #cfc8b4;
  font-size: clamp(20px, 3.6vw, 32px);
  font-weight: 700; color: #2f2c27;
  text-align: center;
  padding: 2px 6px 6px;
  position: relative;
  transition: border-color .15s;
}
.slot .typed { white-space: pre; }
.slot.pending { color: #b9b2a0; }
.slot.active { border-bottom-color: #4a6cf7; }
.slot.active::after {
  content: ''; position: absolute; right: 2px; top: 6px; bottom: 10px;
  width: 3px; background: #4a6cf7; border-radius: 2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.slot.ok { border-bottom-color: #4caf6d; color: #2e7d43; }
.slot.wrong { border-bottom-color: #e5484d; color: #e5484d; }
.slot.wrong.shake { animation: shake .3s; }
.slot.revealed { border-bottom-color: #e8a13d; color: #b97a1e; }
.slot.editing { background: #eef1ff; border-radius: 10px 10px 0 0; border-bottom-color: #4a6cf7; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); } 75% { transform: translateX(5px); }
}
.slot-punct { font-size: clamp(20px, 3.6vw, 32px); font-weight: 700; color: #45423c; align-self: flex-end; padding-bottom: 6px; }

.hint-line { margin-top: 22px; min-height: 24px; font-size: 15px; font-weight: 700; color: #b97a1e; }

.typer {
  position: absolute; opacity: 0; pointer-events: none;
  top: 0; left: 0; width: 10px; height: 10px;
}

/* ---------- Toolbar ---------- */
.toolbar {
  width: min(920px, 94vw);
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 22px 0 34px; flex-wrap: wrap;
}
.tool-btn {
  display: flex; align-items: center; gap: 10px;
  background: #fffdf7; border: 3px solid #e7dfc9; border-radius: 999px;
  padding: 10px 20px 10px 12px;
  font-family: inherit; font-size: 16px; font-weight: 800; color: #4a463d;
  cursor: pointer; box-shadow: 0 3px 0 #d9d0b8;
  transition: transform .1s, box-shadow .1s;
}
.tool-btn:active { transform: translateY(2px); box-shadow: none; }
.tool-btn .key {
  background: #f0e9d6; border-radius: 10px; padding: 5px 10px;
  font-size: 14px; font-weight: 800; color: #6b6555;
}
.tool-btn.primary { background: #4a6cf7; border-color: #4a6cf7; color: #fff; box-shadow: 0 3px 0 #354fb8; }
.tool-btn.primary .key { background: rgba(255,255,255,.25); color: #fff; }
.tool-btn.primary.pulse { animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- Màn hình hoàn thành ---------- */
.done-card { margin-top: 12vh; min-height: auto; padding: 60px 40px; text-align: center; }
.done-emoji { font-size: 64px; }
.done-card h2 { font-size: 34px; margin: 12px 0 8px; }
.done-card p { color: #8a8474; font-size: 17px; margin-bottom: 26px; }
.done-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 640px) {
  .card { padding: 34px 20px; border-radius: 24px; }
  .toolbar { gap: 8px; }
  .tool-btn { font-size: 14px; padding: 8px 14px 8px 10px; }
}
