/* =============================================
   The Last Dungeon — Dark Dungeon Theme
   ============================================= */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0808;
  color: #d4cbb8;
  font-family: system-ui, -apple-system, 'Segoe UI', monospace;
  font-size: 14px;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0808; }
::-webkit-scrollbar-thumb { background: #3a3232; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4a3e3e; }

/* --- Screens --- */
.screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  z-index: 5;
}
.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Auth Screen --- */
#auth-screen {
  background: radial-gradient(ellipse at center bottom, #1a1210 0%, #0a0808 70%);
}

.auth-container { text-align: center; }

.game-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 4rem;
  font-weight: 700;
  color: #ff8830;
  text-shadow:
    0 0 20px rgba(255, 136, 48, 0.5),
    0 0 60px rgba(255, 136, 48, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.8);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.tagline {
  font-size: 1.1rem;
  color: #8a7e6e;
  font-style: italic;
  margin-bottom: 48px;
  letter-spacing: 1px;
}

.auth-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.apple-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 280px;
  height: 44px;
  background: #1a1818;
  color: #d4cbb8;
  border: 1px solid #3a3232;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.apple-btn:hover {
  background: #201e1e;
  border-color: #ff8830;
}
.apple-btn svg { flex-shrink: 0; }

/* --- Panels --- */
.panel {
  background: #1a1818;
  border: 1px solid #2a2424;
  border-radius: 8px;
  padding: 32px;
  min-width: 360px;
  max-width: 480px;
  text-align: center;
}
.panel h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.6rem;
  color: #ff8830;
  margin-bottom: 24px;
  text-shadow: 0 0 10px rgba(255, 136, 48, 0.3);
}

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 10px 24px;
  background: #1a1818;
  color: #d4cbb8;
  border: 1px solid #4a3828;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 12px;
}
.btn:hover {
  background: #201e1e;
  border-color: #ff8830;
  box-shadow: 0 0 12px rgba(255, 136, 48, 0.2);
}
.btn-secondary {
  border-color: #2a2424;
  color: #8a7e6e;
}
.btn-secondary:hover {
  border-color: #5a4e3e;
  box-shadow: none;
}

/* --- Character Select --- */
.character-slots {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.character-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #141212;
  border: 1px solid #2a2424;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.character-slot:hover {
  border-color: #ff8830;
  background: #1a1616;
}

.char-slot-preview {
  image-rendering: pixelated;
  width: 36px;
  height: 48px;
  background: #0a0808;
  border-radius: 3px;
}

.char-info {
  text-align: left;
  flex: 1;
}
.char-name {
  font-size: 15px;
  color: #d4cbb8;
  font-weight: 600;
}
.char-details {
  font-size: 12px;
  color: #8a7e6e;
  margin-top: 2px;
  text-transform: capitalize;
}

