:root {
  --bg-dark: #0a0f14;
  --panel-dark: #1a252f;
  --accent: #3498db;
  --danger: #e74c3c;
  --success: #2ecc71;
  --warning: #f39c12;
  --text: #ecf0f1;
  --muted: #95a5a6;
  --glass: rgba(26, 37, 47, 0.85);
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-dark);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  overflow: hidden;
  touch-action: none;
}

header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 24px;
  background: #000;
  flex-shrink: 0;
  border-bottom: 1px solid #1a252f;
  box-sizing: border-box;
  z-index: 2000;
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

h1 {
  margin: 0;
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  text-transform: uppercase;
  display: flex;
  align-items: center;
}

#logoutBtn {
  background: transparent;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  display: none;
}

#logoutBtn:hover {
  border-color: var(--text);
  color: var(--text);
}

#helpBtn:hover {
  border-color: var(--text) !important;
  color: var(--text) !important;
}

#mainContent {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: stretch;
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
  flex: 1;
  gap: 15px;
  overflow: hidden;
}

#statsPanel {
  background: var(--glass);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  padding: 24px;
  width: 100%;
  box-sizing: border-box;
  color: var(--text);
}

#statsPanel h3 {
  margin-top: 24px;
  margin-bottom: 16px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 10px;
}

#statsPanel h3:first-child {
  margin-top: 0;
}

#statsPanel p {
  margin: 8px 0;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
}

#statsPanel p strong {
  color: var(--muted);
  font-weight: 600;
}

#gameContainer {
  position: relative;
  flex: 1;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
  border: 1px solid #2c3e50;
  background-color: #47aba9;
  background-image: url('../terrain/water.png');
  background-repeat: repeat;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 5000;
  display: none;
  align-items: flex-start;
  padding: 5vh 15px;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  position: relative;
  background: var(--panel-dark);
  max-width: 450px;
  width: 100%;
  margin: auto;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.8);
}

.close-modal {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transition: background 0.2s;
  z-index: 10;
}

.close-modal:hover {
  background: var(--danger);
}

/* Character HUD Styles - Upper Left */
#charTrigger {
  position: fixed;
  top: 60px;
  left: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.2s;
  background: var(--glass);
  padding: 8px 16px;
  border-radius: 40px;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#charTrigger:hover {
  transform: scale(1.05);
}

.avatar-circle {
  width: 72px;
  height: 72px;
  background: var(--panel-dark);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  padding: 6px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  position: relative;
  transition: all 0.3s ease;
}

.avatar-circle.status-criminal {
  border: 2px solid #bdc3c7;
  box-shadow: 0 0 15px rgba(189, 195, 199, 0.4);
}

.avatar-circle.status-murderer {
  border: 2px solid var(--danger);
  box-shadow: 0 0 15px rgba(231, 76, 60, 0.4);
}

.status-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--panel-dark);
  display: none;
  z-index: 10;
}

.status-badge.criminal {
  display: block;
  background: #bdc3c7;
}

.status-badge.murderer {
  display: block;
  background: var(--danger);
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.corner-hp-bar {
  width: 120px;
  height: 10px;
  position: relative;
  background: rgba(0,0,0,0.5);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}

.corner-hp-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #e74c3c, #ff6b6b);
  transition: width 0.3s ease;
}

@media (max-width: 768px), (max-height: 500px) {
  #mainContent {
    flex-direction: column;
    align-items: center;
  }

  #gameContainer {
    width: 100vw;
    height: 100vh;
  }

  #statsPanel {
    display: none;
  }

  /* Scale down UI for mobile landscape */
  #charTrigger {
    top: 50px !important;
    left: 10px !important;
    transform: scale(0.7);
    transform-origin: top left;
  }

  #mobileControls {
    left: 15px !important;
    bottom: 15px !important;
    transform: scale(0.8);
    transform-origin: bottom left;
  }

  #actionControls {
    right: 15px !important;
    bottom: 15px !important;
    transform: scale(0.8);
    transform-origin: bottom right;
  }

  #minimapBox {
    top: 10px !important;
    right: 10px !important;
    transform: scale(0.7);
    transform-origin: top right;
  }
}

/* Landscape Lock */
#landscapeLock {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  z-index: 10000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  box-sizing: border-box;
}

#landscapeLock .icon {
  font-size: 48px;
  margin-bottom: 20px;
  animation: rotate 2s infinite ease-in-out;
}

@keyframes rotate {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
  100% { transform: rotate(-90deg); }
}

@media (orientation: portrait) {
  body.is-playing #landscapeLock { display: flex; }
}

/* Grayscale Overlay for Death */
#deathOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(128, 128, 128, 0.2);
  backdrop-filter: grayscale(1);
  pointer-events: none;
  z-index: 999;
  display: none;
}

body.is-ghost #deathOverlay {
  display: block;
}

body.is-ghost canvas {
  filter: grayscale(100%) brightness(1.2);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Action Buttons - Bottom Right Diamond */
#actionControls {
  position: fixed;
  right: 40px;
  bottom: 40px;
  width: 180px;
  height: 180px;
  display: grid;
  grid-template-areas:
    ". spell ."
    "loot chat attack"
    ". shop .";
  gap: 10px;
  z-index: 100;
  pointer-events: none;
}

