/* ============================================
   NUMERIA — Kingdom of Learning
   style.css — Layout, animations, UI components
   ============================================ */

/* --- CSS Variables (Colour Palette) --- */
:root {
  --arcane-violet: #7C5CE8;
  --kingdom-gold: #EF9F27;
  --enchanted-teal: #1D9E75;
  --dragon-ember: #D85A30;
  --crystal-blue: #378ADD;
  --midnight: #0D0A1A;
  --parchment: #FAF6EE;
  --panel-bg: rgba(13, 10, 26, 0.75);
  --panel-border: rgba(124, 92, 232, 0.3);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--midnight);
  font-family: -apple-system, BlinkMacSystemFont, "San Francisco", "Helvetica Neue", sans-serif;
  color: white;
  touch-action: manipulation;
}

/* --- Screen System --- */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100dvh;
  display: none;
  opacity: 0;
  transition: opacity 300ms ease;
}

.screen.active {
  display: flex;
  opacity: 1;
}

.screen.fade-in {
  opacity: 1;
}

.screen.fade-out {
  opacity: 0;
}

/* --- Splash Screen --- */
#splash {
  background: radial-gradient(ellipse at center, #1a1040 0%, var(--midnight) 100%);
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#crown-logo {
  width: 200px;
  height: 200px;
}

.game-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 56px;
  font-weight: bold;
  background: linear-gradient(180deg, #FFE87A 0%, #EF9F27 50%, #D4920A 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 6px;
  text-shadow: none;
}

.game-subtitle {
  font-size: 18px;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 400;
  letter-spacing: 3px;
  text-transform: uppercase;
}

/* --- Buttons --- */
.btn-primary {
  background: linear-gradient(180deg, var(--arcane-violet) 0%, #5a3cc8 100%);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 16px 48px;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 100ms ease;
  min-width: 48px;
  min-height: 48px;
  box-shadow: 0 4px 16px rgba(124, 92, 232, 0.4);
}

.btn-primary:active,
.btn-primary.pressed {
  transform: scale(0.95);
}

.btn-danger {
  background: linear-gradient(180deg, var(--dragon-ember) 0%, #a03e1e 100%);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
}

.pulse-btn {
  animation: pulse 2s ease-in-out infinite;
}

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

/* --- Kingdom Screen Layout --- */
.kingdom-layout {
  display: flex;
  width: 100%;
  height: calc(100dvh - 48px);
  position: relative;
}

#kingdom {
  flex-direction: column;
}

/* Side Panels */
.side-panel {
  width: 160px;
  min-width: 160px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  overflow-y: auto;
  z-index: 2;
}

#right-panel {
  border-right: none;
  border-left: 1px solid var(--panel-border);
}

.panel-title {
  font-family: Georgia, serif;
  font-size: 16px;
  color: var(--kingdom-gold);
  margin-bottom: 4px;
}

/* Hero Avatar */
.hero-avatar-wrap {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid var(--arcane-violet);
  overflow: hidden;
  background: rgba(124, 92, 232, 0.15);
}

#hero-avatar {
  width: 96px;
  height: 96px;
}

.hero-name {
  font-weight: 600;
  font-size: 16px;
  color: var(--parchment);
}

/* Stats */
.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 8px;
}

.stat-icon {
  width: 24px;
  height: 24px;
  display: inline-block;
}

.star-icon::before {
  content: "\2B50";
  font-size: 20px;
}

.quest-icon::before {
  content: "\2694";
  font-size: 20px;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--kingdom-gold);
}

/* Companions Grid */
.companions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: 100%;
  margin-top: 8px;
}

.companion-slot {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto;
}

.companion-slot.locked {
  opacity: 0.2;
}

.companion-slot.unlocked {
  opacity: 1;
  background: rgba(29, 158, 117, 0.2);
  border: 1px solid var(--enchanted-teal);
}

/* Centre Canvas */
#kingdom-center {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#kingdom-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Dialogue Bubble */
.dialogue-bubble {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 2px solid var(--kingdom-gold);
  border-radius: 16px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  z-index: 5;
  max-width: 300px;
  animation: bubble-float 3s ease-in-out infinite;
}

