/* =====================================================
   传奇世界 - 单机版 UI 样式
   ===================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background: #0d0d0d;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  overflow: hidden;
  color: #e8e8e8;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  margin: 0 auto;
  background: #000;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  background: #111;
}

/* ================= HUD ================= */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hud > * {
  pointer-events: auto;
}

/* 左上面板 */
#player-panel {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid #3a2a1a;
  border-radius: 6px;
  padding: 6px 10px;
}

#avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #6a4a2a, #3a2410);
  border: 2px solid #8a6a3a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  color: #ffd700;
  text-shadow: 1px 1px 2px #000;
}

#bar-block {
  width: 130px;
}

.bar {
  position: relative;
  height: 13px;
  border-radius: 3px;
  overflow: hidden;
  margin: 2px 0;
  background: #2a0a0a;
  border: 1px solid #000;
}

.bar.hp > #hp-fill { background: linear-gradient(180deg, #ff7777, #c22); }
.bar.mp > #mp-fill { background: linear-gradient(180deg, #77bbff, #2266cc); }

#hp-fill, #mp-fill {
  height: 100%;
  width: 100%;
  transition: width 0.15s;
}

.bar span {
  position: absolute;
  inset: 0;
  font-size: 10px;
  line-height: 13px;
  text-align: center;
  color: #fff;
  text-shadow: 1px 1px 1px #000;
}

#name-row {
  margin-top: 3px;
  font-size: 12px;
  color: #ffd700;
  text-shadow: 1px 1px 2px #000;
}

/* 经验条 */
#exp-bar {
  position: absolute;
  top: 92px;
  left: 8px;
  width: 200px;
  height: 14px;
  background: #1a1a1a;
  border: 1px solid #3a3a3a;
  border-radius: 3px;
  overflow: hidden;
}

#exp-fill {
  height: 100%;
  background: linear-gradient(180deg, #8af07a, #2a9a1a);
  width: 0%;
  transition: width 0.2s;
}

#exp-bar span {
  position: absolute;
  inset: 0;
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  text-shadow: 1px 1px 1px #000;
}

/* 右上角 */
#top-right {
  position: absolute;
  top: 8px;
  right: 8px;
  text-align: right;
}

#info-row {
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid #3a2a1a;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
}

#gold-text {
  color: #ffd700;
  font-weight: bold;
}

#skillpoint-text {
  color: #88ccff;
}

#buff-icons {
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.buff-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(60, 140, 255, 0.75);
  border: 2px solid #aaddff;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.buff-icon.buff-hidden {
  background: rgba(120, 120, 120, 0.8);
  border-color: #ccc;
}

#minimap {
  margin-top: 4px;
  border: 2px solid #3a2a1a;
  border-radius: 50%;
  background: #1a1a1a;
}

/* 快捷栏 */
#hotbar-wrap {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
}

#hotbar {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid #3a2a1a;
  border-radius: 6px;
  padding: 4px;
}

.hotbar-slot {
  position: relative;
  width: 40px;
  height: 40px;
  background: #1a1410;
  border: 1px solid #4a3a2a;
  border-radius: 4px;
  cursor: pointer;
  overflow: hidden;
}

.hotbar-slot.empty {
  background: #141414;
  border-style: dashed;
}

.hotbar-icon {
  position: absolute;
  inset: 2px;
}

.hotbar-icon img {
  width: 100%;
  height: 100%;
  display: block;
}

.hotbar-lv {
  position: absolute;
  right: 1px;
  bottom: 1px;
  font-size: 10px;
  color: #ffd700;
  text-shadow: 1px 1px 1px #000;
}

.hotbar-key {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 10px;
  color: #ffd700;
  text-shadow: 1px 1px 1px #000;
}

.hotbar-cd {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0%;
  background: rgba(0, 0, 0, 0.65);
  transition: height 0.1s linear;
}

/* 聊天框 */
#chat-box {
  position: absolute;
  bottom: 8px;
  left: 8px;
  width: 300px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid #3a2a1a;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

#chat-tabs {
  display: flex;
  padding: 3px 4px 0;
  gap: 4px;
}

.chat-tab {
  padding: 1px 8px;
  background: #2a2418;
  color: #aaa;
  border-radius: 3px 3px 0 0;
  font-size: 11px;
}

