/* Shared styles for every page.
   Two modes:
   - "stage" (landscape screens: Mac, iPad sideways): the fixed-size design is scaled so the whole page fits one screen.
   - "flow" (html.flow; phones, tablets in portrait): no scaling, the layout reflows at real size and scrolls.
   js/page.js picks the mode (animation pages stay in flow up to 1199px wide, since their sideways layout fits a tablet screen). */
:root {
  --bg: #FFF6E0;
  --ink: #1E293B;
  --muted: #475569;
  --pink: #E11D74;
  --green: #16A34A;
  --yellow: #FFD500;
  --line: #CBD5E1;
  --head: 'Baloo 2', 'Nunito', sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
}
html, body { margin: 0; background: var(--bg); }
body { font-family: var(--body); color: var(--ink); -webkit-text-size-adjust: 100%; }
.wrap { margin: 0 auto; overflow: hidden; }
.stage { transform-origin: 0 0; }
button { font-family: var(--body); cursor: pointer; }
a, button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 4px solid #2563EB; outline-offset: 3px; }

/* ---- shared pieces ---- */
.sidenav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 80px; border-radius: 18px; background: var(--ink); display: flex; align-items: center; justify-content: center; text-decoration: none; z-index: 5; }
.sidenav.prev { left: 2px; }
.sidenav.next { right: 2px; }
.pill { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 999px; box-sizing: border-box; text-decoration: none; font-weight: 800; font-size: 16px; white-space: nowrap; }
.pill.line { border: 2.5px solid var(--ink); color: var(--ink); background: #FFFFFF; }
.pill.dark { background: var(--ink); color: #FFFFFF; border: none; }
.pill.pink { background: var(--pink); color: #FFFFFF; border: none; }
.badge { background: var(--pink); color: #FFFFFF; font-family: var(--head); font-weight: 800; font-size: 20px; padding: 3px 16px; border-radius: 999px; white-space: nowrap; }
.title { margin: 0; font-family: var(--head); font-weight: 800; font-size: 42px; line-height: 1; }
.spacer { flex-grow: 1; }

/* ---- animation pages (hoat-hinh-N) ---- */
.anim { width: 1280px; height: 720px; box-sizing: border-box; padding: 40px 44px; display: flex; gap: 36px; align-items: center; position: relative; }
.cubebox { width: 640px; height: 640px; flex-shrink: 0; background: #FFFFFF; border-radius: 32px; border: 4px solid var(--ink); box-sizing: border-box; display: flex; align-items: center; justify-content: center; position: relative; }
.cubebox canvas { width: 600px; height: 600px; }
#start { position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); min-height: 64px; padding: 0 34px; border-radius: 999px; border: 4px solid #FFFFFF; background: var(--pink); color: #FFFFFF; font-size: 28px; font-weight: 800; white-space: nowrap; box-shadow: 0 6px 18px rgba(30, 41, 59, .25); }
#doneBadge { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--green); color: #FFFFFF; font-family: var(--head); font-weight: 800; font-size: 32px; padding: 6px 28px; border-radius: 999px; white-space: nowrap; }
.panel { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.topnav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.heading { display: flex; align-items: center; gap: 12px; }
.seg { background: #FFFFFF; border: 3px solid var(--ink); border-radius: 20px; padding: 10px 16px; display: flex; flex-direction: column; gap: 4px; min-height: 96px; box-sizing: border-box; }
#segCount { font-size: 15px; font-weight: 800; color: #B45309; }
#segLabel { font-size: 21px; font-weight: 800; line-height: 1.3; }
.move { background: #FFFFFF; border: 4px solid var(--ink); border-radius: 24px; padding: 10px 20px; display: flex; align-items: center; gap: 18px; }
#moveNum { width: 70px; height: 70px; flex-shrink: 0; border-radius: 50%; background: var(--pink); color: #FFFFFF; font-family: var(--head); font-weight: 800; font-size: 40px; display: flex; align-items: center; justify-content: center; }
#moveTop { font-size: 22px; font-weight: 800; color: var(--muted); }
#moveWord { font-family: var(--head); font-weight: 800; font-size: 54px; line-height: 1; }
#chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.chip { text-align: center; padding: 6px 4px; border-radius: 12px; font-weight: 800; font-size: 15px; line-height: 1.2; background: #FFFFFF; color: var(--muted); border: 2px solid var(--line); }
.chip.on { background: var(--pink); color: #FFFFFF; border-color: var(--pink); }
.controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.controls button { min-height: 52px; padding: 0 12px; border-radius: 999px; font-size: 20px; font-weight: 800; border: 3px solid var(--ink); background: #FFFFFF; color: var(--ink); }
.controls #play { background: var(--ink); color: #FFFFFF; }
.controls #step { background: var(--pink); border-color: var(--pink); color: #FFFFFF; }
.voicerow { display: flex; align-items: center; gap: 12px; }
#voice { min-height: 48px; padding: 0 18px; border-radius: 999px; border: 3px solid #1D4ED8; background: #DBEAFE; color: #1E3A8A; font-size: 18px; font-weight: 800; white-space: nowrap; }
#voiceNote { font-size: 15px; font-weight: 700; color: var(--muted); line-height: 1.3; }

/* ---- home page ---- */
.home { width: 1280px; height: 720px; box-sizing: border-box; padding: 32px 44px; display: flex; flex-direction: column; gap: 18px; position: relative; }
.home-head { display: flex; align-items: center; gap: 20px; }
.home-head img { width: 96px; height: 96px; }
.home-head .titles { display: flex; flex-direction: column; gap: 4px; flex-grow: 1; }
.home-head h1 { margin: 0; font-family: var(--head); font-weight: 800; font-size: 48px; line-height: 1.05; }
.slogan { font-family: var(--head); font-weight: 800; font-size: 28px; color: var(--pink); }
.home-head .pill { min-height: 52px; padding: 0 22px; font-size: 18px; }
.intro { margin: 0; font-size: 18px; font-weight: 700; color: var(--muted); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.card { background: #FFFFFF; border: 3px solid var(--ink); border-radius: 20px; padding: 8px 10px 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.card .pic { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--ink); }
.card .pic img { width: 104px; height: 104px; }
.card .name { display: flex; align-items: center; gap: 6px; font-family: var(--head); font-weight: 800; font-size: 20px; line-height: 1.1; }
.num { width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%; background: var(--pink); color: #FFFFFF; font-family: var(--body); font-weight: 800; font-size: 15px; display: flex; align-items: center; justify-content: center; }
.card .btns { display: flex; gap: 6px; width: 100%; }
.card .btns .pill { flex: 1; padding: 0 8px; }

/* ---- book pages (sach-N): header ---- */
.book { width: 1123px; height: 794px; box-sizing: border-box; padding: 40px 44px; background: var(--bg); display: flex; flex-direction: column; gap: 12px; position: relative; }
.bookhead { display: flex; align-items: center; gap: 14px; }
.dots { display: flex; align-items: center; }
.dots a { display: flex; align-items: center; justify-content: center; width: 40px; height: 44px; text-decoration: none; }
.bookhead .title { white-space: nowrap; }
.dots span { width: 36px; height: 36px; border-radius: 50%; border: 2.5px solid #94A3B8; box-sizing: border-box; color: var(--muted); background: #FFFFFF; font-weight: 800; font-size: 16px; display: flex; align-items: center; justify-content: center; }
.dots a[aria-current] span { background: var(--pink); border-color: var(--pink); color: #FFFFFF; }

/* ---- animation pop-up (home and book pages) ---- */
dialog.player { padding: 0; border: 4px solid var(--ink); border-radius: 28px; width: min(96vw, 1280px); height: min(92vh, 760px); max-width: none; max-height: none; background: var(--bg); overflow: hidden; }
dialog.player::backdrop { background: rgba(30, 41, 59, .65); }
dialog.player iframe { display: block; width: 100%; height: 100%; border: 0; }
.closebtn { position: absolute; top: 12px; right: 12px; z-index: 2; min-height: 48px; padding: 0 20px; border-radius: 999px; border: 3px solid #FFFFFF; background: var(--ink); color: #FFFFFF; font-size: 18px; font-weight: 800; box-shadow: 0 4px 14px rgba(30, 41, 59, .3); }
/* the animation page inside the pop-up: no page navigation */
.embed .sidenav, .embed .topnav { display: none !important; }
.embed body, html.embed { background: var(--bg); }

@page { size: A4 landscape; margin: 0; }
@media print {
  .wrap { width: auto !important; height: auto !important; }
  .stage { transform: none !important; }
  .sidenav { display: none !important; }
}

/* ===== flow mode (html.flow, set by js/page.js): phones, portrait tablets, narrow windows ===== */
html.flow .wrap { width: auto !important; height: auto !important; overflow: visible; }
html.flow .stage { transform: none !important; }
html.flow .anim, html.flow .home, html.flow .book { width: auto !important; height: auto !important; max-width: 760px; margin: 0 auto; padding: 16px 16px 92px !important; }
html.flow .sidenav { position: fixed; top: auto; bottom: 10px; transform: none; width: 50px; height: 50px; border-radius: 50%; box-shadow: 0 4px 14px rgba(30, 41, 59, .3); }
html.flow .sidenav.prev { left: 10px; }
html.flow .sidenav.next { right: 10px; }
html.flow dialog.player { width: 100vw; height: 100dvh; border: 0; border-radius: 0; }
html.flow.embed .anim { padding: 76px 16px 24px !important; }
html.flow .title { font-size: 34px; }
html.flow .topnav { gap: 6px; }
html.flow .topnav .spacer { display: none; }
html.flow .topnav .pill { padding: 0 11px; font-size: 15px; }
html.flow .topnav .pill.dark { margin-left: auto; }
html.flow .badge { font-size: 18px; }

/* animation: panel children placed around the cube */
html.flow .anim { flex-direction: column; align-items: stretch; gap: 12px; }
html.flow .panel { display: contents; }
html.flow .topnav { order: 1; }
html.flow .heading { order: 2; }
html.flow .cubebox { order: 3; width: 100%; height: auto; aspect-ratio: 1; max-width: 50vh; align-self: center; border-radius: 24px; }
html.flow .cubebox canvas { width: 94%; height: auto; }
html.flow .seg { order: 4; min-height: 0; }
html.flow .move { order: 5; }
html.flow #chips { order: 6; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
html.flow .controls { order: 7; }
html.flow .voicerow { order: 8; flex-wrap: wrap; }
html.flow #start { font-size: 22px; min-height: 56px; padding: 0 24px; bottom: 16px; }
html.flow #doneBadge { font-size: 26px; bottom: 16px; }
html.flow #moveNum { width: 56px; height: 56px; font-size: 32px; }
html.flow #moveWord { font-size: 40px; }
html.flow #moveTop { font-size: 19px; }
html.flow #segLabel { font-size: 19px; }
html.flow .controls button { font-size: 18px; }

/* home */
html.flow .home { gap: 12px; }
html.flow .home-head { flex-wrap: wrap; gap: 12px; }
html.flow .home-head img { width: 72px; height: 72px; }
html.flow .home-head .titles { flex: 1 1 200px; }
html.flow .home-head h1 { font-size: 32px; }
html.flow .slogan { font-size: 22px; }
html.flow .home-head .pill { width: 100%; }
html.flow .steps { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
html.flow .card { padding: 10px; }
html.flow .card .btns { flex-direction: column; }

/* book pages: stack the rows, let fixed-width columns fill the width */
html.flow .bookhead { flex-wrap: wrap; gap: 10px; }
html.flow .bookhead .spacer { display: none; }
html.flow .dots { width: 100%; justify-content: space-between; }
html.flow .book { max-width: 1080px; }
html.flow .g-moves img { max-width: 100%; height: auto !important; }

html.flow .g-moves[style*="repeat(11"] { grid-template-columns: repeat(6, minmax(0, 1fr)) !important; row-gap: 12px !important; }
html.flow:not(.land) .anim .sidenav { display: none; }
/* home and book pages scroll: the ‹ › buttons sit in a row at the end of the page instead of floating over the text */
html.flow .home > .sidenav, html.flow .book > .sidenav { position: relative; left: auto; right: auto; bottom: auto; order: 99; box-shadow: none; margin-top: 8px; }
html.flow .home > .sidenav.next, html.flow .book > .sidenav.next { align-self: flex-end; }
html.flow .book > .sidenav.prev ~ .sidenav.next { margin-top: -62px; } /* same row as ‹: 50px button + 12px gap */
html.flow .home, html.flow .book { padding-bottom: 24px !important; } /* portrait: the top buttons already lead home / to the next step */
@media (max-width: 599px) {
  html.flow .g-moves, html.flow .g-moves[style*="repeat(11"] { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)) !important; row-gap: 12px !important; }
}
@media (max-width: 899px) {
  html.flow .row { flex-direction: column !important; }
  html.flow .row > * { width: auto !important; }
  html.flow .row > [style*="flex-direction: row"], html.flow .pair { flex-wrap: wrap; justify-content: center; } /* picture beside text: let them stack */
  html.flow .g-cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; row-gap: 14px !important; }
  html.flow .g-tick { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)) !important; }
}

/* animation on a device held sideways (phone, iPad): cube left, controls right */
html.flow.land .anim { flex-direction: row; align-items: flex-start; max-width: 1100px !important; }
html.flow.land .panel { display: flex; order: 2; }
html.flow.land .cubebox { order: 1; width: calc(100vh - 32px); width: calc(100dvh - 32px); max-width: 46vw; align-self: flex-start; position: sticky; top: 16px; }
html.flow.land.embed .anim { padding-top: 16px !important; }
html.flow.land.embed .panel { padding-top: 60px; } /* room for the pop-up's close button */
html.flow.land .topnav, html.flow.land .heading, html.flow.land .seg, html.flow.land .move, html.flow.land #chips, html.flow.land .controls, html.flow.land .voicerow { order: 0; }

