/* SHADOWREALM - Dark Gothic UI */
:root {
  --bg-black: #050505;
  --panel-bg: #0a0a0a;
  --panel-border: #2a2520;
  --panel-border-light: #3d3530;
  --text-main: #c9c0b6;
  --text-muted: #7a726a;
  --text-red: #c0392b;
  --text-red-bright: #e74c3c;
  --text-gold: #d4af37;
  --text-purple: #9b59b6;
  --hp-red: #c0392b;
  --hp-bg: #2c0b0b;
  --exp-purple: #8e44ad;
  --exp-bg: #2a1030;
  --accent-red: #8b0000;
  --font-heading: 'Cinzel Decorative', 'Cinzel', serif;
  --font-body: 'Cinzel', Georgia, serif;
}

* {
  box-sizing: border-box;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-black);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  overflow: hidden;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
}

.screen.active {
  display: flex;
}

/* ---------- Main Menu & Auth Screens ---------- */
#main-menu-screen.screen.active,
#play-now-screen.screen.active {
  background: radial-gradient(circle at center, #150a0a 0%, #050505 100%);
}

.menu-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 1405px;
  height: 906px;
  padding: 0;
  overflow: hidden;
  background: #0a0a0a;
  border: 3px solid #2a2520;
  box-shadow: 0 0 80px rgba(0,0,0,0.95);
}

.menu-bg-wrap,
.auth-bg-wrap {
  position: relative;
  width: 1561px;
  height: 1007px;
  flex-shrink: 0;
  transform: scale(0.9);
  transform-origin: center center;
}

.menu-bg {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
  box-shadow: 0 0 80px rgba(0,0,0,0.95);
}

.menu-btn-play {
  position: absolute;
  left: 50%;
  top: 65%;
  transform: translateX(-50%);
  width: 35%;
  height: 9%;
  background: transparent;
  border: 2px solid rgba(139, 0, 0, 0.4);
  color: transparent;
  font-size: 0;
  cursor: pointer;
  transition: all 0.15s;
}

.menu-btn-play:hover {
  background: rgba(139, 0, 0, 0.15);
  box-shadow: 0 0 30px rgba(139, 0, 0, 0.35);
}

.menu-status {
  position: absolute;
  left: 50%;
  top: 78%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-family: var(--font-body);
  font-size: 17px;
  letter-spacing: 1.5px;
  text-shadow: 0 2px 6px #000;
}

#server-status {
  color: #e74c3c;
}

#server-status.status-online {
  color: #27ae60;
}

#players-online {
  color: #a29b93;
}

/* Play As Guest: image button under Players Online on the title screen. */
#btn-play-guest {
  width: 240px;
  padding: 0;
  margin-top: 4px;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 0;
}

#btn-play-guest img {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 2px 6px #000);
  transition: transform 0.1s, filter 0.15s;
}

#btn-play-guest:hover img {
  transform: scale(1.03);
  filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.55)) brightness(1.1);
}

.menu-btn-back {
  position: absolute;
  left: 50%;
  bottom: 2.5%;
  transform: translateX(-50%);
  width: 18%;
  height: 5%;
  background: rgba(10, 10, 10, 0.6);
  border: 1px solid rgba(139, 0, 0, 0.4);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.15s;
}

.menu-btn-back:hover {
  background: rgba(139, 0, 0, 0.2);
}

.auth-message {
  position: absolute;
  left: 50%;
  top: 36%;
  transform: translateX(-50%);
  width: 60%;
  text-align: center;
  color: var(--text-red-bright);
  font-size: 16px;
  text-shadow: 0 2px 6px #000;
  pointer-events: none;
}

.login-panel,
.register-panel {
  position: absolute;
  top: 41.5%;
  width: 31.8%;
  height: 45%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 20px 24px;
}

.login-panel {
  left: 14.2%;
}

.register-panel {
  right: 14.2%;
}

.login-panel .form-group,
.register-panel .form-group {
  margin: 0;
}

.login-panel input,
.register-panel input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(8, 8, 8, 0.75);
  border: 1px solid rgba(74, 64, 56, 0.6);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}

.login-panel input:focus,
.register-panel input:focus {
  border-color: var(--accent-red);
}

.login-panel input::placeholder,
.register-panel input::placeholder {
  color: #5a5048;
}

.login-panel .btn,
.register-panel .btn {
  width: 100%;
  padding: 16px;
  margin: 10px 0 0;
  background: rgba(42, 29, 26, 0.85);
  border: 1px solid rgba(74, 48, 40, 0.8);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 16px;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
}