.chat-tab.active {
  background: #4a3a2a;
  color: #ffd700;
}

#chat-body {
  height: 84px;
  overflow-y: auto;
  padding: 3px 6px;
  scrollbar-width: thin;
}

#chat-body::-webkit-scrollbar { width: 4px; }
#chat-body::-webkit-scrollbar-thumb { background: #555; }

.chat-msg {
  margin: 1px 0;
  line-height: 1.4;
  word-break: break-all;
}

#chat-box.collapsed #chat-body { display: none; }

/* 移动端触摸控制 */
#touch-controls {
  display: none;
}

/* 竖屏旋转提示 */
#rotate-hint {
  display: none;
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: #ffd700;
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 13px;
  z-index: 60;
  pointer-events: none;
  white-space: nowrap;
}

/* ================= 面板 ================= */
.panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 620px;
  max-width: 96%;
  max-height: 88%;
  background: rgba(20, 14, 10, 0.96);
  border: 2px solid #6a4a2a;
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
  z-index: 30;
  overflow-y: auto;
  pointer-events: auto;
  padding: 10px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  color: #ffd700;
  border-bottom: 1px solid #4a3a2a;
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.panel-header button, .dialog-btn {
  background: #4a3a2a;
  border: 1px solid #6a4a2a;
  color: #ffd700;
  padding: 3px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.panel-header button:hover, .dialog-btn:hover {
  background: #6a4a2a;
}

.panel-subtitle {
  color: #c9a06a;
  font-size: 12px;
  margin: 8px 0 4px;
}

/* 背包 */
#backpack-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.inv-cell {
  position: relative;
  height: 46px;
  background: #1a1410;
  border: 1px solid #3a3a3a;
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
}

.inv-cell:hover {
  border-color: #ffd700;
}

.inv-cell.selected {
  outline: 2px solid #ffd700;
}

.inv-cell img {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.inv-count {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 11px;
  color: #fff;
  text-shadow: 1px 1px 1px #000;
}

#equip-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

#equip-list {
  grid-column: 1 / 2;
}

.equip-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 6px;
  border-bottom: 1px dashed #3a2a1a;
  font-size: 13px;
  cursor: pointer;
}

.equip-row:hover {
  background: #2a2016;
}

.equip-label {
  color: #c9a06a;
}

.equip-value {
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#equip-attrs {
  grid-column: 2 / 3;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 8px;
  font-size: 12px;
  color: #8ad0a0;
}

/* 技能面板 */
.skill-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px dashed #3a2a1a;
}

.skill-row img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.skill-info {
  flex: 1;
}

.skill-name {
  color: #ffd700;
  font-size: 14px;
}

.skill-desc {
  color: #aaa;
  font-size: 12px;
}

.skill-level {
  width: 56px;
  text-align: center;
  color: #88ccff;
  font-size: 13px;
}

.skill-btn {
  background: #2a5a2a;
  border: 1px solid #4a8a4a;
  color: #fff;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.skill-btn:disabled {
  background: #333;
  border-color: #444;
  color: #888;
  cursor: default;
}

#hotbar-config {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.hotbar-cfg-slot {
  position: relative;
  width: 44px;
  height: 44px;
  background: #1a1410;
  border: 1px solid #4a3a2a;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
  font-size: 20px;
  overflow: hidden;
}

.hotbar-cfg-slot img {
  width: 100%;
  height: 100%;
  display: block;
}

.hotbar-cfg-idx {
  position: absolute;
  top: 0;
  left: 2px;
  font-size: 10px;
  color: #ffd700;
}

/* 任务面板 */
#quest-list {
  font-size: 13px;
}

.quest-item {
  padding: 6px;
  border-bottom: 1px dashed #3a2a1a;
}

.quest-name {
  color: #ffd700;
}

.quest-prog {
  color: #aaa;
  font-size: 12px;
  margin-top: 2px;
}

.quest-empty {
  color: #888;
  padding: 12px;
  text-align: center;
}

/* ================= 对话框 ================= */
#dialog-panel {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  width: 460px;
  max-width: 94%;
  background: rgba(16, 12, 8, 0.97);
  border: 2px solid #6a4a2a;
  border-radius: 8px;
  padding: 12px;
  z-index: 40;
  pointer-events: auto;
}

#dialog-name {
  color: #ffd700;
  font-weight: bold;
  font-size: 15px;
  margin-bottom: 6px;
}

