/**
 * Shared CSS for all 3D trainers.
 * Each trainer imports this, then adds its own overrides.
 */

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #000;
  color: #ff0;
  font-family: "Courier New", monospace;
  overflow: hidden;
}

#canvas { display: block; width: 100vw; height: 100vh; }

/* ---- Loading screen ---- */
#loading-screen {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-title {
  color: #ff0;
  font-size: 1.4rem;
  margin-bottom: 24px;
  letter-spacing: 2px;
}

.loading-bar-track {
  width: 240px;
  height: 6px;
  background: #222;
  border: 1px solid #444;
  border-radius: 3px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: #ff0;
  transition: width 0.15s linear;
}

.loading-text {
  color: #666;
  font-size: 0.7rem;
  margin-top: 12px;
}

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0,0,0,0.85);
  padding: 12px;
  border: 1px solid #ff0;
  border-radius: 4px;
  font-size: 0.8rem;
  z-index: 10;
  min-width: 200px;
}

#hud p { margin-bottom: 3px; }
#hud hr { border: none; border-top: 1px solid #333; margin: 6px 0; }
.hl { color: #888; }
.val { color: #ff0; font-weight: bold; }
.val.idle { color: #44aaff; }
.val.attack { color: #ff4444; }
.val.good { color: #44ff44; }
.val.bad { color: #ff4444; }

#tick-bar {
  width: 100%;
  height: 12px;
  background: #222;
  border: 1px solid #444;
  border-radius: 2px;
  margin: 4px 0;
  overflow: hidden;
}

#tick-bar-fill {
  height: 100%;
  width: 0%;
  background: #44aaff;
  transition: width 0.05s linear;
}

#tick-bar-fill.danger { background: #ff4444; }

/* ---- Top-right toolbar: [compass] [2x2 button grid] ---- */
#top-right-bar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 12;
}

#top-right-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

#action-bar {
  display: contents; /* children flow into the parent grid */
}

.action-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #555;
  background: rgba(0,0,0,0.8);
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.15s;
  backdrop-filter: blur(4px);
}

.action-btn:hover {
  border-color: #ff0;
  color: #ff0;
  transform: scale(1.1);
}

.action-btn:active { transform: scale(0.95); }

.action-btn.action-primary {
  border-color: #ff0;
  color: #ff0;
  background: rgba(255,255,0,0.1);
}

.action-btn.action-primary:hover {
  background: rgba(255,255,0,0.25);
}

.action-btn.action-primary.running {
  border-color: #44ff44;
  color: #44ff44;
  background: rgba(68,255,68,0.1);
}

.action-btn.spin svg {
  animation: spin-once 0.5s ease-out;
}

@keyframes spin-once {
  from { transform: rotate(0deg); }
  to { transform: rotate(-360deg); }
}

/* ---- Settings overlay ---- */
#settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
  opacity: 1;
  transition: opacity 0.2s;
}

#settings-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

#settings-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 420px;
  max-height: 80vh;
  background: rgba(10,10,10,0.96);
  border: 2px solid #ff0;
  border-radius: 12px;
  z-index: 51;
  backdrop-filter: blur(12px);
  overflow-y: auto;
  transition: opacity 0.2s, transform 0.2s;
}

#settings-panel.hidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.95);
  pointer-events: none;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #333;
  color: #ff0;
  font-size: 1rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.settings-close {
  background: none;
  border: none;
  color: #666;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}

.settings-close:hover { color: #ff0; }

.settings-section {
  padding: 12px 20px;
  border-bottom: 1px solid #1a1a1a;
}

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

.settings-section-title {
  color: #666;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.settings-label {
  color: #888;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.overlay-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.overlay-row input[type="color"] {
  width: 26px;
  height: 26px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #111;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s;
}

.overlay-row input[type="color"]:hover { border-color: #ff0; }

/* Slider */
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: #333;
  border-radius: 2px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ff0;
  border: 2px solid #000;
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ff0;
  border: 2px solid #000;
  cursor: pointer;
}

.slider-val {
  color: #666;
  font-size: 0.7rem;
  min-width: 34px;
  text-align: right;
}

/* Big clickable toggle rows */
.toggle {
  color: #aaa;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  user-select: none;
  padding: 8px 12px;
  margin: 0 -12px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.toggle:hover {
  color: #ff0;
  background: rgba(255,255,0,0.06);
}

.toggle input { display: none; }

.toggle-box {
  width: 18px;
  height: 18px;
  border: 2px solid #555;
  border-radius: 3px;
  background: #111;
  display: inline-block;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.toggle input:checked + .toggle-box {
  background: #ff0;
  border-color: #ff0;
}

.toggle input:checked + .toggle-box::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: solid #000;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.toggle:has(input:checked) { color: #ff0; }

/* ---- Gear Panel (bottom-right, resizable via drag handle) ---- */
#gear-panel {
  position: fixed;
  bottom: 10px;
  right: 10px;
  background: rgba(0,0,0,0.85);
  border: 1px solid #ff0;
  border-radius: 4px;
  padding: 10px;
  z-index: 10;
  width: 210px;
}

#gear-drag-handle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  color: #666;
  font-size: 1.1rem;
  cursor: grab;
  padding: 0 2px 4px;
  user-select: none;
  line-height: 1;
}

#gear-drag-handle:active {
  cursor: grabbing;
  color: #ff0;
}

#equipment {
  margin-bottom: 8px;
}

