/* Bản Đồ Trái Tim – giao diện chung. Dùng token ở tokens.css */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--lq-font); font-size: var(--lq-fs-md); line-height: 1.45;
  color: var(--lq-cookie); background: var(--lq-cream);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
  overflow: hidden; overscroll-behavior: none; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; }
img { -webkit-user-drag: none; }
[hidden] { display: none !important; }

/* ---- khung ứng dụng ---- */
#app {
  position: relative; height: 100dvh; width: 100%; max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column; overflow: hidden;
  padding-left: var(--lq-safe-l); padding-right: var(--lq-safe-r);
  background:
    radial-gradient(120% 55% at 50% -8%, rgba(255, 180, 162, 0.55), transparent 62%),
    radial-gradient(90% 40% at 100% 100%, rgba(246, 196, 83, 0.28), transparent 70%),
    linear-gradient(180deg, #FFF4E6 0%, #FFE9D9 100%);
}
#hud {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--lq-s3);
  padding: calc(var(--lq-safe-t) + 6px) var(--lq-s4) 6px; min-height: calc(var(--lq-safe-t) + 56px);
}
#hud[hidden] { display: none; }
#stage {
  position: relative; flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 var(--lq-s4) calc(var(--lq-safe-b) + var(--lq-s4));
  display: flex; flex-direction: column;
}
.lq-screen { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; animation: lq-in 0.45s var(--lq-ease) both; }
.lq-screen--center { justify-content: center; text-align: center; }
.lq-screen:has(#stagebox) { padding-bottom: 150px; }
.lq-grow { flex: 1; }

/* ---- chữ ---- */
.lq-title { font-size: var(--lq-fs-hero); line-height: 1.1; font-weight: 800; color: var(--lq-berry-deep); margin: 0; letter-spacing: -0.01em; }
.lq-h2 { font-size: var(--lq-fs-xl); line-height: 1.2; font-weight: 800; margin: 0; color: var(--lq-cookie); }
.lq-text { font-size: var(--lq-fs-md); margin: 0; }
.lq-muted { color: var(--lq-cookie-soft); font-size: var(--lq-fs-sm); }
.lq-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- nút (>= 48px) ---- */
.lq-btn {
  appearance: none; border: 0; cursor: pointer; min-height: var(--lq-tap); padding: 0 var(--lq-s6);
  border-radius: var(--lq-r-pill); font-weight: 800; font-size: var(--lq-fs-lg);
  color: #fff; background: linear-gradient(180deg, #E24A66, var(--lq-berry-deep));
  box-shadow: inset 0 1px 0.5px rgba(255, 255, 255, 0.5), 0 2px 4px rgba(199, 59, 85, 0.25), 0 10px 22px rgba(199, 59, 85, 0.28);
  transition: transform 0.16s var(--lq-spring), box-shadow 0.16s, opacity 0.2s;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--lq-s2);
}
.lq-btn:active { transform: scale(0.96); }
.lq-btn[disabled] { opacity: 0.45; pointer-events: none; }
.lq-btn--ghost {
  color: var(--lq-cookie); font-weight: 700; font-size: var(--lq-fs-md);
  background: var(--lq-glass); -webkit-backdrop-filter: blur(var(--lq-blur)) saturate(160%); backdrop-filter: blur(var(--lq-blur)) saturate(160%);
  box-shadow: var(--lq-rim), var(--lq-lift-1);
}
.lq-btn--wide { width: 100%; }
.lq-icon-btn {
  appearance: none; border: 0; cursor: pointer; width: var(--lq-tap); height: var(--lq-tap); border-radius: 50%;
  display: grid; place-items: center; color: var(--lq-cookie); background: var(--lq-glass);
  -webkit-backdrop-filter: blur(var(--lq-blur)) saturate(160%); backdrop-filter: blur(var(--lq-blur)) saturate(160%);
  box-shadow: var(--lq-rim), var(--lq-lift-1); transition: transform 0.16s var(--lq-spring);
}
.lq-icon-btn:active { transform: scale(0.92); }

/* ---- thẻ kính ---- */
.lq-glass, .lq-card {
  background: var(--lq-glass); -webkit-backdrop-filter: blur(var(--lq-blur)) saturate(160%); backdrop-filter: blur(var(--lq-blur)) saturate(160%);
  border: 1px solid var(--lq-glass-border); border-radius: var(--lq-r-lg); box-shadow: var(--lq-rim), var(--lq-lift-1);
}
.lq-card { padding: var(--lq-s4) var(--lq-s5); }

