/* ================================================================
   Ghép Chữ Tiếng Việt – giao diện
   ================================================================ */
:root {
  --green: #4cc14c;
  --green-d: #2f9a35;
  --ink: #2c2f36;
  --muted: #7a8190;
  --card: #ffffff;
  --cream: #fff6d6;
  --pink: #f27c87;
  --gold: #ffc531;
  --radius: 18px;
  --font: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #1f2a22 radial-gradient(circle at 30% 20%, #3c5a3f 0, #1f2a22 60%);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
button { font-family: inherit; border: 0; cursor: pointer; color: inherit; background: none; padding: 0; }
svg { display: block; }
i[data-icon] { display: inline-flex; width: 1em; height: 1em; }
i[data-icon] svg { width: 100%; height: 100%; }

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #9fd17a;
}
@media (min-width: 560px) and (min-height: 700px) {
  #app {
    height: min(100dvh - 32px, 940px);
    margin-top: max(16px, (100dvh - 940px) / 2);
    border-radius: 30px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .45), 0 0 0 8px rgba(255, 255, 255, .06);
  }
}

/* ---------------------------------------------------------------- màn hình */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: scale(1.03);
  transition: opacity .3s, transform .3s, visibility 0s .3s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; transition: opacity .3s, transform .3s; }
.screen > * { position: relative; z-index: 1; }
.screen > .sky-bg, .screen > .scene, .screen > .sort-bg, .screen > .float-letters { position: absolute; inset: 0; z-index: 0; }

