/* ==========================================================================
   Hongpak (ห้องพากย์) — Gamification & Pixel Mascot System
   ========================================================================== */

/* ---------- Pixel Art & Mascot Variables ---------- */
:root {
  --px-size: 2px;
  --game-gold: #F59E0B;
  --game-gold-soft: #FEF3C7;
  --game-xp: #8B5CF6;
  --game-xp-soft: #EDE9FE;
  --game-purple: #7C3AED;
  --game-blue: #2563EB;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --game-gold-soft: #3D2D06;
    --game-xp-soft: #2D1B4E;
  }
}
:root[data-theme="dark"] {
  --game-gold-soft: #3D2D06;
  --game-xp-soft: #2D1B4E;
}

/* ---------- Brand Mascot Button (Header) ---------- */
.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mascot-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform .18s cubic-bezier(0.34, 1.56, 0.64, 1), border-color .18s, box-shadow .18s;
  flex-shrink: 0;
  outline: none;
  user-select: none;
}
.brand-mascot-btn:hover {
  transform: translateY(-2px) scale(1.05);
  border-color: var(--air);
  box-shadow: 0 4px 12px rgba(229, 56, 59, 0.18);
}
.brand-mascot-btn:active {
  transform: translateY(0) scale(0.96);
}

.mascot-avatar-frame {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  position: relative;
}
.mascot-avatar-frame svg {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  shape-rendering: crispEdges;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}

.mascot-lvl-pill {
  position: absolute;
  bottom: -6px;
  right: -6px;
  background: linear-gradient(135deg, var(--air), #ff6b6b);
  color: #fff;
  font: 700 10px/1 var(--f-console);
  padding: 3px 6px;
  border-radius: 999px;
  border: 1.5px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  letter-spacing: .02em;
  pointer-events: none;
  white-space: nowrap;
}

/* Brand Title & XP Chip Row */
.brand-text-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.brand-title-row h1 {
  margin: 0;
  font: 700 26px/1 var(--f-console);
  letter-spacing: .01em;
}

.header-xp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 6px;
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s ease;
  user-select: none;
}
.header-xp-chip:hover {
  background: var(--surface);
  border-color: var(--game-xp);
  transform: translateY(-1px);
}
.xp-mini-track {
  width: 44px;
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.xp-mini-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--air), var(--game-xp));
  border-radius: 999px;
  transition: width .4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.xp-mini-text {
  font: 600 11px/1 var(--f-console);
  color: var(--muted);
  white-space: nowrap;
}
.xp-mini-star {
  font-size: 11px;
  line-height: 1;
}

