/* ========== APP SHELL ========== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  border-bottom: 1px solid rgba(255, 238, 187, 0.08);
}

.header-stats {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.85rem;
}

.header-stat {
  display: flex;
  align-items: center;
  gap: 3px;
}
.header-stat-col {
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.header-stat .val {
  color: var(--neon-warm);
  font-weight: 600;
  font-size: 0.75rem;
  line-height: 1;
}

.header-emoji {
  font-size: 1.5rem;
  line-height: 1;
}

.header-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
  color: var(--text-secondary);
}

.header-icon-dragon {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 80px;
}

/* ===== Grade selector (header) ===== */
.grade-selector-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.grade-selector-btn {
  width: 50px;
  height: 50px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  display: block;
  flex-shrink: 0;
}

.grade-selector-icon {
  width: 50px;
  height: 50px;
  display: block;
  transition: transform 0.15s;
}

.grade-selector-btn:hover .grade-selector-icon {
  transform: scale(1.05);
}

.grade-selector-label {
  position: absolute;
  bottom: -2px;
  right: -4px;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--neon-warm);
  background: var(--bg-card, #1a1a2e);
  border: 1px solid rgba(255, 238, 187, 0.3);
  padding: 0 4px;
  border-radius: 6px;
  pointer-events: none;
  line-height: 1.3;
}

/* Tooltip — large preview when hovering icon. z-index above everything. */
.grade-selector-tooltip {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px) scale(0.5);
  transform-origin: top center;
  width: 150px;
  height: 150px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 9999;
  background: radial-gradient(circle at center, rgba(170, 102, 255, 0.18), transparent 70%);
  border-radius: 50%;
  filter: drop-shadow(0 4px 18px rgba(0, 229, 255, 0.35));
}

.grade-selector-tooltip img {
  width: 100%;
  height: 100%;
  display: block;
}

.grade-selector-btn:hover .grade-selector-tooltip,
.grade-selector-tooltip:hover {
  opacity: 1;
  transform: translateX(-50%) translateY(8px) scale(1);
  pointer-events: auto;
}

/* Hide tooltip while dropdown is open (avoid stacking) */
.grade-selector-wrap.open .grade-selector-tooltip {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Dropdown — grid of grade icons */
.grade-selector-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card, #1a1a2e);
  border: 1px solid rgba(255, 238, 187, 0.2);
  border-radius: 14px;
  padding: 10px;
  display: none;
  grid-template-columns: repeat(4, 56px);
  gap: 6px;
  z-index: 9998;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6),
    0 0 24px rgba(170, 102, 255, 0.15);
  max-width: 90vw;
}

.grade-selector-dropdown.show {
  display: grid;
}

.grade-option {
  width: 56px;
  height: 56px;
  cursor: pointer;
  border-radius: 10px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  padding: 2px;
  position: relative;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.grade-option:hover:not(.locked) {
  transform: scale(1.06);
  background: rgba(170, 102, 255, 0.1);
  border-color: rgba(0, 229, 255, 0.4);
}

.grade-option.active {
  border-color: var(--neon-warm, #FFEEBB);
  background: rgba(255, 238, 187, 0.08);
}

.grade-option.locked {
  opacity: 0.28;
  cursor: not-allowed;
  filter: grayscale(70%);
}

.grade-option img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.grade-option-label {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.58rem;
  color: var(--text-secondary);
  background: var(--bg-card, #1a1a2e);
  padding: 0 3px;
  border-radius: 4px;
  pointer-events: none;
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .grade-selector-btn {
    width: 42px;
    height: 42px;
  }

  .grade-selector-icon {
    width: 42px;
    height: 42px;
  }

  .grade-selector-dropdown {
    grid-template-columns: repeat(4, 48px);
  }

  .grade-option {
    width: 48px;
    height: 48px;
  }
}

.email-warning-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 68, 102, 0.15);
  color: #FF4466;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #FF4466;
  margin-right: 8px;
  animation: warning-pulse 1.5s ease-in-out infinite;
  cursor: pointer;
  flex-shrink: 0;
}

@keyframes warning-pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
    box-shadow: 0 0 12px rgba(255, 68, 102, 0.4);
  }
}

/* App hamburger menu — avatar 75px, overflows header bar */
.app-menu-wrap {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 110;
}

.app-menu-btn {
  width: 75px;
  height: 75px;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(255, 238, 187, 0.3);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}

.header-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.app-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--bg-card);
  border: 1px solid rgba(255, 238, 187, 0.12);
  border-radius: var(--radius-md);
  min-width: 160px;
  z-index: 150;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.app-menu-dropdown.show {
  display: block;
}

.app-menu-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  color: var(--text-secondary);
  font-size: 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid rgba(255, 238, 187, 0.05);
  font-family: 'Kanit', sans-serif;
  cursor: pointer;
}

.app-menu-item:last-child {
  border-bottom: none;
}

.app-menu-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 100;
  border-top: 1px solid rgba(255, 238, 187, 0.08);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 20px;
  transition: color 0.2s, transform 0.15s;
  border-radius: 10px;
}

.nav-btn:hover {
  background: rgba(255, 238, 187, 0.04);
}

.nav-btn:active {
  transform: scale(0.96);
}

.nav-btn.active {
  color: var(--neon-warm);
}

.nav-btn .icon {
  font-size: 1.3rem;
}

.nav-btn .icon-svg {
  width: 32px;
  height: 32px;
  display: block;
  filter: brightness(0) saturate(100%) invert(68%) sepia(21%) saturate(286%) hue-rotate(2deg) brightness(94%) contrast(91%);
}

.nav-btn.active .icon-svg {
  filter: brightness(0) saturate(100%) invert(93%) sepia(16%) saturate(1094%) hue-rotate(316deg) brightness(109%) contrast(105%);
}

.main-content {
  flex: 1;
  padding-top: var(--header-h);
  padding-bottom: var(--nav-h);
}

/* ========== SCREENS ========== */
.screen {
  display: none;
  min-height: calc(100dvh - var(--header-h) - var(--nav-h));
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ========== LOGIN SCREEN ========== */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  text-align: center;
}

.login-screen h1 {
  font-size: 2rem;
  margin-bottom: 8px;
  color: var(--neon-warm);
}

.login-screen p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-form {
  width: 100%;
  max-width: 320px;
}

.login-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid rgba(255, 238, 187, 0.15);
  color: var(--text-primary);
  font-size: 1rem;
  margin-bottom: 12px;
  font-family: 'Kanit', sans-serif;
}

.login-input:focus {
  border-color: var(--neon-warm);
  box-shadow: var(--shadow-glow);
}

.login-input::placeholder {
  color: var(--text-muted);
}

select.login-input {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%23EEDDCC' d='M6 9L1 4h10z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.signup-link {
  background: none;
  border: none;
  color: var(--neon-warm);
  font-family: 'Kanit', sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 6px;
}

.signup-link:hover {
  color: var(--neon-gold);
}

.signup-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.signup-modal-content {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 238, 187, 0.15);
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.signup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 1rem;
  border: 1px solid rgba(255, 238, 187, 0.1);
  cursor: pointer;
}

.avatar-pick,
.theme-pick {
  flex: 1;
  padding: 10px 4px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 2px solid rgba(255, 238, 187, 0.1);
  border-radius: 8px;
  font-size: 1.3rem;
  cursor: pointer;
  font-family: 'Kanit', sans-serif;
}

.avatar-pick small,
.theme-pick small {
  font-size: 0.7rem;
  display: block;
}

