* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  overflow: hidden;
  background: #000;
  overscroll-behavior: none;
  touch-action: manipulation;
}

canvas {
  display: block;
}

#ui {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-family: sans-serif;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 1px 3px #000;
}

#timer {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-family: monospace;
  font-size: 22px;
  font-weight: bold;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
  z-index: 20;
  background: rgba(128, 128, 128, 0.6);
  padding: 8px 16px;
  border-radius: 8px;
}

#timer.warning {
  color: #ffeb3b;
  background: rgba(200, 140, 0, 0.7);
}

#question-label {
  display: none;
}

#phase-info {
  position: fixed;
  top: 16px;
  left: 16px;
  color: #fff;
  font-family: sans-serif;
  font-size: 13px;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
  z-index: 20;
  line-height: 1.5;
  max-width: min(52vw, 420px);
  background: rgba(80, 80, 80, 0.6);
  border-radius: 8px;
  padding: 8px 10px;
}

#phase-info strong {
  display: block;
  margin-bottom: 2px;
  font-size: 16px;
  font-weight: bold;
}

.hidden {
  display: none !important;
}

#skip-btn {
  position: fixed;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  border: none;
  border-radius: 8px;
  background: rgba(128, 128, 128, 0.95);
  color: #fff;
  padding: 12px 32px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 0.15s;
  z-index: 18;
  white-space: nowrap;
}

#skip-btn:hover {
  background: rgba(100, 100, 100, 0.95);
}

#ingame-speed {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  padding: 6px 10px;
  z-index: 19;
  color: #fff;
  font-size: 14px;
}

#ingame-speed button {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 16px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  line-height: 1;
}

#ingame-speed button:hover {
  background: rgba(255, 255, 255, 0.4);
}

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  pointer-events: none;
}

#crosshair::before,
#crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.8);
}

#crosshair::before {
  width: 2px;
  height: 100%;
  left: 50%;
  transform: translateX(-50%);
}

#crosshair::after {
  width: 100%;
  height: 2px;
  top: 50%;
  transform: translateY(-50%);
}

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-family: sans-serif;
  text-align: center;
}

#overlay h1 {
  font-size: 2.4rem;
  margin-bottom: 12px;
}

#language-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

#language-select-label {
  font-size: 0.9rem;
  color: #ddd;
}

#language-select {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: rgba(35, 35, 35, 0.9);
  color: #fff;
  font-size: 0.9rem;
  padding: 6px 10px;
}

#overlay p {
  font-size: 1rem;
  color: #ccc;
  margin-bottom: 24px;
  line-height: 1.7;
}

#overlay button {
  padding: 12px 32px;
  font-size: 1rem;
  border: none;
  border-radius: 6px;
  background: #e74c3c;
  color: #fff;
  cursor: pointer;
  margin: 8px;
}

#overlay button:hover {
  background: #c0392b;
}

#difficulty-buttons {
  display: none;
}

#stage-meta {
  display: none;
}

#overlay.hidden {
  display: none;
}

#guessing-ui {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
  pointer-events: none;
}

#photo-view {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(80vw, 1000px);
  height: min(75vh, 700px);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  z-index: 25;
  background: #080808;
  border: none;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.9), 0 0 0 4px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

#photo-view.small {
  top: 16px;
  left: auto;
  right: 16px;
  transform: none;
  width: min(35vw, 480px);
  height: min(30vh, 320px);
  padding: 4px;
}

#photo-view.hidden-photo {
  display: none;
}

#photo-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
  padding-bottom: 0;
  border-bottom: none;
  color: #fff;
  font-family: sans-serif;
  font-size: 14px;
}

#photo-label {
  font-weight: bold;
}

#photo-buttons {
  display: flex;
  gap: 6px;
}

#pano-canvas {
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  border-radius: 4px;
  pointer-events: auto;
  cursor: grab;
  background: #000;
  transition: opacity 0.15s;
}

#photo-center-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-family: sans-serif;
  font-size: clamp(14px, 1.6vw, 20px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
  pointer-events: none;
  z-index: 1;
}

#photo-size-btn,
#photo-hide-btn {
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 4px;
  background: rgba(50, 50, 50, 0.9);
  color: #fff;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
}

#photo-size-btn:hover,
#photo-hide-btn:hover {
  background: rgba(70, 70, 70, 0.9);
}

#photo-show-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 4px;
  background: rgba(50, 50, 50, 0.9);
  color: #fff;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  pointer-events: auto;
  z-index: 24;
  display: none;
}

#photo-show-btn.show {
  display: block;
}

#photo-show-btn:hover {
  background: rgba(70, 70, 70, 0.9);
}

#view-controls {
  position: absolute;
  bottom: 22px;
  right: 4px;
  display: grid;
  grid-template-columns: repeat(3, 36px);
  grid-template-rows: repeat(3, 36px);
  gap: 3px;
  pointer-events: auto;
}

#view-controls-hint {
  position: absolute;
  right: 4px;
  bottom: 4px;
  color: rgba(255, 255, 255, 0.82);
  font-family: sans-serif;
  font-size: 11px;
  line-height: 1.2;
  text-align: right;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

