@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url("assets/fonts/nunito-vietnamese-wght-normal.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url("assets/fonts/nunito-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url("assets/fonts/nunito-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #FFFBF2;
  --surface: #FFFFFF;
  --ink: #3C3C3C;
  --muted: #777777;
  --line: #E8E2D4;
  --green: #58CC02;
  --green-edge: #46A302;
  --blue: #1CB0F6;
  --blue-edge: #1899D6;
  --blue-soft: #DDF4FF;
  --locked: #E5E5E5;
  --locked-edge: #CECECE;
  --star: #FFC800;
  --orange: #FF9600;
  --orange-edge: #CC7800;
  --radius: 16px;
  --step: clamp(28px, 11vw, 44px);
  font-family: "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  font-weight: 700;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
}

.screen {
  min-height: 100dvh;
}

/* Shared buttons */

.icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 4px 0 var(--line);
  font-size: 22px;
  line-height: 1;
}

.icon-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--line);
}

.btn {
  --face: var(--surface);
  --edge: var(--line);
  min-height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius);
  background: var(--face);
  box-shadow: 0 5px 0 var(--edge);
  font-size: 18px;
  font-weight: 900;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--edge);
}

.btn-primary {
  --face: var(--blue);
  --edge: var(--blue-edge);
  color: #FFFFFF;
}

.btn-secondary {
  border: 2px solid var(--line);
  color: var(--ink);
}

.btn-danger {
  border: 2px solid var(--line);
  color: var(--orange-edge);
}

.btn-danger.armed {
  --face: var(--orange);
  --edge: var(--orange-edge);
  border-color: var(--orange);
  color: #FFFFFF;
}

/* Map screen */

.map-screen {
  padding-bottom: 96px;
}

.map-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(255, 251, 242, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--line);
}

.greeting {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
}

.progress-text {
  margin: 2px 0 6px;
  color: var(--muted);
  font-size: 15px;
}

.progress-track,
.quiz-progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--locked);
}

.progress-fill,
.quiz-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--green);
  transition: width 300ms ease;
}

.timeline {
  padding: 16px 16px 0;
}

.chapter {
  margin-bottom: 24px;
}

.chapter-banner {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--green);
  box-shadow: 0 5px 0 var(--green-edge);
  color: #FFFFFF;
}

.chapter-banner strong {
  font-size: 20px;
  font-weight: 900;
}

.chapter-banner span {
  font-size: 15px;
  opacity: 0.92;
}

.path {
  display: grid;
  justify-items: center;
  gap: 22px;
  margin: 0;
  padding: 28px 0 12px;
  list-style: none;
}

.day-node {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  transform: translateX(calc(var(--offset) * var(--step)));
}

.day-button {
  --face: var(--locked);
  --edge: var(--locked-edge);
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--face);
  box-shadow: 0 6px 0 var(--edge);
  color: #FFFFFF;
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.day-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--edge);
}

.day-node.is-done .day-button {
  --face: var(--green);
  --edge: var(--green-edge);
}

.day-node.is-today .day-button {
  --face: var(--blue);
  --edge: var(--blue-edge);
  width: 84px;
  height: 84px;
  font-size: 34px;
  animation: bob 1.6s ease-in-out infinite;
}

.day-node.is-locked .day-button {
  color: #AFAFAF;
  font-size: 24px;
}

.day-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.day-stars {
  display: flex;
  gap: 2px;
  font-size: 16px;
  line-height: 1;
}

.day-stars .star {
  color: var(--locked-edge);
}

.day-stars .star.filled {
  color: var(--star);
}

.today-bubble {
  position: relative;
  margin-bottom: 6px;
  padding: 8px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--blue-edge);
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
}

.today-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}

.day-node.shake .day-button {
  animation: shake 400ms ease;
}

.day-node.just-done .day-button {
  animation: pop 500ms ease;
}

.day-node.just-unlocked .day-button {
  animation: pop 500ms ease 300ms, bob 1.6s ease-in-out 800ms infinite;
}

.chest {
  display: grid;
  justify-items: center;
  gap: 2px;
  margin: 4px 0 8px;
  font-size: 44px;
  line-height: 1;
  filter: grayscale(1) opacity(0.5);
}

.chest.open {
  filter: none;
}

.chest-label {
  color: var(--muted);
  font-size: 13px;
}

.jump-today {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 6;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  box-shadow: 0 5px 0 var(--blue-edge);
  color: #FFFFFF;
  font-weight: 900;
  transform: translateX(-50%);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 7;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(60, 60, 60, 0.92);
  color: #FFFFFF;
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
  animation: toast-in 200ms ease;
}

/* CenStu: standalone bar + footer, embedded layout */