.avatar-pick.active,
.theme-pick.active {
  border-color: var(--neon-warm);
  color: var(--neon-warm);
  background: var(--bg-card-hover);
}

.avatar-pick.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.theme-pick {
  font-size: 0.9rem;
}

/* Password field with eye toggle */
.pw-wrap {
  position: relative;
  display: block;
}

.pw-wrap .login-input {
  padding-right: 40px;
}

.pw-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 6px;
}

.pw-eye:hover {
  color: var(--neon-warm);
  background: rgba(255, 238, 187, 0.06);
}

/* Edit profile modal inputs have margin-bottom from .login-input — reset when wrapped */
.pw-wrap .login-input {
  margin-bottom: 12px;
}

.av-style-btn {
  padding: 6px 10px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1.5px solid rgba(255, 238, 187, 0.1);
  border-radius: 8px;
  font-size: 0.78rem;
  font-family: 'Kanit', sans-serif;
  cursor: pointer;
}

.av-style-btn.active {
  border-color: var(--neon-warm);
  color: var(--neon-warm);
  background: var(--bg-card-hover);
}

/* Category tabs (horizontal scroll) */
.av-cat-btn {
  padding: 5px 10px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1.5px solid rgba(255, 238, 187, 0.1);
  border-radius: 8px;
  font-size: 0.72rem;
  font-family: 'Kanit', sans-serif;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.av-cat-btn.active {
  border-color: var(--neon-warm);
  color: var(--neon-warm);
  background: var(--bg-card-hover);
}

/* Visual picker grid — mini avatar previews */
.av-visual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 8px;
}

.av-visual-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  background: var(--bg-card);
  border: 2px solid rgba(255, 238, 187, 0.08);
  border-radius: 12px;
  cursor: pointer;
  font-family: 'Kanit', sans-serif;
}

.av-visual-option img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--bg-primary);
}

.av-visual-option span {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.av-visual-option.active {
  border-color: var(--neon-warm);
  background: var(--bg-card-hover);
}

.av-visual-option.active span {
  color: var(--neon-warm);
}

.av-visual-option:hover {
  border-color: rgba(255, 238, 187, 0.3);
}

/* Avatar modal — desktop/landscape */
#avatar-modal .signup-modal-content {
  min-width: 600px;
  max-width: 90vw;
  width: 90vw;
  max-height: 800px;
  height: 90dvh;
  display: flex;
  flex-direction: column;
}

#avatar-modal #av-controls {
  flex: 1;
  overflow-y: auto;
  max-height: none !important;
}

/* Avatar modal — mobile portrait: full screen */
@media (orientation: portrait) and (max-width: 767px) {
  #avatar-modal .signup-modal-content {
    min-width: unset !important;
    max-width: 100% !important;
    width: 100% !important;
    height: 100dvh;
    max-height: 100dvh !important;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  #avatar-modal #av-controls {
    flex: 1;
    overflow-y: auto;
    max-height: none !important;
  }

  .av-visual-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 6px;
  }

  .av-visual-option img {
    width: 88px;
    height: 88px;
  }
}

/* ========== BUTTONS ========== */
.btn {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.15s;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, var(--neon-amber), var(--neon-gold));
  color: #0F0F1A;
  font-weight: 600;
}

.btn-primary:hover {
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--neon-warm);
  border: 1px solid rgba(255, 238, 187, 0.2);
}

.btn-full {
  width: 100%;
}

/* ========== CARDS ========== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 238, 187, 0.06);
  padding: 16px;
}

.card:hover {
  background: var(--bg-card-hover);
}

/* ========== SUBJECT DROPDOWN ========== */
.subject-dropdown-wrap {
  padding: 8px 12px;
  position: relative;
}

.subject-dropdown-btn {
  width: 100%;
  min-width: 250px;
  padding: 10px 16px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid rgba(255, 238, 187, 0.15);
  border-radius: var(--radius-md);
  font-size: 1.19rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Kanit', sans-serif;
}

.subject-dropdown-btn:hover {
  border-color: var(--neon-warm);
}

.subject-dropdown-btn .arrow {
  transition: transform 0.2s;
}

.subject-dropdown-btn.open .arrow {
  transform: rotate(180deg);
}

.subject-dropdown-list {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: var(--bg-card);
  border: 1px solid rgba(255, 238, 187, 0.12);
  border-radius: var(--radius-md);
  z-index: 50;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  max-height: 85vh;
  overflow-y: auto;
  padding: 8px;
}

.subject-dropdown-list.show {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}

@media (min-width: 768px) {
  .subject-dropdown-list { min-width: 500px; }
  .subject-dropdown-list.show { grid-template-columns: repeat(4, 1fr); gap: 6px; }
}

@media (min-width: 1200px) {
  .subject-dropdown-list.show { grid-template-columns: repeat(5, 1fr); }
}

.subject-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.0rem;
  transition: background 0.15s;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-align: center;
  font-family: 'Kanit', sans-serif;
}

.subject-option:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 238, 187, 0.1);
}

.subject-option.active {
  color: var(--neon-warm);
  font-weight: 600;
  background: rgba(255, 238, 187, 0.05);
  border-color: var(--neon-warm);
}

.subject-option .subj-icon {
  font-size: 2.8rem;
  line-height: 1;
  height: 75px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.subject-option .dot {
  display: none;
}

.subject-option .count {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.path-map {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px;
  gap: 0;
  overflow-y: auto;
  background-image: url('/images/road-vertical.svg');
  background-repeat: repeat-y;
  background-position: center;
  background-size: 90px auto;
}

.path-map.horizontal {
  flex-direction: row;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 40px 32px;
  cursor: grab;
  user-select: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 238, 187, 0.2) transparent;
  background-image: url('/images/road-horizontal.svg');
  background-repeat: repeat-x;
  background-position: center 47%;
  background-size: auto 90px;
}

.path-map.horizontal:active {
  cursor: grabbing;
}

.path-map.horizontal::-webkit-scrollbar {
  height: 6px;
}

.path-map.horizontal::-webkit-scrollbar-thumb {
  background: rgba(255, 238, 187, 0.2);
  border-radius: 3px;
}

.path-map.horizontal .path-node {
  flex-shrink: 0;
}

/* Vertical override (toggle forces column even on desktop) */
.path-map.vertical {
  flex-direction: column !important;
  align-items: center !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding: 20px 16px !important;
  cursor: default !important;
  background-image: url('/images/road-vertical.svg') !important;
  background-repeat: repeat-y !important;
  background-position: center !important;
  background-size: 90px auto !important;
}

.path-map.vertical .path-node {
  flex-shrink: initial;
}

.path-map.vertical .path-line {
  width: 3px !important;
  height: 40px !important;
  min-width: 0 !important;
}

/* Horizontal map (via class toggle) */
.path-map.horizontal .path-line {
  width: 40px !important;
  height: 3px !important;
  min-width: 40px;
}

.path-map.horizontal .stage-label {
  max-width: 160px;
  font-size: 1.05rem;
}

.path-map.horizontal .stage-stars {
  font-size: 1.0rem;
}

.path-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
}

.path-line {
  width: 3px;
  height: 40px;
  background: var(--bg-card);
}

.path-line.completed {
  background: var(--neon-warm);
  opacity: 0.4;
}