/* ---------- Pixel Mascot Animations ---------- */
@keyframes pixel-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
@keyframes pixel-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}
@keyframes pixel-glow {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(245, 158, 11, 0.4)); }
  50% { filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.9)); }
}
@keyframes float-bubble {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.mascot-animated {
  animation: pixel-bounce 2.2s ease-in-out infinite;
  display: inline-block;
}
.mascot-talking {
  animation: pixel-wiggle 0.6s ease-in-out infinite;
}
.mascot-legend {
  animation: pixel-bounce 2.2s ease-in-out infinite, pixel-glow 2.5s ease-in-out infinite;
}

/* ---------- Floating Companion Widget (Nong Pak) ---------- */
.mascot-companion {
  position: fixed;
  bottom: calc(var(--transport-h) + 16px);
  right: 20px;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.mascot-companion.minimized .companion-bubble {
  display: none;
}
.mascot-companion.minimized .companion-pet-card {
  padding: 6px;
  border-radius: 50%;
}
.mascot-companion.minimized .companion-meta {
  display: none;
}

.companion-bubble {
  pointer-events: auto;
  max-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font: 400 12.5px/1.45 var(--f-ui);
  position: relative;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s;
}
.companion-bubble:hover {
  border-color: var(--air);
  transform: translateY(-2px);
}
.companion-bubble::after {
  content: "";
  position: absolute;
  bottom: 12px;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid var(--surface);
}
.companion-bubble::before {
  content: "";
  position: absolute;
  bottom: 11px;
  right: -10px;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 9px solid var(--line);
}
.companion-bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.companion-bubble-header b {
  font: 600 11.5px/1 var(--f-console);
  color: var(--air);
  display: flex;
  align-items: center;
  gap: 4px;
}
.companion-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.companion-close-btn:hover {
  color: var(--ink);
}
.companion-bubble-text {
  margin: 0;
  color: var(--ink);
}

.companion-pet-card {
  pointer-events: auto;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: transform .18s cubic-bezier(0.34, 1.56, 0.64, 1), border-color .18s;
  user-select: none;
}
.companion-pet-card:hover {
  transform: translateY(-3px) scale(1.03);
  border-color: var(--air);
}
.companion-pet-card:active {
  transform: scale(0.97);
}
.companion-avatar {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.companion-avatar svg {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  shape-rendering: crispEdges;
}
.companion-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.companion-name {
  font: 700 12px/1 var(--f-console);
  color: var(--ink);
}
.companion-level {
  font: 600 11px/1 var(--f-console);
  color: var(--air);
}

/* ---------- Gamification Modal (#mascotDlg) ---------- */
.game-dlg {
  width: min(92vw, 680px);
  max-height: 88vh;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  padding: 0;
  overflow: hidden;
}
.game-dlg::backdrop {
  background: rgba(15, 12, 30, 0.65);
  backdrop-filter: blur(4px);
}
.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--sunk);
}
.game-head h3 {
  margin: 0;
  font: 700 18px/1 var(--f-console);
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(88vh - 70px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Hero Showcase Card */
.mascot-hero-card {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 20px;
  background: linear-gradient(135deg, var(--sunk) 0%, var(--surface) 100%);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px;
  align-items: center;
  position: relative;
  overflow: hidden;
}
.mascot-hero-card::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, rgba(229, 56, 59, 0.12) 0%, transparent 70%);
  pointer-events: none;
}
.mascot-hero-avatar-box {
  width: 128px;
  height: 128px;
  background: var(--surface);
  border: 2px dashed var(--line);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 0 auto;
}
.mascot-hero-avatar-box svg {
  width: 104px;
  height: 104px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  shape-rendering: crispEdges;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.15));
}
.mascot-stage-tag {
  position: absolute;
  bottom: -8px;
  background: var(--ink);
  color: var(--bg);
  font: 600 10px/1 var(--f-console);
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.mascot-hero-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mascot-title-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 700 13px/1 var(--f-console);
  color: var(--air);
}
.mascot-hero-name {
  margin: 0;
  font: 700 22px/1.2 var(--f-console);
  color: var(--ink);
}
.mascot-rank-desc {
  font: 400 13px/1.4 var(--f-ui);
  color: var(--muted);
  margin: 0;
}

/* XP Bar Big */
.game-xp-track {
  width: 100%;
  height: 10px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 2px;
  position: relative;
}
.game-xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--air), var(--game-xp));
  border-radius: 999px;
  transition: width .5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.game-xp-numbers {
  display: flex;
  justify-content: space-between;
  font: 600 11.5px/1 var(--f-console);
  color: var(--muted);
}

/* Quick Stats Bar */
.game-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.game-stat-card {
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px;
  text-align: center;
}
.game-stat-num {
  font: 700 18px/1 var(--f-console);
  color: var(--ink);
  margin-bottom: 3px;
}
.game-stat-label {
  font: 400 11px/1 var(--f-ui);
  color: var(--muted);
}

/* Tabs inside Dialog */
.game-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.game-tab-btn {
  background: none;
  border: 1px solid transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font: 600 13px/1 var(--f-ui);
  color: var(--muted);
  cursor: pointer;
  transition: all .15s ease;
}
.game-tab-btn.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--air);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* Wardrobe / Costume Grid */
.wardrobe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}
.wardrobe-item {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  transition: all .15s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.wardrobe-item:hover:not(.locked) {
  transform: translateY(-2px);
  border-color: var(--air);
  box-shadow: 0 4px 12px rgba(229, 56, 59, 0.12);
}
.wardrobe-item.equipped {
  border-color: var(--air);
  background: var(--sunk);
}
.wardrobe-item.equipped::after {
  content: "ใส่อยู่";
  position: absolute;
  top: 6px;
  right: 6px;
  font: 600 9px/1 var(--f-console);
  background: var(--air);
  color: #fff;
  padding: 2px 6px;
  border-radius: 999px;
}
.wardrobe-item.locked {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.8);
}
.wardrobe-avatar-preview {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wardrobe-avatar-preview svg {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.wardrobe-title {
  font: 600 12px/1.2 var(--f-console);
  color: var(--ink);
}
.wardrobe-req {
  font: 400 10.5px/1.2 var(--f-ui);
  color: var(--muted);
}

/* Badges / Achievements Grid */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.badge-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color .15s;
}
.badge-card.unlocked {
  border-color: var(--game-gold);
  background: linear-gradient(135deg, var(--surface) 0%, var(--game-gold-soft) 100%);
}
.badge-card.locked {
  opacity: 0.55;
  filter: grayscale(0.85);
}
.badge-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--sunk);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}
.badge-card.unlocked .badge-icon-box {
  background: var(--game-gold);
  color: #fff;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
}
.badge-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.badge-title {
  font: 700 12px/1.2 var(--f-console);
  color: var(--ink);
}
.badge-desc {
  font: 400 11px/1.3 var(--f-ui);
  color: var(--muted);
}
.badge-xp-reward {
  font: 600 10px/1 var(--f-console);
  color: var(--air);
}

