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

:root {
  --primary: #4a6741;
  --primary-dark: #2d4028;
  --secondary: #8b7355;
  --accent: #d4a942;
  --bg-dark: #1a1a2e;
  --bg-panel: rgba(26, 26, 46, 0.95);
  --text-light: #f0e6d3;
  --text-muted: #a09080;
  --health: #c94c4c;
  --xp: #5ca4e8;
  --success: #5cb85c;
  --danger: #d9534f;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-dark);
  color: var(--text-light);
  overflow: hidden;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* Login Screen */
#login-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.login-container {
  text-align: center;
  padding: 40px;
  background: var(--bg-panel);
  border-radius: 20px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 50px rgba(212, 169, 66, 0.3);
}

.login-container h1 {
  font-size: 3rem;
  color: var(--accent);
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.tagline {
  color: var(--text-muted);
  margin-bottom: 30px;
  font-style: italic;
}

#username-input {
  width: 100%;
  padding: 15px 20px;
  font-size: 1.1rem;
  border: 2px solid var(--secondary);
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  margin-bottom: 20px;
  outline: none;
  transition: border-color 0.3s;
}

#username-input:focus {
  border-color: var(--accent);
}

#play-btn {
  width: 100%;
  padding: 15px 40px;
  font-size: 1.2rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--text-light);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#play-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(74, 103, 65, 0.5);
}

/* Game Container */
#game-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#game-canvas {
  width: 100%;
  height: 100%;
}

#game-canvas canvas {
  display: block;
}

/* UI Overlay */
#ui-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

#ui-overlay > * {
  pointer-events: auto;
}

/* Top Bar */
#top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 15px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

#player-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

#player-name {
  font-weight: bold;
  font-size: 1.1rem;
}

#player-level {
  background: var(--accent);
  color: var(--bg-dark);
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: bold;
}

#stats-bar {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.stat-container {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat-icon {
  font-size: 1.2rem;
}

.stat-bar {
  width: 80px;
  height: 12px;
  background: rgba(0,0,0,0.5);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  transition: width 0.3s ease;
}

.bar-fill.health {
  background: linear-gradient(90deg, var(--health) 0%, #e57373 100%);
}

.bar-fill.xp {
  background: linear-gradient(90deg, var(--xp) 0%, #81d4fa 100%);
}

#coins-display {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(0,0,0,0.3);
  padding: 5px 12px;
  border-radius: 15px;
}

.coin-icon {
  font-size: 1.2rem;
}

/* Always Visible Minimap */
#minimap-container {
  position: fixed;
  top: 70px;
  right: 10px;
  width: 225px;
  height: 225px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--secondary);
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  background: #2d5a27;
  transform-origin: top right;
  z-index: 150;
}

#minimap-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Quest Tracker */
#quest-tracker {
  position: fixed;
  top: 310px;
  right: 10px;
  width: 250px;
  max-height: 200px;
  background: var(--bg-panel);
  border-radius: 10px;
  padding: 10px;
  overflow-y: auto;
  transform-origin: top right;
  z-index: 150;
}

#quest-tracker h3 {
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 10px;
  border-bottom: 1px solid var(--secondary);
  padding-bottom: 5px;
}

.quest-track-item {
  margin-bottom: 10px;
  padding: 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 5px;
}

.quest-track-item h4 {
  font-size: 0.85rem;
  margin-bottom: 5px;
}

.quest-objective {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.quest-objective.complete {
  color: var(--success);
}

/* Chat Bubbles */
#chat-bubbles {
  position: absolute;
  bottom: 90px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
  z-index: 100;
  pointer-events: none;
}

.chat-bubble {
  background: var(--bg-panel);
  padding: 10px 15px;
  border-radius: 10px;
  border-left: 3px solid var(--accent);
  animation: chatBubbleIn 0.3s ease-out;
  font-size: 0.95rem;
}

.chat-bubble .chat-sender {
  color: var(--accent);
  font-weight: bold;
}

.chat-bubble .chat-text {
  color: var(--text-light);
}

.chat-bubble.fade-out {
  animation: chatBubbleOut 0.5s ease-out forwards;
}

@keyframes chatBubbleIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes chatBubbleOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-20px);
  }
}

/* Bottom Bar */
#bottom-bar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  background: var(--bg-panel);
  padding: 10px 15px;
  border-radius: 25px;
}

.action-btn {
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  font-size: 1.5rem;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

.action-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.1);
}

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

.action-btn {
  position: relative;
}

.btn-key {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
}

/* Mobile Controls */
#mobile-controls {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  justify-content: space-between;
  align-items: flex-end;
}

#joystick-container {
  width: 120px;
  height: 120px;
}