.login-panel .btn:hover,
.register-panel .btn:hover {
  background: rgba(58, 40, 36, 0.9);
  border-color: var(--text-red-bright);
}

/* ---------- Loading Screen ---------- */
#loading-screen {
  background: #000;
  flex-direction: column;
}

.loading-panel {
  text-align: center;
}

.auth-title-img {
  height: 54px;
  width: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.8)) drop-shadow(0 0 20px rgba(139,0,0,0.3));
  margin-bottom: 8px;
}

.loading-bar {
  width: 320px;
  height: 14px;
  margin: 24px auto 12px;
  background: var(--exp-bg);
  border: 1px solid var(--panel-border);
}

.loading-fill {
  width: 0%;
  height: 100%;
  background: var(--exp-purple);
  transition: width 0.3s;
}

.loading-status {
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 1px;
}

/* ---------- Game Wrapper & Container ---------- */
#game-screen.screen.active {
  background: #1a1a1a;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  overflow: auto;
}

#game-wrapper {
  width: 1405px;
  height: 906px;
  background: #1a1a1a;
  border: 4px solid #2a2520;
  box-shadow: 0 0 40px rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#game-container {
  width: 1561px;
  height: 1007px;
  background: var(--bg-black);
  border: 3px solid #2a2520;
  box-shadow: 0 0 60px rgba(0,0,0,0.95), inset 0 0 0 1px #0a0a0a;
  display: flex;
  flex-direction: column;
  position: relative;
  transform: scale(0.9);
  transform-origin: center center;
  flex-shrink: 0;
}

/* ---------- Top Bar ---------- */
#top-bar {
  height: 74px;
  background-color: #080706;
  background-image: url('Dracked Stone Dungeon UI Panel.png');
  background-size: 115% auto;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 12px;
}

.header-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  flex-shrink: 0;
}

.brand-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
}

.brand-img {
  height: 34px;
  width: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.8));
}

.left-column {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
}

.hud-gold {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-gold);
  font-size: 26px;
  font-family: var(--font-heading);
  letter-spacing: 1px;
}

.coin-icon {
  display: inline-block;
  width: 32px;
  height: 32px;
  background: url('assets/gold_top_bar.png') center/contain no-repeat;
  image-rendering: pixelated;
  vertical-align: middle;
}

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  min-width: 0;
}

.header-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 2px;
}

.player-section {
  gap: 0;
}

.hp-section,
.xp-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
}

.bar-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.bar-value {
  position: absolute;
  top: 57%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
  color: #c9c0b6;
  font-family: var(--font-heading);
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  line-height: 1;
  white-space: nowrap;
  z-index: 2;
  pointer-events: none;
}

.section-line {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}

.hud-avatar {
  width: 44px;
  height: 44px;
  background: #111;
  border: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}

.hud-avatar img {
  width: 38px;
  height: 38px;
  image-rendering: pixelated;
}

.hud-avatar:hover .avatar-change {
  opacity: 1;
}

#hud-player-name {
  font-size: 22px;
  color: var(--text-main);
  font-family: var(--font-heading);
  letter-spacing: 1px;
}

#hud-guild {
  font-size: 14px;
  color: var(--text-main);
  font-family: var(--font-heading);
}

.hud-level {
  font-size: 16px;
  color: var(--text-purple);
  margin-left: 4px;
}

.bar-label {
  width: 28px;
  font-size: 18px;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
  font-family: var(--font-heading);
}

.hud-bar {
  width: 400px;
  height: 72px;
  position: relative;
  overflow: hidden;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
}

.hp-section .hud-bar {
  background-image: url('https://shadowrealmgame.alwaysdata.net/sprites/healthbar.png');
}

.xp-section .hud-bar {
  background-image: url('https://shadowrealmgame.alwaysdata.net/sprites/xp_bar.png');
}

.hud-bar canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#hud-hp-text,
#hud-exp-text {
  font-size: 18px;
  color: #c9c0b6;
  color: var(--text-main);
  white-space: nowrap;
  text-align: left;
  flex-shrink: 0;
  font-family: var(--font-heading);
}

.stats-section {
  flex-shrink: 0;
  gap: 0;
  min-width: 80px;
}

.stat-line {
  font-size: 18px;
  color: var(--text-muted);
  font-family: var(--font-heading);
  line-height: 1.05;
}

.stat-line b {
  color: var(--text-gold);
}

.level-line {
  font-size: 18px;
  color: var(--text-purple);
}

.level-line b {
  color: var(--text-purple);
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  color: var(--text-main);
  font-family: var(--font-heading);
  flex-shrink: 0;
}

