/* ==========================================================================
   The Arena Awaits — Quiz & Jigsaw Puzzle Style System
   Theme: Hunger Games Obsidian & Gold
   ========================================================================== */

:root {
  --bg-dark: #0a0a0a;
  --bg-card: rgba(18, 18, 18, 0.92);
  --gold-primary: #d4af37;
  --gold-light: #f1d57a;
  --gold-dark: #8a6d1f;
  --gold-glow: rgba(212, 175, 55, 0.4);
  --gold-gradient: linear-gradient(135deg, #bf953f 0%, #fcf6ba 25%, #b38728 50%, #fbf5b7 75%, #aa771c 100%);
  --font-serif: 'Cinzel', Georgia, 'Times New Roman', serif;
  --font-display: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
  --font-mono: 'Fira Code', 'Courier New', monospace;

  --board-size: min(85vw, 460px);
  --grid-size: 4;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Reset & Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-dark);
  color: #e0e0e0;
  font-family: var(--font-serif);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Canvas Background for Drifting Gold Particles */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 100vh;
  padding: 1.5rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.2rem;
  text-align: center;
  position: relative;
}

.header-content {
  flex: 1;
}

.game-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  font-weight: 700;
  letter-spacing: 4px;
  background: var(--gold-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 20px rgba(212, 175, 55, 0.35);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.game-subtitle {
  font-size: clamp(0.85rem, 2.5vw, 1.1rem);
  color: #a0a0a0;
  letter-spacing: 2px;
  font-style: italic;
}

/* Icon Buttons (Sound, etc.) */
.icon-btn {
  background: rgba(20, 20, 20, 0.7);
  border: 1px solid rgba(212, 175, 55, 0.4);
  color: var(--gold-primary);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(4px);
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.icon-btn:hover,
.icon-btn:focus-visible {
  border-color: var(--gold-light);
  box-shadow: 0 0 12px var(--gold-glow);
  transform: translateY(-50%) scale(1.08);
}

.sound-icon {
  width: 22px;
  height: 22px;
}

.hidden {
  display: none !important;
}

/* Layout */
.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  width: 100%;
}

@media (min-width: 900px) {
  .game-layout {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 2.5rem;
  }
}

/* Status Bar & Dual Counters */
.status-bar {
  margin-bottom: 1rem;
  text-align: center;
}

.status-counter-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: rgba(15, 15, 15, 0.8);
  border: 1px solid rgba(212, 175, 55, 0.3);
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.progress-counter {
  font-size: 0.95rem;
  letter-spacing: 1px;
  color: #ccc;
}

.progress-counter strong {
  color: var(--gold-light);
  font-size: 1.15rem;
}

.progress-divider {
  color: var(--gold-primary);
}

/* 3D Card & Board Container */
.puzzle-perspective {
  perspective: 1200px;
  width: var(--board-size);
  height: var(--board-size);
  margin: 0 auto;
  position: relative;
}

.flip-card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 1.6s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 8px;
}

.flip-card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 15px rgba(212, 175, 55, 0.15);
  overflow: hidden;
}

.card-face.front {
  background: #111;
  border: 1px solid rgba(212, 175, 55, 0.3);
}

.card-face.back {
  transform: rotateY(180deg);
  background: #0a0a0a;
}

/* Puzzle Board Grid Container */
.board-container {
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #0d0d0d;
}

/* Grid Overlay Guide */
.grid-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  pointer-events: none;
  z-index: 1;
}

