/* =============================================
   ADVENTOPIA — Landscape-Only Responsive CSS
   Optimized for mobile, tablet, and desktop
   ============================================= */

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

html, body {
  width: 100%;
  height: 100%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #1a1a2e;
  color: #333;
  overflow: hidden;
}

/* -----------------------------------------------
   ORIENTATION LOCK WARNING
   Shows if user tries to use portrait mode
   ----------------------------------------------- */

#orientation-warning {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #1a1a2e;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
  text-align: center;
  padding: 24px;
}

#orientation-warning.show {
  display: flex;
}

#orientation-warning h2 {
  font-size: 1.8rem;
  margin-bottom: 16px;
  color: #ffb347;
}

#orientation-warning p {
  font-size: 1rem;
  opacity: 0.9;
  max-width: 300px;
  line-height: 1.6;
}

/* -----------------------------------------------
   LOADING SCREEN
   ----------------------------------------------- */

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e 0%, #2C5F8A 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  color: white;
  text-align: center;
}

#loading-screen h1 {
  font-size: 3rem;
  margin-bottom: 12px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#loading-screen p {
  font-size: 1.1rem;
  opacity: 0.85;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.5; }
}

/* -----------------------------------------------
   FREDOKA ONE — Applied selectively to UI labels,
   headings, and buttons only. Dialogue and puzzle
   description text stays in the readable system font.
   ----------------------------------------------- */

#loading-screen h1,
#dialogue-close,
#hint-close,
#reward-close,
#reward-text,
#hint-text,
#orientation-warning h2,
#error-screen h2,
.inventory-slot,
.menu-item,
#menu-btn {
  font-family: 'Fredoka One', 'Segoe UI', sans-serif;
}

/* -----------------------------------------------
   GAME CONTAINER
   Main game layout with HUD and scene
   ----------------------------------------------- */

#game-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #1a1a2e;
  position: relative;
}

#game-container.hidden,
#loading-screen.hidden,
#error-screen.hidden,
#orientation-warning.hidden,
#reward-overlay.hidden,
#hint-overlay.hidden,
#dialogue-box.hidden,
#puzzle-overlay.hidden,
#game-menu.hidden {
  display: none !important;
}

/* -----------------------------------------------
   HUD — inventory only, slim bar
   ----------------------------------------------- */

#hud {
  width: 100%;
  height: 52px;
  background-color: transparent;
  display: flex;
  align-items: center;
  padding: 0 56px 0 16px;
  z-index: 100;
  flex-shrink: 0;
  pointer-events: none;
}

#hud .inventory-slot {
  pointer-events: all;
}

#inventory-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
}

#inventory-bar::-webkit-scrollbar { height: 3px; }
#inventory-bar::-webkit-scrollbar-track { background: rgba(255,255,255,0.1); border-radius: 2px; }
#inventory-bar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }

.inventory-slot {
  width: 40px;
  height: 40px;
  background-color: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.2s;
}

.inventory-slot:hover {
  background-color: rgba(255,255,255,0.25);
  transform: scale(1.05);
}

/* -----------------------------------------------
   FLOATING MENU BUTTON
   ----------------------------------------------- */

#menu-btn {
  position: fixed;
  top: 8px;
  right: 12px;
  width: 42px;
  height: 42px;
  background: rgba(44, 95, 138, 0.92);
  backdrop-filter: blur(6px);
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 12px;
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#menu-btn:hover,
#menu-btn:active {
  background: rgba(58, 125, 201, 0.95);
  transform: scale(1.08);
}

#menu-btn.pulse {
  animation: menuPulse 1.2s ease-in-out 3;
}

@keyframes menuPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,215,0,0.7); }
  50%       { box-shadow: 0 0 0 10px rgba(255,215,0,0); }
}

/* -----------------------------------------------
   SLIDE-DOWN GAME MENU
   ----------------------------------------------- */

#game-menu {
  position: fixed;
  top: 58px;
  right: 12px;
  background: rgba(26, 35, 126, 0.97);
  backdrop-filter: blur(10px);
  border: 1.5px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  padding: 8px;
  z-index: 499;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transform-origin: top right;
}

