/* Load Comic Sans font - use native on iOS/macOS, fallback to TTF on Android */
@font-face {
  font-family: 'Comic Sans MS';
  src: local('Comic Sans MS'),
       local('ComicSansMS'), 
       local('Comic Sans MS Regular'),
       local('Chalkboard SE'),
       local('ChalkboardSE-Regular'),
       url('comic.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Comic Sans';
  src: local('Comic Sans'),
       local('Comic Sans MS'),
       local('ComicSansMS'),
       local('Chalkboard SE'),
       local('ChalkboardSE-Regular'),
       url('comic.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Store safe area values as CSS variables for JS access */
  --sat: env(safe-area-inset-top);
  --sar: env(safe-area-inset-right);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
}

html,body{
  margin:0;
  padding:0;
  overflow:hidden;
  width:100%;
  height:100%;
  position:fixed;
  background:#061522;
  /* Prevent pull-to-refresh on iOS */
  overscroll-behavior-y: none;
  /* Disable text selection */
  -webkit-user-select: none;
  user-select: none;
  /* Disable tap highlight */
  -webkit-tap-highlight-color: transparent;
  /* Smooth scrolling */
  -webkit-overflow-scrolling: touch;
  /* Full screen on mobile - no padding, canvas will handle safe areas */
  box-sizing: border-box;
}

/* Force landscape orientation on mobile */
@media screen and (orientation: portrait) and (max-width: 768px) {
  html {
    transform: rotate(90deg);
    transform-origin: left top;
    width: 100vh;
    height: 100vw;
    position: absolute;
    top: 100%;
    left: 0;
    overflow-x: hidden;
  }
}
canvas{
  display:block;
  position:fixed;
  top:0;
  left:0;
  width:100vw;
  height:100vh;
  /* Full screen - JavaScript will handle safe areas in sizing */
  /* Touch action for better touch handling */
  touch-action: none;
  /* Prevent iOS zoom */
  -webkit-touch-callout: none;
  /* Enable high refresh rate support for iPad Pro and other 120Hz displays */
  will-change: transform;
  /* Force hardware acceleration for smoother rendering */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  /* Optimize for high refresh rate displays */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  /* Force GPU rendering for better performance */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  /* Optimize compositing */
  isolation: isolate;
}

#game {
  z-index: 1;
}

#hud {
  z-index: 10;
  pointer-events: none;
}

#ui-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 20;
  pointer-events: none;
  display: none;
}

/* Loader */
#loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #061522;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

#loader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-content {
  text-align: center;
  color: #fff;
}

.loader-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(74, 144, 226, 0.3);
  border-top-color: #4a90e2;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  font-size: 20px;
  font-weight: bold;
  color: #4a90e2;
  margin-bottom: 10px;
  font-family: 'Arial', sans-serif;
}

.loader-status {
  font-size: 14px;
  color: #888;
  min-height: 20px;
  font-family: 'Arial', sans-serif;
}

@media (max-width: 768px) {
  .loader-spinner {
    width: 50px;
    height: 50px;
    border-width: 3px;
  }
  
  .loader-text {
    font-size: 18px;
  }
  
  .loader-status {
    font-size: 12px;
  }
}

/* iOS standalone mode detection */
@media (display-mode: standalone) {
  body {
    /* When launched from home screen */
    background: #000;
  }
}

/* Prevent zoom on iOS */
input, select, textarea {
  font-size: 16px;
}

/* Hide scrollbars on iOS */
::-webkit-scrollbar {
  display: none;
}

/* Ship Configuration Panel */
#ship-config-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid #4a90e2;
  border-radius: 8px;
  padding: 0;
  font-family: 'Arial', sans-serif;
  color: #fff;
  min-width: 280px;
  max-width: 320px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  user-select: none;
  /* Hide by default - JavaScript will show it if ?priv=kmcfg is present */
  display: none;
}

.config-header {
  background: linear-gradient(135deg, #4a90e2, #357abd);
  padding: 10px 15px;
  border-radius: 6px 6px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: move;
}

.config-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: bold;
}

#toggle-config {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 18px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

#toggle-config:hover {
  background: rgba(255, 255, 255, 0.3);
}

.config-content {
  padding: 15px;
  max-height: 500px;
  overflow-y: auto;
}

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

.ship-section:last-of-type {
  border-bottom: none;
}

.battle-mode-section {
  background: rgba(74, 144, 226, 0.1);
  padding: 10px;
  border-radius: 6px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 13px;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-right: 10px;
  cursor: pointer;
  accent-color: #4a90e2;
}

.checkbox-label span {
  color: #fff;
}

.hint {
  display: block;
  margin-top: 5px;
  color: #888;
  font-size: 10px;
  font-style: italic;
}

.ship-section h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: #4a90e2;
}

.ship-section h5 {
  margin: 15px 0 8px 0;
  font-size: 12px;
  color: #7ab5f5;
  font-weight: normal;
}

.ship-section select {
  width: 100%;
  padding: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid #4a90e2;
  border-radius: 4px;
  color: white;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.ship-section select:hover {
  background: rgba(255, 255, 255, 0.15);
}

.ship-section select option {
  background: #1a1a1a;
  color: white;
}

.ship-section label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  color: #ccc;
}

.ship-section label span {
  display: inline-block;
  min-width: 40px;
  color: #4a90e2;
  font-weight: bold;
}

.ship-section input[type="range"] {
  width: 100%;
  margin-top: 5px;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  outline: none;
}

.ship-section input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #4a90e2;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.ship-section input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #4a90e2;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.ship-section input[type="range"]:hover::-webkit-slider-thumb {
  background: #5ba0f2;
}

.ship-section input[type="range"]:hover::-moz-range-thumb {
  background: #5ba0f2;
}

.config-actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.config-actions button {
  flex: 1;
  padding: 8px 12px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  transition: background 0.2s;
}

.config-actions button:hover {
  background: #357abd;
}

#reset-config {
  background: #e74c3c !important;
}

#reset-config:hover {
  background: #c0392b !important;
}

.config-info {
  margin-top: 10px;
  text-align: center;
  color: #888;
}

.config-info small {
  font-size: 10px;
}

/* Scrollbar for config panel */
.config-content::-webkit-scrollbar {
  width: 6px;
  display: block;
}

.config-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.config-content::-webkit-scrollbar-thumb {
  background: rgba(74, 144, 226, 0.5);
  border-radius: 3px;
}

.config-content::-webkit-scrollbar-thumb:hover {
  background: rgba(74, 144, 226, 0.7);
}