/* ---- polaroid (dùng ở Trạm 1, 4 và album) ---- */
.lq-polaroid {
  position: relative; background: #fff; padding: 8px 8px 30px; border-radius: 6px; width: 100%;
  box-shadow: 0 1px 2px rgba(122, 78, 58, 0.12), 0 10px 24px rgba(122, 78, 58, 0.18); transform: rotate(var(--rot, -2deg));
}
.lq-polaroid__img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #f1e3d0; border-radius: 3px; }
.lq-polaroid__cap { position: absolute; left: 8px; right: 8px; bottom: 6px; text-align: center; font-weight: 800; font-size: var(--lq-fs-sm); color: var(--lq-cookie); }

/* ---- ô nhập (>= 16px để Safari không tự phóng to) ---- */
.lq-input {
  width: 100%; min-height: var(--lq-tap); padding: 0 var(--lq-s4); font: inherit; font-size: 17px; font-weight: 700; color: var(--lq-ink);
  border-radius: var(--lq-r-md); border: 1.5px solid rgba(122, 78, 58, 0.25); background: rgba(255, 255, 255, 0.85);
  outline: none; text-align: center; -webkit-appearance: none; appearance: none;
}
.lq-input:focus { border-color: var(--lq-berry); box-shadow: 0 0 0 4px rgba(229, 86, 110, 0.18); }