/* Wobbly stage wrapper = border ring + inner button */
.stage-ring {
  position: relative;
  width: 70px;
  height: 70px;
  clip-path: url(#wobbly-circle);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(2px 3px 0px rgba(150, 135, 118, 0.3));
}

.stage-btn {
  width: 58px;
  height: 58px;
  border-radius: 0;
  clip-path: url(#wobbly-circle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  position: relative;
  background: var(--bg-secondary);
  color: var(--text-muted);
  transition: all 0.2s;
  padding: 0;
  overflow: hidden;
  border: none;
}

.stage-icon {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-icon svg {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.stage-status {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 0.85rem;
  z-index: 2;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

.stage-status.pulse {
  animation: pulse-glow 2s infinite;
}

/* --- Status colors (applied to .stage-ring background = border color) --- */
.stage-ring.completed {
  background: var(--neon-warm);
  opacity: 0.85;
  filter: drop-shadow(0 0 4px rgba(255, 238, 187, 0.4)) drop-shadow(2px 3px 0px rgba(150, 135, 118, 0.3));
}

.stage-ring.completed .stage-btn {
  background: var(--bg-card);
  color: var(--neon-warm);
}

.stage-ring.current {
  background: var(--neon-gold);
  filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.5)) drop-shadow(0 0 16px rgba(255, 215, 0, 0.3));
  animation: pulse-glow 2s infinite;
}

.stage-ring.current .stage-btn {
  background: var(--bg-card);
  color: var(--neon-gold);
}

.stage-ring.locked {
  opacity: 0.35;
  cursor: default;
  background: var(--bg-card);
}

.stage-ring.open {
  background: var(--neon-warm);
  opacity: 0.75;
  cursor: pointer;
  filter: drop-shadow(0 0 3px rgba(255, 238, 187, 0.3)) drop-shadow(2px 3px 0px rgba(150, 135, 118, 0.2));
}

.stage-ring.open .stage-btn {
  background: var(--bg-card);
  color: var(--text-primary);
}

.stage-ring.open:hover {
  opacity: 1;
  filter: drop-shadow(0 0 5px rgba(255, 238, 187, 0.5)) drop-shadow(0 0 12px rgba(255, 170, 100, 0.3));
}

/* Boss = bigger */
.stage-ring.boss {
  width: 82px;
  height: 82px;
}

.stage-ring.boss .stage-btn {
  width: 68px;
  height: 68px;
  font-size: 1.7rem;
}

/* --- Part colors (override ring background) --- */
.stage-ring.part-mixed {
  background: #C084FC;
  filter: drop-shadow(0 0 4px rgba(192, 132, 252, 0.4)) drop-shadow(2px 3px 0px rgba(150, 135, 118, 0.25));
}

.stage-ring.part-mixed.open {
  animation: rainbow-ring 3s linear infinite;
}

@keyframes rainbow-ring {
  0% {
    background: #FF6B9D;
    filter: drop-shadow(0 0 6px rgba(255, 107, 157, 0.5));
  }

  33% {
    background: #60A5FA;
    filter: drop-shadow(0 0 6px rgba(96, 165, 250, 0.5));
  }

  66% {
    background: #C084FC;
    filter: drop-shadow(0 0 6px rgba(192, 132, 252, 0.5));
  }

  100% {
    background: #FF6B9D;
    filter: drop-shadow(0 0 6px rgba(255, 107, 157, 0.5));
  }
}

.stage-ring.part-exam {
  background: #FFD700;
  filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.5));
  animation: gold-ring 2s ease-in-out infinite;
}

@keyframes gold-ring {

  0%,
  100% {
    filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.4));
  }

  50% {
    filter: drop-shadow(0 0 16px rgba(255, 215, 0, 0.7)) drop-shadow(0 0 30px rgba(255, 179, 71, 0.3));
  }
}

.stage-stars {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  font-size: 1.3rem;
}

.stage-stars .star {
  color: var(--text-muted);
}

.stage-stars .star.earned {
  color: var(--neon-gold);
}

/* Wand button (paid users) */
.wand-btn {
  position: fixed;
  top: 60px;
  right: 12px;
  z-index: 210;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C084FC, #FFD700);
  color: white;
  font-size: 1.3rem;
  border: 2px solid #FFD700;
  box-shadow: 0 0 16px rgba(255, 215, 0, 0.5);
  animation: wand-pulse 1.5s ease-in-out infinite;
}

@keyframes wand-pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.08);
  }
}

/* Avatar selector */
.avatar-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.avatar-btn {
  flex: 1;
  padding: 10px 6px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 2px solid rgba(255, 238, 187, 0.1);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Kanit', sans-serif;
}

.avatar-btn span {
  font-size: 0.7rem;
}

.avatar-btn.active {
  border-color: var(--neon-warm);
  background: var(--bg-card-hover);
  color: var(--neon-warm);
}

.avatar-btn.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Leaderboard */
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.leaderboard-row.me {
  border: 2px solid var(--neon-warm);
}

.leaderboard-row .rank {
  font-weight: 700;
  color: var(--neon-gold);
  min-width: 30px;
}

.leaderboard-row .avatar {
  font-size: 1.4rem;
}

.leaderboard-row .name {
  flex: 1;
  color: var(--text-primary);
}

.leaderboard-row .paid-badge {
  font-size: 0.7rem;
  color: #FFD700;
}

.leaderboard-row .stars-total {
  color: var(--neon-warm);
  font-weight: 600;
}

.friend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.friend-row .avatar {
  font-size: 1.3rem;
}

.friend-row .name {
  flex: 1;
  color: var(--text-primary);
}

.friend-row .stars {
  color: var(--neon-warm);
}

.friend-row .remove-btn {
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
}

/* Part dividers on path map */
.path-part-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  margin: 4px 0;
  width: 100%;
  flex-shrink: 0;
}

.path-part-divider span {
  font-family: 'Mali', cursive;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 6px 18px;
  border-radius: 20px;
  white-space: nowrap;
}

.path-part-divider.part-learn span {
  background: rgba(255, 238, 187, 0.08);
  color: var(--neon-warm);
  border: 1px solid rgba(255, 238, 187, 0.15);
}

.path-part-divider.part-mixed span {
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.15), rgba(96, 165, 250, 0.15), rgba(192, 132, 252, 0.15));
  color: #C084FC;
  border: 1.5px solid rgba(192, 132, 252, 0.3);
}

.path-part-divider.part-exam span {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 179, 71, 0.2));
  color: #FFD700;
  border: 1.5px solid rgba(255, 215, 0, 0.4);
}

@media (min-width: 768px) and (orientation: landscape) {
  .path-part-divider {
    width: auto;
    padding: 0 12px;
    flex-direction: column;
  }
}

/* (Part border styles moved to .stage-ring above) */

/* Fractional stars (0/25/50/75/100% fill per star) */
.star-frac {
  position: relative;
  display: inline-block;
  line-height: 1;
}

.star-frac .star-bg {
  color: var(--text-muted);
  opacity: 0.35;
}

.star-frac .star-fg {
  position: absolute;
  left: 0;
  top: 0;
  color: var(--neon-gold);
  overflow: hidden;
  white-space: nowrap;
}

.stage-label {
  font-family: 'Mali', 'Kanit', cursive, sans-serif;
  font-size: 1.4rem;
  color: var(--text-secondary);
  margin-top: 6px;
  text-align: center;
  max-width: 240px;
  line-height: 1.3;
  font-weight: 600;
}

@keyframes pulse-glow {

  0%,
  100% {
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.25);
  }

  50% {
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.45);
  }
}

/* ========== QUIZ SCREEN ========== */
.quiz-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-primary);
  display: none;
  flex-direction: column;
}

.quiz-screen.active {
  display: flex;
}

