:root { --ink: #33231c; --paper: #fffaee; --plum: #6a2f8a; --coral: #e2563f; --leaf: #3f8f35; --line: #eadcc0; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px); }
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body { font: 500 16px/1.45 "Baloo 2", system-ui, sans-serif; color: var(--ink); background: #bfe8ff; user-select: none; -webkit-user-select: none; }
body.big { font-size: 19px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #1d7fd1; outline-offset: 2px; }
.hidden { display: none !important; }
#c { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; display: block; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; font-size: 1.4em; background: var(--paper); z-index: 90; padding: 24px; text-align: center; }

#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; background: rgba(255,250,238,.92); border-radius: 999px; padding: 1px 10px; font-weight: 700; font-size: .85em; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.18); }

#hud { position: fixed; left: 10px; top: calc(10px + var(--safe-t)); z-index: 5; max-width: calc(100vw - 180px); }
.plate { background: rgba(255,250,238,.94); border-radius: 16px; padding: 5px 14px; box-shadow: 0 2px 8px rgba(0,0,0,.14); display: flex; flex-direction: column; }
#tools { position: fixed; right: 10px; top: calc(10px + var(--safe-t)); z-index: 40; display: flex; gap: 6px; }
#tools button, #btn-home { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--paper); box-shadow: 0 2px 8px rgba(0,0,0,.18); font-size: 20px; }
#goal { position: fixed; left: 50%; top: calc(66px + var(--safe-t)); transform: translateX(-50%); z-index: 4; background: rgba(106,47,138,.92); color: #fff; padding: 6px 16px; border-radius: 16px; text-align: center; width: max-content; max-width: min(92vw, 520px); pointer-events: none; }
#goal b { color: #ffe27a; }
#goal-pips i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,.35); margin: 0 3px; }
#goal-pips i.on { background: #ffe27a; }
#arrow { position: fixed; left: 50%; top: calc(140px + var(--safe-t)); transform: translateX(-50%); z-index: 3; text-align: center; pointer-events: none; font-weight: 800; text-shadow: 0 0 6px #fff, 0 0 3px #fff; }
#arrow i { display: block; font-size: 30px; color: var(--coral); font-style: normal; }
#minimap { position: fixed; right: 10px; top: calc(62px + var(--safe-t)); width: 120px; height: 120px; z-index: 3; pointer-events: none; }
#btn-home { position: fixed; right: 16px; top: calc(190px + var(--safe-t)); z-index: 4; }
#prompt { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 6; border: 0; border-radius: 999px; background: var(--paper); padding: 8px 18px; box-shadow: 0 4px 14px rgba(0,0,0,.25); width: max-content; max-width: 92vw; }
kbd { background: #f0e4c8; border-radius: 5px; padding: 0 6px; font: 700 .85em system-ui; }
#helpbar { position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 2; background: rgba(255,250,238,.85); border-radius: 999px; padding: 3px 14px; font-size: .82em; white-space: nowrap; pointer-events: none; }
#joy { position: fixed; left: 18px; bottom: calc(20px + var(--safe-b)); width: 124px; height: 124px; border-radius: 50%; background: rgba(255,250,238,.55); border: 3px solid rgba(255,255,255,.9); z-index: 5; touch-action: none; display: none; }
#joy-knob { position: absolute; left: 33px; top: 33px; width: 52px; height: 52px; border-radius: 50%; background: var(--plum); opacity: .85; }
#actions { position: fixed; right: 14px; bottom: calc(20px + var(--safe-b)); z-index: 5; display: none; gap: 10px; align-items: flex-end; }
#actions button { width: 66px; height: 66px; border-radius: 50%; border: 0; background: var(--paper); font-size: 22px; box-shadow: 0 3px 10px rgba(0,0,0,.22); touch-action: none; line-height: 1; }
#actions small { display: block; font-size: 11px; font-weight: 700; }
#act-talk.ready { background: #ffe27a; }
@media (pointer: coarse) { #joy { display: block; } #actions { display: flex; } #helpbar { display: none; } #joy.hidden, #actions.hidden { display: none; } }

#floating { position: fixed; left: 0; right: 0; bottom: calc(160px + var(--safe-b)); z-index: 6; display: flex; flex-direction: column; align-items: center; pointer-events: none; gap: 8px; }
#floating > * { pointer-events: auto; }
.dock { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; background: rgba(255,250,238,.94); border-radius: 18px; padding: 8px; max-width: min(96vw, 760px); max-height: 30vh; overflow: auto; }

.btn { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 8px 16px; font-weight: 700; text-decoration: none; display: inline-block; color: var(--ink); }
.btn:hover:not(:disabled) { border-color: var(--plum); }
.btn.primary { background: var(--plum); border-color: var(--plum); color: #fff; }
.btn.big { font-size: 1.15em; padding: 11px 24px; }
.btn.ghost { background: rgba(255,250,238,.9); }
.btn.option { font-weight: 600; text-align: center; }
.btn.option.picked, .btn.choice.picked { border-color: var(--plum); background: #f3e6fb; }
.btn.option.ok { border-color: var(--leaf); background: #e5f6df; }
.btn.option.no { border-color: var(--coral); opacity: .55; }
.btn:disabled { opacity: .65; }

.layer { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; background: rgba(40,20,60,.35); z-index: 20; }
.panel { background: var(--paper); border-radius: 22px; box-shadow: 0 12px 40px rgba(0,0,0,.3); width: min(640px, 100%); max-height: 100%; display: flex; flex-direction: column; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.panel header { padding: 14px 18px 0; text-align: center; }
.panel header:empty { display: none; }
.panel h2 { font-size: 1.35em; line-height: 1.25; color: var(--plum); }
.panel h3 { font-size: 1.05em; margin: 12px 0 4px; color: var(--plum); }
.badge { display: inline-block; background: #ffe9a8; border-radius: 999px; padding: 0 12px; font-size: .8em; font-weight: 700; }
.panel .body { padding: 10px 18px; overflow: auto; overscroll-behavior: contain; }
.panel footer { padding: 8px 18px 14px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.panel footer:empty { display: none; }
.panel.center .body { text-align: center; }
.modal { max-height: 100%; }
/* bảng giáo viên nằm trên hội thoại; hộp mở từ bảng nằm trên bảng */
.layer.modal { z-index: 35; background: rgba(40,20,60,.55); }
.layer.modal ~ .layer { z-index: 36; }
.big-icon { font-size: 64px; line-height: 1.2; }
.small { font-size: .84em; opacity: .8; margin-top: 6px; }
.question { font-size: 1.12em; font-weight: 700; margin-bottom: 8px; }
.quote { font-size: 1.2em; font-weight: 700; color: var(--plum); margin: 8px 0; }
.warn { background: #fff0cc; border-radius: 10px; padding: 6px 10px; font-size: .9em; }
.hearts { font-size: 1.1em; }

.stanza { margin: 8px 0; padding: 8px 12px; border-radius: 12px; text-align: center; font-weight: 600; font-size: 1.08em; }
.stanza.reading, .reading .stanza { background: #fff0bf; }
.ref .stanza { background: #fff; border: 2px dashed var(--line); font-size: 1em; }
mark { background: #ffe27a; border-radius: 4px; padding: 0 3px; }
.layer.poem.bottom { align-items: flex-end; background: transparent; }

.lightpoem .stanza { padding: 0; margin: 0 0 10px; }
.line { display: block; width: 100%; border: 2px solid transparent; background: #fff; border-radius: 10px; padding: 4px 8px; margin: 3px 0; font-weight: 600; }
.line.lit { background: #ffe27a; border-color: #e8a100; box-shadow: 0 0 12px #ffd23f; }
.line.shake { animation: shake .35s; border-color: var(--coral); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.area > .btn.option { display: block; width: 100%; margin: 6px 0; }
.pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0; }
.timeline { list-style-position: inside; margin: 4px 0; }
.timeline li { background: #e5f6df; border-radius: 10px; padding: 5px 12px; margin: 4px 0; font-weight: 700; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: flex; flex-direction: column; gap: 8px; }
.match .btn { flex: 1; padding: 8px; }
.card { background: #fff; border: 3px solid var(--plum); border-radius: 14px; padding: 12px; text-align: center; font-weight: 700; }
.bins { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bin { background: #fff; border-radius: 12px; padding: 8px; min-height: 90px; text-align: center; }
.bin h3 { margin-top: 0; font-size: .95em; }
.bin p { background: #e5f6df; border-radius: 8px; padding: 4px; margin-top: 4px; font-size: .9em; }
.fill .slot { display: inline-block; min-width: 4em; border-bottom: 3px solid var(--line); color: var(--plum); font-weight: 800; }
.fill .slot.now { background: #ffe27a; border-color: #e8a100; }
.note { margin-top: 8px; min-height: 1.4em; font-weight: 600; text-align: center; }
.note.good { background: #e5f6df; border-radius: 12px; padding: 8px 12px; }

.dialog { position: fixed; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); width: min(700px, calc(100vw - 16px)); background: var(--paper); border: 3px solid var(--plum); border-radius: 20px; padding: 10px 16px 12px; z-index: 30; box-shadow: 0 8px 30px rgba(0,0,0,.3); max-height: 70vh; overflow: auto; }
.dialog .who { display: flex; align-items: center; gap: 8px; }
.dialog .who i { font-style: normal; font-size: 30px; width: 48px; height: 48px; border-radius: 50%; background: #f3e6fb; display: grid; place-items: center; }
.dialog .again { margin-left: auto; border: 0; background: #ffe9a8; border-radius: 999px; padding: 4px 12px; font-weight: 700; }
.dialog p { font-size: 1.12em; margin: 8px 0; }
.dialog .choices { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.layer.create { background: transparent; justify-content: flex-end; pointer-events: none; }
.layer.create .panel { pointer-events: auto; width: min(430px, 46vw); }
.namerow { display: flex; gap: 6px; }
.namerow .btn { white-space: nowrap; }
input[type=text], textarea { width: 100%; border: 2px solid var(--line); border-radius: 12px; padding: 7px 10px; background: #fff; user-select: text; -webkit-user-select: text; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 8px; }
.tabs button { border: 0; background: #f0e4c8; border-radius: 999px; padding: 3px 10px; font-size: .85em; font-weight: 700; }
.tabs button[aria-selected=true] { background: var(--plum); color: #fff; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; min-height: 90px; align-content: flex-start; }
.chip { border: 3px solid var(--line); background: #fff; border-radius: 12px; padding: 6px 12px; font-weight: 700; }
.swatch { width: 46px; height: 46px; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.3); }
.chip[aria-pressed=true], .swatch[aria-pressed=true] { border-color: var(--plum); outline: 3px solid #ffd23f; }
@media (max-width: 720px), (orientation: portrait) {
  .layer.create { align-items: flex-end; justify-content: center; padding: 6px; }
  .layer.create .panel { width: 100%; max-height: 60dvh; }
  .layer.create h2 { display: none; }
}

.layer.title { background: linear-gradient(rgba(255,250,238,0), rgba(106,47,138,.25)); align-items: flex-end; padding-bottom: 5vh; }
.layer.title .panel { text-align: center; width: min(520px, 100%); background: rgba(255,250,238,.95); }
.logo h1 { text-wrap: balance; color: var(--plum); font-size: clamp(1.8em, 7vw, 2.6em); line-height: 1.15; }
.logo small { font-weight: 800; color: var(--coral); text-transform: uppercase; letter-spacing: 1px; }

.field { display: block; margin: 8px 0; }
.field span { font-weight: 800; }
.check { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--plum); }
.slider { display: flex; gap: 12px; align-items: center; padding: 6px 0; }
.slider span { width: 100px; }
.slider input { flex: 1; accent-color: var(--plum); }
.pad { width: 100%; max-height: 52vh; object-fit: contain; background: #fffdf6; border: 3px solid var(--line); border-radius: 12px; touch-action: none; aspect-ratio: 640/440; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.sw { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.cardview img { display: block; max-width: 100%; max-height: 56vh; margin: 0 auto; border-radius: 12px; }
.evidence { list-style: none; text-align: left; }
.evidence li { background: #fff; border-radius: 10px; padding: 4px 10px; margin: 3px 0; }
.evidence small { display: block; opacity: .75; }
.evidence .none { opacity: .55; }
.book { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.book div { background: #fff; border-radius: 14px; padding: 10px; text-align: center; opacity: .45; }
.book div.got { opacity: 1; border: 3px solid #ffd23f; }
.book i { display: block; font-size: 40px; font-style: normal; }
.book span { display: block; font-size: .85em; }

#banner { position: fixed; left: 50%; top: 32%; transform: translate(-50%, 10px); z-index: 12; text-align: center; color: #fff; background: rgba(106,47,138,.92); border-radius: 20px; padding: 10px 28px; opacity: 0; pointer-events: none; transition: .4s; width: max-content; max-width: 92vw; }
#banner.on { opacity: 1; transform: translate(-50%, 0); }
#banner small { display: block; font-weight: 700; color: #ffe27a; }
#banner b { font-size: 1.5em; line-height: 1.25; }
#toast { position: fixed; left: 50%; top: calc(150px + var(--safe-t)); transform: translateX(-50%); z-index: 50; background: #33231c; color: #fff; border-radius: 14px; padding: 8px 18px; opacity: 0; pointer-events: none; transition: opacity .25s; width: max-content; max-width: min(92vw, 520px); text-align: center; }
#toast.on { opacity: .95; }
#sleep { position: fixed; inset: 0; background: #1c1740; z-index: 10; display: grid; place-items: center; font-size: 80px; opacity: 0; pointer-events: none; transition: opacity .6s; }
body.sleep #sleep { opacity: 1; }
body.cine #goal, body.cine #minimap, body.cine #btn-home { display: none; }

@media (max-width: 640px) {
  body { font-size: 15px; }
  #minimap { width: 84px; height: 84px; }
  #btn-home { top: calc(152px + var(--safe-t)); right: 10px; }
  #goal { left: 8px; transform: none; max-width: calc(100vw - 112px); top: calc(94px + var(--safe-t)); font-size: .92em; }
  #hud .plate { padding: 4px 10px; font-size: .86em; line-height: 1.3; }
  #prompt { bottom: calc(160px + var(--safe-b)); }
  #arrow { top: calc(196px + var(--safe-t)); }
  #toast { top: calc(250px + var(--safe-t)); }
}
@media (max-height: 480px) {
  #minimap { width: 80px; height: 80px; }
  #btn-home { top: calc(148px + var(--safe-t)); }
  #goal { top: calc(8px + var(--safe-t)); max-width: 46vw; }
  #arrow { top: 70px; }
  #prompt { bottom: 20px; }
  #floating { bottom: 100px; }
}
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } #banner { transition: none; } }

/* biểu tượng 3D thay emoji */
.ico { display: inline-block; width: 1.35em; height: 1.35em; vertical-align: -.32em; background: center / contain no-repeat; overflow: hidden; text-indent: -99em; white-space: nowrap; line-height: 1; }
#tools .ico, #btn-home .ico { width: 1.6em; height: 1.6em; vertical-align: middle; }