/* ---- chip chọn ---- */
.lq-chips { display: flex; flex-wrap: wrap; gap: var(--lq-s2); justify-content: center; }
.lq-chip {
  appearance: none; border: 1.5px solid transparent; cursor: pointer; min-height: var(--lq-tap); padding: 0 var(--lq-s4);
  border-radius: var(--lq-r-pill); font-weight: 700; color: var(--lq-cookie); background: var(--lq-glass);
  -webkit-backdrop-filter: blur(var(--lq-blur)); backdrop-filter: blur(var(--lq-blur)); box-shadow: var(--lq-rim), var(--lq-lift-1);
  transition: transform 0.16s var(--lq-spring), border-color 0.16s;
}
.lq-chip[aria-pressed="true"] { border-color: var(--lq-berry-deep); background: #fff; color: var(--lq-berry-deep); }
.lq-chip:active { transform: scale(0.95); }

/* ---- hiệu ứng ---- */
@keyframes lq-in { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes lq-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
@keyframes lq-pop { 0% { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes lq-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes lq-float-up { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(-60px) scale(1.4); } }
@keyframes lq-twinkle { 0%, 100% { opacity: 0.2; transform: scale(0.6); } 50% { opacity: 1; transform: scale(1); } }
.lq-shake { animation: lq-shake 0.45s ease; }
.lq-pop { animation: lq-pop 0.5s var(--lq-spring) both; }
.lq-bob { animation: lq-bob 2.4s ease-in-out infinite; }

/* ---- HUD: tiến trình 4 mảnh ---- */
.lq-hud__map { display: flex; align-items: center; gap: var(--lq-s2); min-height: var(--lq-tap); padding: 0 var(--lq-s3); border-radius: var(--lq-r-pill); }
.lq-hud__heart { width: 44px; height: 40px; display: block; }
.lq-hud__label { font-weight: 800; font-size: var(--lq-fs-sm); color: var(--lq-cookie); }
.lq-hud__hero { width: 40px; height: 46px; flex: none; display: grid; place-items: end center; }
.lq-hud__hero .lq-hero { height: 100%; }
.lq-hud__hero canvas { display: block; height: 46px !important; width: auto !important; }
.lq-hud__hero .lq-hero__ground { display: none; }
.lq-hud__right { display: flex; align-items: center; gap: var(--lq-s2); }
.lq-hud__piece { transition: fill 0.6s var(--lq-ease), opacity 0.6s; }

/* ---- Bé Bản Đồ + bong bóng ---- */
.lq-dialog { position: fixed; inset: auto 0 0 0; z-index: 40; pointer-events: none; display: flex; justify-content: center; padding: 0 var(--lq-s4) calc(var(--lq-safe-b) + var(--lq-s4)); }
.lq-dialog__row { width: 100%; max-width: 528px; display: flex; align-items: flex-end; gap: var(--lq-s2); pointer-events: auto; animation: lq-in 0.35s var(--lq-ease) both; }
.lq-dialog__mascot { width: 64px; height: 76px; flex: none; animation: lq-bob 2.6s ease-in-out infinite; }
.lq-dialog__bubble {
  position: relative; flex: 1; min-height: var(--lq-tap); padding: var(--lq-s4) var(--lq-s5); cursor: pointer;
  background: var(--lq-glass-strong); -webkit-backdrop-filter: blur(var(--lq-blur)) saturate(170%); backdrop-filter: blur(var(--lq-blur)) saturate(170%);
  border: 1px solid var(--lq-glass-border); border-radius: var(--lq-r-lg) var(--lq-r-lg) var(--lq-r-lg) 6px; box-shadow: var(--lq-rim), var(--lq-lift-2);
  color: var(--lq-ink); font-size: var(--lq-fs-md); font-weight: 600;
}
.lq-dialog__who { display: block; font-size: 12px; font-weight: 800; letter-spacing: 0.04em; color: var(--lq-berry-deep); margin-bottom: 2px; }
.lq-dialog__more { position: absolute; right: 14px; bottom: 8px; font-size: 12px; color: var(--lq-berry-deep); animation: lq-bob 1.2s ease-in-out infinite; }
.lq-scrim { position: fixed; inset: 0; z-index: 30; background: rgba(74, 47, 34, 0.18); }

/* ---- mật thư ---- */
.lq-letter-layer { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(var(--lq-safe-t) + 16px) var(--lq-s4) calc(var(--lq-safe-b) + 16px); background: rgba(74, 47, 34, 0.35); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: lq-in 0.3s ease both; }
.lq-letter { position: relative; width: 100%; max-width: 420px; max-height: 100%; display: flex; flex-direction: column; filter: drop-shadow(0 18px 28px rgba(74, 47, 34, 0.35)); }
.lq-letter__roll { height: 26px; flex: none; border-radius: 13px; background: linear-gradient(180deg, #F4DDA8, var(--lq-paper-edge) 55%, #CDAF74); box-shadow: inset 0 -3px 5px rgba(122, 78, 58, 0.25); position: relative; z-index: 1; }
.lq-letter__roll--bottom { margin-top: -2px; }
.lq-letter__paper {
  flex: 0 1 auto; min-height: 0; overflow: hidden; margin: -6px 12px; padding: 0 var(--lq-s5);
  background: repeating-linear-gradient(180deg, transparent 0 31px, rgba(199, 150, 90, 0.18) 31px 32px), var(--lq-paper);
  color: var(--lq-ink); max-height: 0; opacity: 0.2; transition: max-height 0.9s var(--lq-ease), opacity 0.5s, padding 0.5s;
}
.lq-letter--open .lq-letter__paper { max-height: calc(100dvh - 210px - var(--lq-safe-t) - var(--lq-safe-b)); opacity: 1; padding: var(--lq-s6) var(--lq-s5) var(--lq-s5); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.lq-letter__title { margin: 0 0 var(--lq-s3); font-size: var(--lq-fs-lg); font-weight: 800; color: var(--lq-berry-deep); text-align: center; }
/* dòng chỉ hiện sau khi mở */
.lq-letter:not(.lq-letter--open) .lq-letter__line { animation: none !important; opacity: 0; }
.lq-letter__line { margin: 0 0 var(--lq-s2); font-size: 16px; line-height: 1.42; font-weight: 600; }
.lq-letter__line b { color: var(--lq-berry-deep); font-weight: 900; font-size: 1.22em; }
.lq-letter__foot { display: flex; align-items: center; justify-content: space-between; margin-top: var(--lq-s4); }
.lq-letter__paw { width: 28px; height: 28px; opacity: 0.7; }
.lq-letter__hint { margin-top: var(--lq-s3); }
.lq-letter__hintbtn { appearance: none; border: 1.5px dashed rgba(122, 78, 58, 0.45); background: transparent; border-radius: var(--lq-r-md); min-height: 44px; width: 100%; font-weight: 700; color: var(--lq-cookie); cursor: pointer; }
.lq-letter__hinttext { margin: 0; padding: var(--lq-s3); border-radius: var(--lq-r-md); background: rgba(246, 196, 83, 0.28); font-weight: 700; }
.lq-letter__actions { display: flex; justify-content: center; margin-top: var(--lq-s4); }
.lq-letter__closed { text-align: center; color: #fff; font-weight: 800; margin-top: var(--lq-s4); text-shadow: 0 1px 6px rgba(74, 47, 34, 0.5); }

/* ---- màn chào ---- */
.lq-splash__map { width: min(62vw, 240px); height: auto; margin: 0 auto var(--lq-s5); filter: drop-shadow(0 14px 22px rgba(122, 78, 58, 0.28)); }
.lq-splash__sub { margin: var(--lq-s3) auto var(--lq-s8); max-width: 300px; color: var(--lq-cookie); font-weight: 600; }
.lq-splash__tap { animation: lq-bob 1.8s ease-in-out infinite; }

/* ---- tạo nhân vật ---- */
.lq-create__stage { position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.lq-hero { position: relative; display: grid; place-items: end center; }
.lq-hero__ground { position: absolute; left: 50%; bottom: 2px; width: 62%; height: 16px; transform: translateX(-50%); border-radius: 50%; background: radial-gradient(closest-side, rgba(122, 78, 58, 0.28), transparent); }
.lq-hero canvas { position: relative; image-rendering: pixelated; display: block; }
.lq-name { margin: var(--lq-s2) 0 0; font-size: var(--lq-fs-lg); font-weight: 800; color: var(--lq-cookie); text-align: center; }
.lq-carousel { width: calc(100% + 2 * var(--lq-s4)); margin: 0 calc(-1 * var(--lq-s4)); }
.lq-carousel__track { display: flex; gap: var(--lq-s3); overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; padding: var(--lq-s3) calc(50% - 46px); scrollbar-width: none; }
.lq-carousel__track::-webkit-scrollbar { display: none; }
.lq-card-ch {
  flex: none; scroll-snap-align: center; width: 92px; height: 128px; padding: 0; border: 2px solid transparent; border-radius: var(--lq-r-md);
  background: var(--lq-glass); box-shadow: var(--lq-rim), var(--lq-lift-1); display: grid; place-items: center; cursor: pointer; overflow: hidden;
  opacity: 1; transform: scale(0.9); transition: transform 0.25s var(--lq-spring), opacity 0.25s, border-color 0.25s;
}
.lq-card-ch img { width: 82px; height: auto; display: block; }
.lq-card-ch[aria-current="true"] { opacity: 1; transform: scale(1.04); border-color: var(--lq-berry-deep); background: #fff; }
.lq-dots { display: flex; gap: 6px; justify-content: center; margin-top: 2px; }
.lq-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(122, 78, 58, 0.25); transition: all 0.25s; }
.lq-dots i.on { width: 18px; border-radius: 3px; background: var(--lq-berry-deep); }
.lq-field { width: 100%; max-width: 320px; }
.lq-field label { display: block; font-weight: 800; margin-bottom: var(--lq-s2); text-align: center; }

/* ---- trao mũ ---- */
.lq-hat-scene { position: relative; width: 100%; display: flex; justify-content: center; align-items: flex-end; gap: 0; min-height: 250px; }
.lq-hat-scene .lq-hero + .lq-hero { margin-left: -26px; }
.lq-sparkle { position: absolute; width: 14px; height: 14px; pointer-events: none; animation: lq-twinkle 1.1s ease-in-out infinite; }
.lq-sparkle::before, .lq-sparkle::after { content: ""; position: absolute; left: 50%; top: 0; width: 3px; height: 100%; margin-left: -1.5px; border-radius: 2px; background: var(--lq-honey); }
.lq-sparkle::after { transform: rotate(90deg); }
.lq-cat { position: absolute; bottom: -2px; height: auto; image-rendering: auto; pointer-events: none; transition: left 1.6s linear; }
.lq-hatcard { text-align: center; max-width: 340px; }
.lq-hatcard__name { margin: 0 0 var(--lq-s2); font-weight: 900; font-size: var(--lq-fs-lg); color: var(--lq-berry-deep); }
.lq-hatcard p { margin: 0; font-weight: 600; color: var(--lq-ink); }

/* ---- stub trạm ---- */
.lq-stub { text-align: center; gap: var(--lq-s4); }

/* ---- thấp màn hình (iPhone SE 375x667) ---- */
@media (max-height: 700px) {
  .lq-title { font-size: 30px; }
  .lq-card-ch { width: 82px; height: 114px; }
  .lq-card-ch img { width: 72px; }
  .lq-carousel__track { padding-left: calc(50% - 41px); padding-right: calc(50% - 41px); }
  .lq-hat-scene { min-height: 210px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
/* khoá xoay dọc: gợi ý khi nằm ngang */
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  #rotate { position: fixed; inset: 0; z-index: 99; display: grid; place-items: center; text-align: center; padding: 24px; background: var(--lq-cream); font-weight: 800; font-size: var(--lq-fs-lg); color: var(--lq-berry-deep); }
}

/* ---- mật thư: ô điền đáp án + gợi ý (letter.js) ---- */
.lq-letter__ans { margin-top: var(--lq-s4); display: flex; flex-direction: column; gap: var(--lq-s2); }
.lq-letter__anslabel { font-weight: 800; color: var(--lq-berry-deep); }
.lq-letter__ansrow { display: flex; gap: var(--lq-s2); align-items: stretch; }
.lq-letter__input { flex: 1 1 auto; min-width: 0; font-size: 16px; }
.lq-letter__check { flex: none; padding-inline: var(--lq-s4); }
.lq-letter__msg { margin: 0; min-height: 1.4em; font-weight: 700; color: var(--lq-cookie); }
.lq-letter__msg--bad { color: var(--lq-berry-deep); }
.lq-letter__msg--ok { color: #2f8f5b; }
.lq-letter__hintbtn:disabled { opacity: 0.5; cursor: default; }
.lq-letter__hintlist { display: flex; flex-direction: column; gap: var(--lq-s2); margin-top: var(--lq-s2); }
.lq-letter__hinttext b { color: var(--lq-berry-deep); }