/* XP Rules List */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--sunk);
  border-radius: var(--r-sm);
  font: 400 13px/1 var(--f-ui);
}
.rule-reward {
  font: 700 12px/1 var(--f-console);
  color: var(--air);
  background: var(--surface);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

/* ---------- Level Up Celebration Dialog ---------- */
.levelup-dlg {
  position: fixed;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  width: min(90vw, 420px);
  border: 2px solid var(--game-gold);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  padding: 24px;
  text-align: center;
  z-index: 95;
  overflow: hidden;
}
.levelup-dlg::backdrop {
  display: none;
}
.levelup-confetti-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}
.levelup-avatar-box {
  width: 100px;
  height: 100px;
  margin: 12px auto;
  position: relative;
  animation: pixel-bounce 1.5s ease-in-out infinite;
}
.levelup-avatar-box svg {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 6px 16px rgba(245, 158, 11, 0.4));
}
.levelup-header {
  font: 700 26px/1.2 var(--f-console);
  color: var(--game-gold);
  margin: 0 0 6px;
  letter-spacing: .02em;
}
.levelup-sub {
  font: 500 15px/1.4 var(--f-ui);
  color: var(--ink);
  margin: 0 0 16px;
}
.levelup-perk-box {
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  margin-bottom: 20px;
  font: 400 13px/1.4 var(--f-ui);
  color: var(--muted);
}
.levelup-perk-box b {
  color: var(--ink);
  display: block;
  font: 600 13.5px/1.2 var(--f-console);
  margin-bottom: 4px;
}

/* Floating XP Toast Indicator (+50 XP) */
.xp-float-toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: linear-gradient(135deg, var(--air), var(--game-xp));
  color: #fff;
  font: 700 13px/1 var(--f-console);
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: transform .6s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity .3s ease;
}
.xp-float-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-12px);
}

/* ---------- Responsive Adjustments ---------- */
@media (max-width: 560px) {
  .top {
    gap: 8px;
    padding: 12px 12px 6px;
  }
  .brand {
    gap: 8px;
    min-width: 0;
  }
  .brand-mascot-btn {
    padding: 1px;
  }
  .mascot-avatar-frame {
    width: 34px;
    height: 34px;
  }
  .mascot-lvl-pill {
    font-size: 8.5px;
    padding: 1px 4px;
    bottom: -3px;
    right: -3px;
  }
  .brand-title-row {
    gap: 4px;
  }
  .brand-title-row h1 {
    font-size: 19px;
  }
  .header-xp-chip {
    display: none; /* Keep header ultra compact on mobile */
  }
  .lamp {
    padding: 5px 8px;
  }
  .lamp #lampText {
    display: none; /* Keep lamp indicator dot */
  }
  .icon-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
  }
  .mascot-hero-card {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 12px;
  }
  .mascot-hero-avatar-box {
    width: 96px;
    height: 96px;
  }
  .mascot-hero-avatar-box svg {
    width: 80px;
    height: 80px;
  }
  .mascot-companion {
    right: 12px;
    bottom: calc(var(--transport-h) + 12px);
  }
  .companion-bubble {
    max-width: 180px;
    font-size: 11.5px;
    padding: 8px 10px;
  }
  .companion-avatar {
    width: 36px;
    height: 36px;
  }
  .game-stats-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .wardrobe-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .badges-grid {
    grid-template-columns: 1fr;
  }
}