#actionControls button {
  pointer-events: auto;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
  width: 60px;
  height: 60px;
}

#spellBtn { grid-area: spell; }
#lootBtn { grid-area: loot; }
#hudChatBtn { grid-area: chat; pointer-events: auto; }
#attackBtn { grid-area: attack; }
#shopBtn { grid-area: shop; }

/* Shop Layout Helpers */
.shop-container {
  display: flex;
  gap: 20px;
  width: 100%;
  box-sizing: border-box;
}

.shop-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

@media (max-width: 850px) {
  .shop-container {
    flex-direction: column;
  }
}

#minimapBox {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 120px;
  height: 120px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 4px;
  z-index: 50;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#minimapCanvas {
  width: 110px;
  height: 110px;
  border-radius: 8px;
  display: block;
}

#chatOverlay {
  position: absolute;
  bottom: 140px;
  /* Above the action buttons */
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 600px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  border-radius: 12px;
  padding: 10px;
  display: none;
  z-index: 1000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#chatInput {
  width: 100%;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 16px;
  padding: 10px;
  outline: none;
  font-family: 'Inter', sans-serif;
}

#chatInput::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

button {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  background-color: #e74c3c;
  color: white;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

button:active {
  transform: scale(0.95);
}

.action-btn {
  position: relative;
  z-index: 10;
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s;
  backdrop-filter: blur(4px);
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.action-btn:active {
  transform: translateY(0) scale(0.95);
  background: rgba(255, 255, 255, 0.15);
}

.action-btn.red-btn {
  border-color: rgba(231, 76, 60, 0.3);
}

.action-btn.red-btn:hover {
  background: rgba(231, 76, 60, 0.1);
}

.action-btn img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  pointer-events: none;
}

.action-btn span {
  font-size: 9px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
  pointer-events: none;
  text-transform: uppercase;
}

#mobileControls {
  position: fixed;
  left: 60px;
  bottom: 60px;
  z-index: 100;
  display: block;
  width: 120px;
  height: 120px;
}

#joystick {
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  position: relative;
  backdrop-filter: blur(4px);
}

#joystickKnob {
  width: 50px;
  height: 50px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
  transition: transform 0.1s;
  pointer-events: none;
}

.joystick-dir-indicator {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
}

.joystick-dir-indicator div {
  position: absolute;
  color: rgba(255,255,255,0.2);
  font-size: 10px;
  font-weight: bold;
}
.dir-n { top: 5px; left: 50%; transform: translateX(-50%); }
.dir-s { bottom: 5px; left: 50%; transform: translateX(-50%); }
.dir-w { left: 5px; top: 50%; transform: translateY(-50%); }
.dir-e { right: 5px; top: 50%; transform: translateY(-50%); }

.skill-item:last-child {
  border-bottom: none;
}

.combat-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
  font-size: 14px;
}

.stat-box {
  text-align: center;
}

.equip-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s;
}

.equip-box span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 4px;
}

.stat-box span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-bottom: 2px;
}

.stat-box b {
  color: var(--accent);
}

.skill-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.skill-item {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.skill-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text);
}

.skill-bar-bg {
  height: 4px;
  background: #12181f;
  border-radius: 2px;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.skill-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.hp-bar-container {
  height: 12px;
  background: #12181f;
  border-radius: 6px;
  width: 100%;
  margin: 8px 0;
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  background: var(--success);
  transition: width 0.3s ease, background 0.3s ease;
}

.skill-toggles {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.skill-toggles button {
  border: none;
  padding: 10px 4px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  background-color: #1a252f;
  border-radius: 6px;
  flex: 1;
  transition: all 0.2s;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.skill-toggles button:hover:not(.active-btn) {
  background-color: #2c3e50;
  color: white;
}

.skill-toggles .active-btn {
  background-color: var(--success) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(46, 204, 113, 0.4);
  font-weight: 700;
  pointer-events: none;
}

#authOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at center, #2c3e50 0%, #12181f 100%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.auth-box {
  background: var(--glass);
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.6);
  width: 100%;
  max-width: 400px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.auth-box h2 {
  margin-top: 0;
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  letter-spacing: 2px;
  margin-bottom: 30px;
}

.auth-box input,
.auth-box select {
  width: 100%;
  padding: 14px;
  margin-bottom: 15px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: 15px;
}

.auth-box button {
  width: 100%;
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  letter-spacing: 1px;
}

.error-msg {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 20px;
  min-height: 20px;
  font-weight: 600;
}

@media (max-width: 768px) {
  #mobileControls {
    display: flex;
  }
}

#resurrectionOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 3000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

.res-box {
  background: var(--panel-dark);
  padding: 30px;
  border-radius: 12px;
  text-align: center;
  border: 2px solid var(--success);
  box-shadow: 0 0 30px rgba(46, 204, 113, 0.3);
}

.res-box h2 {
  font-family: 'Outfit', sans-serif;
  color: var(--success);
  margin-top: 0;
}

.res-box p {
  margin-bottom: 25px;
  color: var(--muted);
}

.res-btn-group {
  display: flex;
  gap: 15px;
  justify-content: center;
}

.login-footer {
  margin-top: 24px;
  font-size: 13px;
  color: var(--muted);
}

.login-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.login-footer a:hover {
  text-decoration: underline;
}