/* Quiz menu wrap */
/* Quiz avatar menu — inside quiz-header, absolute right, overflows bar */
.quiz-menu-wrap {
  position: relative;
  flex-shrink: 0;
  z-index: 230;
}

/* Quiz menu button (avatar) — 75px, overflows the bar */
.quiz-menu-btn {
  width: 75px;
  height: 75px;
  border-radius: 50%;
  background: rgba(30, 30, 56, 0.85);
  backdrop-filter: blur(4px);
  border: 3px solid rgba(255, 238, 187, 0.3);
  color: var(--neon-warm);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
}

.quiz-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.quiz-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-card);
  border: 1px solid rgba(255, 238, 187, 0.12);
  border-radius: var(--radius-md);
  min-width: 170px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  z-index: 240;
}

.quiz-menu-dropdown.show {
  display: block;
}

.quiz-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  position: relative;
  z-index: 215;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
  }

  to {
    transform: translateY(0);
  }
}

.quiz-close {
  background: none;
  color: var(--text-secondary);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.quiz-close:hover {
  color: var(--text-primary);
}

.quiz-progress {
  flex: 1;
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
}

.quiz-progress-bar {
  height: 100%;
  background: var(--neon-warm);
  border-radius: 4px;
  transition: width 0.3s;
}

.quiz-counter {
  font-size: 1.6rem;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 600;
}

.quiz-hearts {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.heart-display {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.heart-emoji {
  font-size: 2.2rem;
  line-height: 1;
}
.heart-num {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -45%);
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.heart-mini .heart-emoji {
  font-size: 1.6rem;
}
.heart-mini .heart-num {
  font-size: 0.65rem;
}

.quiz-hearts .heart {
  transition: opacity 0.3s;
}

.quiz-hearts .heart.lost {
  opacity: 0.2;
}

.quiz-timer {
  font-size: 1.7rem;
  color: var(--neon-amber);
  font-weight: 700;
  min-width: 44px;
  text-align: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255, 179, 71, 0.1);
  transition: all 0.3s;
}

.quiz-timer.danger {
  color: var(--wrong);
  background: rgba(255, 68, 102, 0.15);
  animation: timer-pulse 0.5s infinite alternate;
}

@keyframes timer-pulse {
  0% {
    transform: scale(1);
  }

  100% {
    transform: scale(1.1);
  }
}

/* Mini status bar (hidden — quiz-header is always visible now) */
.quiz-mini-bar {
  display: none;
}

.quiz-mini-home {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.quiz-mini-home:hover {
  color: var(--text-primary);
}

.quiz-mini-bar .quiz-progress {
  height: 5px;
}

.quiz-mini-bar .quiz-timer {
  font-size: 1.4rem;
  min-width: 38px;
}

/* Content wrapper — mobile: just fills space; desktop: centers quiz-left + positions explain */
.quiz-content-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.quiz-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.quiz-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  overflow-y: auto;
  gap: 4px;
}

.quiz-question {
  font-family: 'Mali', 'Kanit', cursive, sans-serif;
  font-size: 1.55rem;
  font-weight: 600;
  /* base ×1.5 */
  line-height: 1.45;
  color: var(--text-primary);
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-shrink: 0;
}

.header-icon-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  background: var(--bg-card);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--neon-warm);
  border: 1px solid rgba(255, 238, 187, 0.15);
  cursor: pointer;
  padding: 0;
}

@media (min-width: 768px) {
  .header-icon-btn {
    display: flex;
  }
}

.header-icon-btn:active {
  background: var(--neon-warm);
  color: var(--bg-primary);
}

.tts-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  background: var(--bg-card);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--neon-warm);
  font-size: 0.85rem;
  border: 1px solid rgba(255, 238, 187, 0.15);
  padding: 0;
  cursor: pointer;
}

.tts-btn:active {
  background: var(--neon-warm);
  color: var(--bg-primary);
}

.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.choice-btn {
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: 'Mali', 'Kanit', cursive, sans-serif;
  font-size: 1.35rem;
  line-height: 1.3;
  /* base ×1.5 */
  border: 2px solid rgba(255, 238, 187, 0.08);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 12dvh;
  /* 13% viewport height for portrait mobile */
}

.choice-btn:hover:not(.answered) {
  border-color: rgba(255, 238, 187, 0.25);
}

.choice-btn:active:not(.answered) {
  transform: scale(0.98);
}

.choice-btn.correct {
  border-color: var(--correct);
  background: rgba(0, 255, 136, 0.1);
  color: var(--correct);
}

.choice-btn.wrong {
  border-color: var(--wrong);
  background: rgba(255, 68, 102, 0.1);
  color: var(--wrong);
}

.choice-btn.answered {
  pointer-events: none;
}

.choice-btn .label {
  font-weight: 700;
  color: var(--neon-warm);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: rgba(255, 238, 187, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
}

.choice-btn.correct .label {
  background: rgba(0, 255, 136, 0.2);
  color: var(--correct);
}

.choice-btn.wrong .label {
  background: rgba(255, 68, 102, 0.2);
  color: var(--wrong);
}

.choice-btn img {
  max-height: 11.55dvh;
  width: auto;
  max-width: calc(11.55dvh * 1.77778);
  border-radius: 4px;
  object-fit: contain;
}

.choice-btn .choice-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

/* Question images */
.quiz-question img {
  max-height: 15dvh;
  width: auto;
  max-width: calc(15dvh * 1.77778);
  border-radius: var(--radius-sm);
}

.quiz-question-body {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.filler-img-float {
  float: right;
  width: 100px;
  height: 100px;
  object-fit: contain;
  margin: 0;
  opacity: 0.75;
  border-radius: 8px;
}

.filler-img-reason {
  display: block;
  max-height: 125px;
  max-width: 225px;
  width: auto;
  height: auto;
  object-fit: contain;
  margin: 8px 0;
  opacity: 0.75;
  border-radius: 8px;
}

.combo-display {
  position: fixed;
  top: 8px;
  left: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--neon-gold);
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
  z-index: 210;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.combo-display.show {
  opacity: 1;
}

/* ========== EXPLAIN OVERLAY ========== */
/* Mobile portrait: full screen */
.explain-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  padding: 16px;
  padding-bottom: 60px;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  z-index: 205;
}

.explain-overlay.show {
  display: flex;
}

.explain-result {
  font-family: 'Mali', 'Kanit', cursive, sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.explain-result.is-correct {
  color: var(--correct);
}

.explain-result.is-wrong {
  color: var(--wrong);
}

.explain-answer {
  font-size: 0.95rem;
  color: var(--neon-warm);
  margin-bottom: 8px;
  font-weight: 600;
}

.explain-text {
  color: var(--text-primary);
  font-family: 'Mali', 'Kanit', cursive, sans-serif;
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 12px;
}

.explain-text strong {
  color: var(--neon-warm);
}

.explain-question-recall {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  line-height: 1.4;
  padding: 8px 10px;
  background: rgba(255, 238, 187, 0.04);
  border-radius: var(--radius-sm);
  border-left: 3px solid rgba(255, 238, 187, 0.15);
  display: none;
}

@media (orientation: portrait) and (max-width: 767px) {
  .explain-question-recall {
    display: block;
  }
}

.explain-user-answer {
  font-size: 0.85rem;
  margin-bottom: 6px;
  font-weight: 500;
}

.explain-user-answer.user-correct {
  color: var(--correct);
}

.explain-user-answer.user-wrong {
  color: var(--wrong);
}

.explain-divider {
  border: none;
  border-top: 1px solid rgba(255, 238, 187, 0.12);
  margin: 10px 0;
}

.explain-xp {
  font-size: 0.9rem;
  color: var(--neon-gold);
  margin-bottom: 8px;
}

.explain-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.explain-hide-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 238, 187, 0.1);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

/* Report button */
.report-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  opacity: 0.5;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
}
.report-btn:hover { opacity: 0.9; }