.delete-char-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: #5a4444;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}
.delete-char-btn:hover { color: #c0392b; }

/* --- Character Create --- */
.create-panel {
  min-width: 400px;
  max-width: 520px;
}

.create-form { text-align: left; }

.form-row { margin-bottom: 16px; }
.form-row label {
  display: block;
  font-size: 12px;
  color: #8a7e6e;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.form-row input[type="text"] {
  width: 100%;
  padding: 8px 12px;
  background: #0a0808;
  border: 1px solid #2a2424;
  border-radius: 4px;
  color: #d4cbb8;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.form-row input[type="text"]:focus { border-color: #ff8830; }
.form-row input[type="text"]::placeholder { color: #4a4040; }

.option-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.option-btn {
  padding: 6px 14px;
  background: #0a0808;
  border: 1px solid #2a2424;
  border-radius: 4px;
  color: #8a7e6e;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.option-btn:hover {
  border-color: #4a3e3e;
  color: #d4cbb8;
}
.option-btn.selected {
  background: #2a1e14;
  border-color: #ff8830;
  color: #ff8830;
  box-shadow: 0 0 8px rgba(255, 136, 48, 0.15);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.color-row label {
  display: inline;
  margin-bottom: 0;
}
.color-row input[type="color"] {
  width: 36px;
  height: 28px;
  border: 1px solid #2a2424;
  border-radius: 3px;
  background: #0a0808;
  cursor: pointer;
  padding: 0;
}
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.color-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.preview-container {
  display: flex;
  justify-content: center;
  padding: 16px 0;
}
#char-preview {
  image-rendering: pixelated;
  background: #0a0808;
  border: 1px solid #2a2424;
  border-radius: 4px;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.error-text {
  color: #c0392b;
  font-size: 13px;
  text-align: center;
  margin-top: 8px;
  min-height: 18px;
}

/* --- Game Screen --- */
#game-screen {
  display: none;
  z-index: 1;
}
#game-screen.active { display: block; }

#game-canvas-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 1;
}
#game-canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ============================================================
   HUD — grounded frame + resource bars + hotbar
   ============================================================ */
#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  pointer-events: none;
  /* Engraved stone-panel feel */
  background: rgba(8, 6, 6, 0.82);
  border: 1px solid #3a2e24;
  border-radius: 6px;
  padding: 10px 12px 8px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.04),
    0 2px 8px rgba(0,0,0,0.7);
  /* Thin warm top edge — torch-glow effect */
  border-top-color: #5a3e24;
}

/* Decorative corner accents (pure CSS) */
#hud::before, #hud::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: #ff8830;
  border-style: solid;
  opacity: 0.5;
}
#hud::before {
  top: -1px; left: -1px;
  border-width: 2px 0 0 2px;
}
#hud::after {
  top: -1px; right: -1px;
  border-width: 2px 2px 0 0;
}

.bar-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 6px;
}

.bar {
  position: relative;
  width: 190px;
  height: 14px;
  background: #0c0a0a;
  border: 1px solid #2a2020;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
}

.bar-fill {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  transition: width 0.3s ease;
  border-radius: 1px;
}

/* Bevel highlight on fill */
.bar-fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  right: 0;
  height: 40%;
  background: rgba(255,255,255,0.1);
  border-radius: 1px 1px 0 0;
}

/* HP — deep crimson, classic EQ feel */
.hp-bar .bar-fill {
  background: linear-gradient(to bottom, #9c2a28 0%, #6a1816 60%, #4e1010 100%);
}

/* Low HP pulse */
.hp-bar.bar-critical .bar-fill {
  animation: hp-pulse 0.9s ease-in-out infinite;
}
@keyframes hp-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

/* MP — deep indigo */
.mp-bar .bar-fill {
  background: linear-gradient(to bottom, #2e4e94 0%, #1e3268 60%, #14224a 100%);
}

/* Stamina — forest green */
.stamina-bar .bar-fill {
  background: linear-gradient(to bottom, #2e6640 0%, #1e4428 60%, #122c18 100%);
}

.bar span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 9px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
  white-space: nowrap;
  z-index: 1;
  letter-spacing: 0.5px;
}

.player-info {
  display: flex;
  gap: 8px;
  font-size: 11px;
  margin-bottom: 8px;
}
#player-name {
  color: #e8c87a;
  font-weight: 600;
  text-shadow: 0 0 8px rgba(232,200,122,0.3);
}
#player-level { color: #8a7e6e; }

/* --- Hotbar --- */
.hotbar {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.hotbar-slot {
  position: relative;
  width: 40px;
  height: 40px;
  background: #0e0c0c;
  border: 1px solid #3a2e1e;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.hotbar-icon {
  font-size: 18px;
  color: #c0a860;
  line-height: 1;
  /* Pushed slightly up to leave room for key label */
  margin-bottom: 6px;
}

.hotbar-key {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 9px;
  color: #5a5040;
  font-family: monospace;
  font-weight: 600;
  letter-spacing: 0;
}

/* Cooldown overlay — fills from bottom up, dark semi-transparent */
.hotbar-cd {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;          /* driven by HUD.js */
  background: rgba(0, 0, 0, 0.72);
  transition: height 0.05s linear;
  pointer-events: none;
}

/* --- Chat Panel --- */
#chat-panel {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 310px;
  z-index: 10;
}

#chat-messages {
  height: 200px;
  overflow-y: auto;
  padding: 8px;
  /* Increased opacity for legibility on any background */
  background: rgba(8, 6, 6, 0.88);
  border: 1px solid #2a2020;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
}

