:root {
  --pink: #F7A8C4; --pinkL: #FFF0F5; --cream: #FFF8EC; --berry: #DD5277; --mint: #A9D6BF; --ink: #65394B;
  --sa-t: env(safe-area-inset-top, 0px); --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px); --sa-r: env(safe-area-inset-right, 0px);
  --gap: 10px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #FFE9F0; overscroll-behavior: none; }
body { font-family: "Baloo 2", ui-rounded, "SF Pro Rounded", system-ui, sans-serif; color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; position: fixed; inset: 0; }
#game { position: fixed; inset: 0; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { width: 30px; height: 30px; display: block; flex: none; }

/* ---------- nút trên cảnh */
#hud > div { position: fixed; display: flex; gap: var(--gap); pointer-events: none; z-index: 5; }
#hud .tl { top: calc(var(--sa-t) + 10px); left: calc(var(--sa-l) + 10px); }
#hud .tr { top: calc(var(--sa-t) + 10px); right: calc(var(--sa-r) + 10px); }
#hud .bl { bottom: calc(var(--sa-b) + 12px); left: calc(var(--sa-l) + 12px); }
#hud .br { bottom: calc(var(--sa-b) + 12px); right: calc(var(--sa-r) + 12px); }
.hb { pointer-events: auto; min-width: 54px; min-height: 54px; padding: 6px 8px 4px; border-radius: 20px;
  background: rgba(255,255,255,0.9); box-shadow: 0 3px 0 rgba(221,82,119,0.18), 0 6px 16px rgba(101,57,75,0.12);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; position: relative;
  transition: transform .15s; }