/* Report popup */
.report-popup {
  display: none;
  position: fixed;
  bottom: 60px;
  right: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255,238,187,0.15);
  border-radius: 12px;
  padding: 12px;
  z-index: 250;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-width: 320px;
  width: 90%;
}
.report-popup.show { display: flex; gap: 10px; }
.report-popup img { width: 60px; height: 60px; object-fit: contain; flex-shrink: 0; align-self: flex-start; }
.report-right { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.report-right .report-label { font-size: 0.8rem; color: var(--text-secondary); font-family: 'Kanit', sans-serif; }
.report-right input {
  padding: 8px 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid rgba(255,238,187,0.15);
  border-radius: 8px;
  font-family: 'Kanit', sans-serif;
  font-size: 0.85rem;
}
.report-right input:focus { border-color: var(--neon-warm); outline: none; }
.report-send-btn {
  padding: 6px 14px;
  background: var(--neon-warm);
  color: var(--bg-primary);
  border: none;
  border-radius: 8px;
  font-family: 'Mali', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  align-self: flex-end;
}

/* Report thank you */
.report-thanks {
  position: fixed;
  bottom: 80px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 260;
  animation: reportFadeIn 0.3s ease, reportFadeOut 0.5s ease 1.5s forwards;
  pointer-events: none;
}
.report-thanks img { width: 120px; height: 120px; object-fit: contain; }
.report-thanks span { font-size: 1.1rem; color: var(--neon-warm); font-family: 'Mali', sans-serif; font-weight: 600; }
@keyframes reportFadeIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
@keyframes reportFadeOut { from { opacity: 1; } to { opacity: 0; } }

/* Version in dropdown */
.app-menu-version {
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 4px 0 6px;
  opacity: 0.6;
}

/* "Learn more" button in explain text */
.more-learn-btn {
  display: block;
  margin-top: 10px;
  padding: 8px 14px;
  background: rgba(255, 238, 187, 0.08);
  border: 1px solid rgba(255, 238, 187, 0.2);
  border-radius: 10px;
  color: var(--neon-warm);
  font-family: 'Mali', cursive;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.more-learn-btn:hover {
  background: rgba(255, 238, 187, 0.15);
}

[data-theme="bright"] .more-learn-btn {
  background: rgba(255, 107, 157, 0.06);
  border-color: rgba(255, 107, 157, 0.2);
  color: #FF6B9D;
}

[data-theme="bright"] .more-learn-btn:hover {
  background: rgba(255, 107, 157, 0.12);
}

/* ========== MORE TOPICS POPUP ========== */
.more-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 230;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
}

.more-overlay.show {
  display: flex;
}

.more-popup {
  position: relative;
  background: var(--bg-secondary);
  border-radius: 16px;
  max-width: 500px;
  width: 92%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 238, 187, 0.1);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

/* ===== Treasure chest feature (in moreTopics popup) ===== */
/* Wrapper — holds locked chest, draggable */
.more-filler-wrap {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  width: 130px;
  height: 140px;
  display: block;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.more-filler-wrap:active {
  cursor: grabbing;
}

/* Explosion particles */
.treasure-explosion {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.treasure-explosion .particle {
  position: absolute;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: radial-gradient(circle, #FFD700, #FF8800);
  box-shadow: 0 0 8px #FFD700, 0 0 16px rgba(255, 215, 0, 0.7);
  opacity: 0;
  animation: particle-burst 0.6s ease-out forwards;
}

@keyframes particle-burst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0.4);
  }

  60% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: var(--particle-end) scale(1.2);
  }
}

/* Treasure chest (locked state) */
.treasure-chest {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  animation: chest-idle-bob 3s ease-in-out infinite;
}

@keyframes chest-idle-bob {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }
}

/* Open chest — shake then glow */
.treasure-chest.opening {
  animation: chest-open-shake 1.5s ease-in-out;
}

@keyframes chest-open-shake {
  0% {
    transform: rotate(0) scale(1);
  }

  10% {
    transform: rotate(-4deg) scale(1.02);
  }

  20% {
    transform: rotate(4deg) scale(1.04);
  }

  30% {
    transform: rotate(-3deg) scale(1.06);
  }

  40% {
    transform: rotate(3deg) scale(1.08);
  }

  50% {
    transform: rotate(-2deg) scale(1.1);
  }

  60% {
    transform: rotate(2deg) scale(1.08);
  }

  70% {
    transform: rotate(-1deg) scale(1.05);
  }

  80% {
    transform: rotate(1deg) scale(1.03);
  }

  100% {
    transform: rotate(0) scale(1);
  }
}

.more-filler-wrap.chest-opened {
  filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.8));
}

/* Reward badge that flies out of opened chest */
.treasure-reward {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: linear-gradient(135deg, #FFD700, #FF8800);
  color: #1a1a2e;
  font-family: 'Mali', cursive;
  font-weight: 700;
  font-size: 1.05rem;
  border-radius: 24px;
  box-shadow: 0 6px 24px rgba(255, 215, 0, 0.6),
    0 0 40px rgba(255, 215, 0, 0.4);
  pointer-events: none;
  white-space: nowrap;
  animation: reward-pop 1.6s ease-out forwards;
  z-index: 10;
}

@keyframes reward-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3);
  }

  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
  }

  40% {
    transform: translate(-50%, -50%) scale(1);
  }

  85% {
    opacity: 1;
    transform: translate(-50%, -100%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -160%) scale(1);
  }
}

/* Floating buttons in more popup — no header bar */
.more-float-btns {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 12px;
}

.more-float-btn {
  background: none;
  border: none;
  color: #FF8C00;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  opacity: 0.9;
  transition: opacity 0.15s;
}
.more-float-btn svg {
  stroke: #FF8C00;
}
.report-more-float {
  opacity: 0.5;
}
.report-more-float svg {
  stroke: var(--text-muted);
}
.report-more-float:hover {
  opacity: 0.9;
}
.more-float-btn:hover {
  opacity: 1;
}

.more-body {
  flex: 1;
  padding: 8px 12px 12px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
  font-family: 'Kanit', sans-serif;
}

.more-body svg {
  display: block;
  margin: 10px auto;
  max-width: 100%;
}

.more-topic-img {
  display: block;
  margin: 0 auto 12px;
  width: 100%;
  max-width: 380px;
  max-height: 760px;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  cursor: zoom-in;
}

/*
 * Mobile portrait: render moreTopicImageUrl edge-to-edge of the screen.
 * Use 100vw + negative left margin to break out of every parent's padding.
 * Aspect ratio is preserved (height: auto), so the image may extend below the
 * fold — that's intentional. No rounded corners on edge-to-edge mode.
 */
@media (max-width: 767px),
(orientation: portrait) {
  .more-topic-img {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    margin-top: 0;
    margin-bottom: 12px;
    border-radius: 0;
    max-height: none;
    cursor: zoom-in;
  }
}

/* ===== Image zoom overlay (desktop click-to-zoom) ===== */
.image-zoom-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 99999;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 16px;
}

.image-zoom-overlay.show {
  display: flex;
  animation: zoom-fade-in 0.2s ease-out;
}