.dialogue-bubble.hidden {
  display: none;
}

#dialogue-text {
  font-size: 14px;
  color: var(--parchment);
}

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

/* Quest Log */
.quest-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.quest-card {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background 200ms ease;
}

.quest-card.active {
  background: rgba(124, 92, 232, 0.2);
  border: 1px solid var(--arcane-violet);
}

.quest-card.completed {
  background: rgba(29, 158, 117, 0.15);
  border: 1px solid rgba(29, 158, 117, 0.3);
}

.quest-card.locked {
  opacity: 0.4;
}

.quest-card-icon {
  font-size: 18px;
  min-width: 24px;
  text-align: center;
}

.quest-card-info {
  flex: 1;
}

.quest-card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--parchment);
}

.quest-card-reward {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
}

/* Bottom Nav */
.bottom-nav {
  height: 48px;
  background: var(--panel-bg);
  border-top: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 10;
}

.nav-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 24px;
  padding: 8px 24px;
  cursor: pointer;
  position: relative;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 200ms ease;
}

.nav-btn.active {
  color: white;
}

.nav-btn.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: var(--arcane-violet);
  border-radius: 2px;
}

/* --- Quest Intro Screen --- */
.quest-intro-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: radial-gradient(ellipse at center, #1a1040 0%, var(--midnight) 100%);
  padding: 32px;
}

#npc-avatar {
  width: 200px;
  height: 200px;
}

.speech-bubble {
  background: var(--panel-bg);
  border: 2px solid var(--kingdom-gold);
  border-radius: 20px;
  padding: 20px 28px;
  max-width: 500px;
  position: relative;
}

.speech-bubble p {
  font-size: 18px;
  line-height: 1.5;
  color: var(--parchment);
}

.speech-bubble::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 12px solid var(--kingdom-gold);
}

/* --- Puzzle Screens (shared) --- */
.puzzle-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: radial-gradient(ellipse at center, #1a1040 0%, var(--midnight) 100%);
  padding: 16px;
  position: relative;
}

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

.star-tracker {
  display: flex;
  gap: 4px;
}

.star-tracker .star {
  font-size: 20px;
  opacity: 0.3;
}

.star-tracker .star.earned {
  opacity: 1;
  animation: star-pop 300ms ease;
}

@keyframes star-pop {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.progress-label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
}

.puzzle-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

/* Math Question */
.math-question {
  font-family: Georgia, serif;
  font-size: 64px;
  font-weight: bold;
  color: white;
  text-align: center;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.math-question .blank {
  width: 72px;
  height: 72px;
  border: 3px dashed var(--kingdom-gold);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--kingdom-gold);
  font-size: 48px;
}

/* Answer Grid */
.answer-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.answer-btn {
  width: 80px;
  height: 80px;
  border-radius: 16px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: white;
  font-family: Georgia, serif;
  font-size: 36px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 100ms ease, background 200ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
}

.answer-btn:active,
.answer-btn.pressed {
  transform: scale(0.95);
}

.answer-btn.correct {
  background: rgba(29, 158, 117, 0.4);
  border-color: var(--enchanted-teal);
  animation: correct-flash 500ms ease;
}

.answer-btn.wrong {
  background: rgba(216, 90, 48, 0.4);
  border-color: var(--dragon-ember);
  animation: wrong-shake 400ms ease;
}

@keyframes correct-flash {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 24px var(--enchanted-teal); }
}

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

/* Hint Button */
.hint-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid var(--kingdom-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hint-btn.hidden {
  display: none;
}

.hint-icon {
  font-size: 28px;
}

/* Number Line */
.number-line {
  display: flex;
  gap: 2px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  margin-top: 8px;
}

.number-line.hidden {
  display: none;
}

.number-line .nl-num {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.5);
}

.number-line .nl-num.highlight {
  background: var(--arcane-violet);
  color: white;
}

/* --- Chess Board --- */
.chess-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.chess-dialogue {
  font-size: 16px;
  color: var(--parchment);
  text-align: center;
  min-height: 24px;
  max-width: 500px;
}