#hud-coords,
#hud-time {
  font-size: 24px;
  line-height: 1;
}

.btn-tiny {
  padding: 2px 6px;
  background: linear-gradient(180deg, #1f1614 0%, #15100e 100%);
  border: 1px solid #3d3530;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 9px;
  letter-spacing: 0.5px;
  cursor: pointer;
  text-transform: uppercase;
}

.btn-tiny:hover {
  border-color: var(--accent-red);
}

/* ---------- Main Body ---------- */
#main-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#world-column {
  width: 1220px;
  display: flex;
  flex-direction: column;
  border-right: 2px solid #1a1512;
}

#world-viewport {
  width: 1220px;
  height: 654px;
  background: #000;
  position: relative;
  overflow: hidden;
}

#world-canvas {
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
  outline: none;
}

#world-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}

#zoom-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(8, 8, 8, 0.85);
  border: 1px solid #3d3530;
  padding: 4px 8px;
  pointer-events: auto;
  z-index: 10;
}

#zoom-controls button {
  width: 24px;
  height: 24px;
  background: #1a1512;
  border: 1px solid #4a4038;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

#zoom-controls button:hover {
  border-color: var(--text-red-bright);
}

#zoom-value {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 38px;
  text-align: center;
}

/* Equipped grimoire book square: bottom-left of the game map (Fire Blast or
   Immortal Shield icon); grays out with a countdown while it recharges. */
#book-slot {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 58px;
  height: 58px;
  border: 2px solid #ffd700;
  background: rgba(8, 8, 8, 0.75);
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

#book-slot.hidden {
  display: none;
}

#book-slot img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
}

#book-slot.cooling {
  filter: grayscale(1);
  border-color: #6b6b6b;
  cursor: default;
}

#book-slot-cd {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: bold 20px 'Cinzel', serif;
  color: #ffffff;
  text-shadow: 0 0 4px #000000;
  pointer-events: none;
}

/* BUILD/CRAFT/OPTIONS: image squares floating in the bottom-right corner of
   the game map — same 58px square size as the book slot bottom-left. Hovering
   shows a plain text label above the button. */
#corner-actions {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
  z-index: 15;
}

.corner-btn {
  position: relative;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 2px solid #3d3530;
  background: rgba(8, 8, 8, 0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.corner-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.corner-btn:hover {
  border-color: #ffd700;
  filter: brightness(1.15);
}

.corner-btn::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 8, 8, 0.92);
  border: 1px solid #3d3530;
  color: #e8dffb;
  font: 700 13px 'Cinzel', serif;
  letter-spacing: 1.5px;
  padding: 4px 10px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.corner-btn:hover::after {
  opacity: 1;
}

/* ---------- Chat ---------- */
#chat-panel {
  height: 279px;
  background-color: #080706;
  border: 2px solid transparent;
  border-image: url('Dark Pixel-Art Stone Frame.png') 130 / 26px / 0 stretch;
  display: flex;
  flex-direction: column;
}

#chat-tabs {
  display: flex;
  padding: 6px 8px 0;
  gap: 4px;
  border-bottom: 1px solid #1f1a16;
}

.chat-tab {
  padding: 5px 10px;
  background: #12100e;
  border: 1px solid #2a2520;
  border-bottom: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 24px;
  letter-spacing: 1px;
  cursor: pointer;
}

.chat-tab.active {
  background: #1a1512;
  color: var(--text-red-bright);
  border-color: #4a3530;
}

#chat-messages {
  flex: 1;
  padding: 8px 12px;
  overflow-y: auto;
  font-size: 26px;
  line-height: 1.25;
  color: var(--text-main);
}

.chat-line {
  margin-bottom: 1px;
}

.chat-global { color: #7dcea0; }
.chat-guild { color: #f7dc6f; }
.chat-local { color: #85c1e9; }
.chat-system { color: var(--text-red-bright); }
.chat-personal { color: #d7bde2; }

#chat-input-row {
  display: flex;
  padding: 6px 8px 8px;
  gap: 8px;
}

#chat-input {
  flex: 1;
  padding: 8px 12px;
  background: #0f0d0c;
  border: 1px solid #2a2520;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 24px;
  outline: none;
}

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

#chat-send {
  padding: 8px 18px;
  background: #1a1512;
  border: 1px solid #3d3530;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 24px;
  letter-spacing: 1px;
  cursor: pointer;
}

#chat-send:hover {
  border-color: var(--accent-red);
}

