/* === 全局基础 === */
body {
  font-family: "Microsoft YaHei", sans-serif;
  background-color: #0e0e0e;
  color: #e0e0e0;
  margin: 0;
  padding: 0;
}

/* === 顶部区域 === */
header {
  background: #1a1a1a;
  padding: 12px 16px;
  border-bottom: 2px solid #333;
}

h2 {
  margin: 0;
  color: #ffaa33;
}

#moneyDisplay {
  color: #ffaa33;
  font-weight: bold;
}

.twemoji {
  display: inline-block;
  width: 1em;
  height: 1em;
  margin: 0 0.05em;
  vertical-align: -0.12em;
}

#actionTitle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.action-title-name {
  color: #ffaa33;
}

.action-title-name.area-risk-low {
  color: #33ff88;
}

.action-title-name.area-risk-high {
  color: #ff3355;
}

.action-title-tag {
  padding: 3px 8px;
  color: #111;
  background: #ffaa33;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.2;
}

.action-title-tag.area-risk-low {
  background: #33ff88;
  color: #07140b;
}

.action-title-tag.area-risk-medium {
  background: #ffaa33;
  color: #111;
}

.action-title-tag.area-risk-high {
  background: #ff3355;
  color: #160606;
}

.action-title-stage {
  color: #bbb;
  font-size: 14px;
  font-weight: 600;
}

/* === 顶部状态区 === */
.adventure-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
}

.adventure-equip,
.adventure-backpack {
  flex: 1;
  padding: 10px;
  background: #222;
  border-radius: 8px;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.05);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 6px;
  color: #ffaa33;
  border-bottom: 1px solid #444;
  padding-bottom: 4px;
}

.adventure-equip h4,
.adventure-backpack h4 {
  margin: 0;
  color: #ffaa33;
  font-size: 16px;
}

.compact-action-btn {
  flex: 0 0 auto;
  margin: 0;
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid #444;
  background: #2a2a2a;
}

.compact-action-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

/* === 状态栏 === */
#playerStatus {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex: 1 1 auto;
  gap: 12px;
  min-width: 0;
  margin-top: 0;
  font-size: 15px;
  color: #33aaff;
  font-weight: bold;
  transition: color 0.3s;
  padding: 6px;
  border-radius: 6px;
}

.player-health,
.player-stamina {
  white-space: nowrap;
}

.player-stamina {
  margin-left: auto;
  color: #ffcc66;
}

.player-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
  margin-top: 8px;
}

.quick-heal-area {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
}

#quickHealBtn {
  margin: 0;
  white-space: nowrap;
}

/* === 主内容 === */
.content {
  padding: 15px;
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  justify-content: flex-start;
  margin-bottom: 10px;
}

.home-actions a {
  min-width: 0;
}

.home-actions button {
  width: 100%;
  min-height: 48px;
  margin: 0;
  border-radius: 8px;
  font-size: 17px;
  font-weight: bold;
}

.home-primary-action {
  min-width: 126px;
  background: #ffaa33;
  color: #1a1a1a;
  font-size: 17px;
  font-weight: bold;
  border: 1px solid #d5861d;
  box-shadow: 0 2px 10px rgba(255, 170, 51, 0.24);
}

.empty-slot {
  color: #666;
}

.home-primary-action:hover {
  background: #ffb84d;
  color: #111;
}

.warehouse, .inventory {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  align-items: flex-start;
}

#warehouse.warehouse,
#marketList.warehouse {
  display: grid;
  gap: 12px;
}

.warehouse-group {
  padding: 10px;
  background: #181818;
  border: 1px solid #333;
  border-radius: 8px;
}

.warehouse-group h4 {
  margin: 0 0 8px;
  color: #ffaa33;
}

.warehouse-group-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* === 物品显示 === */
.item {
  padding: 6px 10px;
  background: #333;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid #444;
  flex-shrink: 0;
  white-space: nowrap;
}
.item:hover {
  background: #444;
  transform: scale(1.02);
  box-shadow: 0 2px 12px rgba(255, 170, 51, 0.4);
}

.item.sale-selectable.selected {
  background: #4a3a16;
  border-color: #ffaa33;
  box-shadow: 0 0 0 2px rgba(255, 170, 51, 0.35);
}