#submit-guess-btn {
  position: fixed;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  border: none;
  border-radius: 8px;
  background: rgba(231, 76, 60, 0.95);
  color: #fff;
  padding: 12px 32px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 0.15s;
  z-index: 30;
  white-space: nowrap;
}

#submit-guess-btn.moving {
  opacity: 0.2;
  pointer-events: none;
}

#submit-guess-btn:hover {
  background: rgba(192, 57, 43, 0.95);
}

#controls-guide {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-family: sans-serif;
  font-size: 12px;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  z-index: 20;
}

.view-btn {
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 0;
  width: 36px;
  height: 36px;
  font-size: 13px;
  cursor: pointer;
}

.view-btn.up {
  grid-column: 2;
  grid-row: 1;
}

.view-btn.right {
  grid-column: 3;
  grid-row: 2;
}

.view-btn.down {
  grid-column: 2;
  grid-row: 3;
}

.view-btn.left {
  grid-column: 1;
  grid-row: 2;
}

.view-btn.active {
  background: #e74c3c;
  border-color: #e74c3c;
}

#map-view {
  position: fixed;
  bottom: 16px;
  left: 16px;
  width: 300px;
  height: 300px;
  background: rgba(50, 50, 50, 0.95);
  border: 2px solid #fff;
  cursor: crosshair;
  pointer-events: auto;
  border-radius: 4px;
}

#guessing-info {
  position: fixed;
  bottom: 16px;
  right: 16px;
  color: #fff;
  font-family: sans-serif;
  font-size: 14px;
  text-align: right;
  pointer-events: none;
  text-shadow: 0 1px 3px #000;
  display: none;
}

#score-display {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.95);
  color: #fff;
  padding: 40px;
  border-radius: 8px;
  text-align: center;
  display: none;
  pointer-events: auto;
  z-index: 1000;
}

#score-display.show {
  display: block;
}

#score-display h2 {
  font-size: 2rem;
  margin-bottom: 16px;
}

#score-display p {
  font-size: 1.2rem;
  margin: 8px 0;
}

#score-display button {
  padding: 12px 24px;
  margin-top: 20px;
  font-size: 1rem;
  border: none;
  background: #e74c3c;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}

#exploration-end-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1100;
  pointer-events: auto;
}

#exploration-end-modal.show {
  display: flex;
}

#exploration-end-card {
  min-width: min(88vw, 420px);
  background: rgba(20, 20, 20, 0.95);
  color: #fff;
  border-radius: 10px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font-family: sans-serif;
}

#exploration-end-card h3 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

#exploration-end-card p {
  color: #ccc;
  margin-bottom: 18px;
}

#exploration-end-card button {
  border: none;
  border-radius: 6px;
  padding: 12px 22px;
  background: #e74c3c;
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
}

#exploration-end-card button:hover {
  background: #c0392b;
}

#guessing-ui.hidden {
  display: none;
}

#skip-confirmation-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1100;
  pointer-events: auto;
}

#skip-confirmation-modal.show {
  display: flex;
}

#skip-confirmation-card {
  min-width: min(88vw, 420px);
  background: rgba(20, 20, 20, 0.95);
  color: #fff;
  border-radius: 10px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font-family: sans-serif;
}

#skip-confirmation-card h3 {
  font-size: 1.2rem;
  margin-bottom: 16px;
}

#skip-confirmation-card button {
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  margin: 8px 6px;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
}

#skip-confirmation-yes {
  background: rgba(100, 100, 100, 0.9);
  color: #fff;
}

#skip-confirmation-yes:hover {
  background: rgba(80, 80, 80, 0.9);
}

#skip-confirmation-no {
  background: #e74c3c;
  color: #fff;
}

#skip-confirmation-no:hover {
  background: #c0392b;
}

/* Virtual D-Pad for Mobile */
#virtual-dpad {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 120px;
  height: 120px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  z-index: 120;
  pointer-events: auto;
}

#virtual-dpad.hidden {
  display: none;
}

.dpad-btn {
  font-size: 18px;
  font-weight: bold;
  background: rgba(120, 120, 120, 0.45);
  border: 2px solid rgba(210, 210, 210, 0.6);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.1s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.dpad-btn:active {
  background: rgba(90, 90, 90, 0.7);
  transform: scale(0.95);
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 3;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

#debug-panel {
  position: fixed;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.85) !important;
  color: #0f0 !important;
  font-family: 'Courier New', monospace !important;
  font-size: 11px !important;
  line-height: 1.4 !important;
  padding: 8px 12px !important;
  border: 1px solid #0f0 !important;
  border-radius: 4px !important;
  pointer-events: none !important;
  z-index: 9999 !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  max-width: 320px !important;
  box-shadow: 0 0 10px rgba(0, 255, 0, 0.3) !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  #language-switcher {
    margin-top: 10px;
  }

  #overlay h1 {
    font-size: 1.8rem;
  }

  #map-view {
    width: min(45vw, 200px);
    height: min(45vw, 200px);
  }

  #ingame-speed {
    display: none;
  }
}