.thanh-ve-kho {
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface);
  border-bottom: 2px solid var(--line);
  font-size: 14px;
}

.thanh-ve-kho a,
.chan-trang a {
  color: var(--blue-edge);
  text-decoration: none;
}

.chan-trang {
  padding: 8px 16px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.dang-nhung .chi-doc-lap {
  display: none;
}

/* Portal frame is 100% x (100dvh - 44px): fit it without page scroll; only the timeline scrolls. */
.dang-nhung,
.dang-nhung body {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.dang-nhung .app-shell,
.dang-nhung .screen {
  height: 100dvh;
  min-height: 0;
}

.dang-nhung .map-screen {
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

.dang-nhung .timeline {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 96px;
}

.dang-nhung .quiz-screen,
.dang-nhung .result-screen {
  overflow: hidden;
}

/* Quiz screen */

.quiz-screen {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
}

.quiz-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
}

.quiz-progress-track {
  height: 16px;
}

.question-counter {
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.star-score {
  color: #B38600;
  font-size: 18px;
  font-weight: 900;
  white-space: nowrap;
}

.star-score span[aria-hidden="true"] {
  color: var(--star);
}

.listen-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 8px 0;
}

.speaker-button {
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 6px 0 var(--blue-edge);
  font-size: 48px;
  line-height: 1;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.speaker-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--blue-edge);
}

.slow-button {
  min-height: 48px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 4px 0 var(--line);
  color: var(--blue-edge);
  font-weight: 900;
}

.slow-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--line);
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 8px;
}

.choice-card {
  display: grid;
  gap: 6px;
  padding: 4px;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 5px 0 var(--line);
  touch-action: manipulation;
  transition: transform 80ms ease, box-shadow 80ms ease, opacity 200ms ease;
}

.choice-card:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--line);
}

.choice-card[disabled] {
  cursor: default;
}

.choice-card.correct {
  border-color: var(--green);
  box-shadow: 0 5px 0 var(--green-edge);
  animation: pop 400ms ease;
}

.choice-card.incorrect {
  border-color: var(--orange);
  box-shadow: 0 5px 0 var(--orange-edge);
  opacity: 0.55;
  animation: shake 400ms ease;
}

.choice-art {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 14px;
  background: #F7F3EA;
}

.scene-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.choice-copy {
  padding: 0 2px 2px;
}

.choice-title {
  margin: 0;
  font-size: clamp(14px, 3.8vw, 18px);
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}

.hide-choice-hints .choice-copy {
  display: none;
}

.feedback {
  min-height: 28px;
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.feedback.good {
  color: var(--green-edge);
}

.feedback.retry {
  color: var(--orange-edge);
}

/* Result screen */

.result-screen {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 32px 16px calc(32px + env(safe-area-inset-bottom));
  text-align: center;
}

.result-stars {
  display: flex;
  gap: 8px;
  font-size: 56px;
  line-height: 1;
}

.result-stars .star {
  color: var(--locked);
}

.result-stars .star.filled {
  color: var(--star);
  animation: star-in 450ms ease both;
}

.result-stars .star.filled:nth-child(2) {
  animation-delay: 250ms;
}

.result-stars .star.filled:nth-child(3) {
  animation-delay: 500ms;
}

.result-day {
  margin: 8px 0 0;
  font-size: 28px;
  font-weight: 900;
}

.result-score {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
}

.result-praise {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 800;
}

.result-actions {
  display: grid;
  gap: 12px;
  width: 100%;
}

.result-secondary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -16px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: fall 2.4s ease-in forwards;
}

/* Settings sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  gap: 18px;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  animation: slide-up 250ms ease;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-label {
  padding: 0;
  font-weight: 900;
}

.text-input {
  min-height: 52px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 18px;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  border: 2px solid var(--line);
  border-radius: 14px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}

.segmented input:checked + span {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue-edge);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.switch-field {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.switch {
  position: relative;
  width: 56px;
  height: 32px;
  margin: 0;
  border-radius: 999px;
  background: var(--locked);
  appearance: none;
  cursor: pointer;
  transition: background 150ms ease;
}

.switch::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  transition: transform 150ms ease;
}

.switch:checked {
  background: var(--green);
}

.switch:checked::before {
  transform: translateX(24px);
}

/* Exit dialog */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.4);
}

.dialog-panel {
  width: min(360px, 100%);
  display: grid;
  gap: 20px;
  padding: 24px;
  border-radius: 20px;
  background: var(--surface);
  text-align: center;
}

.dialog-title {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
}

.dialog-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* Animations */

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes star-in {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  70% { transform: scale(1.2) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes fall {
  to { transform: translateY(110vh) rotate(540deg); }
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .confetti {
    display: none !important;
  }
}