/* === 等级颜色 === */
.lvl1 { color: #00ff00; }
.lvl2 { color: #33aaff; }
.lvl3 { color: #bb66ff; }
.lvl4 { color: #ffaa33; }

/* === 按钮样式 === */
button {
  margin: 6px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: #333;
  color: #eee;
  cursor: pointer;
  transition: 0.2s;
  font-size: 14px;
}
button:hover {
  background: #555;
  transform: scale(1.05);
}

/* === 行动按钮组 === */
.action-control-panel {
  position: sticky;
  top: 0;
  z-index: 20;
  margin-bottom: 12px;
  padding: 10px;
  background: #181818;
  border: 1px solid #333;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

.action-buttons {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 10px;
  margin-top: 0;
}

.action-buttons button {
  min-height: 48px;
  margin: 0;
  border-radius: 8px;
  font-weight: bold;
}

#findSuppliesBtn {
  color: #111;
  background: #ffaa33;
  border-color: #ffaa33;
}

#retreatBtn,
.home-primary-action {
  color: #111;
  background: #ffaa33;
  border-color: #ffaa33;
}

#evacuateBtn {
  color: #e7f3ff;
  background: #59aa7b;
  border-color: #43c767;
}

.area-select {
  margin-bottom: 14px;
}

.area-select h3 {
  margin: 0 0 10px;
  color: #ffaa33;
}

.area-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.area-return {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.area-return a {
  width: min(50%, 160px);
}

.area-return-btn {
  width: 100%;
  min-height: 46px;
  margin: 0;
  color: #fff;
  font-weight: bold;
}

.area-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 64px;
  margin: 0;
  padding: 12px;
  text-align: center;
  background: #202020;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  line-height: 1.35;
}

.area-card:hover {
  border-color: #ffaa33;
  background: #282828;
}

.area-card.area-risk-low {
  background: #14261c;
  border-color: #2d7a4b;
}

.area-card.area-risk-low:hover {
  background: #193321;
  border-color: #43c767;
}

.area-card.area-risk-low .area-card-title {
  color: #70e892;
}

.area-card.area-risk-low .area-card-risk {
  background: #43c767;
  color: #07140b;
}

.area-card.area-risk-medium {
  background: #2b2113;
  border-color: #a8691f;
}

.area-card.area-risk-medium:hover {
  background: #352816;
  border-color: #ffaa33;
}

.area-card.area-risk-medium .area-card-risk {
  background: #ffaa33;
  color: #111;
}

.area-card.area-risk-high {
  background: #2d1717;
  border-color: #8b3737;
}

.area-card.area-risk-high:hover {
  background: #391b1b;
  border-color: #ff6666;
}

.area-card.area-risk-high .area-card-title {
  color: #ff7a7a;
}

.area-card.area-risk-high .area-card-risk {
  background: #ff6666;
  color: #160606;
}

.area-card-title {
  color: #ffaa33;
  font-size: 17px;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
}

.area-card-risk {
  min-width: 62px;
  padding: 3px 8px;
  color: #111;
  background: #ffaa33;
  border-radius: 6px;
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
}

.selected-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 12px;
  padding: 10px;
  background: #181818;
  border: 1px solid #333;
  border-radius: 8px;
  color: #bbb;
}

.selected-area strong {
  color: #ffaa33;
  font-size: 17px;
}

/* === 日志与敌人信息 === */
#adventureLog {
  max-height: none;
  margin-top: 8px;
  padding: 0;
  overflow: visible;
  color: #8f8f8f;
  background: transparent;
  font-size: 12px;
  line-height: 1.45;
}

#adventureLog:empty {
  display: none;
}

.action-log-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.action-log-record {
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 0;
  line-height: inherit;
}

.action-log-record.is-active {
  background: transparent;
  border: 0;
}

.action-log-record.is-dimmed {
  opacity: 0.55;
  border: 0;
}

.action-log-entry + .action-log-entry {
  margin-top: 2px;
  padding-top: 0;
  border-top: 0;
}

.action-log-overlay {
  position: fixed;
  inset: 0;
  z-index: 2350;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,0.55);
}

.action-log-overlay.show {
  display: flex;
}

.action-log-dialog,
.action-end-dialog {
  width: min(360px, 100%);
  padding: 18px;
  color: #ddd;
  background: #202020;
  border: 1px solid #555;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
  text-align: center;
}

.action-log-dialog h3,
.action-end-dialog h3 {
  margin: 0 0 12px;
  color: #ffaa33;
}

.action-log-dialog-content {
  max-height: 58vh;
  margin-bottom: 14px;
  padding: 10px;
  overflow-y: auto;
  color: #ddd;
  background: #151515;
  border: 1px solid #333;
  border-radius: 8px;
  line-height: 1.55;
  text-align: left;
  -webkit-overflow-scrolling: touch;
}