#game-menu:not(.hidden) {
  animation: menuOpen 0.2s ease-out;
}

@keyframes menuOpen {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.menu-item {
  background: rgba(255,255,255,0.08);
  color: white;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-family: 'Fredoka One', 'Segoe UI', sans-serif;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.menu-item:hover,
.menu-item:active {
  background: rgba(255,255,255,0.18);
}

.menu-item.danger {
  color: #ff8a80;
  border-color: rgba(255,138,128,0.25);
}

.menu-item.danger:hover,
.menu-item.danger:active {
  background: rgba(229,57,53,0.2);
}

/* -----------------------------------------------
   SCENE AREA
   Main game canvas and interactive area
   ----------------------------------------------- */

#scene-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0f0f1e;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
  touch-action: none;
}

/* -----------------------------------------------
   DIALOGUE BOX
   NPC dialogue and story text
   ----------------------------------------------- */

#dialogue-box {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 600px;
  background-color: white;
  border-radius: 16px;
  padding: 20px 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 200;
  text-align: center;
}

#dialogue-box:not(.hidden) {
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

#dialogue-text {
  font-size: 1rem;
  color: #333;
  line-height: 1.6;
  margin-bottom: 14px;
}

#dialogue-close {
  background-color: #2C5F8A;
  color: white;
  border: none;
  border-radius: 20px;
  padding: 8px 28px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.2s;
  user-select: none;
}

#dialogue-close:hover,
#dialogue-close:active {
  background-color: #3A7DC9;
}

/* -----------------------------------------------
   PUZZLE OVERLAY
   Puzzle interface container
   ----------------------------------------------- */

#puzzle-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
  z-index: 300;
}

#puzzle-overlay:not(.hidden) {
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#puzzle-container {
  background-color: white;
  border-radius: 20px;
  padding: 28px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  scroll-behavior: smooth;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  text-align: center;
}

#puzzle-container::-webkit-scrollbar {
  width: 8px;
}

#puzzle-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

#puzzle-container::-webkit-scrollbar-thumb {
  background: #2C5F8A;
  border-radius: 4px;
}

#puzzle-container::-webkit-scrollbar-thumb:hover {
  background: #3A7DC9;
}

/* -----------------------------------------------
   HINT OVERLAY
   Lumie the hint character
   ----------------------------------------------- */

#hint-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 400;
}

#hint-overlay:not(.hidden) {
  animation: fadeIn 0.2s ease-out;
}

#hint-box {
  background: linear-gradient(135deg, #fffbe6, #fff8d0);
  border: 3px solid #f5c842;
  border-radius: 20px;
  padding: 28px;
  width: 85%;
  max-width: 460px;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}

#hint-overlay:not(.hidden) #hint-box {
  animation: bounceIn 0.4s ease-out;
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

#hint-text {
  font-size: 1rem;
  color: #444;
  line-height: 1.6;
  margin-bottom: 16px;
}

#hint-close {
  background-color: #f5c842;
  color: #333;
  border: none;
  border-radius: 20px;
  padding: 8px 28px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.2s;
  user-select: none;
}

#hint-close:hover,
#hint-close:active {
  background-color: #e0b030;
}

/* -----------------------------------------------
   REWARD OVERLAY
   Badges and key pieces celebration
   ----------------------------------------------- */

#reward-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  z-index: 400;
}

#reward-overlay:not(.hidden) {
  animation: fadeIn 0.2s ease-out;
}

#reward-box {
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  border: 3px solid #4CAF50;
  border-radius: 20px;
  padding: 32px;
  width: 85%;
  max-width: 460px;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}

#reward-overlay:not(.hidden) #reward-box {
  animation: bounceIn 0.4s ease-out;
}

#reward-text {
  font-size: 1.1rem;
  color: #2e7d32;
  line-height: 1.6;
  margin-bottom: 16px;
  font-weight: bold;
}

#reward-close {
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 20px;
  padding: 8px 28px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.2s;
  user-select: none;
}

#reward-close:hover,
#reward-close:active {
  background-color: #388e3c;
}

/* -----------------------------------------------
   ERROR SCREEN
   ----------------------------------------------- */