/* ---------- Right Sidebar ---------- */
#right-sidebar {
  width: 341px;
  background-color: #080706;
  background-image: url('Dothic Stone UI Frame.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 10px;
  gap: 8px;
  overflow-y: auto;
  /* Reserve the 6px scrollbar gutter permanently: the scrollbar still only
     appears when the content (e.g. a long selected-object description)
     actually overflows, but its appearing/disappearing can never shift or
     resize the panels. */
  scrollbar-gutter: stable;
}

.side-panel {
  background: rgba(10, 9, 8, 0.85);
  border: 1px solid var(--panel-border);
  padding: 10px 12px;
  position: relative;
}

.side-panel::before, .side-panel::after {
  content: '';
  position: absolute;
  width: 8px; height: 8px;
  border: 1px solid #4a4038;
}

.side-panel::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.side-panel::after { top: -1px; right: -1px; border-left: none; border-bottom: none; }

.panel-title {
  font-family: var(--font-body);
  font-size: 36px;
  letter-spacing: 2px;
  color: var(--text-red-bright);
  text-align: center;
  margin: 0 0 10px;
  font-weight: 700;
}

/* Inventory Panel */
#inventory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.inv-slot {
  aspect-ratio: 1;
  background: #0d0c0b;
  border: 1px solid #2a2520;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

.inv-slot.selected {
  border-color: var(--text-red-bright);
  box-shadow: inset 0 0 8px rgba(192, 57, 43, 0.3);
}

.inv-slot.equipped {
  border-color: #ff3333;
  box-shadow: inset 0 0 10px rgba(255, 51, 51, 0.5);
}

.inv-slot.equipped-shield {
  border-color: #3399ff;
  box-shadow: inset 0 0 10px rgba(51, 153, 255, 0.5);
}

/* Equipped grimoire book (special slot): yellow outline glow. */
.inv-slot.equipped-special {
  border-color: #ffd700;
  box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.6), 0 0 8px rgba(255, 215, 0, 0.55);
}

.inv-slot img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  image-rendering: pixelated;
}

.inv-qty {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 30px;
  color: var(--text-main);
  text-shadow: 0 1px 2px #000;
}

#inventory-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

#inventory-nav button {
  background: #151210;
  border: 1px solid #2a2520;
  color: var(--text-main);
  width: 44px;
  height: 36px;
  font-size: 20px;
  cursor: pointer;
}

#inventory-nav button:hover {
  border-color: var(--accent-red);
}

#inv-page {
  font-size: 20px;
  color: var(--text-muted);
}

#sidebar-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-small {
  width: 100%;
  padding: 16px;
  margin: 0;
  font-size: 22px;
  letter-spacing: 1.5px;
  background: linear-gradient(180deg, #1f1614 0%, #15100e 100%);
  border: 1px solid #3d3530;
  color: var(--text-main);
}

.btn-small:hover {
  background: linear-gradient(180deg, #2a1e1b 0%, #1b1412 100%);
  border-color: var(--accent-red);
}

/* Selected Object Panel */
#selected-content {
  min-height: 160px;
}

#selected-content.empty {
  color: var(--text-muted);
  font-size: 22px;
  text-align: center;
  padding-top: 30px;
}

.sel-icon {
  width: 96px;
  height: 96px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sel-icon img {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
}

.sel-name {
  text-align: center;
  font-size: 24px;
  color: var(--text-main);
  margin-bottom: 6px;
}

.sel-owner {
  text-align: center;
  font-size: 18px;
  color: #b0a090;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.sel-desc {
  text-align: center;
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.sel-hp {
  text-align: center;
  font-size: 20px;
  margin-bottom: 14px;
}

.sel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.sel-actions button {
  flex: 1 1 auto;
  min-width: 70px;
  padding: 8px 10px;
  background: #151210;
  border: 1px solid #3d3530;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 15px;
  letter-spacing: 1px;
  cursor: pointer;
  white-space: nowrap;
}

.sel-actions button:hover {
  border-color: var(--accent-red);
}

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed;
  display: none;
  background: rgba(8, 7, 6, 0.95);
  border: 1px solid #3d3530;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-main);
  pointer-events: none;
  z-index: 9999;
  max-width: 220px;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0908; }
::-webkit-scrollbar-thumb { background: #2a2520; }
::-webkit-scrollbar-thumb:hover { background: #3d3530; }

/* ---------- Death Screen ---------- */
#death-screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 4, 3, 0.96);
  z-index: 10000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#death-screen.active {
  display: flex;
}

#death-image {
  max-width: 80%;
  max-height: 45%;
  margin-bottom: 28px;
  border: 2px solid #3d3530;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.9);
}

#death-message {
  color: var(--text-gold);
  font-size: 22px;
  font-family: 'Cinzel', serif;
  max-width: 700px;
  margin-bottom: 36px;
  padding: 0 24px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

#death-sub {
  color: #c9c0b6;
  font-size: 15px;
  font-family: 'Cinzel', serif;
  max-width: 700px;
  margin-bottom: 36px;
  padding: 0 24px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

#death-ok {
  font-size: 20px;
  padding: 14px 42px;
  min-width: 160px;
}