.action-log-dialog-content .action-log-entry + .action-log-entry,
.action-end-content .action-log-entry + .action-log-entry {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #333;
}

.action-log-dialog button {
  width: 100%;
  min-height: 44px;
  margin: 0;
  color: #111;
  background: #ffaa33;
  font-weight: bold;
}

/* === 行动等待圆环 === */
.action-wait-overlay {
  position: fixed;
  inset: 0;
  z-index: 2450;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,0.55);
}

.action-wait-overlay.show {
  display: flex;
}

.action-wait-dialog {
  width: 128px;
  height: 128px;
  display: grid;
  place-items: center;
  background: #202020;
  border: 1px solid #555;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
}

.action-wait-ring {
  width: 96px;
  height: 96px;
}

.action-wait-track,
.action-wait-segment {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.action-wait-track {
  stroke: #363636;
  stroke-dasharray: 21 4;
}

.action-wait-segment {
  stroke: #fff;
  stroke-dasharray: 0 100;
  stroke-dashoffset: var(--dash-offset);
  transition-property: stroke-dasharray;
  transition-timing-function: linear;
}

.action-wait-segment.filled {
  stroke-dasharray: 21 100;
}

.log {
  background: #222;
  padding: 10px;
  border-radius: 8px;
  margin-top: 10px;
  border-left: 3px solid #ffaa33;
}

.enemy-area {
  margin-top: 15px;
}

/* === 行动结束弹窗 === */
.action-end-overlay {
  position: fixed;
  inset: 0;
  z-index: 2400;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,0.55);
}

.action-end-overlay.show {
  display: flex;
}

.action-end-log {
  margin: 0 0 8px;
  padding: 0 0 8px;
  color: inherit;
  border-bottom: 1px solid #333;
  line-height: inherit;
  text-align: left;
}

.action-end-log:empty {
  margin: 0;
  padding: 0;
  border: 0;
}

.action-end-message {
  color: #ddd;
  line-height: 1.55;
  text-align: left;
}

.action-end-loot-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
}

.action-end-dialog.danger {
  border-color: #884444;
}

.action-end-dialog.danger h3 {
  color: #ff6666;
}

/* === 黑市出售模式 === */
.market-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.market-actions button {
  margin: 0;
}

#showWarehouseSaleBtn {
  margin-left: auto;
}

.market-sale-panel {
  background: #181818;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
}

.market-sale-header,
.market-sale-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.market-sale-header h3 {
  margin: 0;
  color: #ffaa33;
}

.market-sale-footer {
  margin-top: 12px;
}

.market-sale-footer .hint {
  flex: 1;
  margin: 0;
}

.market-sale-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.market-sale-controls button {
  margin: 0;
}

#sellSelectedWarehouseBtn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

/* === 详情弹窗 === */
#itemDetail, .item-detail {
  background: #222;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
}

/* === 背包内物品 === */
#adventureBackpack .item, #bagStatus .item {
  font-size: 13px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
}
#adventureBackpack .item:hover, #bagStatus .item:hover {
  background: #444;
}

/* === 提示 === */
.hint {
  font-size: 13px;
  color: #888;
  background: #1a1a1a;
  padding: 6px 8px;
  border-left: 3px solid #ffaa33;
  border-radius: 4px;
  margin: 8px 0;
}

/* === 轻量提示 === */
#toastStack {
  position: fixed;
  left: 50%;
  top: calc(18px + env(safe-area-inset-top, 0px));
  z-index: 2800;
  display: grid;
  gap: 8px;
  width: min(340px, calc(100vw - 24px));
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  padding: 10px 12px;
  color: #eee;
  background: rgba(28, 28, 28, 0.96);
  border: 1px solid #444;
  border-left: 4px solid #ffaa33;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  font-size: 14px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-info {
  border-left-color: #33aaff;
}

.toast-success {
  border-left-color: #43c767;
}

.toast-warning {
  border-left-color: #ffaa33;
}

.toast-danger {
  border-left-color: #ff6666;
}

/* === 新物品获得动画 === */
.new-item {
  animation: pulse 0.6s ease-out;
}
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); background: #556; }
  100% { transform: scale(1); }
}