.chat-message {
  font-size: 12px;
  line-height: 1.4;
  margin-bottom: 2px;
  word-wrap: break-word;
  /* Subtle text shadow for legibility against any canvas color */
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
.chat-name {
  color: #ff8830;
  font-weight: 600;
}

#chat-input {
  width: 100%;
  padding: 6px 10px;
  background: rgba(8, 6, 6, 0.92);
  border: 1px solid #2a2020;
  border-radius: 0 0 4px 4px;
  color: #d4cbb8;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
#chat-input:focus {
  border-color: #ff8830;
  background: rgba(18, 14, 14, 0.95);
}
#chat-input::placeholder { color: #4a4040; }

/* --- Skills Overlay --- */
#skills-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: min(420px, calc(100vh - 24px));
  overflow-y: auto;
  z-index: 12;
  background: rgba(10, 8, 8, 0.94);
  border: 1px solid #4a3828;
  border-radius: 8px;
  padding: 12px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.04),
    0 8px 24px rgba(0,0,0,0.55);
}

.skills-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  color: #e8c87a;
  font-size: 16px;
  font-family: Georgia, 'Times New Roman', serif;
}

.skills-hint {
  color: #8a7e6e;
  font-size: 11px;
  font-family: inherit;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.skills-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skill-entry {
  background: rgba(20, 18, 18, 0.92);
  border: 1px solid #2e2620;
  border-radius: 6px;
  padding: 10px;
}

.skill-entry.hotbar-skill {
  border-color: #6a4d28;
  box-shadow: inset 0 0 0 1px rgba(232,200,122,0.08);
}

.skill-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.skill-name {
  color: #f0dfb0;
  font-weight: 600;
}

.skill-slot {
  color: #c0a860;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.skill-meta {
  color: #8a7e6e;
  font-size: 11px;
  margin-bottom: 4px;
}

.skill-desc {
  color: #d4cbb8;
  font-size: 12px;
  line-height: 1.4;
}

.game-menu-panel .btn {
  width: 100%;
  margin-top: 0;
}

/* --- Map Overlay --- */
#map-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 20;
  background: rgba(8, 6, 6, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#map-overlay.hidden { display: none; }

#map-canvas {
  image-rendering: pixelated;
  max-width: 80vw;
  max-height: 70vh;
  border: 1px solid #ff8830;
  border-radius: 4px;
  box-shadow: 0 0 20px rgba(255,136,48,0.35);
}

.map-title {
  margin-top: 12px;
  font-size: 13px;
  color: #8a7e6e;
  letter-spacing: 1px;
}

/* --- Escape Menu --- */
#game-menu {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 6, 0.72);
  backdrop-filter: blur(2px);
}

.game-menu-panel {
  width: min(320px, calc(100vw - 32px));
  background: linear-gradient(to bottom, rgba(24, 18, 18, 0.98), rgba(12, 10, 10, 0.98));
  border: 1px solid #5a3e24;
  border-radius: 8px;
  padding: 20px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.05),
    0 12px 32px rgba(0,0,0,0.7);
}

.game-menu-title {
  margin-bottom: 14px;
  color: #f0cf8c;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 24px;
  text-align: center;
  text-shadow: 0 0 12px rgba(255,136,48,0.18);
}

.game-menu-panel .btn + .btn {
  margin-top: 10px;
}

.game-menu-hint {
  margin-top: 14px;
  color: #8a7e6e;
  font-size: 11px;
  text-align: center;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* --- Utilities --- */
.hidden { display: none !important; }

@media (max-width: 700px) {
  #skills-overlay {
    top: auto;
    bottom: 12px;
    right: 12px;
    max-height: min(45vh, 320px);
  }
}
