/* ========================================
   Base Styles
   ======================================== */

body { 
  margin: 0; 
  overflow: hidden;
  background: #111;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  text-rendering: optimizeSpeed;
  font-family: 'Helvetica', 'Arial', sans-serif;
}

canvas { 
  display: block; 
}

/* ========================================
   Game UI
   ======================================== */

.ui {
  color: #ffffff;
  font-size: 24px;
  font-weight: normal;
  text-shadow: 2px 2px 0 rgba(0,0,0,1);
}

#timer {
  position: absolute;
  top: 20px;
  right: calc(50% + 70px);
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #ffffff;
  transition: color 0.3s;
  font-size: 150%;
  font-weight: bold;
}

#timer.low {
  color: #ff4444;
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#money-display {
  position: absolute;
  top: 45px;
  left: 20px;      
  color: #ffffff;
  text-shadow: 2px 2px 0 rgba(0,0,0,1);
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

#money-numeral {
  font-size: 125%;
}

/* Portrait mode - move money to bottom */
@media (orientation: portrait) {
  #money-display {
    top: auto;
    bottom: 20px;
    left: 20px;
  }
}

#compass {
  position: absolute;
  top: 20px;
  left: calc(50% - 50px);
  width: 100px;
  height: 100px;
  border: 2px solid rgba(255,255,255,0.75);
  border-radius: 50%;
  pointer-events: none;
  background: rgba(0,0,0,0.5);
}

#compass-arrow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 40px solid #ffaa44;
  transform-origin: 50% 100%;
  margin-left: -8px;
  margin-top: -40px;
}

#objective-box {
  display: grid;
  place-items: center;
  height: 100px;
  position: absolute;
  top: 20px;
  left: calc(50% + 70px);
  width: 150px;
  text-align: center;
  color: #ffaa44;
  line-height: 1.0;
}

#objective {
  display: grid;
  place-items: center;
  gap: 5px;
}

#objective-chinese {
  font-size: 175%;
  font-family: sans-serif;
}

#objective-english {
  font-size: 75%; 
  font-weight: bold;
}

/* ========================================
   Area Notification
   ======================================== */

#area-notification {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 8px 20px;
  background: rgba(192, 0, 0, 1);
  color: #ffffff;
  font-size: 16px;
  text-align: center;
  border: 2px solid #ffffff;
  pointer-events: none;
  opacity: 0;
  /*transition: opacity 0.3s ease;*/
  z-index: 100;
}

#area-chinese {
  font-size: 24px;
  margin-bottom: 4px;
}

#area-english {
  font-size: 14px;
  font-weight: bold;
  text-transform: uppercase;
}

/* Portrait mode - move area notification to bottom */
@media (orientation: portrait) {
  #area-notification {
    top: auto;
    bottom: 20px;
    right: 20px;
  }
}

/* ========================================
   Notifications
   ======================================== */

#notification-message {
  position: absolute;
  top: 140px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.25);
  color: #ffffff;
  font-size: 18px;
  text-align: center;
  text-shadow: 1px 1px 0 rgba(0,0,0,1);
  pointer-events: none;
  opacity: 0;
  max-width: 80%;
  white-space: pre-line;
  line-height: 1.4;
  z-index: 1000;
}

#notification-message.show {
  opacity: 1;
}

#notification-message.success {
  border-color: #ffffff;
  color: #ffffff;
}

#notification-message.warning {
  border-color: #ffffff;
  color: #ffffff;
}

#notification-message.error {
  border-color: #ff3333;
  color: #ff3333;
}

/* ========================================
   Debug & FPS
   ======================================== */

#fps {
  position: absolute;
  top: calc(100vh - 90px);
  left: 20px;
  font-size: 14px;
  color: rgba(255,255,255,0.6);
  font-family: monospace;
}

#performance-display {
  position: absolute;
  bottom: 20px;
  right: 20px;
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  font-family: monospace;
  background: rgba(0,0,0,0.7);
  padding: 10px;
  border-radius: 4px;
  min-width: 200px;
}

#performance-display .perf-header {
  font-weight: bold;
  margin-bottom: 8px;
  color: #ffffff;
  font-size: 14px;
}

#performance-display .perf-line {
  margin: 2px 0;
  display: flex;
  justify-content: space-between;
}

#performance-display .perf-line.perf-subline {
  margin-left: 12px;
  font-size: 11px;
  color: rgba(255,255,255,0.6);
}

#performance-display .perf-line .perf-label {
  color: rgba(255,255,255,0.7);
}

#performance-display .perf-line .perf-value {
  color: #00ff00;
  font-weight: bold;
}

#performance-display .perf-line .perf-percent {
  color: rgba(255,255,255,0.5);
  margin-left: 8px;
}