/* ---------- Modals ---------- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 4, 3, 0.92);
  z-index: 10001;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-panel {
  background: linear-gradient(180deg, #110e0c 0%, #080706 100%);
  border: 2px solid #3d3530;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.95), inset 0 0 0 1px #1a1512;
  padding: 28px 36px;
  min-width: 420px;
  max-width: 90vw;
  text-align: center;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 32px;
  color: var(--text-red-bright);
  letter-spacing: 3px;
  margin: 0 0 22px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
}

.btn-option {
  width: 100%;
  padding: 18px;
  background: linear-gradient(180deg, #1f1614 0%, #15100e 100%);
  border: 1px solid #3d3530;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 20px;
  letter-spacing: 2px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.15s;
}

.btn-option:hover {
  background: linear-gradient(180deg, #2a1e1b 0%, #1b1412 100%);
  border-color: var(--accent-red);
}

/* Quick Start Guide modal: the guide image fills the panel with an OK button
   under it; the overlay itself (or OK) dismisses it. */
.quick-start-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 22px 26px;
}

#quick-start-img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(800px, 82vw);
  max-height: 66vh;
  border: 1px solid #3d3530;
}

.quick-start-panel #quick-start-ok {
  width: 220px;
  margin: 0;
}

/* Character Selection Grid */
.character-modal-panel {
  width: 95vw;
  max-width: 1400px;
  height: 85vh;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  padding: 28px 36px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  overflow-y: auto;
  padding: 10px;
  margin-bottom: 22px;
  flex: 1;
}

.character-option {
  background: rgba(10, 9, 8, 0.85);
  border: 2px solid #2a2520;
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.character-option:hover {
  border-color: var(--accent-red);
  background: rgba(20, 15, 13, 0.9);
}

.character-option.selected {
  border-color: var(--text-red-bright);
  box-shadow: inset 0 0 16px rgba(192, 57, 43, 0.45);
}

.character-preview {
  width: 180px;
  height: 180px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0908;
  border: 1px solid #2a2520;
}

.character-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.character-name {
  font-size: 18px;
  letter-spacing: 0.5px;
  color: var(--text-main);
}

/* Player Avatar Change Indicator */
.player-avatar {
  position: relative;
  cursor: pointer;
}

.player-avatar:hover .avatar-change {
  opacity: 1;
}

.avatar-change {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(139, 0, 0, 0.85);
  color: #fff;
  font-size: 9px;
  letter-spacing: 0.5px;
  text-align: center;
  padding: 2px 0;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

/* ---------- Chest Loot Modal ---------- */
.chest-modal-panel {
  min-width: 360px;
  max-width: 520px;
  width: 90vw;
  display: flex;
  flex-direction: column;
}

.chest-timer {
  font-size: 13px;
  color: #aaa;
  margin-bottom: 16px;
  letter-spacing: 1px;
}

.chest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 8px;
  background: rgba(8, 7, 6, 0.6);
  border: 1px solid #2a2520;
  margin-bottom: 18px;
}

.chest-slot {
  background: rgba(15, 13, 11, 0.95);
  border: 1px solid #3d3530;
  padding: 8px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70px;
}

.chest-slot:hover {
  border-color: var(--accent-red);
  background: rgba(25, 18, 15, 0.95);
}

.chest-slot img {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
  margin-bottom: 4px;
}

.chest-slot .chest-qty {
  font-size: 11px;
  color: #c9c0b6;
}

.chest-slot .chest-name {
  font-size: 9px;
  color: #998;
  text-align: center;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.chest-empty {
  color: #777;
  font-size: 13px;
  padding: 18px 0;
  text-align: center;
}

/* ---------- Shop Modal ---------- */
.shop-modal-panel {
  min-width: 380px;
  max-width: 560px;
  width: 90vw;
  display: flex;
  flex-direction: column;
}

.shop-owner {
  color: #998;
  font-size: 13px;
  margin-bottom: 4px;
  letter-spacing: 1px;
  text-align: left;
}

.shop-gold {
  color: #d4af37;
  font-size: 13px;
  margin-bottom: 8px;
  letter-spacing: 1px;
  text-align: left;
}

.shop-section-title {
  color: #c9c0b6;
  font-size: 12px;
  letter-spacing: 2px;
  margin: 12px 0 6px;
  text-align: left;
}

.shop-grid {
  max-height: 24vh;
  margin-bottom: 4px;
}

.shop-price {
  font-size: 11px;
  color: #d4af37;
  margin-top: 3px;
}

.shop-empty {
  color: #555;
}

.shop-btn {
  margin-top: 6px;
  padding: 3px 8px;
  font-size: 10px;
  width: 100%;
}

.shop-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.shop-picker {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #2a2520;
}

.shop-picker .chest-grid {
  max-height: 26vh;
  margin-bottom: 8px;
}

.shop-form-title {
  color: #998;
  font-size: 12px;
  margin-bottom: 8px;
  text-align: left;
}

.shop-form-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 6px;
}

.shop-form-label {
  color: #998;
  font-size: 12px;
  letter-spacing: 1px;
}

.shop-form-row select,
.shop-form-row input {
  background: #0f0d0b;
  border: 1px solid #3d3530;
  color: #c9c0b6;
  padding: 6px;
  font-size: 12px;
}

.shop-form-row input[type="number"] {
  width: 72px;
}

.shop-form-hint {
  color: #777;
  font-size: 11px;
  margin-top: 6px;
  text-align: left;
}

/* ---------- Shop Menu 2x Scale ----------
   Everything inside the shop modal (the OPEN button's menu) is doubled:
   panel width, slot squares, images, fonts, spacing, and buttons. Scoped to
   #shop-modal so the chest, guild, and build menus keep their normal size. */
#shop-modal {
  overflow-y: auto;
  align-items: flex-start;
}