.equip-label, .inv-label {
  color: #888;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.equip-slots {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.equip-slot {
  width: 40px;
  height: 40px;
  background: #1a1a1a;
  border: 1px solid #444;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.equip-slot img {
  max-width: 36px;
  max-height: 36px;
  image-rendering: pixelated;
}

#inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
}

.inv-slot {
  aspect-ratio: 1;
  background: #111;
  border: 1px solid #333;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

.inv-slot:hover {
  border-color: #ff0;
}

.inv-slot.has-item:hover {
  background: #222;
}

.inv-slot.click-flash {
  background: #ff0 !important;
  border-color: #ff0 !important;
  transition: none;
}

.inv-slot.click-flash img {
  filter: brightness(2);
}

.inv-slot.dragging {
  opacity: 0.5;
  border-color: #ff0;
}

.inv-slot.drag-over {
  border-color: #44ff44;
  background: #1a2a1a;
}

.inv-slot img {
  max-width: 80%;
  max-height: 80%;
  image-rendering: pixelated;
}

.inv-tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: #ff0;
  border: 1px solid #ff0;
  padding: 2px 6px;
  font-size: 0.65rem;
  white-space: nowrap;
  border-radius: 2px;
  z-index: 20;
}

.inv-slot:hover .inv-tooltip {
  display: block;
}

/* ---- Compass ---- */
#compass {
  flex-shrink: 0;
}

.compass-ring {
  width: 64px;
  height: 64px;
  border: 2px solid #555;
  border-radius: 50%;
  background: rgba(0,0,0,0.85);
  position: relative;
}

.compass-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.compass-ring span {
  position: absolute;
  font-size: 0.6rem;
  font-weight: bold;
  color: #888;
  text-align: center;
  width: 16px;
  margin-left: -8px;
  line-height: 1;
  pointer-events: none;
}

.compass-n { top: 4px; left: 50%; color: #ff0 !important; }
.compass-s { bottom: 4px; left: 50%; }
.compass-e { right: 2px; top: 50%; transform: translateY(-50%); margin-left: 0; }
.compass-w { left: 2px; top: 50%; transform: translateY(-50%); margin-left: 0; }

/* ---- Feedback ---- */
#feedback {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  font-weight: bold;
  z-index: 15;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 0 8px #000, 0 0 16px #000;
  opacity: 0;
  transition: opacity 0.3s;
}

#feedback.show { opacity: 1; }
#feedback.good { color: #44ff44; }
#feedback.bad { color: #ff4444; }
#feedback.warn { color: #ffaa00; }
#feedback.info { color: #44aaff; }

/* ---- Gear panel resize grip (bottom-left corner) ---- */
#gear-resize-grip {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 16px;
  height: 16px;
  cursor: nesw-resize;
}
#gear-resize-grip::after {
  content: '';
  position: absolute;
  bottom: 3px;
  left: 3px;
  width: 8px;
  height: 8px;
  border-left: 2px solid #555;
  border-bottom: 2px solid #555;
}
#gear-resize-grip:hover::after {
  border-color: #ff0;
}

/* ---- FPS Counter ---- */
#fps-counter {
  position: fixed;
  bottom: 12px;
  left: 12px;
  font-family: "Courier New", monospace;
  font-size: 0.7rem;
  color: #888;
  z-index: 12;
  pointer-events: none;
  line-height: 1;
}
#fps-counter .fps-value {
  font-size: 0.85rem;
  font-weight: bold;
}
#fps-counter .fps-good { color: #44ff44; }
#fps-counter .fps-ok { color: #ffaa00; }
#fps-counter .fps-bad { color: #ff4444; }

#fps-graph {
  display: block;
  margin-top: 3px;
  border: 1px solid #333;
  border-radius: 2px;
  background: rgba(0,0,0,0.5);
}

.hidden { display: none !important; }