/* ---------------------------------------------------------------- nút chung */
.round-btn {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(20, 30, 20, .32);
  border: 2px solid rgba(255, 255, 255, .35);
  color: #fff;
  font-size: 22px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform .12s;
}
.round-btn:active, .side-btn:active, .cream-btn:active, .big-btn:active, .mode-card:active { transform: scale(.93); }
.round-btn.ghost { visibility: hidden; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px 0 6px;
  border-radius: 999px;
  background: rgba(20, 30, 20, .32);
  border: 2px solid rgba(255, 255, 255, .35);
  color: #fff; font-weight: 900; font-size: 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.pill i[data-icon] { font-size: 26px; }
.gem-pill i[data-icon] { width: 1.35em; }

.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 26px;
  border-radius: 16px;
  background: linear-gradient(#66d466, var(--green-d));
  box-shadow: 0 5px 0 #23782a, 0 10px 20px rgba(47, 154, 53, .3);
  color: #fff; font-weight: 900; font-size: 18px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .2);
  transition: transform .12s;
}
.ghost-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 52px; min-height: 52px; padding: 0 16px;
  border-radius: 16px;
  background: #eef2f0; color: var(--ink); font-weight: 800; font-size: 22px;
  box-shadow: 0 4px 0 #cfd8d3;
}
.danger-btn { width: 100%; margin-top: 14px; padding: 12px; border-radius: 14px; color: #d64545; font-weight: 800; background: #fff1f1; }

/* ================================================================ TRANG CHỦ */
.sky-bg {
  background:
    radial-gradient(ellipse 80% 30% at 20% 100%, #8fd16a 0 60%, transparent 61%),
    radial-gradient(ellipse 90% 34% at 90% 104%, #6fbf55 0 60%, transparent 61%),
    radial-gradient(circle at 80% 14%, #fff7c2 0 40px, rgba(255, 240, 160, .5) 41px 70px, transparent 71px),
    linear-gradient(#a8e1ff, #e3f6ff 55%, #fff8de);
}
.float-letters { pointer-events: none; overflow: hidden; }
.float-letters span {
  position: absolute;
  font-weight: 900;
  opacity: .32;
  transform: rotate(var(--r));
  text-shadow: 0 2px 0 rgba(0, 0, 0, .15), 0 4px 0 rgba(0, 0, 0, .08), 0 8px 14px rgba(0, 0, 0, .12);
  animation: drift 9s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translateY(0) rotate(var(--r)); }
  to { transform: translateY(-18px) rotate(calc(var(--r) * -1)); }
}

.home-top {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: calc(14px + var(--safe-t)) 16px 0;
}
.home-top .pill { background: rgba(255, 255, 255, .7); color: var(--ink); border-color: #fff; }

.logo { text-align: center; margin: clamp(10px, 4dvh, 40px) 0 clamp(10px, 3dvh, 28px); }
.logo-row { display: flex; justify-content: center; gap: 7px; margin-bottom: 8px; }
.logo-row b {
  width: clamp(48px, 15vw, 64px); aspect-ratio: 1;
  display: grid; place-items: center;
  border-radius: 14px;
  background: linear-gradient(#72db72, #3caf3c);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .14), 0 6px 0 #2a8a2f, 0 12px 20px rgba(0, 0, 0, .18);
  color: #fff; font-size: clamp(30px, 9.5vw, 42px); font-weight: 900;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .18);
  animation: hop 2.8s ease-in-out infinite;
}
.logo-row b.alt { background: linear-gradient(#ffc061, #f08a24); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .14), 0 6px 0 #c4641a, 0 12px 20px rgba(0, 0, 0, .18); }
.logo-row b:nth-child(2) { animation-delay: .15s; }
.logo-row b:nth-child(3) { animation-delay: .3s; }
.logo-row b:nth-child(4) { animation-delay: .45s; }
@keyframes hop { 0%, 70%, 100% { transform: translateY(0); } 80% { transform: translateY(-10px) rotate(-3deg); } 90% { transform: translateY(0) rotate(2deg); } }
.logo-sub {
  display: inline-block; margin-top: 6px; padding: 6px 26px;
  background: var(--pink); color: #fff; font-weight: 900; font-size: 22px; letter-spacing: 1px;
  border-radius: 6px 20px 6px 20px;
  transform: rotate(-2deg);
  box-shadow: 0 4px 0 #c95560;
}

.mode-cards { display: flex; flex-direction: column; gap: 14px; padding: 0 18px; }
.mode-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px;
  border-radius: 22px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 6px 0 rgba(0, 0, 0, .08), 0 14px 28px rgba(40, 80, 40, .15);
  text-align: left;
  transition: transform .12s;
}
.mode-ico {
  width: 62px; height: 62px; flex: none;
  display: grid; place-items: center;
  border-radius: 18px; color: #fff; font-size: 34px;
}
.mode-cross .mode-ico { background: linear-gradient(#6fd66f, #36a83b); box-shadow: 0 4px 0 #278a2d; }
.mode-sort .mode-ico { background: linear-gradient(#ff9aa3, #e9566a); box-shadow: 0 4px 0 #c03c50; }
.mode-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mode-text strong { font-size: 21px; font-weight: 900; }
.mode-text small { color: var(--muted); font-size: 13.5px; font-weight: 700; line-height: 1.3; }
.mode-text em { font-style: normal; font-size: 12.5px; font-weight: 800; color: var(--green-d); margin-top: 4px; }
.mode-sort .mode-text em { color: #d4485c; }
.mode-play {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center; border-radius: 50%;
  background: #f0f5f1; color: var(--green-d); font-size: 18px;
}
.mode-sort .mode-play { color: #d4485c; background: #fff0f2; }
.home-links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 18px 16px; margin-top: auto; margin-bottom: calc(10px + var(--safe-b)); }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, .75); font-weight: 800; font-size: 14px; color: #2d5e27;
}

/* ================================================================ CHỌN MÀN */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(12px + var(--safe-t)) 12px 6px;
}
.map-title { flex: 1; text-align: center; font-size: 22px; font-weight: 900; color: #24452a; }
#screen-map .topbar .round-btn { background: rgba(255, 255, 255, .75); color: var(--ink); border-color: #fff; }
.map-list { flex: 1; overflow-y: auto; padding: 8px 16px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.chapter {
  margin-bottom: 14px; padding: 12px;
  border-radius: 20px; background: rgba(255, 255, 255, .9);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .08);
}
.chapter-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; margin-bottom: 10px; border-radius: 12px;
  background: linear-gradient(90deg, var(--sky2), var(--h1));
  color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.chapter-head span { font-weight: 800; font-size: 13px; }
.chapter.locked { opacity: .65; }
.bubbles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.bubble {
  aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 900; font-size: 17px;
  background: #fff; border: 3px solid var(--green); color: var(--green-d);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .1);
}
.bubble.done { background: linear-gradient(#6fd66f, #3caf3c); color: #fff; border-color: #fff; }
.bubble.lock { background: #e8ecea; border-color: #e8ecea; color: #a5aea9; }
.bubble.lock svg { width: 18px; height: 18px; }
.bubble.cur { box-shadow: 0 0 0 4px rgba(255, 197, 49, .8); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 197, 49, .35); } }

/* ================================================================ NỐI CHỮ */
.scene { background: linear-gradient(var(--sky1), var(--sky2)); overflow: hidden; }
.scene-hills { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 62%; }
.scene-hills .h1 { fill: var(--h1); }
.scene-hills .h2 { fill: var(--h2); }
.scene-hills .h3 { fill: var(--h3); }
.bokeh {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 15% 22%, rgba(255, 255, 255, .35) 0 26px, transparent 46px),
    radial-gradient(circle at 82% 12%, var(--sun, rgba(255, 250, 210, .7)) 0 34px, transparent 70px),
    radial-gradient(circle at 70% 38%, rgba(255, 255, 255, .18) 0 18px, transparent 34px),
    radial-gradient(circle at 30% 55%, rgba(255, 255, 255, .14) 0 40px, transparent 70px),
    radial-gradient(circle at 92% 64%, rgba(255, 255, 255, .16) 0 22px, transparent 40px);
  filter: blur(2px);
}

/* chủ đề cảnh theo chương */
[data-theme="forest"], .theme-forest   { --sky1: #b6e08c; --sky2: #5e9a45; --h1: #4f8f3e; --h2: #3b7531; --h3: #2d5e27; }
[data-theme="field"], .theme-field     { --sky1: #fff1b8; --sky2: #b9d66a; --h1: #c9d65a; --h2: #a7c046; --h3: #7fa636; }
[data-theme="sea"], .theme-sea         { --sky1: #a9e4ff; --sky2: #3d9bdb; --h1: #3fa7e0; --h2: #2b8ac6; --h3: #1f6ea6; }
[data-theme="sunset"], .theme-sunset   { --sky1: #ffd28f; --sky2: #f0706a; --h1: #c4566b; --h2: #8e3d63; --h3: #5e2a52; --sun: rgba(255, 236, 160, .9); }
[data-theme="lotus"], .theme-lotus     { --sky1: #d4f5e6; --sky2: #7cc7a8; --h1: #e9a3c0; --h2: #6bb38f; --h3: #3f8f6c; }
[data-theme="peach"], .theme-peach     { --sky1: #ffe9ee; --sky2: #f5a3b8; --h1: #e98aa5; --h2: #c96b8b; --h3: #9f4f6f; }
[data-theme="night"], .theme-night     { --sky1: #34478f; --sky2: #141c3d; --h1: #2a3870; --h2: #1f2a58; --h3: #131b3d; --sun: rgba(255, 252, 225, .95); }
[data-theme="terrace"], .theme-terrace { --sky1: #d2f0ff; --sky2: #98d371; --h1: #9fd36a; --h2: #78b94c; --h3: #5a9a38; }
[data-theme="autumn"], .theme-autumn   { --sky1: #ffe3a8; --sky2: #e89a4b; --h1: #d97b3a; --h2: #b85f2d; --h3: #8f4522; }
[data-theme="bay"], .theme-bay         { --sky1: #c9edf6; --sky2: #5bb6c9; --h1: #4c9a8e; --h2: #3b7f75; --h3: #2a635b; }
[data-theme="bamboo"], .theme-bamboo   { --sky1: #ddf4c8; --sky2: #74b056; --h1: #4f8a3a; --h2: #3d722c; --h3: #2c5a20; }
[data-theme="oldtown"], .theme-oldtown { --sky1: #ffeccc; --sky2: #e6a75a; --h1: #b5652f; --h2: #934f25; --h3: #6f3a1b; }
.theme-sort { --sky2: #f27c87; --h1: #ffb35c; }
#screen-cross[data-theme="night"] .bokeh { background:
    radial-gradient(circle at 80% 12%, rgba(255, 252, 225, .95) 0 26px, rgba(255, 252, 225, .2) 27px 50px, transparent 51px),
    radial-gradient(1.5px 1.5px at 10% 10%, #fff, transparent), radial-gradient(1.5px 1.5px at 30% 22%, #fff, transparent),
    radial-gradient(2px 2px at 55% 8%, #fff, transparent), radial-gradient(1.5px 1.5px at 65% 30%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 20% 40%, #fff, transparent), radial-gradient(2px 2px at 90% 35%, #fff, transparent); filter: none; }

#screen-cross .topbar { gap: 8px; }
.level-pill {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  max-width: 150px; margin: 0 auto; padding: 4px 6px 5px;
  border-radius: 12px;
  background: rgba(20, 30, 20, .32);
  border: 2px solid rgba(255, 255, 255, .45);
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.level-pill b { font-size: 15px; font-weight: 900; letter-spacing: .5px; }
.level-pill small {
  width: 100%; text-align: center; border-radius: 6px;
  background: rgba(255, 255, 255, .88); color: #333; font-size: 11.5px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 1px 4px;
}
#screen-cross .coin-pill { padding-right: 10px; }

.board-area { flex: 1; min-height: 0; position: relative; }
.board { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.cell {
  position: absolute;
  width: var(--cell); height: var(--cell);
  border-radius: calc(var(--cell) * .14);
  background: rgba(255, 255, 255, .86);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .12), 0 6px 12px rgba(0, 0, 0, .08);
  display: grid; place-items: center;
  transition: background .2s;
}
.cell span {
  font-size: calc(var(--cell) * .6); font-weight: 900; line-height: 1;
  color: #fff; opacity: 0;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .18);
}
.cell.open { background: linear-gradient(#73d673, #3fae3f); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .14), 0 3px 0 rgba(0, 0, 0, .15); }
.cell.open span { opacity: 1; }
.cell.pop { animation: cellpop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes cellpop { 0% { transform: scale(.4); } 100% { transform: scale(1); } }
.cell.flash { animation: flash .6s; }
@keyframes flash { 30% { filter: brightness(1.35); transform: scale(1.12); } }
.picking .cell:not(.open) { cursor: pointer; animation: glow 1s ease-in-out infinite; }
@keyframes glow { 50% { background: #fff6c4; box-shadow: 0 0 0 3px var(--gold), 0 0 16px var(--gold); } }

.preview { height: 54px; display: flex; align-items: center; justify-content: center; flex: none; }
.preview-inner {
  min-width: 120px; padding: 6px 34px;
  font-size: 26px; font-weight: 900; letter-spacing: 3px; color: #3a3d44;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 60' preserveAspectRatio='none'%3E%3Cpath d='M8 14 C 40 6 90 9 150 7 C 210 5 260 4 292 10 L 296 22 L 288 30 L 297 40 L 290 52 C 240 56 180 54 120 56 C 70 57 30 55 6 50 L 12 40 L 2 30 L 10 22 Z' fill='%23ffffff' fill-opacity='.95'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .15));
  text-align: center; white-space: nowrap;
  opacity: 0; transform: scale(.6);
  transition: opacity .15s, transform .15s;
}
.preview-inner.show { opacity: 1; transform: none; }
.preview-inner.good { color: var(--green-d); animation: rise .9s ease-out forwards; }
.preview-inner.bad { color: #d64545; animation: shake .4s; }
.preview-inner.dup { color: #c58a00; animation: flash .5s; }
.preview-inner.bonus { color: #1e7fd0; }
.preview-inner.bonus::before { content: '★ '; color: var(--gold); }
.preview-inner.hide { opacity: 0; transform: scale(.9); transition: opacity .25s, transform .25s; }
@keyframes rise { 0% { transform: scale(1.1); } 60% { transform: scale(1); opacity: 1; } 100% { transform: translateY(-30px) scale(.9); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.wheel-zone {
  --wd: min(76vw, 300px, 40dvh);
  flex: none; position: relative;
  padding: 4px 0 calc(16px + var(--safe-b));
}
.wheel {
  position: relative; margin: 0 auto;
  width: var(--wd); height: var(--wd);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .95) 0 64%, rgba(255, 255, 255, .86) 65%);
  box-shadow: 0 0 0 10px rgba(255, 255, 255, .22), 0 14px 40px rgba(0, 0, 0, .2);
  touch-action: none;
  cursor: pointer;
}
.wheel-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.wheel-lines path { fill: none; stroke: var(--green); stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.wl {
  position: absolute; left: 0; top: 0; z-index: 2;
  width: var(--lsize); height: var(--lsize);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: calc(var(--lsize) * .62); font-weight: 900; line-height: 1;
  color: #34373d;
  transition: transform .35s cubic-bezier(.3, 1.3, .5, 1), background .1s, color .1s;
  pointer-events: none;
}
.wl.on { background: var(--green); color: #fff; box-shadow: 0 3px 0 var(--green-d); text-shadow: 0 2px 0 rgba(0, 0, 0, .15); }

.side-btn {
  position: absolute; top: 2px; z-index: 3;
  width: 50px; height: 50px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(20, 30, 20, .34);
  border: 2px solid rgba(255, 255, 255, .45);
  color: #fff; font-size: 26px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform .12s;
}
.side-btn.left { left: 12px; }
.side-btn.right { right: 12px; }
.side-btn.low { top: auto; bottom: calc(26px + var(--safe-b)); }
.side-btn .cost {
  position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%);
  min-width: 40px; padding: 1px 6px; border-radius: 6px;
  background: #fff; color: #333; font-size: 12px; font-weight: 900; text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
}
#btn-bulb .cost::before, #btn-target .cost::before { content: ''; display: inline-block; width: 9px; height: 9px; margin-right: 3px; border-radius: 50%; background: var(--gold); box-shadow: inset 0 0 0 2px #e8a200; vertical-align: -1px; }
#btn-bonus { color: var(--gold); }
#btn-bonus.bump { animation: cellpop .5s cubic-bezier(.3, 1.8, .5, 1); }
#btn-target.active { background: var(--gold); color: #5b3c00; animation: pulse 1s infinite; }

/* ================================================================ SẮP XẾP */
.sort-bg { background: linear-gradient(#e8eef2 0%, #f5f0d6 38%, #fbe9ad 100%); }
.float-letters.dense span { opacity: .42; }
.sort-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + var(--safe-t)) 18px 0;
}
.cloud-badge {
  min-width: 46px; height: 46px; padding: 0 8px;
  display: grid; place-items: center;
  border-radius: 46% 54% 50% 50% / 55% 50% 50% 45%;
  background: var(--cream); border: 2.5px solid #4a4a4a;
  font-size: 20px; font-weight: 900;
  box-shadow: 0 3px 0 #4a4a4a;
}
.gem-pill.big { height: 42px; padding: 0 18px 0 8px; background: var(--cream); color: #8a5a00; border: 2.5px solid #4a4a4a; box-shadow: 0 3px 0 #4a4a4a; font-size: 19px; backdrop-filter: none; }
.gem-pill.big i[data-icon] { font-size: 30px; }

.question { display: flex; align-items: flex-end; gap: 4px; padding: clamp(8px, 3dvh, 28px) 14px 0; }
.teacher { width: 29%; max-width: 120px; flex: none; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-1deg); } }
.q-right { flex: 1; min-width: 0; padding-bottom: 6px; }
.q-label { font-weight: 900; font-size: 15px; color: #3a3a3a; margin: 0 0 6px 18px; }
.brush-card {
  padding: 14px 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 120' preserveAspectRatio='none'%3E%3Cpath d='M14 12 C 70 2 150 8 230 4 C 262 3 286 8 296 14 L 290 30 L 299 44 L 291 62 L 298 80 L 288 98 C 290 108 270 116 230 114 C 160 118 90 112 40 116 C 20 117 8 112 6 104 L 12 86 L 2 70 L 10 54 L 3 38 L 11 24 Z' fill='%23f27c87'/%3E%3Cpath d='M30 112 l 10 6 l 6 -5 M250 116 l 8 3' fill='none' stroke='%23f27c87' stroke-width='3'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  filter: drop-shadow(0 4px 0 rgba(180, 60, 75, .25));
}
.q-frame {
  border: 2.5px solid rgba(255, 255, 255, .95);
  padding: 10px 8px;
  text-align: center;
  color: #4a1b22; font-weight: 900;
  font-size: clamp(18px, 6vw, 28px); line-height: 1.25;
  word-break: break-all;
}
.js-scrambled { letter-spacing: .5px; }
.q-group { margin: 8px 0 0 18px; font-size: 12.5px; font-weight: 800; color: #9a7a3a; }

.slots, .tiles {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 8px 6px;
  padding: 0 16px;
}
.slots { margin-top: clamp(18px, 6dvh, 60px); column-gap: 16px; }
.slots.bad { animation: shake .45s; }
.slot-group { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.tiles { margin-top: clamp(22px, 7dvh, 70px); }
.slot, .tile {
  width: var(--t, 44px); height: calc(var(--t, 44px) * 1.05);
  display: grid; place-items: center;
  border-radius: calc(var(--t, 44px) * .2);
  font-size: calc(var(--t, 44px) * .56); font-weight: 900; line-height: 1;
}
.slot { border: 2px dashed #8f99a3; background: rgba(255, 255, 255, .45); color: #2c2f36; }
.slot.filled { border: 1.5px solid #6d7a84; background: linear-gradient(#ffffff, #e8eff4); box-shadow: 0 3px 0 #99a8b3; }
.slot.drop { animation: cellpop .3s cubic-bezier(.3, 1.6, .5, 1); }
.slot.locked { background: linear-gradient(#e2f4ff, #bfe3fa); border-color: #5aa6d6; box-shadow: 0 3px 0 #5aa6d6; color: #1f5f8a; }
.slot.good { background: linear-gradient(#7ee08a, #3fbf55); border-color: #2f9a45; box-shadow: 0 3px 0 #2a8a3d; color: #fff; animation: cellpop .4s cubic-bezier(.3, 1.6, .5, 1); }
.slots.bad .slot.filled:not(.locked) { background: linear-gradient(#ffd5d5, #ff9a9a); border-color: #d64545; color: #8a1f1f; }
.tile {
  background: linear-gradient(#ffffff, #e4edf3);
  border: 1.5px solid #6d7a84;
  box-shadow: 0 4px 0 #8c9ca8, 0 6px 10px rgba(0, 0, 0, .08);
  transition: transform .1s, opacity .15s;
}
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 #8c9ca8; }
.tile.used { opacity: 0; pointer-events: none; transform: scale(.6); }
/* câu dài: thu gọn để vừa một màn hình */
#screen-sort.long .question { padding-top: 4px; }
#screen-sort.long .teacher { width: 22%; }
#screen-sort.long .q-frame { font-size: clamp(15px, 4.6vw, 21px); padding: 6px; }
#screen-sort.long .slots { margin-top: clamp(10px, 2.5dvh, 24px); row-gap: 6px; }
#screen-sort.long .tiles { margin-top: clamp(14px, 3dvh, 30px); row-gap: 8px; }
#screen-sort.long .sort-bottom { padding-top: 8px; }

.sort-bottom {
  margin-top: auto;
  display: flex; justify-content: center; gap: clamp(28px, 10vw, 48px);
  padding: 12px 0 calc(22px + var(--safe-b));
}
.cream-btn {
  position: relative;
  width: 58px; height: 58px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--cream); border: 2.5px solid #3e3e3e;
  box-shadow: 0 4px 0 #3e3e3e;
  color: #3e3e3e; font-size: 26px;
  transition: transform .12s;
}
.cream-btn .cost {
  position: absolute; top: -8px; right: -10px;
  padding: 0 6px; border-radius: 999px;
  background: #e9566a; color: #fff; font-size: 12px; font-weight: 900; border: 2px solid #fff;
}

.sort-result {
  position: absolute !important; inset: 0; z-index: 5 !important;
  display: flex; align-items: flex-end;
  background: rgba(40, 30, 10, .35);
  opacity: 0; visibility: hidden; transition: opacity .25s, visibility 0s .25s;
}
.sort-result.show { opacity: 1; visibility: visible; transition: opacity .25s; }
.answer-card {
  width: 100%; padding: 26px 22px calc(26px + var(--safe-b));
  border-radius: 28px 28px 0 0; background: #fff; text-align: center;
  transform: translateY(100%); transition: transform .35s cubic-bezier(.3, 1.2, .5, 1);
}
.sort-result.show .answer-card { transform: none; }
.answer-label { font-size: 14px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.answer-text { font-size: clamp(26px, 8vw, 36px); font-weight: 900; color: #2f9a45; margin: 6px 0 8px; line-height: 1.2; }
.answer-reward { display: inline-flex; align-items: center; gap: 6px; font-weight: 900; color: #8a5a00; margin-bottom: 16px; font-size: 18px; }
.answer-reward i { width: 1.6em; height: 1.2em; }
.answer-card .big-btn { width: 100%; }

/* ================================================================ HỘP THOẠI */
.modal {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 18px;
  background: rgba(10, 20, 12, .5);
  opacity: 0; visibility: hidden; transition: opacity .2s, visibility 0s .2s;
}
.modal.show { opacity: 1; visibility: visible; transition: opacity .2s; }
.modal-card {
  width: 100%; max-width: 400px; max-height: 88%; overflow-y: auto;
  padding: 24px 20px 20px; border-radius: 26px;
  background: #fff; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  transform: scale(.85); transition: transform .3s cubic-bezier(.3, 1.5, .5, 1);
}
.modal.show .modal-card { transform: none; }
.modal-card h2 { margin: 0 0 4px; font-size: 26px; font-weight: 900; }
.modal-card h3 { margin: 18px 0 8px; font-size: 17px; font-weight: 900; }
.modal-card h3 small { color: var(--muted); }
.muted { color: var(--muted); font-weight: 700; margin: 4px 0 12px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  background: #e9f8e9; color: #23782a; font-weight: 900; font-size: 15px; letter-spacing: 1px;
}
.chip.locked { background: #f0f2f1; color: #a5aea9; letter-spacing: 3px; cursor: default; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.modal-actions .big-btn { flex: 1; }
.win-stars { display: flex; justify-content: center; gap: 4px; color: var(--gold); font-size: 52px; margin: -6px 0 6px; filter: drop-shadow(0 3px 0 #e09a00); }
.win-stars i { animation: starin .6s cubic-bezier(.3, 1.8, .5, 1) backwards; }
.win-stars i:nth-child(2) { font-size: 66px; margin-top: -14px; animation-delay: .15s; }
.win-stars i:nth-child(3) { animation-delay: .3s; }
@keyframes starin { from { transform: scale(0) rotate(-90deg); } }
.reward { display: inline-flex; align-items: center; gap: 8px; margin: 4px 0 14px; padding: 8px 18px; border-radius: 999px; background: #fff6d6; color: #8a5a00; font-weight: 900; font-size: 20px; }
.reward i { font-size: 28px; }
.unlock { color: #d4485c; font-weight: 800; margin: 0 0 12px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px; border-bottom: 1px solid #eef1ef; font-weight: 800; font-size: 16px; cursor: pointer; }
.toggle-row span { display: inline-flex; align-items: center; gap: 10px; }
.toggle-row span i { color: var(--green-d); font-size: 22px; }
.toggle-row input { display: none; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 99px; background: #d5dbd8; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .2s; }
.toggle-row input:checked + .switch { background: var(--green); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }

#toast {
  position: absolute; left: 50%; top: calc(76px + var(--safe-t)); z-index: 30;
  max-width: 88%; padding: 10px 18px; border-radius: 14px;
  background: rgba(25, 30, 28, .88); color: #fff; font-weight: 800; font-size: 14.5px; text-align: center;
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#fx { position: absolute; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.confetti {
  position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall 2s cubic-bezier(.25, .6, .5, 1) forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--rot)); opacity: .9; } }
.fly-coin { position: absolute; width: 24px; height: 24px; animation: fly .8s cubic-bezier(.5, -0.3, .7, 1) forwards; }
@keyframes fly { to { transform: translate(var(--tx), var(--ty)) scale(.7); opacity: .4; } }

@media (max-height: 640px) {
  .logo-row b { width: 46px; font-size: 28px; }
  .mode-ico { width: 52px; height: 52px; font-size: 28px; }
  .preview { height: 44px; }
  .preview-inner { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