.grid-cell-guide {
  border: 1px dashed rgba(212, 175, 55, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: rgba(212, 175, 55, 0.3);
  transition: all 0.2s ease;
}

.board-container.all-locked .grid-overlay {
  opacity: 0;
  transition: opacity 0.5s ease;
}

/* Hint Preview */
.hint-preview {
  position: absolute;
  inset: 0;
  background-image: url('assets/puzzle-front.png?v=2');
  background-size: cover;
  background-position: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 2;
}

.hint-preview.active {
  opacity: 0.35;
}

/* Gold Sweep Light Effect */
.gold-sweep {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background: linear-gradient(90deg, transparent 0%, rgba(241, 213, 122, 0.6) 50%, transparent 100%);
  transform: skewX(-25deg);
  left: -100%;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
}

.gold-sweep.active {
  opacity: 1;
  animation: goldSweep 1.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes goldSweep {
  0% {
    left: -100%;
    opacity: 0.9;
  }

  100% {
    left: 200%;
    opacity: 0;
  }
}

/* Back Card Design */
.back-card {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  background-color: #080808;
  border: 2px solid var(--gold-primary);
  outline: 1px solid var(--gold-dark);
  outline-offset: -8px;
}

/* Corner SVGs */
.corner-ornament {
  position: absolute;
  width: 36px;
  height: 36px;
  pointer-events: none;
  z-index: 3;
}

.corner-ornament.top-left {
  top: 12px;
  left: 12px;
}

.corner-ornament.top-right {
  top: 12px;
  right: 12px;
}

.corner-ornament.bottom-left {
  bottom: 12px;
  left: 12px;
}

.corner-ornament.bottom-right {
  bottom: 12px;
  right: 12px;
}

/* Back Pattern */
.back-pattern {
  position: absolute;
  inset: 12px;
  opacity: 0.08;
  background-image: radial-gradient(circle, var(--gold-primary) 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
}

.back-content {
  position: relative;
  z-index: 4;
  text-align: center;
  padding: 1rem;
}

.emblem-symbol {
  color: var(--gold-primary);
  font-size: 1.2rem;
  letter-spacing: 6px;
  margin-bottom: 1rem;
}

.back-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 5vw, 2.5rem);
  font-weight: 900;
  letter-spacing: 4px;
  background: var(--gold-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 25px rgba(241, 213, 122, 0.5);
  margin-bottom: 0.8rem;
  text-transform: uppercase;
}

.gold-divider {
  width: 80px;
  height: 2px;
  background: var(--gold-gradient);
  margin: 0.8rem auto;
  box-shadow: 0 0 8px var(--gold-glow);
}

.back-subtitle {
  font-size: clamp(0.9rem, 2.5vw, 1.15rem);
  color: var(--gold-light);
  font-style: italic;
  letter-spacing: 1.5px;
  opacity: 0.95;
}

/* Reveal Container & Buttons */
.reveal-container {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 55px;
}

.tap-reveal-btn {
  position: relative;
  background: #000000;
  border: 2px solid var(--gold-primary);
  color: var(--gold-light);
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 0.85rem 2.2rem;
  border-radius: 4px;
  cursor: pointer;
  overflow: hidden;
  transition: all var(--transition-normal);
  box-shadow: 0 0 15px rgba(212, 175, 55, 0.25);
  animation: pulseGlow 2.5s infinite ease-in-out;
}

.tap-reveal-btn:hover,
.tap-reveal-btn:focus-visible {
  border-color: #fff;
  color: #fff;
  transform: scale(1.05);
  box-shadow: 0 0 25px rgba(241, 213, 122, 0.6);
}

@keyframes pulseGlow {

  0%,
  100% {
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.25);
  }

  50% {
    box-shadow: 0 0 28px rgba(241, 213, 122, 0.6);
  }
}

.flip-back-btn {
  background: transparent;
  border: 1px solid rgba(212, 175, 55, 0.5);
  color: var(--gold-primary);
  font-size: 0.9rem;
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.flip-back-btn:hover,
.flip-back-btn:focus-visible {
  border-color: var(--gold-light);
  color: var(--gold-light);
  background: rgba(212, 175, 55, 0.1);
}

/* Side Section (Questions + Tray) */
.side-section {
  width: var(--board-size);
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

/* Questions Grid Panel */
.questions-panel {
  background: var(--bg-card);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.panel-header h2,
.tray-header h2 {
  font-size: 0.95rem;
  letter-spacing: 2px;
  color: var(--gold-primary);
  margin-bottom: 0.8rem;
  text-transform: uppercase;
}

.questions-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.q-btn {
  background: rgba(25, 25, 25, 0.8);
  border: 1px solid rgba(212, 175, 55, 0.4);
  color: var(--gold-light);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.65rem 0.2rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}

.q-btn:hover,
.q-btn:focus-visible {
  border-color: #fff;
  color: #fff;
  background: rgba(50, 50, 50, 0.9);
  box-shadow: 0 0 10px var(--gold-glow);
  transform: translateY(-2px);
}

.q-btn.solved {
  background: var(--gold-gradient);
  border-color: var(--gold-light);
  color: #000;
  box-shadow: 0 0 8px var(--gold-glow);
  cursor: default;
}

.q-btn.solved:hover {
  transform: none;
}

.q-btn.cooldown {
  opacity: 0.5;
  border-color: #e74c3c;
  color: #ff6b6b;
  cursor: not-allowed;
  font-size: 0.75rem;
}

/* Tray Panel */
.tray-panel {
  background: var(--bg-card);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
}

.tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(212, 175, 55, 0.15);
  padding-bottom: 0.6rem;
}

.tray-controls {
  display: flex;
  gap: 0.5rem;
}

.action-btn {
  background: rgba(30, 30, 30, 0.8);
  border: 1px solid rgba(212, 175, 55, 0.4);
  color: #e0e0e0;
  font-family: var(--font-serif);
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.action-btn:hover,
.action-btn:focus-visible {
  border-color: var(--gold-light);
  color: var(--gold-light);
  background: rgba(50, 50, 50, 0.9);
}

.action-btn.danger:hover,
.action-btn.danger:focus-visible {
  border-color: #e74c3c;
  color: #ff6b6b;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #555;
}

/* Piece Tray Container */
.piece-tray {
  min-height: 260px;
  position: relative;
  background: rgba(10, 10, 10, 0.6);
  border: 1px inset rgba(212, 175, 55, 0.15);
  border-radius: 6px;
  overflow: visible;
  touch-action: none;
  margin-top: 0.8rem;
}

/* Square Puzzle Piece Element */
.puzzle-piece {
  position: absolute;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  box-sizing: border-box;
  border: 1px solid var(--gold-primary);
  border-radius: 3px;
  background-image: url('assets/puzzle-front.png?v=2');
  background-repeat: no-repeat;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), inset 0 0 6px rgba(212, 175, 55, 0.25);
  will-change: transform, left, top;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  z-index: 10;
}

.puzzle-piece:hover {
  border-color: var(--gold-light);
  box-shadow: 0 0 15px var(--gold-glow), inset 0 0 10px rgba(241, 213, 122, 0.4);
}

.puzzle-piece:active,
.puzzle-piece.dragging {
  cursor: grabbing;
  z-index: 2000 !important;
  border-color: #ffffff;
  box-shadow: 0 8px 25px rgba(241, 213, 122, 0.7);
}

/* Movable Piece on Board Grid */
.puzzle-piece.on-board {
  border-color: var(--gold-light);
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.3);
  z-index: 5;
}

/* Quiz-Locked Piece State */
.puzzle-piece.quiz-locked {
  cursor: not-allowed !important;
  pointer-events: auto;
  border-color: rgba(138, 109, 31, 0.4);
  filter: brightness(0.2) grayscale(0.5);
  z-index: 1 !important;
}

.piece-lock-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-light);
  font-size: 1.5rem;
  z-index: 20;
  border-radius: 2px;
  pointer-events: none;
}