#joystick-base {
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  position: relative;
}

#joystick-stick {
  width: 50px;
  height: 50px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: none;
}

#action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mobile-action {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  font-size: 1.8rem;
  color: var(--text-light);
}

/* Panels */
.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-panel);
  border-radius: 15px;
  border: 2px solid var(--secondary);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  z-index: 200;
  max-width: 90vw;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid var(--secondary);
}

.panel-header span {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--accent);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.2s;
}

.close-btn:hover {
  color: var(--danger);
}

.panel-content {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--secondary);
}

.tab-btn {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

/* Chat Window */
#chat-window {
  position: fixed;
  bottom: 90px;
  left: 10px;
  width: 350px;
  height: 300px;
  top: auto;
  transform: none;
}

#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background: rgba(0,0,0,0.3);
}

#chat-messages {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  max-height: 200px;
}

.chat-message {
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.chat-message .username {
  color: var(--accent);
  font-weight: bold;
}

.chat-message .message {
  color: var(--text-light);
}

.chat-message.system {
  color: var(--text-muted);
  font-style: italic;
}

#chat-input-container {
  display: flex;
  padding: 10px;
  gap: 10px;
  border-top: 1px solid var(--secondary);
}

#chat-input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--secondary);
  border-radius: 5px;
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  outline: none;
}

#send-chat {
  padding: 10px 15px;
  background: var(--primary);
  border: none;
  border-radius: 5px;
  color: var(--text-light);
  cursor: pointer;
}

/* Inventory */
#equipped-items {
  margin-bottom: 20px;
}

#equipped-items h4 {
  margin-bottom: 10px;
  color: var(--accent);
}

#equipped-slots {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.equip-slot {
  width: 80px;
  height: 100px;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--secondary);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px;
}

.slot-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.slot-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

#inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 10px;
}

.inventory-item {
  width: 60px;
  height: 60px;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--secondary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.inventory-item:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.inventory-item .item-tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-dark);
  padding: 10px;
  border-radius: 5px;
  white-space: nowrap;
  z-index: 10;
  font-size: 0.8rem;
}

.inventory-item:hover .item-tooltip {
  display: block;
}

/* Quest List */
.quest-item {
  background: rgba(0,0,0,0.2);
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 10px;
  border-left: 3px solid var(--accent);
}

.quest-item h4 {
  margin-bottom: 5px;
}

.quest-item p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.quest-rewards {
  display: flex;
  gap: 15px;
  font-size: 0.85rem;
}

.quest-btn {
  margin-top: 10px;
  padding: 8px 15px;
  background: var(--primary);
  border: none;
  border-radius: 5px;
  color: var(--text-light);
  cursor: pointer;
}

.quest-btn:hover {
  background: var(--primary-dark);
}

/* Shop */
#shop-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
}

.shop-item {
  background: rgba(0,0,0,0.2);
  padding: 15px;
  border-radius: 10px;
  border: 1px solid var(--secondary);
}

.shop-item h4 {
  color: var(--accent);
  margin-bottom: 5px;
}

.shop-item p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.shop-item .price {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 10px;
}

.buy-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border: none;
  border-radius: 5px;
  color: var(--bg-dark);
  font-weight: bold;
  cursor: pointer;
}

.buy-btn:hover {
  background: #e6b84d;
}

.buy-btn:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

/* World Map Panel - Fullscreen */
#map-panel {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  top: 0;
  left: 0;
  transform: none;
  border-radius: 0;
}

#world-map-container {
  width: 100%;
  height: calc(100vh - 150px);
  overflow: hidden;
  cursor: grab;
  border-radius: 0;
  background: #1a3a1a;
  border: none;
  border-top: 2px solid var(--secondary);
  border-bottom: 2px solid var(--secondary);
  margin-bottom: 15px;
  position: relative;
}

#world-map-container:active {
  cursor: grabbing;
}

#world-map-canvas {
  display: block;
}

#map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-bottom: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.legend-dot.player { background: var(--success); }
.legend-dot.other { background: var(--xp); }
.legend-dot.npc { background: var(--accent); }
.legend-dot.boss { background: var(--danger); }

#map-controls {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-top: 5px;
  border-top: 1px solid var(--secondary);
}

/* Interaction Prompt */
#interaction-prompt {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  padding: 12px 24px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  font-size: 1rem;
}

#interaction-prompt kbd {
  background: var(--accent);
  color: var(--bg-dark);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: bold;
  margin: 0 4px;
}

#interact-target-name {
  color: var(--accent);
  font-weight: bold;
}

/* Notifications */
#notifications {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
  pointer-events: none;
}

.notification {
  background: var(--bg-panel);
  padding: 15px 25px;
  border-radius: 10px;
  border-left: 4px solid var(--accent);
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
}