#error-screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #1a1a2e;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  color: white;
  text-align: center;
  padding: 24px;
}

#error-screen h2 {
  font-size: 2rem;
  margin-bottom: 12px;
  color: #ff6b6b;
}

#error-screen p {
  font-size: 1rem;
  opacity: 0.8;
  margin-bottom: 24px;
  max-width: 360px;
  line-height: 1.6;
}

#error-screen button {
  background-color: #3A7DC9;
  color: white;
  border: none;
  border-radius: 20px;
  padding: 10px 32px;
  font-size: 1rem;
  cursor: pointer;
  user-select: none;
}

#error-screen button:hover {
  background-color: #4a8dd9;
}

/* -----------------------------------------------
   RESPONSIVE DESIGN
   Landscape-optimized breakpoints
   ----------------------------------------------- */

/* Mobile Landscape (320px - 767px width) */
@media (max-width: 767px) {
  #hud {
    height: 52px;
    padding: 0 56px 0 10px;
  }

  .inventory-slot {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
  }

  #dialogue-box {
    width: 85%;
    max-width: 500px;
    padding: 16px 20px;
    bottom: 12px;
  }

  #dialogue-text {
    font-size: 0.95rem;
  }

  #puzzle-container {
    width: 95%;
    max-width: 480px;
    padding: 20px 16px;
    max-height: 80vh;
  }

  #hint-box,
  #reward-box {
    width: 90%;
    max-width: 420px;
    padding: 20px;
  }

  #hint-text,
  #reward-text {
    font-size: 0.95rem;
  }
}

/* Tablet Landscape (768px - 1024px width) */
@media (min-width: 768px) and (max-width: 1024px) {
  #hud {
    height: 64px;
    padding: 0 62px 0 20px;
  }

  .inventory-slot {
    width: 48px;
    height: 48px;
    font-size: 1.5rem;
  }

  #dialogue-box {
    width: 80%;
    max-width: 650px;
    padding: 22px 28px;
  }

  #puzzle-container {
    width: 85%;
    max-width: 600px;
    padding: 32px;
    max-height: 82vh;
  }

  #hint-box,
  #reward-box {
    width: 80%;
    max-width: 500px;
    padding: 28px;
  }
}

/* Desktop Landscape (1025px and above) */
@media (min-width: 1025px) {
  #hud {
    height: 70px;
    padding: 0 66px 0 24px;
  }

  .inventory-slot {
    width: 52px;
    height: 52px;
    font-size: 1.6rem;
  }

  #dialogue-box {
    width: 75%;
    max-width: 700px;
    padding: 24px 32px;
  }

  #puzzle-container {
    width: 80%;
    max-width: 700px;
    padding: 36px;
    max-height: 85vh;
  }

  #hint-box,
  #reward-box {
    width: 75%;
    max-width: 550px;
    padding: 32px;
  }

  #hint-text,
  #reward-text {
    font-size: 1.1rem;
  }
}

/* -----------------------------------------------
   TOUCH OPTIMIZATION
   For mobile and tablet devices
   ----------------------------------------------- */

@media (hover: none) and (pointer: coarse) {
  button {
    min-height: 44px;
    min-width: 44px;
  }

  .inventory-slot {
    min-height: 44px;
    min-width: 44px;
  }
}

/* -----------------------------------------------
   HIGH DPI SCREENS
   Retina and 4K displays
   ----------------------------------------------- */

@media (min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  #game-canvas {
    image-rendering: -webkit-optimize-contrast;
  }
}

/* -----------------------------------------------
   PORTRAIT MODE — ROTATE TO LANDSCAPE
   Rotates the entire game 90 degrees when the
   device is held in portrait. Keeps the game
   always displaying as landscape without any
   layout redesign.
   ----------------------------------------------- */

@media (orientation: portrait) {
  body {
    width: 100vh;
    height: 100vw;
    transform: rotate(90deg);
    transform-origin: left top;
    position: fixed;
    top: 0;
    left: 100%;
    overflow: hidden;
  }
}

/* -----------------------------------------------
   REDUCED MOTION
   Respects device accessibility settings
   Disables animations for motion-sensitive users
   ----------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