#shop-modal .modal-panel {
  padding: 56px 72px;
  margin: 32px auto;
}

#shop-modal .modal-title {
  font-size: 64px;
  letter-spacing: 6px;
  margin-bottom: 44px;
}

#shop-modal .shop-modal-panel {
  min-width: min(760px, 95vw);
  max-width: 1120px;
}

#shop-modal .shop-owner {
  font-size: 26px;
  margin-bottom: 8px;
  letter-spacing: 2px;
}

#shop-modal .shop-gold {
  font-size: 26px;
  margin-bottom: 16px;
  letter-spacing: 2px;
}

#shop-modal .shop-section-title {
  font-size: 24px;
  letter-spacing: 4px;
  margin: 24px 0 12px;
}

#shop-modal .chest-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  padding: 16px;
  margin-bottom: 36px;
}

#shop-modal .shop-grid {
  max-height: 48vh;
  margin-bottom: 8px;
}

#shop-modal .shop-picker .chest-grid {
  max-height: 52vh;
  margin-bottom: 16px;
}

#shop-modal .chest-slot {
  min-height: 140px;
  padding: 16px;
}

#shop-modal .chest-slot img {
  width: 72px;
  height: 72px;
  margin-bottom: 8px;
}

#shop-modal .chest-qty {
  font-size: 22px;
}

#shop-modal .chest-name {
  font-size: 18px;
  margin-top: 4px;
}

#shop-modal .chest-empty {
  font-size: 26px;
  padding: 36px 0;
}

#shop-modal .shop-price {
  font-size: 22px;
  margin-top: 6px;
}

#shop-modal .btn-small {
  padding: 32px;
  font-size: 44px;
  letter-spacing: 3px;
}

#shop-modal .shop-btn {
  margin-top: 12px;
  padding: 6px 16px;
  font-size: 20px;
}

#shop-modal .shop-picker {
  margin-top: 20px;
  padding-top: 16px;
}

#shop-modal .shop-form-title {
  font-size: 24px;
  margin-bottom: 16px;
}

#shop-modal .shop-form-row {
  gap: 12px;
  margin-bottom: 12px;
}

#shop-modal .shop-form-label {
  font-size: 24px;
  letter-spacing: 2px;
}

#shop-modal .shop-form-row select,
#shop-modal .shop-form-row input {
  padding: 12px;
  font-size: 24px;
}

#shop-modal .shop-form-row input[type="number"] {
  width: 144px;
}

#shop-modal .shop-form-hint {
  font-size: 22px;
  margin-top: 12px;
}