.notification.success { border-color: var(--success); }
.notification.error { border-color: var(--danger); }
.notification.info { border-color: var(--xp); }

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* NPC Dialog */
#npc-dialogue-text {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 20px;
  padding: 15px;
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
}

#npc-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.npc-option-btn {
  padding: 12px 20px;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  color: var(--text-light);
  cursor: pointer;
  text-align: left;
  transition: background 0.2s;
}

.npc-option-btn:hover {
  background: var(--primary-dark);
}

/* Responsive */
@media (max-width: 768px) {
  #mobile-controls {
    display: flex;
  }

  #interaction-prompt {
    display: none;
  }

  #bottom-bar {
    bottom: 140px;
  }

  #chat-bubbles {
    bottom: 210px;
    max-width: 300px;
    font-size: 0.9rem;
  }

  #minimap-container {
    width: 180px;
    height: 180px;
  }

  #quest-tracker {
    top: 265px;
    width: 180px;
    font-size: 0.85rem;
  }

  #world-map-container {
    height: calc(100vh - 120px);
  }

  #chat-window {
    width: calc(100% - 20px);
    left: 10px;
    right: 10px;
  }

  .panel {
    width: 95vw;
  }

  .stat-bar {
    width: 60px;
  }

  #stats-bar {
    font-size: 0.85rem;
  }

  #world-map-container {
    height: 300px;
  }
}

/* Landscape mode on mobile devices */
@media (max-height: 500px) and (orientation: landscape) {
  #mobile-controls {
    display: flex;
    padding: 10px;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
  }

  #joystick-container,
  #joystick-base {
    width: 80px;
    height: 80px;
  }

  #joystick-stick {
    width: 35px;
    height: 35px;
  }

  .mobile-action {
    width: 50px;
    height: 50px;
    font-size: 1.4rem;
  }

  #bottom-bar {
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
  }

  #interaction-prompt {
    display: none;
  }

  #minimap-container {
    width: 150px;
    height: 150px;
    top: 10px !important;
    right: 10px !important;
    left: auto;
    bottom: auto;
  }

  #quest-tracker {
    display: none;
  }

  #top-bar {
    transform: scale(0.8);
    transform-origin: top left;
  }
}

@media (max-width: 480px) {
  .login-container h1 {
    font-size: 2rem;
  }

  #top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  #minimap-container {
    width: 120px;
    height: 120px;
    top: 60px;
  }

  #quest-tracker {
    display: none;
  }

  .action-btn {
    width: 45px;
    height: 45px;
    font-size: 1.3rem;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.2);
}

::-webkit-scrollbar-thumb {
  background: var(--secondary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* Level Editor */
#editor-toggle {
  position: fixed;
  top: 10px;
  left: 10px;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 10px;
  background: var(--bg-panel);
  border: 2px solid var(--secondary);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 100;
  transition: all 0.2s;
}

#editor-toggle:hover {
  background: var(--primary);
  transform: scale(1.1);
}

#editor-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
}

#editor-panel {
  position: fixed;
  top: 70px;
  left: 10px;
  width: 280px;
  max-height: calc(100vh - 90px);
  transform: none;
  overflow-y: auto;
}

#editor-panel .panel-content {
  padding: 15px;
}

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

.editor-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.editor-section h4 {
  margin: 0 0 10px 0;
  color: var(--accent);
  font-size: 0.9rem;
}

.editor-modes,
.editor-objects,
.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.editor-mode-btn,
.editor-obj-btn {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.85rem;
}

.editor-mode-btn:hover,
.editor-obj-btn:hover {
  background: rgba(255,255,255,0.2);
}

.editor-mode-btn.active,
.editor-obj-btn.active {
  background: var(--accent);
  color: #000;
}

.editor-actions button {
  flex: 1;
  min-width: 100px;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.85rem;
}

.editor-actions button:hover {
  background: var(--primary-dark);
}

#editor-clear {
  background: #c0392b !important;
}

#editor-clear:hover {
  background: #a93226 !important;
}

#editor-scale {
  width: 100%;
  margin-bottom: 5px;
}

#editor-scale-value {
  color: var(--text-muted);
  font-size: 0.85rem;
}

#editor-info {
  background: rgba(0,0,0,0.2);
  padding: 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}

#editor-info p {
  margin: 5px 0;
  color: var(--text-muted);
}

/* Editor cursor preview */
#editor-cursor {
  position: fixed;
  pointer-events: none;
  font-size: 2rem;
  z-index: 1000;
  transform: translate(-50%, -50%);
  opacity: 0.7;
  display: none;
}

.editor-active #editor-cursor {
  display: block;
}