@keyframes zoom-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.image-zoom-overlay img {
  display: block;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 64px rgba(0, 0, 0, 0.6);
  animation: zoom-pop-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes zoom-pop-in {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.image-zoom-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-zoom-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

@media (max-width: 767px),
(orientation: portrait) {
  .more-popup {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
}

/* Bright theme */
[data-theme="bright"] .more-popup {
  background: white;
  border-color: rgba(255, 107, 157, 0.15);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12);
}

/* ========== SCRATCHPAD ========== */
.scratch-toggle-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.scratch-toggle-btn:hover {
  color: var(--neon-warm);
}

.scratch-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: 0;
  z-index: 210;
  flex-direction: column;
}

.scratch-overlay.show {
  display: flex;
}

.scratch-toolbar {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(15, 15, 26, 0.9);
  backdrop-filter: blur(6px);
  z-index: 2;
  justify-content: center;
}

.scratch-tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 238, 187, 0.08);
  border: 1px solid rgba(255, 238, 187, 0.15);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.scratch-tool-btn:hover,
.scratch-tool-btn.scratch-tool-active {
  color: var(--neon-warm);
  border-color: var(--neon-warm);
  background: rgba(255, 238, 187, 0.12);
}

.scratch-canvas-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: rgba(15, 15, 26, 0.75);
  touch-action: none;
}

.scratch-canvas-wrap canvas {
  position: absolute;
  top: 0;
  left: 0;
}

/* Bright theme */
[data-theme="bright"] .scratch-toolbar {
  background: rgba(255, 255, 255, 0.92);
}

[data-theme="bright"] .scratch-canvas-wrap {
  background: rgba(255, 247, 237, 0.75);
}

[data-theme="bright"] .scratch-tool-btn {
  background: rgba(255, 107, 157, 0.06);
  border-color: rgba(255, 107, 157, 0.15);
}

[data-theme="bright"] .scratch-tool-btn:hover,
[data-theme="bright"] .scratch-tool-btn.scratch-tool-active {
  color: #FF6B9D;
  border-color: #FF6B9D;
}

/* ========== QUIZ FOOTER (fixed) ========== */
.quiz-footer {
  flex-shrink: 0;
  padding: 8px 10px;
  background: var(--bg-secondary);
  border-top: 1px solid rgba(255, 238, 187, 0.08);
  z-index: 210;
}

.quiz-footer .btn {
  width: 100%;
}

/* ========== LANDSCAPE / DESKTOP ========== */
@media (orientation: landscape) and (min-width: 768px) {

  /* 1. Quiz screen = vertical column layout */
  .quiz-screen.active {
    flex-direction: column;
  }

  /* Header: static top bar on desktop */
  .quiz-header {
    position: static;
    height: 50px;
    flex-shrink: 0;
  }

  .quiz-hearts {
    flex-shrink: 0;
  }

  /* Content area: ROW direction, centers quiz-left, positions explain absolutely */
  .quiz-content-wrap {
    flex: 1;
    display: flex;
    flex-direction: row;
    /* override mobile column */
    justify-content: center;
    /* center quiz-left horizontally */
    overflow: hidden;
    position: relative;
    /* anchor for absolute explain */
  }

  /*
   * Layout: |--- ≥340px ---|--- quiz 600px ---|--- explain 340px ---|--- rest ---|
   * quiz-left centered via justify-content:center
   * explain: absolute, flush right of quiz-left
   */

  /* quiz-left: fixed 600px, always centered, never shifts */
  .quiz-left {
    width: 600px;
    flex: 0 0 600px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* Font size: base × 1.5 × 1.20 = ×1.8 from mobile base */
  .quiz-question {
    font-size: 1.75rem;
  }

  .choice-btn {
    font-size: 1.6rem;
  }

  .explain-result {
    font-size: 1.75rem;
  }

  .explain-answer {
    font-size: 1.4rem;
  }

  .explain-text {
    font-size: 1.4rem;
  }

  .explain-xp {
    font-size: 1.3rem;
  }

  /* Choice height 80px */
  .choice-btn {
    min-height: 80px;
    padding: 8px 14px;
  }

  .choice-btn img {
    max-height: 100px;
    max-width: calc(100px * 1.77778);
  }

  .choice-btn .label {
    width: 32px;
    height: 32px;
    font-size: 1.1rem;
  }

  .quiz-question img {
    max-height: 120px;
    max-width: calc(120px * 1.77778);
  }

  /* Explain panel: absolute, 340-600px, flush right of quiz-left */
  .explain-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    /* flush right of quiz-left (center + half of 600) */
    left: calc(50% + 300px);
    /* Fill remaining space: from quiz-left right edge to screen edge */
    /* min 340px, max 600px, fluid in between */
    width: calc(50% - 300px);
    /* = remaining half of screen */
    min-width: 340px;
    max-width: 600px;
    border-radius: 0;
    padding: 0;
    overflow: hidden;
  }

  .explain-overlay.show {
    display: flex;
    padding: 20px;
    border-left: 1px solid rgba(255, 238, 187, 0.08);
    overflow-y: auto;
  }

  /* Footer stays inside quiz-left */
  .quiz-footer {
    /* already inside quiz-left, no absolute needed */
  }
}

/* Tablet landscape (iPad etc.) — narrower quiz + explain so both fit on screen */
@media (orientation: landscape) and (min-width: 768px) and (max-width: 1279px) {
  .quiz-left {
    width: 420px;
    flex: 0 0 420px;
  }

  .quiz-question {
    font-size: 1.4rem;
  }

  .choice-btn {
    font-size: 1.3rem;
    min-height: 64px;
    padding: 6px 12px;
  }

  .choice-btn .label {
    width: 28px;
    height: 28px;
    font-size: 1rem;
  }

  .quiz-question img {
    max-height: 100px;
    max-width: calc(100px * 1.77778);
  }

  .choice-btn img {
    max-height: 80px;
    max-width: calc(80px * 1.77778);
  }

  .explain-overlay {
    left: calc(50% + 210px);
    width: calc(50% - 210px);
    min-width: 280px;
    max-width: 480px;
  }

  .explain-result {
    font-size: 1.4rem;
  }

  .explain-answer {
    font-size: 1.2rem;
  }

  .explain-text {
    font-size: 1.2rem;
  }

  .explain-xp {
    font-size: 1.1rem;
  }
}

/* ========== RESULT SCREEN ========== */
.result-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-primary);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.result-screen.active {
  display: flex;
}

.result-stars {
  font-size: 2rem;
  margin-bottom: 12px;
  letter-spacing: 4px;
}

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

.result-stars .star.earned {
  color: var(--neon-gold);
}

.result-title {
  font-family: 'Mali', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--neon-warm);
  margin-bottom: 4px;
}

.result-score {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.result-rewards {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.reward-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.reward-item .val {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--neon-gold);
}

.result-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.result-actions .btn {
  flex: 1;
}

/* ========== PROFILE SCREEN ========== */
.profile-section {
  padding: 20px 16px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  border: 2px solid var(--neon-warm);
}

.profile-info h2 {
  font-size: 1.2rem;
  color: var(--neon-warm);
}

.profile-info p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}

.stat-card .val {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--neon-warm);
}

.stat-card .label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ========== RESPONSIVE ========== */
/* Tablet portrait only */
@media (min-width: 768px) and (orientation: portrait) {
  .main-content {
    max-width: 600px;
    margin: 0 auto;
  }

  .quiz-body {
    padding: 16px 24px;
  }
}