/* Piece Unlocked Animation */
.puzzle-piece.just-unlocked {
  animation: unlockFlash 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes unlockFlash {
  0% {
    transform: scale(1.3);
    filter: drop-shadow(0 0 25px #f1d57a);
  }

  100% {
    transform: scale(1);
    filter: drop-shadow(0 0 5px rgba(212, 175, 55, 0.4));
  }
}

/* Snap Pulse Animation */
.snap-lock-anim {
  animation: snapPulse 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes snapPulse {
  0% {
    transform: scale(1.1);
    box-shadow: 0 0 25px #f1d57a;
  }

  100% {
    transform: scale(1);
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.4);
  }
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  padding: 1rem;
}

.modal-box {
  background: #141414;
  border: 1px solid var(--gold-primary);
  border-radius: 8px;
  padding: 1.8rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.9), 0 0 20px var(--gold-glow);
  position: relative;
}

.modal-close-x {
  position: absolute;
  top: 10px;
  right: 14px;
  background: transparent;
  border: none;
  color: #888;
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close-x:hover {
  color: var(--gold-light);
}

.modal-title {
  font-family: var(--font-display);
  color: var(--gold-light);
  font-size: 1.25rem;
  letter-spacing: 2px;
  margin-bottom: 1rem;
}

.modal-text {
  font-size: 0.95rem;
  color: #ccc;
  line-height: 1.5;
  margin-bottom: 1.2rem;
}

/* Quiz Question Text Body */
.quiz-question-body {
  text-align: left;
  background: #080808;
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1.2rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #e0e0e0;
  white-space: pre-wrap;
}

.quiz-question-body code,
.quiz-question-body pre {
  font-family: var(--font-mono);
  background: #1a1a1a;
  color: var(--gold-light);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.quiz-question-body pre {
  padding: 0.8rem;
  margin-top: 0.5rem;
  overflow-x: auto;
}

.quiz-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

@media (min-width: 480px) {
  .quiz-form {
    flex-direction: row;
  }
}

.code-input-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.code-input {
  flex: 1;
  background: #080808;
  border: 1px solid rgba(212, 175, 55, 0.4);
  color: var(--gold-light);
  font-family: var(--font-serif);
  font-size: 1rem;
  padding: 0.65rem 0.8rem;
  border-radius: 4px;
  outline: none;
}

.code-input:focus {
  border-color: var(--gold-light);
  box-shadow: 0 0 10px var(--gold-glow);
}

.quiz-status-msg {
  font-size: 0.9rem;
  margin-bottom: 1rem;
  padding: 0.5rem;
  border-radius: 4px;
}

.quiz-status-msg.error {
  color: #ff6b6b;
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid rgba(231, 76, 60, 0.4);
}

.quiz-status-msg.cooldown {
  color: #f39c12;
  background: rgba(243, 156, 18, 0.15);
  border: 1px solid rgba(243, 156, 18, 0.4);
}

.quiz-status-msg.success {
  color: #2ecc71;
  background: rgba(46, 204, 113, 0.15);
  border: 1px solid rgba(46, 204, 113, 0.4);
}

.code-error {
  color: #ff6b6b;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.modal-btn {
  padding: 0.6rem 1.4rem;
  font-family: var(--font-serif);
  font-size: 0.9rem;
  letter-spacing: 1px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-btn.primary {
  background: var(--gold-primary);
  border: 1px solid var(--gold-light);
  color: #000;
  font-weight: 700;
}

.modal-btn.primary:hover {
  background: var(--gold-light);
  box-shadow: 0 0 12px var(--gold-glow);
}

.modal-btn.secondary {
  background: transparent;
  border: 1px solid #555;
  color: #ccc;
}

.modal-btn.secondary:hover {
  border-color: #888;
  color: #fff;
}

/* Modal Shake Animation */
.modal-box.shake {
  animation: modalShake 0.4s ease;
}

@keyframes modalShake {

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

  20%,
  60% {
    transform: translateX(-8px);
  }

  40%,
  80% {
    transform: translateX(8px);
  }
}

/* Screen Shake Animation for Reveal Flip */
.app-container.screen-shake {
  animation: screenShake 0.6s ease-in-out;
}

@keyframes screenShake {

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

  15%,
  45%,
  75% {
    transform: translate(-5px, 3px);
  }

  30%,
  60%,
  90% {
    transform: translate(5px, -3px);
  }
}

/* Dim Page Background during Flip */
body.flipping #bg-canvas {
  filter: brightness(0.3);
  transition: filter 1s ease;
}

/* Footer Link */
.game-footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.75rem;
  color: #666;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}


/* SVG Defs Helper */
.svg-defs-container {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .flip-card {
    transition: transform 0.3s ease !important;
  }

  .app-container.screen-shake {
    animation: none !important;
  }

  .tap-reveal-btn {
    animation: none !important;
  }

  #bg-canvas {
    display: none;
  }
}