/* Bảng vẽ. Mọi lớp ở đây đều bắt đầu bằng gd- */
body[data-scene="bang-ve"] { --sky1: #1FBFA8; --sky2: #D6FBEF; }

/* cả trò vừa một màn hình: chiều cao còn lại sau thanh trên; tờ giấy lấy hết phần thừa */
.gd-wrap {
  --gd-h: calc(var(--vh) - var(--bar) - 40px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  height: var(--gd-h); min-height: 0; margin-inline: -8px;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
}
.gd-wrap > .ask { flex: none; padding-inline: 8px; }
.gd-paper { position: relative; flex: 1 1 0; min-width: 0; min-height: 120px; background: #fff; border: 5px solid #fff; border-radius: 24px; overflow: hidden; box-shadow: var(--lift); }
.gd-paper canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; -webkit-user-select: none; user-select: none; }
/* bút đối xứng: đường gập giữa tờ giấy */
.gd-paper.gd-mirror::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 0; border-left: 3px dashed #C9D3EE; translate: -1.5px 0; pointer-events: none; }

/* công cụ: hàng thẻ + cỡ nét, dải nút của thẻ đang mở, hàng tẩy / hoàn tác / lưu / xóa */
.gd-tools { flex: none; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.gd-top, .gd-acts, .gd-sizes, .gd-tabs { display: flex; align-items: center; gap: 6px; }
.gd-top { flex: none; justify-content: space-between; }
.gd-acts { flex: none; gap: 8px; }
.gd-tabs { flex: 1 1 0; min-width: 0; max-width: 520px; }
.gd-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: rgba(255, 255, 255, .5); border-radius: 22px; }

.gd-tools button { border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.gd-tools button > * { pointer-events: none; }
.gd-tools button[aria-pressed="true"] { outline: 4px solid var(--navy, #1E2A5E); outline-offset: 1px; }
.gd-tools button:active { transform: translateY(2px); }
.gd-tools button:disabled { opacity: .4; cursor: default; }
.gd-ico { display: grid; place-items: center; flex: none; }

.gd-tools .gd-tab { flex: 1 1 0; min-width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 6px; background: #fff; border-radius: 18px; font-size: 34px; box-shadow: 0 4px 0 rgba(30, 42, 94, .2); }
.gd-tools .gd-tab[aria-pressed="true"] { background: var(--yellow, #FFD23F); outline-width: 3px; outline-offset: 0; }
.gd-tab img.emo { width: 36px; height: 36px; display: block; }
.gd-tab svg { width: 36px; height: 36px; display: block; }
.gd-tab b { display: none; font-size: 1rem; font-weight: 800; line-height: 1.05; white-space: nowrap; }

/* dải nút: cuộn ngang khi không đủ chỗ, hai mép mờ đi để báo còn nút */
.gd-strip { --fa: 0px; --fb: 0px; display: flex; gap: 6px; min-height: 0; padding: 7px 7px 10px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; touch-action: pan-x; overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--fa), #000 calc(100% - var(--fb)), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 var(--fa), #000 calc(100% - var(--fb)), transparent 100%); }
.gd-strip::-webkit-scrollbar { display: none; }
.gd-strip[hidden] { display: none; }
.gd-strip.gd-more-a { --fa: 30px; }
.gd-strip.gd-more-b { --fb: 30px; }
.gd-strip > :first-child { margin-left: auto; }
.gd-strip > :last-child { margin-right: auto; }
.gd-strip > * { flex: none; }

.gd-tools .gd-crayon { width: 50px; height: 50px; margin-block: 3px; border-radius: 50%; background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, .55) 0 12%, transparent 13%), var(--c); border: 3px solid #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 60%, #000); }
.gd-tools .gd-btn { width: 56px; height: 56px; flex: none; display: grid; place-items: center; background: #fff; border-radius: 50%; box-shadow: 0 4px 0 rgba(30, 42, 94, .2); }
.gd-tools .gd-stamp { border-radius: 16px; font-size: 38px; line-height: 1; }
.gd-tools .gd-stamp img { width: 44px; height: 44px; display: block; object-fit: contain; }
.gd-tools .gd-brush { flex: 1 1 56px; min-width: 56px; max-width: 104px; border-radius: 16px; }
.gd-brush canvas { width: min(100% - 4px, 72px); height: auto; aspect-ratio: 16 / 11; display: block; }
.gd-size i { display: block; width: 10px; height: 10px; border-radius: 50%; background: var(--navy, #1E2A5E); }
.gd-size.gd-big i { width: 26px; height: 26px; }
.gd-tools .gd-clear { flex: 1 1 0; min-width: 0; height: 56px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 2px 10px; background: #fff; border-radius: 999px; font-size: .95rem; line-height: 1.05; box-shadow: 0 4px 0 rgba(30, 42, 94, .2); overflow: hidden; }
.gd-clear b { font-weight: 800; }
.gd-tools .gd-clear.gd-armed { background: #FF5964; color: #fff; font-size: .85rem; }
.gd-clear.gd-armed .gd-ico { display: none; }

/* đủ rộng thì thẻ có thêm chữ */
@media (min-width: 620px) and (max-aspect-ratio: 5/4) {
  .gd-tab b { display: block; }
  .gd-tools .gd-clear { flex: 0 1 230px; margin-left: auto; font-size: 1.05rem; }
  .gd-strip { gap: 10px; }
}
/* đ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) {
  .gd-wrap > .ask { display: none; }
}

/* màn hình ngang: giấy bên trái cao hết cỡ, công cụ thành một cột bên phải */
@media (min-aspect-ratio: 5/4) {
  .gd-wrap {
    --gd-col: clamp(310px, 25vw, 350px);
    align-self: center; width: min(1500px, calc(100vw - 24px)); max-width: none; margin-inline: 0; /* được phép rộng hơn khung 1000px của trang */
    display: grid; grid-template-columns: minmax(0, 1fr) var(--gd-col); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "paper ask" "paper tools"; gap: 8px 12px;
  }
  .gd-paper { grid-area: paper; }
  .gd-wrap > .ask { grid-area: ask; padding-inline: 0; gap: 8px; }
  .gd-wrap > .ask > span { width: 56px; }
  .gd-wrap > .ask .bubble { padding: 6px 12px; font-size: 1rem; }
  .gd-tools { grid-area: tools; justify-content: center; gap: 8px; }
  .gd-panel { flex: 0 1 auto; }
  /* dải nút xếp thành nhiều hàng, cuộn dọc khi không đủ chỗ */
  .gd-strip { flex-wrap: wrap; justify-content: center; align-content: flex-start; overflow-x: hidden; overflow-y: auto; touch-action: pan-y;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fa), #000 calc(100% - var(--fb)), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fa), #000 calc(100% - var(--fb)), transparent 100%); }
  .gd-strip > :first-child { margin-left: 0; }
  .gd-strip > :last-child { margin-right: 0; }
  .gd-strip-magic { gap: 8px; }
  .gd-tools .gd-brush { flex: 0 0 88px; }
}
/* màn hình ngang thấp (điện thoại nằm ngang): bỏ câu của Gấu Con, chỉ còn giấy và cột công cụ */
@media (min-aspect-ratio: 5/4) and (max-height: 560px) {
  .gd-wrap { --gd-h: calc(var(--vh) - var(--bar) - 30px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); grid-template-rows: minmax(0, 1fr); grid-template-areas: "paper tools"; }
  .gd-wrap > .ask { display: none; }
  .gd-tools { gap: 6px; }
}

/* ---------- wave 5: polish ---------- */
/* hàng nút dưới cùng: tẩy / bỏ nét / lưu tranh là ô có hình kèm chữ nhỏ, chia đều bề ngang với nút "Xóa hết" */
.gd-tools .gd-act { flex: 1 1 0; width: auto; min-width: 56px; height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: 2px 2px 3px; border-radius: 18px; }
.gd-act svg { width: 26px; height: 26px; display: block; }
.gd-act b { font: 800 .72rem/1.1 var(--font-ui); color: var(--navy, #1E2A5E); white-space: nowrap; }
.gd-tools .gd-eraser[aria-pressed="true"] { background: var(--yellow, #FFD23F); outline-width: 3px; outline-offset: 0; }
.gd-tools .gd-clear { flex: 1.25 1 0; gap: 4px; padding: 2px 6px; border-radius: 18px; }
.gd-tools .gd-clear b { color: #D92B3A; }
.gd-tools .gd-clear.gd-armed b { color: #fff; }
@media (max-width: 400px) and (max-aspect-ratio: 5/4), (min-aspect-ratio: 5/4) { .gd-tools .gd-clear { flex-direction: column; gap: 0; font-size: .72rem; } .gd-clear svg { width: 26px; height: 26px; } .gd-tools .gd-clear.gd-armed { font-size: .78rem; } }
@media (min-width: 620px) and (max-aspect-ratio: 5/4) {
  .gd-tools .gd-act { flex: 0 1 132px; flex-direction: row; gap: 8px; } .gd-act b { font-size: 1rem; }
  .gd-tools .gd-clear { flex: 0 1 200px; }
}

/* ---------- wave 7: hình khối (3D) ---------- */
/* tờ giấy căng trên bảng vẽ bằng gỗ: viền là mặt gỗ có vân, giấy lõm xuống, mép dưới là bề dày của bảng, bóng đổ xuống bàn */
.gd-paper { border: 8px solid transparent; border-radius: 22px; margin-bottom: 8px;
  background:
    linear-gradient(180deg, #FFFFFC, #FCF8EE) 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, .28), 0 1px 0 #FFE2B4, 0 7px 0 #9C6530, 0 8px 0 #7C4C20, 0 18px 22px rgba(30, 42, 94, .3); }
.gd-paper canvas { border-radius: 14px; }

/* nút công cụ: phím nổi (mặt vồng sáng ở trên, cạnh dày ở dưới, bóng đổ); nút đang chọn có vành cam */
.gd-tools .gd-tab, .gd-tools .gd-btn { background: linear-gradient(#fff, #E6ECFB); box-shadow: inset 0 2px 0 #fff, inset 0 -4px 0 rgba(30, 42, 94, .1), 0 4px 0 #AEBBDD, 0 8px 10px rgba(30, 42, 94, .22); }
.gd-tools button[aria-pressed="true"] { outline: 0; }
.gd-tools .gd-tab[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 4px 0 #C58A00, 0 8px 10px rgba(30, 42, 94, .26); }
.gd-tools .gd-btn[aria-pressed="true"], .gd-tools .gd-eraser[aria-pressed="true"] { background: linear-gradient(#FFF7CC, #FFD95A);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .85), inset 0 -4px 0 rgba(160, 100, 0, .2), 0 0 0 3px var(--orange), 0 4px 0 3px #B66A00, 0 9px 10px rgba(30, 42, 94, .26); }
.gd-tab img.emo { width: 42px; height: 42px; filter: drop-shadow(0 2px 0 rgba(30, 42, 94, .22)); }
.gd-tools .gd-stamp img { filter: drop-shadow(0 2px 0 rgba(30, 42, 94, .2)); }
/* cỡ nét: hai viên bi nhỏ và to */
.gd-size i { background: radial-gradient(circle at 34% 28%, #A9B6EE 0, #3A4A9A 42%, #141C4E 100%); box-shadow: 0 2px 2px rgba(30, 42, 94, .4); }
/* khay đựng bút */
.gd-panel { background: linear-gradient(rgba(255, 255, 255, .6), rgba(255, 255, 255, .84)); box-shadow: inset 0 3px 5px rgba(30, 42, 94, .2), 0 2px 0 rgba(255, 255, 255, .7); }

/* 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 và sáng viền */
.gd-tools .gd-crayon { position: relative; z-index: 0; width: 50px; height: 58px; margin-block: 0; border: 0; border-radius: 10px; background: none; box-shadow: none; transition: transform .14s; }
.gd-crayon::before { content: ""; position: absolute; left: 50%; bottom: 5px; width: 32px; height: 51px; margin-left: -16px; 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%); }
.gd-crayon::after { content: ""; position: absolute; z-index: -1; left: 50%; bottom: 0; width: 42px; height: 10px; margin-left: -21px; border-radius: 50%; background: radial-gradient(ellipse at center, rgba(30, 42, 94, .42) 0, rgba(30, 42, 94, 0) 70%); }
.gd-tools .gd-crayon[aria-pressed="true"] { transform: translateY(-5px) scale(1.1); filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 2px #fff) drop-shadow(0 0 3px rgba(30, 42, 94, .95)); }
.gd-tools .gd-crayon:active { transform: translateY(2px); }

/* hàng nút dưới: hình 3D (cục tẩy, mũi tên quay lại, đĩa lưu, thùng rác) */
.gd-act img.emo, .gd-act .gd-pic svg { width: 32px; height: 32px; display: block; }
.gd-act .gd-pic svg { overflow: visible; }
.gd-act .gd-ico { filter: drop-shadow(0 2px 0 rgba(30, 42, 94, .2)); }
.gd-clear img.emo { width: 32px; height: 32px; display: block; }
.gd-tools .gd-clear { background: linear-gradient(#fff, #FFE6EA); box-shadow: inset 0 2px 0 #fff, inset 0 -4px 0 rgba(200, 40, 60, .1), 0 4px 0 #E2A0AA, 0 8px 10px rgba(30, 42, 94, .22); }
.gd-tools .gd-clear.gd-armed { background: linear-gradient(#FF7A84, #F2404E); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .4), inset 0 -4px 0 rgba(120, 0, 20, .22), 0 4px 0 #A82634, 0 8px 10px rgba(30, 42, 94, .26); }
@media (prefers-reduced-motion: reduce) { .gd-tools .gd-crayon { 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 (.gd-crayon) nay không còn dùng color-mix nên không cần dòng dự phòng */
/* chưa có translate/rotate/scale rời */
@supports not (translate: 0) {
  .gd-paper.gd-mirror::after { --i-tx: -1.5px; --i-ty: 0px; transform: var(--i-t); }
}