/* === 玩家状态变化动画 === */
.damage-flash {
  animation: damageFlash 0.6s ease;
}
.heal-flash {
  animation: healFlash 0.6s ease;
}
@keyframes damageFlash {
  0% { background: #400; }
  50% { background: #a00; }
  100% { background: none; }
}
@keyframes healFlash {
  0% { background: #040; }
  50% { background: #0f0; }
  100% { background: none; }
}

/* === 界面淡入淡出动画 === */
.fade-in { animation: fadeIn 0.6s ease; }
.fade-out { animation: fadeOut 0.6s ease; }
@keyframes fadeIn { from {opacity:0;} to {opacity:1;} }
@keyframes fadeOut { from {opacity:1;} to {opacity:0;} }

/* === 响应式优化 === */
@media (max-width: 768px) {
  .adventure-header {
    flex-direction: column;
    gap: 12px;
  }
  .market-sale-header,
  .market-sale-footer {
    align-items: stretch;
    flex-direction: column;
  }
  .quick-heal-area {
    flex: 0 0 auto;
  }
  .adventure-equip, .adventure-backpack {
    padding: 12px;
  }
  #adventureLog {
    max-height: 200px;
  }
}

/* === 手机端交互优化（480px以下） === */
@media (max-width: 480px) {
  .action-buttons {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .action-buttons button {
    width: 100%;
    margin: 0;
    padding: 12px 0;
    font-size: 16px;
  }
}

/* ==========================
   弹窗显示优化样式（桌面 + 移动通用）
   ========================== */

/* 基础弹窗样式 */
#itemDetail {
  position: fixed;
  left: 50%;
  top: 15vh;
  transform: translateX(-50%);
  width: 380px;
  max-height: 60vh;
  overflow-y: auto;
  background: rgba(20,20,20,0.95);
  border: 1px solid #555;
  border-radius: 16px;
  box-shadow: 0 0 25px rgba(0,0,0,0.45);
  padding: 18px;
  color: #ddd;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  display: none;
}
#itemDetail.show {
  display: block;
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 按钮美化 */
#itemDetail button.dynamic {
  background: #333;
  color: #eee;
  border: 1px solid #555;
  border-radius: 8px;
  padding: 6px 12px;
  margin: 6px;
  cursor: pointer;
  transition: background 0.2s;
}
#itemDetail button.dynamic:hover {
  background: #555;
}

/* 装备栏弹窗更靠近装备 */
#itemDetail.equip-mode {
  width: 280px;
  left: auto;
  transform: none;
  background: rgba(30,30,30,0.95);
  border-color: #666;
  box-shadow: 0 0 16px rgba(0,0,0,0.4);
}

/* 背包弹窗（气泡） */
#itemDetail.bag-mode {
  width: 260px;
  max-height: none;
  background: rgba(40,40,40,0.96);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  border-radius: 12px;
}

/* 遮罩层（点击关闭） */
#detailOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1500;
  display: none;
  opacity: 0;
  transition: opacity 0.2s;
}
#detailOverlay.show {
  display: block;
  opacity: 1;
}

@media (max-width: 768px) {
  #itemDetail,
  #itemDetail.show,
  #itemDetail.equip-mode,
  #itemDetail.bag-mode {
    box-sizing: border-box;
    left: 12px !important;
    right: 12px !important;
    top: 50% !important;
    bottom: auto !important;
    width: auto !important;
    max-height: 72vh !important;
    max-height: min(72vh, calc(100dvh - 24px)) !important;
    padding: 16px;
    transform: translateY(-50%) !important;
    border-radius: 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #itemDetail h4 {
    margin: 0 0 8px;
    font-size: 17px;
  }

  #detailInfo {
    margin: 0 0 10px;
    line-height: 1.6;
  }

  #itemDetail button,
  #itemDetail button.dynamic {
    width: 100%;
    min-height: 44px;
    margin: 6px 0 0;
    padding: 10px 12px;
    font-size: 15px;
  }
}

/* === 开发调试页 === */
.debug-page {
  display: grid;
  gap: 14px;
}

.debug-panel {
  background: #181818;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 12px;
}

.debug-panel h3 {
  margin: 0 0 10px;
  color: #ffaa33;
}

.debug-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.debug-controls button {
  margin: 0;
}

.debug-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: #bbb;
}

.debug-field input {
  width: 120px;
  padding: 8px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #111;
  color: #eee;
}

.debug-output {
  min-height: 72px;
  white-space: pre-wrap;
  overflow-x: auto;
  margin: 0;
  padding: 10px;
  border-radius: 6px;
  background: #111;
  color: #ddd;
  border: 1px solid #303030;
}

.debug-hidden {
  display: none;
}