/* ---------- Guild Modal ---------- */
.guild-modal-panel {
  min-width: 360px;
  max-width: 520px;
  width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.guild-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 22px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.guild-section h3 {
  font-family: var(--font-heading);
  font-size: 18px;
  color: var(--text-red-bright);
  letter-spacing: 2px;
  margin: 0 0 10px;
  text-align: center;
}

.guild-section .btn-option {
  margin-bottom: 8px;
}

.guild-banner-preview {
  display: block;
  margin: 0 auto 12px;
  image-rendering: pixelated;
  background: rgba(10, 9, 8, 0.7);
  border: 1px solid #2a2520;
  padding: 8px;
}

.guild-banner-locked {
  text-align: center;
  color: var(--text-main);
  font-size: 14px;
  letter-spacing: 1px;
  opacity: 0.85;
  margin-bottom: 8px;
}

.guild-banner-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-family: var(--font-heading);
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--text-main);
}

.guild-banner-field input[type="color"] {
  width: 56px;
  height: 28px;
  padding: 2px;
  background: #1a1a1a;
  border: 1px solid #5a4a3a;
  cursor: pointer;
}

.guild-banner-text-field {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font-family: 'Cinzel', serif;
  font-size: 14px;
  background: #1a1a1a;
  color: #c9c0b6;
  border: 1px solid #5a4a3a;
}

.guild-banner-text-field:focus {
  outline: none;
  border-color: #8b7355;
}

.guild-response {
  min-height: 28px;
  text-align: center;
  color: var(--text-main);
  font-size: 16px;
  margin-bottom: 16px;
  padding: 6px 10px;
  background: rgba(10, 9, 8, 0.7);
  border: 1px solid #2a2520;
}

/* ---------- Buildable Object Menu Modal ---------- */
.buildable-menu-panel {
  min-width: 320px;
  max-width: 420px;
  width: 90vw;
  display: flex;
  flex-direction: column;
}

.buildable-menu-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
}

.buildable-menu-content .btn-option {
  margin-bottom: 0;
}

/* ---------- Guild Invites Modal ---------- */
.guild-invites-panel {
  min-width: 360px;
  max-width: 520px;
  width: 90vw;
  display: flex;
  flex-direction: column;
}

.guild-invites-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
  max-height: 320px;
  overflow-y: auto;
}

.guild-invite-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 13, 11, 0.95);
  border: 1px solid #3d3530;
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.guild-invite-option:hover {
  border-color: var(--accent-red);
  background: rgba(25, 18, 15, 0.95);
}

.guild-invite-name {
  font-size: 18px;
  color: var(--text-main);
}

.guild-invite-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 18px;
  padding: 20px;
}