/* Portrait mode - move area notification to bottom */
@media (orientation: portrait) {
  #fps {
    width: 100%;
    text-align: center;
  }
}

/* ========================================
   Mobile Controls
   ======================================== */

#mobile-controls {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 10px;
  z-index: 1000;
}

#mobile-controls button {
  padding: 12px 24px;
  font-size: 16px;
  font-family: monospace;
  background: rgba(0,0,0,0.7);
  color: white;
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 8px;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

#mobile-controls button:active {
  background: rgba(255,255,255,0.2);
}

#enable-tilt {
  display: inline-block;
}

#calibrate {
  display: none;
}

/* Touch control circles - HIDDEN, using full screen areas instead */
.touch-control {
  display: none !important;
}

/* ========================================
   Calibration UI
   ======================================== */

#calibration-ui {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.calibration-container {
  background: rgba(20, 20, 20, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  padding: 40px;
  max-width: 500px;
  text-align: center;
}

#calibration-step {
  color: white;
  font-family: monospace;
  font-size: 18px;
  margin-bottom: 30px;
  line-height: 1.5;
}

/* ========================================
   Pause Menu
   ======================================== */

#pause-menu {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  pointer-events: none;
}

.pause-menu-buttons {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.level-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid #888;
  min-width: 250px;
}

.level-selector label {
  color: #fff;
  font-family: monospace;
  font-size: 14px;
  white-space: nowrap;
}

.level-selector select {
  font-family: monospace;
  font-size: 14px;
  flex: 1;
  min-width: 150px;
  touch-action: manipulation;
}

/* Portrait mode - stack buttons vertically */
@media (orientation: portrait) {
  .pause-menu-buttons {
    flex-direction: column;
    gap: 8px;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

.menu-button {
  padding: 12px 24px;
  font-size: 15px;
  font-family: monospace;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border: 2px solid #888;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.menu-button:hover {
  background: rgba(50, 50, 50, 0.85);
}

/* ========================================
   Settings Menu
   ======================================== */

#settings-menu {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* background: rgba(0, 0, 0, 0.3); */
  z-index: 10000;
  color: white;
  font-family: monospace;
}

#stats-menu {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 10000;
  color: white;
  font-family: monospace;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
  color: #aaa;
  font-size: 14px;
}

.stat-value {
  color: #fff;
  font-size: 16px;
  font-weight: bold;
}

/* ========================================
   Map View
   ======================================== */

#map-view {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9998;
  pointer-events: none; /* Keep this none so canvas below can receive events */
}

#map-view.active {
  display: block;
  /* Don't set pointer-events: auto here - we want the canvas to receive events */
}

#map-controls {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
}

#map-help {
  padding: 12px 24px;
  font-size: 14px;
  font-family: monospace;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border: 2px solid #888;
  text-align: center;
  white-space: nowrap;
}

.settings-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  background: rgba(0, 0, 0, 0.9);
  border: 2px solid #888;
}

.settings-title {
  display: none;
  margin: 0 0 15px 0;
  font-size: 24px;
  font-weight: normal;
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.9);
}

/* Grid layout for main settings */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 15px;
}

.settings-item {
  background: rgba(255, 255, 255, 0.05);
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.settings-item-full {
  grid-column: 1 / -1;
}

.settings-label {
  display: block;
  font-size: 11px;
  color: #aaa;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-select {
  width: 100%;
  padding: 6px;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: 1px solid #666;
  border-radius: 3px;
  font-size: 12px;
  font-family: monospace;
}

.settings-select option {
  background: #000;
}

.settings-container input {
  width: calc(100% - 20px);
}

/* Quality labels - more compact */
.quality-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #666;
  margin-bottom: 2px;
  padding: 0 2px;
}

.quality-labels span {
  width: 16.67%;
}