@media (min-width: 768px) {
  .main-content {
    max-width: 600px;
    margin: 0 auto;
  }

  .stage-ring {
    width: 78px;
    height: 78px;
  }

  .stage-ring .stage-btn {
    width: 66px;
    height: 66px;
  }

  .stage-ring.boss {
    width: 90px;
    height: 90px;
  }

  .stage-ring.boss .stage-btn {
    width: 76px;
    height: 76px;
  }

  /* Map screen breaks out of 600px container to use full width */
  #screen-map {
    width: 100vw;
    margin-left: calc(-50vw + 50%);
  }

  #screen-map .subject-dropdown-wrap {
    max-width: 600px;
    margin: 0 auto;
  }

  #screen-map .path-map {
    width: 100%;
    max-width: none;
  }
}

/* Portrait (mobile + tablet) — quiz text, smaller map labels, bigger explanation */
@media (orientation: portrait) {
  .quiz-question {
    font-size: 1.53rem;
  }

  .choice-btn {
    font-size: 1.53rem;
  }

  .stage-label {
    font-size: 1.0rem;
  }

  .explain-result {
    font-size: 1.6rem;
  }

  .explain-answer {
    font-size: 1.2rem;
  }

  .explain-text {
    font-size: 1.2rem;
  }

  .explain-user-answer {
    font-size: 1.1rem;
  }

  .explain-question-recall {
    font-size: 1.1rem;
  }
}

/* Small phones portrait — extra compact */
@media (max-height: 700px) and (orientation: portrait) {
  .quiz-question {
    font-size: 1.32rem;
  }

  .choice-btn {
    padding: 8px 12px;
    font-size: 1.15rem;
  }

  .quiz-body {
    gap: 6px;
    padding: 8px;
  }

  .quiz-header {
    padding: 6px 10px;
  }

  .quiz-footer {
    padding: 8px 10px;
  }
}

/* ========== CROWN + STAR SLOTS (stage map + result screen) ========== */
.stage-stars .slot,
.result-stars .slot {
  display: inline-block;
  line-height: 1;
}

.stage-stars .slot.star.earned,
.result-stars .slot.star.earned {
  color: #FFA726;
  /* explicit orange — distinct from gold crowns */
  text-shadow: 0 0 6px rgba(255, 167, 38, 0.55);
}

.stage-stars .slot.star.empty,
.result-stars .slot.star.empty {
  color: var(--text-muted);
  opacity: 0.35;
}

.stage-stars .slot.crown,
.result-stars .slot.crown {
  filter: drop-shadow(0 0 4px rgba(255, 215, 0, 0.85)) drop-shadow(0 0 10px rgba(255, 179, 71, 0.5));
  animation: crown-shimmer 2.4s ease-in-out infinite;
}

@keyframes crown-shimmer {

  0%,
  100% {
    filter: drop-shadow(0 0 4px rgba(255, 215, 0, 0.85)) drop-shadow(0 0 10px rgba(255, 179, 71, 0.5));
    transform: translateY(0);
  }

  50% {
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 1)) drop-shadow(0 0 18px rgba(255, 179, 71, 0.8));
    transform: translateY(-1px);
  }
}

/* 5-star explosion: each slot pops in sequence */
.result-stars.explode .slot {
  animation: star-pop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) both;
  display: inline-block;
}

.result-stars.explode .slot:nth-child(1) {
  animation-delay: 0.00s;
}

.result-stars.explode .slot:nth-child(2) {
  animation-delay: 0.10s;
}

.result-stars.explode .slot:nth-child(3) {
  animation-delay: 0.20s;
}

.result-stars.explode .slot:nth-child(4) {
  animation-delay: 0.30s;
}

.result-stars.explode .slot:nth-child(5) {
  animation-delay: 0.40s;
}

@keyframes star-pop {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  60% {
    transform: scale(1.6);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* "Got new crown" message under the star row */
.result-crown-msg {
  font-family: 'Mali', 'Kanit', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--neon-gold, #FFD700);
  margin: 4px 0 8px;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
  animation: crown-msg-in 0.6s ease-out;
}

@keyframes crown-msg-in {
  0% {
    transform: translateY(-8px) scale(0.9);
    opacity: 0;
  }

  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Near-miss encouragement under the score line */
.result-near-miss {
  font-family: 'Mali', 'Kanit', sans-serif;
  font-size: 0.95rem;
  color: var(--text-secondary);
  background: rgba(255, 179, 71, 0.10);
  border: 1px solid rgba(255, 179, 71, 0.35);
  border-radius: 12px;
  padding: 8px 14px;
  margin: 0 auto 16px;
  max-width: 360px;
  line-height: 1.4;
}

.result-near-miss b {
  color: #FFA726;
}

/* ========== CROWN REVEAL FULL-SCREEN OVERLAY ========== */
.crown-reveal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: radial-gradient(ellipse at center, rgba(48, 24, 0, 0.92) 0%, rgba(0, 0, 0, 0.96) 70%);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  pointer-events: none;
}

.crown-reveal.show {
  display: flex;
  animation: crown-bg-in 0.4s ease-out;
}

@keyframes crown-bg-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.crown-reveal-burst {
  position: absolute;
  width: 80vmin;
  height: 80vmin;
  background: radial-gradient(circle, rgba(255, 215, 0, 0.45) 0%, rgba(255, 179, 71, 0.15) 35%, transparent 70%);
  border-radius: 50%;
  animation: crown-burst 1.6s ease-out;
}

@keyframes crown-burst {
  0% {
    transform: scale(0.2);
    opacity: 0;
  }

  30% {
    transform: scale(1.0);
    opacity: 1;
  }

  100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

.crown-reveal-icon {
  font-size: clamp(160px, 38vmin, 360px);
  line-height: 1;
  filter: drop-shadow(0 0 24px rgba(255, 215, 0, 1)) drop-shadow(0 0 60px rgba(255, 179, 71, 0.85));
  animation: crown-pop 1.1s cubic-bezier(0.2, 1.6, 0.4, 1);
  transform-origin: center;
  position: relative;
  z-index: 1;
}

@keyframes crown-pop {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  40% {
    transform: scale(1.25) rotate(-6deg);
    opacity: 1;
  }

  60% {
    transform: scale(0.95) rotate(4deg);
  }

  80% {
    transform: scale(1.05) rotate(-2deg);
  }

  100% {
    transform: scale(1) rotate(0);
  }
}

.crown-reveal-text {
  margin-top: 24px;
  font-family: 'Mali', 'Kanit', sans-serif;
  font-size: clamp(28px, 6vmin, 56px);
  font-weight: 900;
  color: #FFE066;
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.95), 0 0 32px rgba(255, 179, 71, 0.6);
  letter-spacing: 2px;
  animation: crown-text-in 0.6s ease-out 0.6s both;
  position: relative;
  z-index: 1;
}

@keyframes crown-text-in {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Shrink phase: crown + text fly toward upper-center then fade */
.crown-reveal.shrink .crown-reveal-icon {
  animation: crown-shrink 0.9s ease-in forwards;
}

.crown-reveal.shrink .crown-reveal-text {
  animation: crown-text-out 0.7s ease-in forwards;
}

.crown-reveal.shrink .crown-reveal-burst {
  opacity: 0;
  transition: opacity 0.4s;
}

@keyframes crown-shrink {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  100% {
    transform: scale(0.18) translateY(-30vh);
    opacity: 0;
  }
}

@keyframes crown-text-out {
  0% {
    transform: translateY(0);
    opacity: 1;
  }

  100% {
    transform: translateY(-40vh) scale(0.5);
    opacity: 0;
  }
}

/* Bigger result-stars row (so the star/crown slots have visual weight) */
.result-stars {
  font-size: 2.4rem;
  letter-spacing: 6px;
}

.result-stars .slot.crown {
  font-size: 1.05em;
  /* crowns slightly larger than stars */
}

/* ===== Compact quiz-header (status bar @30px, 50% translucent bg) ===== */
.quiz-header,
#quiz-header-panel {
  height: 30px !important;
  min-height: 30px;
  padding: 0 !important;
  margin: 0 !important;
  gap: 2px !important;
  overflow: visible;
  padding-right: 80px !important; /* keep home button clear of avatar */
  background: rgba(20, 20, 35, 0.5) !important;
  backdrop-filter: blur(2px);
}
.quiz-header > *,
#quiz-header-panel > * {
  margin: 0 !important;
}
.quiz-header .quiz-timer,
#quiz-header-panel .quiz-timer {
  height: 30px;
  line-height: 30px;
  font-size: 0.95rem;
  padding: 0 2px !important;
  min-width: 32px;
  background: transparent;
  border-radius: 0;
}
.quiz-header .quiz-counter,
#quiz-header-panel .quiz-counter {
  font-size: 0.85rem;
  line-height: 30px;
  padding: 0 2px !important;
}
.quiz-header .quiz-hearts,
#quiz-header-panel .quiz-hearts {
  height: 30px;
  padding: 0 2px !important;
}
.quiz-header .quiz-hearts .heart-emoji,
#quiz-header-panel .heart-emoji {
  font-size: 1.55rem; /* ~30% smaller than 2.2rem */
  line-height: 30px;
}
.quiz-header .heart-num {
  font-size: 0.85rem; /* unchanged */
}
.quiz-header .quiz-progress,
#quiz-header-panel .quiz-progress {
  height: 6px;
}
.quiz-header .scratch-toggle-btn,
.quiz-header .tts-btn,
.quiz-header .quiz-close,
#quiz-header-panel .scratch-toggle-btn,
#quiz-header-panel .tts-btn,
#quiz-header-panel .quiz-close {
  width: 30px !important;
  height: 30px !important;
  padding: 0 2px !important;
  margin: 0 !important;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  flex-shrink: 0;
}
.quiz-header .scratch-toggle-btn svg,
.quiz-header .tts-btn svg,
.quiz-header .quiz-close svg,
#quiz-header-panel .scratch-toggle-btn svg,
#quiz-header-panel .tts-btn svg,
#quiz-header-panel .quiz-close svg {
  width: 26px;
  height: 26px;
  display: block;
}
/* Avatar still overflows header height; stays above all */
.quiz-header .quiz-menu-wrap,
#quiz-header-panel .quiz-menu-wrap {
  position: absolute !important;
  right: 4px;
  top: 0;
  z-index: 500 !important;
}
.quiz-header .quiz-menu-btn,
#quiz-header-panel .quiz-menu-btn {
  width: 60px;
  height: 60px;
}

