:root {
  --ink: #2d2150;
  --muted: #6b5b8c;
  --paper: #fff8ff;
  --accent: #7c4dff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Fredoka", "Noto Sans Thai", sans-serif;
  color: var(--ink);
  background: #12081f;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
a {
  font-family: inherit;
}

.a-scene,
a-scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#arjs-video,
.a-canvas {
  z-index: 1 !important;
}

body:not(.playing) #arjs-video,
body:not(.playing) .a-canvas {
  opacity: 0 !important;
  pointer-events: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  padding: max(16px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

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

#screen-home {
  z-index: 30;
  background: linear-gradient(180deg, #fff3fb 0%, #efe7ff 48%, #d9f4ff 100%);
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(8px);
  opacity: 0.55;
  animation: drift 8s ease-in-out infinite;
}

.blob-a {
  width: 180px;
  height: 180px;
  background: #ffb3d9;
  top: -40px;
  left: -30px;
}

.blob-b {
  width: 160px;
  height: 160px;
  background: #b39dff;
  top: 20%;
  right: -50px;
  animation-delay: -2s;
}

.blob-c {
  width: 200px;
  height: 200px;
  background: #9be7ff;
  bottom: -60px;
  left: 20%;
  animation-delay: -4s;
}

.home-hero {
  position: relative;
  text-align: center;
  margin-top: 24px;
}

.mascot {
  animation: bounce 2.4s ease-in-out infinite;
}

.badge {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.home-hero h1 {
  font-size: clamp(32px, 8vw, 48px);
  letter-spacing: 0.5px;
  margin-top: 8px;
}

.home-hero h1 span {
  color: #fff;
  background: linear-gradient(90deg, #ff6db3, #7c4dff, #26c6da);
  padding: 2px 12px 6px;
  border-radius: 16px;
}

.tagline {
  margin-top: 8px;
  color: var(--muted);
  font-size: 16px;
}

.mode-grid {
  position: relative;
  width: min(460px, 100%);
  display: grid;
  gap: 12px;
}

.mode-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 14px;
  text-align: left;
  border: 0;
  border-radius: 28px;
  padding: 18px 18px 18px 16px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(86, 40, 140, 0.12);
  cursor: pointer;
}

.mode-card.featured {
  background: linear-gradient(135deg, #7c4dff, #ff6db3);
  color: #fff;
}

.mode-card.featured small {
  color: rgba(255, 255, 255, 0.88);
}

.mode-card:active {
  transform: scale(0.97);
}

.mode-icon {
  grid-row: 1 / span 2;
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: #f4edff;
  font-size: 28px;
}

.mode-card.featured .mode-icon {
  background: rgba(255, 255, 255, 0.2);
}

.mode-card strong {
  font-size: 22px;
}

.mode-card small {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.home-actions {
  position: relative;
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.ghost-btn,
.primary-btn,
.speak-btn,
.icon-btn {
  border: 0;
  cursor: pointer;
}

.ghost-btn {
  text-decoration: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
}

.primary-btn {
  width: 100%;
  margin-top: 8px;
  padding: 14px 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, #7c4dff, #ff6db3);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(124, 77, 255, 0.28);
}

.panel {
  margin: auto;
  width: min(420px, 100%);
  background: var(--paper);
  border-radius: 32px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.panel h2 {
  font-size: 32px;
  margin-bottom: 12px;
}

.howto-list {
  text-align: left;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.6;
}

.howto-list li + li {
  margin-top: 8px;
}

.tip {
  margin: 16px 0 8px;
  color: #7c4dff;
  font-weight: 600;
}

#screen-howto,
#screen-complete {
  background: rgba(18, 8, 31, 0.45);
  backdrop-filter: blur(8px);
  z-index: 40;
}

#screen-play {
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(18, 8, 31, 0.55), transparent 18%, transparent 78%, rgba(18, 8, 31, 0.5));
  z-index: 15;
  pointer-events: none;
}

#screen-play button {
  pointer-events: auto;
}

.play-top {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 22px;
}

.mission-info {
  text-align: center;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.mission-info p {
  font-size: 13px;
  opacity: 0.9;
}

.mission-info h2 {
  font-size: 24px;
}

.score-pill {
  min-width: 64px;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 10px 12px;
  font-weight: 700;
}

.play-spacer {
  flex: 1;
}

.play-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.scan-hint {
  color: #fff;
  font-weight: 600;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.speak-btn {
  background: #fff;
  color: var(--ink);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.hidden {
  display: none !important;
}

.palette {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
}

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.75);
  opacity: 0.35;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: #fff;
  font-weight: 700;
}

.swatch.done {
  opacity: 1;
  transform: scale(1.08);
}

.swatch.current {
  opacity: 1;
  outline: 3px solid #fff;
  outline-offset: 2px;
  animation: pulse 1.2s ease-in-out infinite;
}

.overlay-screen {
  align-items: center;
  justify-content: center;
}

.complete-panel p {
  color: var(--muted);
  margin-bottom: 12px;
}

.rainbow-row {
  font-size: 64px;
  animation: bounce 1.6s ease-in-out infinite;
}

.complete-words {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 12px;
}

.word-chip {
  padding: 6px 10px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.cam-error {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  background: rgba(18, 8, 31, 0.72);
}

.cam-error.is-open {
  display: flex;
}

.cam-error .panel p {
  color: var(--muted);
  line-height: 1.55;
}

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

@keyframes drift {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(12px, 16px);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.12);
  }
}