.hb span { font-size: 12px; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.hb:active { transform: scale(0.93); }
.hb.soft { background: rgba(255,255,255,0.7); }
.hb.big { min-width: 68px; min-height: 68px; border-radius: 24px; }
.hb.big svg { width: 38px; height: 38px; }
.hb b { position: absolute; top: -6px; right: -6px; background: var(--berry); color: #fff; font-size: 13px; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; padding: 0 5px; }
.hb.hot { transform: scale(1.18); background: #FFE3EA; box-shadow: 0 0 0 5px rgba(255,255,255,0.9), 0 0 22px rgba(221,82,119,0.5); }
.hb.pulse { animation: pulse .6s; }
.hb.wiggle { animation: wig 1.6s ease-in-out infinite; }
@keyframes pulse { 40% { transform: scale(1.22); } }
@keyframes wig { 0%, 70%, 100% { transform: rotate(0); } 78% { transform: rotate(-9deg); } 86% { transform: rotate(8deg); } 94% { transform: rotate(-4deg); } }
body.calm .hb.wiggle { animation: none; }
body.recording #hud .tr #bRec, body.recording #hud .tr #bStories, body.recording #hud .tr #bSet { display: none; }
@media (max-width: 420px) { .hb span { font-size: 11px; } #hud .tr { gap: 6px; } .hb { min-width: 50px; min-height: 52px; padding: 5px 5px 3px; } }

/* ---------- panel */
.panel { position: fixed; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -46%) scale(.96); opacity: 0; pointer-events: none;
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px - var(--sa-t) - var(--sa-b));
  background: var(--cream); border-radius: 28px; box-shadow: 0 10px 0 rgba(221,82,119,0.15), 0 20px 50px rgba(101,57,75,0.25);
  display: flex; flex-direction: column; overflow: hidden; transition: opacity .2s, transform .2s; border: 4px solid #fff; }
.panel.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.panel header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 20px; background: var(--pinkL); }
.panel h2 { margin: 0; font-size: 22px; font-weight: 800; }
.panel h2 small { font-size: 15px; opacity: .7; }
.panel header button { width: 48px; height: 48px; border-radius: 50%; background: #fff; display: grid; place-items: center; }
.panel > div, .panel > p { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel .note { font-size: 14px; opacity: .8; margin: 8px 18px; line-height: 1.35; }
.panel .warn { background: #FFF1D6; border-radius: 14px; padding: 10px 12px; margin: 10px 14px; font-size: 14px; line-height: 1.35; }
.panel .empty { text-align: center; padding: 18px; opacity: .8; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 8px 16px; border-radius: 18px;
  background: #fff; font-weight: 700; font-size: 16px; box-shadow: 0 3px 0 rgba(221,82,119,0.2); margin: 8px 14px 14px; }
.btn.main { background: var(--pink); color: #fff; }
.btn.main svg { color: #fff; }
.btn:disabled { opacity: .5; }
.btn:active { transform: translateY(2px); box-shadow: none; }

/* bảng bên (túi, cài đặt): nằm cạnh, không che Thỏ khi ngang máy */
@media (orientation: landscape) {
  .panel.side, .panel.ward { left: auto; right: calc(var(--sa-r) + 12px); transform: translate(0, -46%) scale(.96); width: min(360px, 44vw); }
  .panel.side.show, .panel.ward.show { transform: translate(0, -50%) scale(1); }
}
@media (orientation: portrait) {
  .panel.ward { top: calc(var(--sa-t) + 12px); transform: translate(-50%, -10px); max-height: 46dvh; }
  .panel.ward.show { transform: translate(-50%, 0); }
}

/* bản đồ */
.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 14px; }
.room-card { background: #fff; border-radius: 18px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: 0 3px 0 rgba(221,82,119,0.15); }
.room-card canvas { width: 100% !important; height: auto !important; border-radius: 12px; }
.room-card span { font-weight: 800; font-size: 16px; }
.room-card em { font-style: normal; font-size: 12px; color: var(--berry); }
.room-card.cur { outline: 4px solid var(--pink); }
@media (max-width: 420px) { .rooms { grid-template-columns: 1fr; } .room-card { flex-direction: row; } .room-card canvas { width: 45% !important; } }

/* túi */
.bag-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px; }
.bag-item { background: #fff; border-radius: 16px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; font-size: 12px; font-weight: 700; min-height: 88px; }
.bag-grid .empty { grid-column: 1 / -1; }

/* tủ đồ */
.outfits { display: flex; gap: 8px; padding: 12px; overflow-x: auto; }
.outfit { background: #fff; border-radius: 18px; padding: 6px 6px 4px; display: flex; flex-direction: column; align-items: center; font-size: 13px; font-weight: 700; flex: none; min-width: 80px; }
.outfit.cur { outline: 4px solid var(--pink); background: var(--pinkL); }
@media (orientation: landscape) { .outfits { flex-wrap: wrap; justify-content: center; } }

/* gợi ý */
#hintBody { padding: 0 12px; }
.quest { background: #fff; border-radius: 18px; padding: 10px 12px; margin: 8px 0; }
.quest h3 { margin: 0 0 6px; font-size: 18px; }
.quest.done { opacity: .75; }
.steps { display: flex; gap: 6px; overflow-x: auto; }
.step { flex: none; width: 96px; display: flex; flex-direction: column; align-items: center; text-align: center; font-size: 12px; line-height: 1.2; font-weight: 600; background: var(--pinkL); border-radius: 14px; padding: 6px 4px; }
.done-note { font-size: 13px; margin: 6px 0 0; color: var(--berry); }

/* cài đặt */
.set-body, .par-body { padding: 10px 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.tog, .hold { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 14px; border-radius: 18px; background: #fff; font-weight: 700; font-size: 16px; text-align: left; position: relative; overflow: hidden; }
.tog span, .hold span { flex: 1; }
.tog i { width: 48px; height: 28px; border-radius: 14px; background: #E8D6DC; position: relative; flex: none; transition: background .2s; }
.tog i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.tog.on i { background: var(--berry); }
.tog.on i::after { transform: translateX(20px); }
.hold small { font-weight: 500; opacity: .7; }
.hold i { position: absolute; left: 0; bottom: 0; height: 5px; width: 0; background: var(--berry); }
.hold.holding i { width: 100%; transition: width var(--hold, 2s) linear; }
.hold.danger { background: #FFE9E6; }
.par-row { display: flex; gap: 8px; flex-wrap: wrap; }
.par-row .btn { margin: 0; flex: 1; }
.par-body p { margin: 4px 2px; font-size: 14px; line-height: 1.4; }
.par-info { background: #fff; border-radius: 16px; padding: 8px 12px; }
.par-info a { color: var(--berry); font-weight: 700; }
.par-body .tog { font-size: 15px; }

/* studio */
.panel.studio { width: min(620px, calc(100vw - 24px)); }
#studioBody { padding: 10px 14px 0; }
.rec-preview { margin: 0 auto 8px; border-radius: 16px; overflow: hidden; background: #FFE3EA; border: 3px solid #fff; }
.rec-preview canvas { width: 100%; height: 100%; display: block; }
.rec-preview.wide { width: 100%; aspect-ratio: 16/9; max-height: 28dvh; max-width: calc(28dvh * 16 / 9); }
.rec-preview.tall { height: 30dvh; aspect-ratio: 9/16; }
.rec-opts { display: flex; flex-direction: column; gap: 6px; }
.rec-opts .tog { min-height: 50px; }
.meter { height: 8px; border-radius: 4px; background: #F3DDE4; overflow: hidden; margin: -2px 6px 2px; }
.meter i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--mint), var(--berry)); transform-origin: left; transform: scaleX(0); transition: transform .08s; }
.cam-opts, .aspect { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { min-width: 48px; min-height: 44px; border-radius: 14px; background: #fff; font-weight: 700; font-size: 18px; padding: 0 12px; }
.chip.on { background: var(--pink); color: #fff; }
.chip.big { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 15px; min-height: 52px; }
.btn.rec { background: var(--berry); color: #fff; font-size: 18px; }
.btn.rec i, #recStop i { width: 20px; height: 20px; border-radius: 50%; background: #fff; display: block; }
#reviewBody { padding: 10px 14px; display: flex; flex-direction: column; align-items: center; }
#reviewBody video { border-radius: 16px; background: #000; max-width: 100%; }
#reviewBody video.wide { width: 100%; max-height: 38dvh; }
#reviewBody video.tall { height: 40dvh; }
.name { font: inherit; font-size: 18px; font-weight: 700; color: var(--ink); border: 3px solid var(--pink); border-radius: 14px; padding: 8px 12px; margin: 8px 0; width: 100%; background: #fff; -webkit-user-select: text; user-select: text; }
.meta, .status { font-size: 14px; margin: 2px 0; text-align: center; }
.rev-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.rev-row .btn { margin: 0; }

/* kho */
#storiesBody { padding: 4px 12px 14px; }
.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.story { background: #fff; border-radius: 18px; padding: 8px; display: flex; flex-direction: column; gap: 3px; }
.story .thumb { position: relative; aspect-ratio: 16/10; border-radius: 12px; overflow: hidden; background: var(--pinkL); display: grid; place-items: center; }
.story .thumb img { width: 100%; height: 100%; object-fit: cover; }
.story .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(101,57,75,.8); color: #fff; font-size: 12px; border-radius: 8px; padding: 0 6px; }
.story .nm { font-weight: 800; font-size: 15px; line-height: 1.2; }
.story small { font-size: 12px; opacity: .75; }
.story-act { display: flex; gap: 4px; }
.mini { flex: 1; min-height: 48px; border-radius: 12px; background: var(--pinkL); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; position: relative; overflow: hidden; }
.mini svg { width: 22px; height: 22px; }
.mini.holding::after { content: ''; position: absolute; left: 0; bottom: 0; height: 4px; width: 100%; background: var(--berry); }
#viewer { position: fixed; inset: 0; z-index: 40; background: rgba(60,30,45,.92); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: calc(var(--sa-t) + 12px) 12px calc(var(--sa-b) + 12px); }
#viewer.show { display: flex; }
#viewer video, #viewer img { max-width: 100%; max-height: 70dvh; border-radius: 16px; background: #000; }
#viewer .name { max-width: 420px; }

/* đang quay */
#recBar { position: fixed; z-index: 15; top: calc(var(--sa-t) + 10px); left: 50%; transform: translate(-50%, -140%); display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.95); border-radius: 30px; padding: 6px 6px 6px 16px; box-shadow: 0 6px 20px rgba(101,57,75,.2); transition: transform .25s; }
#recBar.show { transform: translate(-50%, 0); }
#recBar .dot { width: 14px; height: 14px; border-radius: 50%; background: #E53950; animation: blink 1s infinite; }
#recBar b { font-size: 18px; font-variant-numeric: tabular-nums; }
#recBar em { font-style: normal; font-size: 13px; color: #C2334B; }
#recStop { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 18px; border-radius: 26px; background: #E53950; color: #fff; font-weight: 800; font-size: 17px; }
#recStop i { border-radius: 4px; width: 16px; height: 16px; }
@keyframes blink { 50% { opacity: .25; } }
body.recording #hud .tl { top: calc(var(--sa-t) + 74px); }
#countdown { position: fixed; inset: 0; z-index: 30; display: none; place-items: center; font-size: 160px; font-weight: 800; color: #fff; text-shadow: 0 6px 0 var(--berry), 0 10px 40px rgba(101,57,75,.4); background: rgba(255,240,245,.35); pointer-events: none; }
#countdown.show { display: grid; }
#finishing { position: fixed; inset: 0; z-index: 30; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(255,240,245,.85); font-size: 20px; font-weight: 800; }
#finishing.show { display: flex; }
.spin { width: 54px; height: 54px; border-radius: 50%; border: 6px solid #fff; border-top-color: var(--berry); animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

#toast { position: fixed; z-index: 50; left: 50%; bottom: calc(var(--sa-b) + 96px); transform: translate(-50%, 20px); opacity: 0; background: rgba(101,57,75,.92); color: #fff;
  padding: 10px 18px; border-radius: 22px; font-weight: 700; font-size: 16px; transition: .25s; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* màn chào */
#start { position: fixed; inset: 0; z-index: 60; display: grid; place-items: end center; padding-bottom: calc(var(--sa-b) + 8vh); background: linear-gradient(to top, rgba(255,240,245,.9), rgba(255,240,245,0) 60%); transition: opacity .5s; cursor: pointer; }
#start.hide { opacity: 0; pointer-events: none; }
#start .card { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#start img { width: min(260px, 60vw); height: auto; filter: drop-shadow(0 4px 0 #fff); }
#start .tap { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 40px; padding: 10px 26px; box-shadow: 0 5px 0 rgba(221,82,119,.25); animation: bob 1.4s ease-in-out infinite; }
#start .tap b { font-size: 24px; }
#start .hand { font-size: 32px; }
@keyframes bob { 50% { transform: translateY(-8px); } }
body.panel-open #hud { opacity: .35; }

/* ---------- mốc 3–4 */
.map-h { margin: 10px 16px 0; font-size: 17px; }
.room-card em.fr { color: #5E8C7A; }
.outfit.locked span { opacity: .7; }
.row2 { display: flex; gap: 8px; padding: 0 6px 6px; }
.row2 .btn { flex: 1; margin: 8px 6px 10px; }
.btn.small { min-height: 46px; font-size: 15px; margin: 6px 0 0; padding: 6px 12px; }
.stk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; padding: 12px; }
.stk { display: flex; flex-direction: column; align-items: center; text-align: center; font-size: 12px; font-weight: 700; background: #fff; border-radius: 16px; padding: 6px 4px; line-height: 1.2; }
.stk:not(.has) { opacity: .6; }
.panel.easel { width: min(720px, calc(100vw - 16px)); }
.easel-wrap { padding: 8px 12px 0; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#easelCanvas { width: 100%; max-width: 640px; max-height: 52dvh; aspect-ratio: 4/3; object-fit: contain; background: #fff; border-radius: 14px; border: 4px solid var(--pink); touch-action: none; }
.pal { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.sw { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(101,57,75,.2); }
.sw.on { outline: 4px solid var(--ink); }
#stageBar { position: fixed; z-index: 16; left: 50%; bottom: calc(var(--sa-b) + 8px); transform: translate(-50%, 160%); display: flex; gap: 6px; overflow-x: auto; max-width: calc(100vw - 180px);
  background: rgba(255,255,255,.92); border-radius: 22px; padding: 6px; box-shadow: 0 6px 20px rgba(101,57,75,.2); transition: transform .25s; -webkit-overflow-scrolling: touch; }
#stageBar.show { transform: translate(-50%, 0); }
#stageBar .st { flex: none; min-width: 56px; min-height: 56px; border-radius: 14px; background: var(--pinkL); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; padding: 2px 4px; }
#stageBar .st.fr { background: #E9F5EE; }
#stageBar .st svg { width: 26px; height: 26px; }
#recBar.paused .dot { animation: none; background: #FFB347; }
#recPause { margin: 0; min-height: 44px; }
.ed-h { font-size: 16px; margin: 12px 0 4px; align-self: flex-start; }
#editBody { padding: 10px 14px; display: flex; flex-direction: column; align-items: stretch; }
#editBody video { border-radius: 14px; background: #000; max-width: 100%; align-self: center; }
#editBody video.wide { width: 100%; max-height: 30dvh; }
#editBody video.tall { height: 34dvh; }
.trim { display: flex; flex-direction: column; gap: 6px; }
.rng { display: flex; flex-direction: column; font-size: 14px; font-weight: 700; }
.rng input { width: 100%; height: 36px; accent-color: var(--berry); }
.cap-row { display: flex; gap: 6px; align-items: center; }
.cap-row .name { margin: 0; }
.cap-row .btn { margin: 0; }
.cap-list { margin: 4px 0; padding-left: 18px; font-size: 14px; }
.cap-list .chip { min-height: 30px; min-width: 30px; font-size: 13px; padding: 0 8px; }
.join-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.join { font-size: 14px; }
.prog { height: 10px; border-radius: 5px; background: #F3DDE4; overflow: hidden; margin: 8px 0; }
.prog i { display: block; height: 100%; background: var(--berry); transform-origin: left; transform: scaleX(0); }
@media (max-width: 520px) { #stageBar { max-width: calc(100vw - 16px); bottom: calc(var(--sa-b) + 90px); } }

/* bảng bên né Thỏ + tablet */
@media (orientation: landscape) {
  .panel.side.at-left, .panel.ward.at-left { right: auto; left: calc(var(--sa-l) + 12px); }
}
@media (orientation: portrait) {
  .panel.side, .panel.ward { width: min(520px, calc(100vw - 24px)); max-height: 44dvh; }
  .panel.side.at-top, .panel.ward.at-top { top: calc(var(--sa-t) + 78px); bottom: auto; transform: translate(-50%, -8px); }
  .panel.side.at-top.show, .panel.ward.at-top.show { transform: translate(-50%, 0); }
  .panel.side.at-bottom, .panel.ward.at-bottom { top: auto; bottom: calc(var(--sa-b) + 96px); transform: translate(-50%, 8px); }
  .panel.side.at-bottom.show, .panel.ward.at-bottom.show { transform: translate(-50%, 0); }
}
body.recording #hud .tr { top: calc(var(--sa-t) + 74px); }
@media (max-width: 560px) { #recBar { left: 8px; right: 8px; transform: translate(0, -140%); justify-content: center; } #recBar.show { transform: translate(0, 0); } }
/* studio trên màn thấp (điện thoại ngang): xem trước bên trái, tuỳ chọn bên phải — không phải cuộn tìm nút */
@media (orientation: landscape) and (max-height: 520px) {
  .panel.studio { width: min(760px, calc(100vw - 24px)); }
  #studioBody { display: grid; grid-template-columns: 42% 1fr; gap: 10px; align-items: start; }
  #studioBody > .warn, #studioBody > .note, #studioBody > .name { grid-column: 1 / -1; }
  .rec-preview.wide { max-height: none; max-width: none; }
  .rec-preview.tall { height: 46dvh; }
  .panel header { padding: 6px 10px 4px 16px; }
  .panel h2 { font-size: 19px; }
  .panel header button { width: 44px; height: 44px; }
  .rec-opts .tog { min-height: 46px; }
}
/* tablet: nút và chữ to hơn một chút */
@media (min-width: 760px) and (min-height: 700px) {
  .hb { min-width: 64px; min-height: 64px; }
  .hb svg { width: 34px; height: 34px; }
  .hb span { font-size: 13px; }
  .hb.big { min-width: 80px; min-height: 80px; }
}