#dialog-text {
  min-height: 44px;
  color: #e8e8e8;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-line;
}

#dialog-options {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.dialog-btn {
  font-size: 14px;
  padding: 6px 16px;
}

/* ================= 角色创建 ================= */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: auto;
}

.create-box {
  width: 520px;
  max-width: 94%;
  text-align: center;
  background: linear-gradient(180deg, #2a1808, #1a0e04);
  border: 3px solid #8a6a3a;
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 0 40px rgba(138, 90, 30, 0.35);
}

.create-box h1 {
  font-size: 34px;
  color: #ffd700;
  letter-spacing: 8px;
  text-shadow: 2px 2px 4px #000;
  font-weight: bold;
}

.create-box .subtitle {
  color: #c9a06a;
  font-size: 13px;
  margin: 6px 0 20px;
}

.class-select {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}

.class-card {
  width: 130px;
  padding: 12px 8px;
  background: #241608;
  border: 2px solid #4a3a2a;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.class-card:hover {
  border-color: #c9a06a;
}

.class-card.selected {
  border-color: #ffd700;
  background: #3a2410;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.3);
}

.class-icon {
  font-size: 30px;
  color: #ffd700;
  margin-bottom: 4px;
  font-weight: bold;
}

.class-name {
  color: #fff;
  font-size: 16px;
  font-weight: bold;
}

.class-desc {
  color: #aaa;
  font-size: 11px;
  margin-top: 4px;
}

#char-name {
  width: 70%;
  padding: 8px 12px;
  font-size: 15px;
  background: #14100c;
  border: 1px solid #6a4a2a;
  border-radius: 5px;
  color: #fff;
  text-align: center;
  outline: none;
}

#char-name:focus {
  border-color: #ffd700;
}

.btn-row {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-row button {
  padding: 10px 28px;
  font-size: 16px;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid #6a4a2a;
  background: #4a2a10;
  color: #ffd700;
}

.btn-row button:hover {
  background: #6a3a18;
}

.btn-row .primary-btn {
  background: #8a1a0a;
  border-color: #c22;
  color: #fff;
}

.btn-row .primary-btn:hover {
  background: #a52a12;
}

.tips {
  margin-top: 18px;
  font-size: 11px;
  color: #8a8a8a;
  line-height: 1.7;
}

.hidden {
  display: none !important;
}

/* ================= 移动端适配 ================= */
@media (pointer: coarse), (max-width: 820px) {
  @media (orientation: portrait) {
    #rotate-hint {
      display: block;
    }
    /* 竖屏保持 16:9 等比显示，避免拉伸变形 */
    #game-canvas {
      object-fit: contain;
    }
  }
  #player-panel {
    transform: scale(0.85);
    transform-origin: top left;
  }
  #top-right {
    transform: scale(0.8);
    transform-origin: top right;
  }
  #chat-box {
    display: none;
  }
  #hotbar-wrap {
    bottom: 96px;
    transform: translateX(-50%) scale(0.85);
  }
  #touch-controls {
    display: block;
  }
  #touch-stick {
    position: absolute;
    left: 20px;
    bottom: 20px;
    width: 100px;
    height: 100px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
  }
  #touch-stick.active {
    display: flex;
  }
  #touch-stick-knob {
    width: 40px;
    height: 40px;
    background: rgba(255, 215, 0, 0.6);
    border-radius: 50%;
  }
  #touch-skill-btns {
    position: absolute;
    right: 10px;
    bottom: 16px;
    display: grid;
    grid-template-columns: repeat(4, 44px);
    grid-template-rows: repeat(2, 44px);
    gap: 6px;
  }
  .touch-skill-btn {
    background: rgba(60, 30, 10, 0.85);
    border: 1px solid #6a4a2a;
    border-radius: 50%;
    color: #ffd700;
    font-weight: bold;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .touch-skill-btn:active {
    background: rgba(138, 26, 10, 0.9);
  }
}

/* 滚动条美化 */
#skill-panel::-webkit-scrollbar,
#backpack-panel::-webkit-scrollbar {
  width: 6px;
}
#skill-panel::-webkit-scrollbar-thumb,
#backpack-panel::-webkit-scrollbar-thumb {
  background: #5a4a3a;
  border-radius: 3px;
}