/* Mobile settings */
.settings-mobile {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

/* Collapsible details */
.settings-details {
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.settings-summary {
  padding: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  user-select: none;
}

.settings-summary:hover {
  background: rgba(255, 255, 255, 0.05);
}

.settings-details[open] .settings-summary {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 8px;
}

.settings-details .settings-item {
  margin: 8px;
  background: rgba(0, 0, 0, 0.3);
}

/* Compact buttons */
.menu-button-compact {
  flex: 1;
  margin: 0 4px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid #666;
  cursor: pointer;
  font-family: monospace;
  font-size: 11px;
  text-transform: uppercase;
  border-radius: 3px;
}

.menu-button-compact:hover {
  background: rgba(255, 255, 255, 0.2);
}

.settings-item-full {
  display: flex;
  gap: 8px;
}

/* Calibration status */
.calibration-status {
  margin-top: 8px;
  font-size: 11px;
  color: #aaa;
  min-height: 16px;
}

/* Responsive - single column on very small screens */
@media (max-width: 400px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

.slider {
  width: 100%;
  height: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  accent-color: #888;
  touch-action: manipulation;
}

.slider-value {
  text-align: center;
  font-size: 15px;
  font-weight: bold;
}

.back-button {
  width: 100%;
  padding: 12px;
  margin: 20px 0 0 0;
  font-size: 16px;
}

.mobile-only {
  display: block;
}

/* Hide mobile-only sections on desktop */
@media (min-width: 768px) {
  .mobile-only {
    display: none !important;
  }
}

.calibration-status {
  display: none;
  margin-top: 12px;
  padding: 8px;
  background: rgba(0, 255, 0, 0.2);
  color: #0f0;
  border: 1px solid #0f0;
  font-size: 12px;
  text-align: center;
}

/* ========================================
   Loading Screen
   ======================================== */

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #111;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  font-family: monospace;
  text-align: center;
  color: #fff;
}

#loading-title {
  font-size: 48px;
  font-weight: bold;
  margin-bottom: 30px;
  letter-spacing: 4px;
}

#loading-status {
  font-size: 16px;
  color: #888;
  min-height: 20px;
}

#loading-screen.hidden {
  display: none;
}

/* ========================================
   Touch Overlay (Mobile Slide Controls)
   ======================================== */

#touch-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 50;
}

#touch-overlay.active {
  display: flex;
}

/* Swipe mode: single full-screen zone */
#touch-overlay.swipe-mode {
  display: flex;
}

/* Swipe mode input indicators */
.swipe-indicator {
  position: absolute;
  background-color: rgba(255, 255, 255, 0.3);
  transition: opacity 0.2s;
  opacity: 0;
}

#touch-overlay.swipe-mode .swipe-indicator {
  opacity: 1;
}

.swipe-indicator {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.3);
  border: 3px solid rgba(255, 255, 255, 0.4);
  pointer-events: none;
}

/* Active portions of indicator */
.swipe-indicator-fill {
  position: absolute;
  background-color: rgba(100, 200, 255, 0.9);
  transition: all 0.05s;
  border-radius: 2px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background-color: rgba(255, 100, 100, 0.9);
}

/* ========================================
   Developer Tools
   ======================================== */

.dev-tools-button {
  position: fixed;
  top: 10px;
  right: 10px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.75);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.75);
  font-family: monospace;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  z-index: 9000;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background 0.2s;
}

.dev-tools-button:hover {
  background: rgba(255, 255, 255, 0.25);
}

.dev-tools-panel {
  display: none;
  position: fixed;
  top: 60px;
  right: 10px;
  width: 400px;
  max-height: 80vh;
  background: rgba(20, 20, 30, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.5);
  padding: 0;
  z-index: 9000;
  font-family: monospace;
  font-size: 12px;
  color: white;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.dev-tools-container {
  padding: 16px;
}

.dev-tool-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.dev-tool-section:last-child {
  border-bottom: none;
}

.dev-tool-title {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dev-tool-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dev-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}

.dev-label {
  flex: 0 0 120px;
  font-size: 11px;
  color: #aaa;
  text-transform: uppercase;
}

.dev-select {
  flex: 1;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: 1px solid #666;
  border-radius: 3px;
  font-family: monospace;
  font-size: 11px;
}

.dev-select option {
  background: #000;
}

.dev-color {
  width: 50px;
  height: 28px;
  border: 1px solid #666;
  border-radius: 3px;
  cursor: pointer;
  background: transparent;
}

.dev-hex {
  font-size: 11px;
  color: #aaa;
  font-family: monospace;
}

.dev-slider {
  flex: 1;
  height: 6px;
  cursor: pointer;
  accent-color: #ff8800;
}

.dev-value {
  flex: 0 0 50px;
  text-align: right;
  font-size: 11px;
  color: #fff;
  font-family: monospace;
}

.dev-button {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid #666;
  border-radius: 3px;
  cursor: pointer;
  font-family: monospace;
  font-size: 11px;
  text-transform: uppercase;
  transition: background 0.2s;
}

.dev-button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.dev-tools-close {
  width: 100%;
  padding: 10px;
  background: rgba(255, 100, 0, 0.3);
  color: white;
  border: none;
  border-top: 1px solid rgba(255, 150, 0, 0.5);
  cursor: pointer;
  font-family: monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background 0.2s;
}

.dev-tools-close:hover {
  background: rgba(255, 120, 0, 0.4);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .dev-tools-panel {
    width: calc(100% - 20px);
    right: 10px;
    max-height: 70vh;
  }
  
  .dev-label {
    flex: 0 0 100px;
    font-size: 10px;
  }
}