/* Tập tô: tô từng nét theo mũi tên. Mọi lớp ở đây đều bắt đầu bằng gt- */

/* cả trò vừa một màn hình: chiều cao còn lại sau thanh trên */
.gt-wrap {
  --gt-h: calc(var(--vh) - var(--bar) - 44px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  height: var(--gt-h); min-height: 0; margin-inline: -10px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.gt-wrap > .ask { flex: none; width: 100%; padding-inline: 10px; }
.gt-top { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.gt-wrap .round { width: 58px; height: 58px; border-width: 4px; }
.gt-wrap .round svg { width: 28px; height: 28px; }
.gt-wrap .round.hinted { border-radius: 50%; }

.gt-tabs { display: flex; min-width: 0; background: #fff; border-radius: 999px; padding: 4px; box-shadow: 0 5px 0 rgba(30, 42, 94, .2); }
.gt-tabs button { min-height: 56px; min-width: 56px; padding: 4px 14px; border-radius: 999px; font-weight: 800; font-size: 1.05rem; line-height: 1.05; }
.gt-tabs button[aria-pressed="true"] { background: var(--yellow); box-shadow: inset 0 -4px 0 rgba(30, 42, 94, .14); }

/* tờ giấy: hình vuông to nhất còn vừa chỗ */
.gt-stage { flex: 1 1 0; min-height: 0; width: 100%; container-type: size; display: grid; place-items: center; }
.gt-paper {
  position: relative; box-sizing: border-box;
  width: min(92vw, 50vh); height: min(92vw, 50vh);                         /* máy cũ chưa có đơn vị cq */
  width: min(100cqw, 100cqh, 860px); height: min(100cqw, 100cqh, 860px);
  border: 5px solid transparent; border-radius: 30px; box-shadow: var(--lift);
  background: linear-gradient(#fff, #fff) padding-box, var(--rainbow, linear-gradient(90deg, #FF5964, #FFD23F, #3CCB6B, #3B9CFF, #9A6BFF)) border-box;
  touch-action: none; cursor: crosshair; container-type: size;
  -webkit-user-select: none; user-select: none;
}
.gt-paper > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 25px; pointer-events: none; }
.gt-paper path, .gt-paper line { fill: none; stroke-linecap: round; stroke-linejoin: round; }

.gt-lines line { stroke-linecap: butt; }
.gt-l-base { stroke: #F7A8B8; }
.gt-l-top { stroke: #B9D6F5; }
.gt-l-mid { stroke: #B9D6F5; }
.gt-edge path { stroke: #7F8FBF; }
.gt-ghost path { stroke: #E9EEF8; }
.gt-dash { stroke: #47548C; }
.gt-arrows path { fill: #1E2A5E; stroke: #fff; stroke-width: .9; }
.gt-runner { fill: #17B34F; stroke: #fff; stroke-width: 1; }
.gt-ink path.gt-pop { animation: gt-pop .35s ease-out; }
.gt-demoink path { opacity: .92; }

/* chấm xanh có số: chỗ bé đặt ngón tay */
.gt-dot {
  position: absolute; z-index: 2; left: 50%; top: 50%; width: 44px; height: 44px; width: 12cqw; height: 12cqw; min-width: 30px; min-height: 30px; margin: 0; translate: -50% -50%;
  display: grid; place-items: center; border-radius: 50%; background: #17B34F; border: 3px solid #fff; border: max(2px, .9cqw) solid #fff; color: #fff;
  font: 800 24px/1 var(--font-ui); font-size: 6.6cqw; box-shadow: 0 3px 0 #0C7A33, 0 0 0 0 rgba(23, 179, 79, .6); pointer-events: none;
  animation: gt-beat 1.3s ease-out infinite;
}
.gt-dot.hinted { border-radius: 50%; animation: none; }
.gt-dot.gt-shake { animation: gt-shake .4s; }
.gt-down .gt-dot { opacity: .45; animation: none; }
.gt-finger { position: absolute; z-index: 3; left: 50%; top: 50%; display: none; font-size: 15cqw; line-height: 1; translate: -42% -8%; pointer-events: none; filter: drop-shadow(0 3px 0 rgba(30, 42, 94, .3)); }
.gt-finger img.emo { width: 15cqw; height: 15cqw; display: block; }

/* đang xem mẫu: ẩn bài của bé và phần chỉ dẫn */
.gt-demo .gt-ink, .gt-demo .gt-dash, .gt-demo .gt-arrows, .gt-demo .gt-runner, .gt-demo .gt-dot { display: none !important; }
.gt-demo .gt-finger { display: block; }
/* tô xong: chỉ còn chữ của bé */
.gt-done .gt-edge, .gt-done .gt-ghost { opacity: .0; }
.gt-paper.gt-done { animation: gt-cheer .6s ease-out; }

/* bút màu và nút */
.gt-tools { flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px; width: 100%; }
.gt-colors, .gt-acts { display: flex; align-items: center; justify-content: center; gap: 8px; }
.gt-tools button { -webkit-tap-highlight-color: transparent; }
.gt-crayon { width: 56px; height: 56px; flex: none; border-radius: 50%; background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, .55) 0 12%, transparent 13%), var(--c); border: 4px solid #fff; box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 60%, #000); }
.gt-crayon[aria-pressed="true"] { outline: 5px solid var(--navy); outline-offset: 1px; }
.gt-btn { min-height: 56px; display: inline-flex; align-items: center; gap: 8px; padding: 4px 20px 4px 14px; border-radius: 999px; background: #fff; border: 3px solid #C9DBF7; font-weight: 800; font-size: 1.1rem; white-space: nowrap; box-shadow: 0 5px 0 rgba(30, 42, 94, .2); }
.gt-btn svg { width: 26px; height: 26px; flex: none; fill: var(--navy); }
.gt-btn > * { pointer-events: none; }
.gt-btn:active, .gt-crayon:active { transform: translateY(3px); }
.gt-demobtn { background: #E9FBEF; border-color: #8FDDAA; }
.gt-demobtn svg { fill: #12A150; }
.gt-demobtn[aria-pressed="true"] { background: var(--yellow); border-color: #fff; }

@keyframes gt-beat { 0% { box-shadow: 0 3px 0 #0C7A33, 0 0 0 0 rgba(23, 179, 79, .6); } 100% { box-shadow: 0 3px 0 #0C7A33, 0 0 0 4.5cqw rgba(23, 179, 79, 0); } }
@keyframes gt-shake { 0%, 100% { translate: -50% -50%; } 25% { translate: -62% -50%; } 75% { translate: -38% -50%; } }
@keyframes gt-pop { 0% { opacity: .55; } 100% { opacity: 1; } }
@keyframes gt-cheer { 0% { scale: 1; } 40% { scale: 1.04; } 100% { scale: 1; } }

/* điện thoại đứng thấp: nhường hết chỗ cho tờ giấy */
@media (max-height: 700px) and (max-aspect-ratio: 5/4) {
  .gt-wrap { gap: 8px; }
  .gt-wrap > .ask { display: none; }
}
@media (max-width: 400px) {
  .gt-top { gap: 6px; }
  .gt-tabs button { padding: 4px 10px; font-size: 1rem; }
  .gt-acts { gap: 10px; }
}

/* màn hình ngang: giấy bên trái cao hết cỡ, nút bấm xếp thành cột bên phải */
@media (min-aspect-ratio: 5/4) {
  .gt-wrap {
    align-self: center; width: min(1300px, calc(100vw - 32px)); max-width: none; /* được phép rộng hơn khung 1000px của trang */
    margin-inline: 0; display: grid; grid-template-columns: auto minmax(0, 400px); grid-template-rows: 1fr auto auto auto 1fr;
    grid-template-areas: "stage ." "stage ask" "stage top" "stage tools" "stage ."; align-content: center; justify-content: center; align-items: center; column-gap: 22px; row-gap: clamp(8px, 2.4vh, 22px);
  }
  .gt-wrap > .ask { grid-area: ask; padding-inline: 0; }
  .gt-top { grid-area: top; }
  .gt-tools { grid-area: tools; gap: 12px 16px; }
  /* cột nút bên phải cần ít nhất 360px: 100vw - 32 (lề) - 22 (khe) - 360 */
  .gt-stage { grid-area: stage; flex: none; width: min(var(--gt-h), calc(100vw - 414px), 860px); height: min(var(--gt-h), calc(100vw - 414px), 860px); }
}
@media (min-aspect-ratio: 5/4) and (max-height: 560px) {
  .gt-wrap { --gt-h: calc(var(--vh) - var(--bar) - 34px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); row-gap: 6px; }
  .gt-tools { gap: 8px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .gt-dot, .gt-paper.gt-done, .gt-ink path.gt-pop { animation: none; }
}

/* ---------- wave 7: hình khối (3D) ---------- */
/* Tờ giấy thật nằm trên tấm bảng gỗ: viền là mặt gỗ có vân, giấy lõm xuống một chút, mép dưới là bề dày của bảng, bóng đổ xuống bàn;
   hai góc trên có băng dính vàng giữ giấy. Nét chữ mẫu và nét bé tô vẫn như cũ. */
.gt-paper { border: 5px solid transparent; border-radius: 26px; /* viền vẫn 5px như trước (cỡ tờ giấy không đổi, bài kiểm thử tô chữ tính theo cỡ này); phần gỗ còn lại là vành ngoài bằng box-shadow */
  background:
    repeating-linear-gradient(0deg, rgba(150, 130, 90, .04) 0, rgba(150, 130, 90, .04) 1px, rgba(255, 255, 255, 0) 1px, rgba(255, 255, 255, 0) 4px) padding-box,
    linear-gradient(180deg, #FFFFFB, #FBF6E9) padding-box,
    repeating-linear-gradient(94deg, rgba(110, 62, 18, .17) 0, rgba(110, 62, 18, .17) 2px, rgba(110, 62, 18, 0) 2px, rgba(110, 62, 18, 0) 11px) border-box,
    linear-gradient(135deg, #F2C184 0, #DB9D58 38%, #C4803F 62%, #E2AB68 100%) border-box;
  box-shadow: inset 0 0 0 1px rgba(96, 54, 14, .4), inset 0 4px 7px rgba(70, 40, 8, .3), inset 0 -2px 4px rgba(70, 40, 8, .12),
    0 0 0 4px #D49650, 0 -1px 0 4px #F3C68C, 0 0 0 5px #8E5A2B, 0 7px 0 4px #9C6530, 0 8px 0 5px #7C4C20, 0 20px 24px 2px rgba(30, 42, 94, .32); }
.gt-paper > svg { border-radius: 21px; }
.gt-paper::before, .gt-paper::after { content: ""; position: absolute; z-index: 1; top: 1.6%; width: 16%; height: 5.2%; min-height: 12px; pointer-events: none; opacity: .92;
  background: linear-gradient(90deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0) 70%, rgba(255, 255, 255, .32)), repeating-linear-gradient(45deg, #FFD84D 0, #FFD84D 6px, #FFC21A 6px, #FFC21A 12px);
  box-shadow: 0 2px 3px rgba(30, 42, 94, .28); }
.gt-paper::before { left: -3.4%; transform: rotate(-40deg); }
.gt-paper::after { right: -3.4%; transform: rotate(40deg); }

/* mũi tên có bề dày, chấm chạy là một hạt bóng */
.gt-arrows path { fill: #2F7DF2; fill: url(#gt-g-arrow) #2F7DF2; stroke: #fff; stroke-width: .9; }
.gt-arrows path.gt-arsh { fill: #13205C; stroke: #13205C; stroke-width: 1.3; }
.gt-runner { fill: #17B34F; fill: url(#gt-g-bead) #17B34F; }

/* chấm xanh: hạt cườm bóng nổi trên giấy (có điểm sáng, bóng đổ), vòng sáng lan ra để gọi bé đặt tay */
.gt-dot { background: radial-gradient(circle at 33% 27%, #CFFFDD 0, #62E490 15%, #1FBF58 48%, #0E8E3C 82%, #0A6E2E 100%); text-shadow: 0 1px 0 rgba(4, 70, 26, .75), 0 0 3px rgba(4, 70, 26, .5);
  box-shadow: inset 0 -3px 5px rgba(0, 60, 20, .45), 0 3px 0 #0A6E2E, 0 7px 8px rgba(10, 60, 30, .45); animation: none; }
.gt-dot::before { content: ""; position: absolute; z-index: -1; left: 17%; top: 9%; width: 40%; height: 27%; border-radius: 50%; background: linear-gradient(rgba(255, 255, 255, .92), rgba(255, 255, 255, .08)); transform: rotate(-28deg); pointer-events: none; }
.gt-dot::after { content: ""; position: absolute; top: -4px; right: -4px; bottom: -4px; left: -4px; border-radius: 50%; border: 3px solid rgba(23, 179, 79, .8); animation: gt-ring 1.3s ease-out infinite; pointer-events: none; }
.gt-dot.hinted::after, .gt-down .gt-dot::after, .gt-dot.gt-shake::after { animation: none; opacity: 0; }
@keyframes gt-ring { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.85); opacity: 0; } }

/* dải chọn bảng: máng lõm, thẻ đang chọn là một phím nổi bóng */
.gt-tabs { padding: 5px; background: linear-gradient(#DCE4F6, #F7F9FF); box-shadow: inset 0 3px 5px rgba(30, 42, 94, .26), inset 0 -1px 0 #fff, 0 2px 0 rgba(255, 255, 255, .8), 0 7px 10px rgba(30, 42, 94, .2); }
.gt-tabs button { transition: transform .08s; }
.gt-tabs button[aria-pressed="true"] { background: linear-gradient(#FFEA85, #FFC51F); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -4px 0 rgba(160, 100, 0, .26), 0 3px 0 #C58A00, 0 6px 8px rgba(30, 42, 94, .26); }
.gt-tabs button:active { transform: translateY(2px); }

/* nút tròn sang chữ trước / chữ sau: mặt nút vồng bóng, mũi tên trắng nổi */
.gt-wrap .round { background: radial-gradient(circle at 34% 24%, rgba(255, 255, 255, .8) 0, rgba(255, 255, 255, 0) 40%), linear-gradient(rgba(255, 255, 255, .22), rgba(150, 80, 0, .16)), var(--c);
  box-shadow: inset 0 -4px 0 rgba(150, 80, 0, .22), 0 5px 0 #C58A00, 0 10px 12px rgba(30, 42, 94, .26); }
.gt-wrap .round:active { box-shadow: inset 0 -2px 0 rgba(150, 80, 0, .22), 0 1px 0 #C58A00; }
.gt-wrap .round svg { fill: #fff; stroke: #A86A00; stroke-width: 1.4; stroke-linejoin: round; paint-order: stroke; overflow: visible; filter: drop-shadow(0 2px 0 rgba(120, 70, 0, .5)); }

/* bút sáp thật: thân trụ có vệt sáng dọc, băng giấy quấn quanh, đầu bút vát nhọn; cây đang cầm thì nhô lên */
.gt-crayon { position: relative; z-index: 0; width: 56px; height: 62px; border: 0; border-radius: 12px; background: none; box-shadow: none; transition: transform .14s; }
.gt-crayon::before { content: ""; position: absolute; left: 50%; bottom: 5px; width: 34px; height: 55px; margin-left: -17px; border-radius: 0 0 6px 6px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .3) 0, rgba(0, 0, 0, 0) 20%, rgba(255, 255, 255, .55) 32%, rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, .1) 76%, rgba(0, 0, 0, .36) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 43%, rgba(0, 0, 0, .34) 43%, rgba(0, 0, 0, .34) 46%, rgba(255, 255, 255, .3) 46%, rgba(255, 255, 255, .3) 84%, rgba(0, 0, 0, .34) 84%, rgba(0, 0, 0, .34) 87%, rgba(0, 0, 0, 0) 87%),
    var(--c);
  -webkit-clip-path: polygon(50% 0, 63% 3%, 76% 25%, 100% 29%, 100% 100%, 0 100%, 0 29%, 24% 25%, 37% 3%);
  clip-path: polygon(50% 0, 63% 3%, 76% 25%, 100% 29%, 100% 100%, 0 100%, 0 29%, 24% 25%, 37% 3%); }
.gt-crayon::after { content: ""; position: absolute; left: 50%; bottom: 0; width: 44px; height: 10px; margin-left: -22px; border-radius: 50%; background: radial-gradient(ellipse at center, rgba(30, 42, 94, .42) 0, rgba(30, 42, 94, 0) 70%); z-index: -1; }
.gt-crayon[aria-pressed="true"] { outline: 0; transform: translateY(-9px) scale(1.12); filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 2px #fff) drop-shadow(0 0 3px rgba(30, 42, 94, .95)); }
.gt-crayon[aria-pressed="true"]::after { bottom: -8px; width: 34px; margin-left: -17px; opacity: .7; }
.gt-crayon:active { transform: translateY(2px); }
.gt-colors { gap: 2px; align-items: flex-end; padding: 6px 6px 0; border-radius: 18px; background: linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .78)); box-shadow: inset 0 2px 4px rgba(30, 42, 94, .16), 0 2px 0 rgba(255, 255, 255, .7); }

/* nút "Tô lại", "Xem mẫu": phím nổi có hình 3D */
.gt-btn { padding: 4px 18px 4px 8px; border: 3px solid #fff; background: linear-gradient(#fff, #E6ECFB); box-shadow: inset 0 -4px 0 rgba(30, 42, 94, .1), 0 5px 0 #AEBBDD, 0 10px 12px rgba(30, 42, 94, .24); transition: transform .08s, box-shadow .08s; }
.gt-btn img.emo { width: 40px; height: 40px; flex: none; filter: drop-shadow(0 2px 0 rgba(30, 42, 94, .25)); }
.gt-btn:active { transform: translateY(4px); box-shadow: inset 0 -2px 0 rgba(30, 42, 94, .1), 0 1px 0 #AEBBDD; }
.gt-demobtn { background: linear-gradient(#F4FFF7, #CDF4D9); border-color: #fff; box-shadow: inset 0 -4px 0 rgba(10, 110, 50, .12), 0 5px 0 #74C792, 0 10px 12px rgba(30, 42, 94, .24); }
.gt-demobtn:active { box-shadow: inset 0 -2px 0 rgba(10, 110, 50, .12), 0 1px 0 #74C792; }
.gt-demobtn[aria-pressed="true"] { background: linear-gradient(#FFEA85, #FFC51F); border-color: #fff; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -4px 0 rgba(160, 100, 0, .26), 0 5px 0 #C58A00, 0 10px 12px rgba(30, 42, 94, .24); }
@media (max-width: 400px) { .gt-btn { padding-right: 12px; font-size: 1rem; } .gt-btn img.emo { width: 34px; height: 34px; } }
@media (min-aspect-ratio: 5/4) and (max-height: 560px) { .gt-crayon { height: 58px; } .gt-crayon::before { height: 51px; } }
@media (prefers-reduced-motion: reduce) { .gt-dot::after { animation: none; opacity: 0; } .gt-crayon, .gt-btn, .gt-tabs button { transition: none; } }

/* ---------- wave 6: compat (trình duyệt cũ) ---------- */
/* Bản dự phòng cho máy cũ của các luật phía trên (giải thích ở cuối css/style.css); sửa luật gốc thì sửa luôn dòng tương ứng ở đây. */
/* chưa có color-mix(): bút sáp (.gt-crayon) nay không còn dùng color-mix nên không cần dòng dự phòng */
/* chưa có đơn vị cqw/cqh, @container */
@supports not (width: 1cqw) {
  .gt-stage { --cq: size; contain: size; }
  .gt-paper { width: min(calc(100 * var(--cqw)), calc(100 * var(--cqh)), 860px); height: min(calc(100 * var(--cqw)), calc(100 * var(--cqh)), 860px); --cq: size; contain: size; }
  .gt-dot { width: calc(12 * var(--cqw)); height: calc(12 * var(--cqw)); border: max(2px, calc(.9 * var(--cqw))) solid #fff; font-size: calc(6.6 * var(--cqw)); }
  .gt-finger { font-size: calc(15 * var(--cqw)); }
  .gt-finger img.emo { width: calc(15 * var(--cqw)); height: calc(15 * var(--cqw)); }
  @keyframes gt-beat { 0% { box-shadow: 0 3px 0 #0C7A33, 0 0 0 0 rgba(23, 179, 79, .6); } 100% { box-shadow: 0 3px 0 #0C7A33, 0 0 0 calc(4.5 * var(--cqw)) rgba(23, 179, 79, 0); } }
}
/* chưa có translate/rotate/scale rời */
@supports not (translate: 0) {
  .gt-dot { --i-tx: -50%; --i-ty: -50%; transform: var(--i-t); }
  :where(.gt-dot.gt-shake) { transform: var(--i-t); }
  .gt-finger { --i-tx: -42%; --i-ty: -8%; transform: var(--i-t); }
  :where(.gt-paper.gt-done) { transform: var(--i-t); }
  @keyframes gt-shake { 0%, 100% { --i-tx: -50%; --i-ty: -50%; } 25% { --i-tx: -62%; --i-ty: -50%; } 75% { --i-tx: -38%; --i-ty: -50%; } }
  @keyframes gt-cheer { 0% { --i-sx: 1; --i-sy: 1; } 40% { --i-sx: 1.04; --i-sy: 1.04; } 100% { --i-sx: 1; --i-sy: 1; } }
}