.chess-board {
  display: grid;
  grid-template-columns: 24px repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr) 24px;
  width: min(512px, calc(100dvh - 200px));
  height: min(512px, calc(100dvh - 200px));
  aspect-ratio: 1;
  border: 3px solid rgba(124, 92, 232, 0.5);
  border-radius: 4px;
}

.chess-rank-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  width: 24px;
}

.chess-file-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  height: 24px;
}

.chess-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  position: relative;
  cursor: pointer;
  transition: background 200ms ease;
}

.chess-cell.light {
  background: rgba(250, 246, 238, 0.15);
}

.chess-cell.dark {
  background: rgba(124, 92, 232, 0.15);
}

.chess-cell.valid-move {
  border: 4px solid var(--enchanted-teal);
  background: rgba(29, 158, 117, 0.2);
}

.chess-cell .square-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: 10px;
  color: white;
  background: rgba(0, 0, 0, 0.5);
  padding: 1px 3px;
  border-radius: 3px;
}

.chess-cell .square-badge.pulse-gold {
  animation: badge-pulse 600ms ease 3;
  color: var(--kingdom-gold);
}

@keyframes badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); color: var(--kingdom-gold); }
}

.chess-cell.danger {
  background: rgba(216, 90, 48, 0.3);
}

/* --- Spell Scroll --- */
.spell-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
}

.scroll-area {
  background: linear-gradient(180deg, #FAF6EE 0%, #E8DFD0 100%);
  border-radius: 12px;
  padding: 24px 32px;
  min-width: 280px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.scroll-area .letter-slot {
  width: 56px;
  height: 56px;
  border: 2px dashed rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, serif;
  font-size: 36px;
  font-weight: bold;
  color: #2A0A60;
}

.scroll-area .letter-slot.filled {
  border-color: var(--enchanted-teal);
  background: rgba(29, 158, 117, 0.1);
}

.letter-tiles {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.letter-tile {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  font-family: Georgia, serif;
  font-size: 32px;
  font-weight: bold;
  color: #2A0A60;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 200ms ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.letter-tile.gold {
  background: linear-gradient(180deg, #FFE44A, #EF9F27);
}

.letter-tile.blue {
  background: linear-gradient(180deg, #5BAEFF, #378ADD);
}

.letter-tile:active {
  transform: scale(0.9);
}

.letter-tile.snapped {
  transform: scale(0);
  opacity: 0;
  transition: all 300ms ease;
}

/* --- Quest Complete Screen --- */
.celebration-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: radial-gradient(ellipse at center, #1a1040 0%, var(--midnight) 100%);
}

.celebration-title {
  font-family: Georgia, serif;
  font-size: 40px;
  background: linear-gradient(180deg, #FFE87A 0%, #EF9F27 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stars-awarded {
  display: flex;
  gap: 8px;
  font-size: 32px;
}

.building-text {
  font-size: 18px;
  color: var(--parchment);
  text-align: center;
}

/* --- Parent Menu --- */
.parent-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--midnight);
  padding: 32px;
  max-width: 400px;
  margin: 0 auto;
}

#parent_menu {
  justify-content: center;
  align-items: center;
}

.parent-title {
  font-family: Georgia, serif;
  font-size: 24px;
  color: var(--kingdom-gold);
}

.setting-group {
  width: 100%;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-group label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
}

.setting-group select,
.setting-group input[type="range"] {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 14px;
}

.setting-group select option {
  background: var(--midnight);
  color: white;
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

/* --- Feedback Overlays --- */
.feedback-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: bold;
  z-index: 100;
  pointer-events: none;
  animation: feedback-show 800ms ease forwards;
}

.feedback-overlay.correct {
  color: var(--enchanted-teal);
}

.feedback-overlay.wrong {
  color: var(--dragon-ember);
}

@keyframes feedback-show {
  0% { opacity: 0; transform: scale(0.5); }
  30% { opacity: 1; transform: scale(1.2); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1) translateY(-30px); }
}

/* --- Star Burst Particles (CSS fallback) --- */
@keyframes star-burst {
  0% { opacity: 1; transform: scale(0) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.5) rotate(180deg); }
  100% { opacity: 0; transform: scale(0.5) rotate(360deg) translateY(-60px); }
}