/* ===== Report button in quiz-header (top-left) ===== */
.report-btn-header {
  width: 26px;
  height: 30px;
  padding: 0 2px !important;
  margin: 0 !important;
  background: transparent;
  border: none;
  opacity: 0.85;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.report-btn-header:hover { opacity: 1; }
.report-btn-header svg { width: 22px; height: 22px; }

/* ===== Report popup (redesigned) ===== */
.report-popup {
  width: 400px !important;
  max-width: calc(100vw - 32px) !important;
  bottom: 100px !important;
  right: 16px !important;
  left: auto;
  padding: 14px !important;
  gap: 14px;
}
.report-popup.show { display: flex !important; gap: 14px; }
.report-popup img {
  width: 100px !important;
  height: 100px !important;
  object-fit: contain;
  flex-shrink: 0;
  align-self: flex-start;
}
.report-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.report-right .report-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--neon-warm);
}
.report-subject {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.35;
  max-height: 3em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.report-popup textarea#report-input {
  width: 100%;
  min-height: 4.5em; /* ~3 lines */
  padding: 8px 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid rgba(255,238,187,0.15);
  border-radius: 8px;
  font-family: 'Kanit', sans-serif;
  font-size: 0.85rem;
  resize: vertical;
}
.report-popup textarea#report-input:focus { border-color: var(--neon-warm); outline: none; }
.report-send-btn {
  align-self: flex-end;
}
.report-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.report-cancel-btn {
  padding: 6px 14px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid rgba(255,238,187,0.12);
  border-radius: 8px;
  font-family: 'Kanit', sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
}
.report-cancel-btn:hover { color: var(--text-primary); }

/* ===== Email-warning item in dropdown ===== */
.email-warning-item {
  color: #ff8888 !important;
}
.email-warning-item svg { stroke: #ff8888; }

/* ===== Override .report-btn (explain overlay) and moreTopic report to top-left, dark blue, 70% opaque ===== */
.report-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  right: auto;
  color: #0b2c6b !important;
  opacity: 0.7 !important;
  background: none;
  border: none;
  padding: 4px;
}
.report-btn:hover { opacity: 1 !important; }

/* moreTopic floating buttons: orange, 70% opaque, 25% larger.
   Container now spans full width so report button can sit flush-left while
   others stay flush-right. */
.more-float-btns {
  top: 0 !important;
  left: 10px;
  right: 10px;
  gap: 8px !important;
  justify-content: flex-end;
}
/* Push the report button to the far left of the header row */
.more-float-btns .report-more-float {
  margin-right: auto;
}
.more-float-btn {
  color: #FF8C00 !important;
  opacity: 0.7 !important;
  font-size: 1.875rem !important; /* 1.5 * 1.25 */
  padding: 5px !important;
}
.more-float-btn svg {
  stroke: #FF8C00 !important;
  width: 25px !important;
  height: 25px !important;
}
.report-more-float {
  opacity: 0.7 !important;
}
.report-more-float svg {
  stroke: #FF8C00 !important;
  width: 22px !important;
  height: 22px !important;
}

/* ===== Global ➤ next button: fixed bottom-right, above popups ===== */
#quiz-next-btn,
.quiz-footer #quiz-next-btn.btn,
.quiz-footer #quiz-next-btn.btn-primary {
  position: fixed !important;
  bottom: 16px;
  right: 16px;
  left: auto;
  top: auto;
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #FF8C00 !important;
  font-size: 4.5rem !important; /* ~3x original */
  line-height: 1;
  opacity: 0.7 !important;
  padding: 4px 10px !important;
  width: auto !important;
  z-index: 9999 !important;
}
.quiz-footer {
  background: transparent !important;
  border-top: none !important;
  padding: 0 !important;
}

/* ===== Profile stars/crowns breakdown modal ===== */
.breakdown-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.breakdown-overlay.show { display: flex; }
.breakdown-modal {
  background: var(--bg-secondary);
  border: 1px solid rgba(255,238,187,0.12);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
.breakdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,238,187,0.08);
}
.breakdown-header h2 {
  font-size: 1.1rem;
  color: var(--neon-warm);
  margin: 0;
}
.breakdown-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
}
.breakdown-close:hover { color: var(--text-primary); }
.breakdown-body {
  overflow-y: auto;
  padding: 8px 12px 16px;
}
.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,238,187,0.06);
}
.breakdown-row-title { font-size: 0.9rem; color: var(--text-primary); }
.breakdown-row-sub { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.breakdown-row-count {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 2px;
}

/* ===== Treasure-chest filler: 70% opaque (30% transparent) ===== */
.more-filler-wrap {
  opacity: 0.7;
}