/* ---------- Build Menu Modal ---------- */
.build-modal-panel {
  min-width: 520px;
  max-width: 720px;
  width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.build-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.build-option {
  background: rgba(15, 13, 11, 0.95);
  border: 1px solid #3d3530;
  padding: 18px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
}

.build-option:hover {
  border-color: var(--accent-red);
  background: rgba(25, 18, 15, 0.95);
}

.build-option img {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.build-info {
  flex: 1;
}

.build-name {
  font-size: 22px;
  color: #c9c0b6;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.build-cost {
  font-size: 16px;
  color: #998;
}

.build-desc {
  font-size: 14px;
  color: #777;
  margin-top: 4px;
}

/* ---------- Craft Menu Modal ---------- */
.craft-modal-panel {
  min-width: 520px;
  max-width: 720px;
  width: 90vw;
  display: flex;
  flex-direction: column;
}

.craft-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 8px;
}

.craft-option {
  background: rgba(15, 13, 11, 0.95);
  border: 1px solid #3d3530;
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}

.craft-option:hover {
  border-color: var(--accent-red);
  background: rgba(25, 18, 15, 0.95);
}

.craft-option img {
  width: 52px;
  height: 52px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.craft-info {
  flex: 1;
}

.craft-name {
  font-size: 20px;
  color: #c9c0b6;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.craft-cost {
  font-size: 15px;
  color: #998;
}

.craft-desc {
  font-size: 13px;
  color: #777;
  margin-top: 3px;
}

.destroy-confirm-panel {
  min-width: 420px;
  max-width: 90vw;
}

.destroy-confirm-text {
  font-size: 20px;
  color: #c9c0b6;
  margin-bottom: 24px;
}

.destroy-confirm-actions {
  display: flex;
  gap: 16px;
}

.destroy-confirm-actions .btn-option {
  flex: 1;
}

.game-alert-panel,
.game-confirm-panel,
.game-input-panel {
  min-width: 420px;
  max-width: 90vw;
}

.game-alert-text,
.game-confirm-text,
.game-input-text {
  font-size: 18px;
  color: #c9c0b6;
  margin-bottom: 20px;
  word-break: break-word;
}

.game-confirm-actions,
.game-input-actions {
  display: flex;
  gap: 16px;
}

.game-confirm-actions .btn-option,
.game-input-actions .btn-option {
  flex: 1;
}

.game-input-field {
  width: 100%;
  padding: 10px;
  font-family: 'Cinzel', serif;
  font-size: 16px;
  background: #1a1a1a;
  color: #c9c0b6;
  border: 1px solid #5a4a3a;
  margin-bottom: 20px;
  box-sizing: border-box;
}

.game-input-field:focus {
  outline: none;
  border-color: #8b7355;
}

/* Teleportation Crystal coordinate modal: two side-by-side X/Y boxes, a
   hint block, and a red inline error line for non-edge coordinates. */
.teleport-text {
  white-space: pre-line;
}

.teleport-coords {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.teleport-coord-label {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  color: #c9c0b6;
}

.teleport-coord-field {
  width: 110px;
  flex: 0 0 auto;
  margin-bottom: 0;
  text-align: center;
}

.teleport-error {
  min-height: 20px;
  margin: 10px 0 16px;
  font-size: 15px;
  color: #e74c3c;
  word-break: break-word;
}

/* Mortician admin modal: a GIVE section (item dropdown + amount) and a
   BUILD section (object dropdown), stacked in two labeled groups. */
.admin-panel {
  min-width: 420px;
  max-width: 90vw;
}

.admin-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.admin-section-title {
  font-family: 'Cinzel', serif;
  font-size: 17px;
  letter-spacing: 2px;
  color: #c9c0b6;
}

.admin-select {
  width: 100%;
  padding: 10px;
  font-family: 'Cinzel', serif;
  font-size: 15px;
  background: #1a1a1a;
  color: #c9c0b6;
  border: 1px solid #5a4a3a;
  box-sizing: border-box;
}

.admin-select:focus {
  outline: none;
  border-color: #8b7355;
}

.admin-qty-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-qty-label {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  color: #c9c0b6;
}

.admin-qty-input {
  width: 140px;
  padding: 8px 10px;
  font-family: 'Cinzel', serif;
  font-size: 15px;
  background: #1a1a1a;
  color: #c9c0b6;
  border: 1px solid #5a4a3a;
  box-sizing: border-box;
}

.admin-qty-input:focus {
  outline: none;
  border-color: #8b7355;
}

.admin-qty-input:disabled {
  opacity: 0.5;
}

.admin-hint {
  font-size: 14px;
  color: #8f867c;
  margin: 0;
}

.leaderboard-panel {
  min-width: 420px;
  max-width: 90vw;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.leaderboard-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid #5a4a3a;
  padding: 12px 16px;
  color: #c9c0b6;
  font-size: 16px;
}

.leaderboard-rank {
  font-weight: bold;
  color: #d4af37;
  min-width: 30px;
}

.leaderboard-name {
  flex: 1;
  text-align: left;
  padding: 0 12px;
}

.leaderboard-guild {
  color: #aaa;
  font-size: 14px;
  font-style: italic;
}

.leaderboard-level {
  color: #e74c3c;
  font-weight: bold;
  min-width: 60px;
  text-align: right;
}

/* Player Manual — long scrollable guide opened from the Options menu */
.manual-panel {
  width: min(860px, 92vw);
  min-width: 420px;
  height: 86vh;
  max-height: 860px;
  display: flex;
  flex-direction: column;
}

.manual-text {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  text-align: left;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: #c9c0b6;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid #2a2520;
  padding: 6px 20px 6px 16px;
  margin-bottom: 18px;
}

.manual-text h3 {
  font-family: var(--font-heading);
  font-size: 19px;
  color: var(--text-red-bright);
  letter-spacing: 2px;
  margin: 20px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #3d3530;
}

.manual-text h3:first-child {
  margin-top: 4px;
}

.manual-text p {
  margin: 0 0 10px;
}

.manual-text ul {
  margin: 0 0 12px;
  padding-left: 22px;
}

.manual-text li {
  margin-bottom: 6px;
}

.manual-text b {
  color: #e8dcc8;
}

/* ---------- Potion Effect Read-out (top-left of the map) ---------- */
/* Red countdown text shown only while a timed potion effect is running. */
/* Top-left effect texts stack in one column: the potion line sits above the
   Immortal Shield countdown, and either hides itself when its effect ends. */
#effect-stack {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
  max-width: 70%;
}

#potion-effect-display {
  display: none;
  color: #ff2b2b;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000, 0 0 4px rgba(0, 0, 0, 0.9);
}

#shield-effect-display {
  display: none;
  color: #ffd700;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000, 0 0 4px rgba(0, 0, 0, 0.9);
}
