/* 废土主题:暗色终端风 + 手机适配 */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  /* 移动端 100vh 地址栏问题 */
  height: 100dvh;
}
body {
  background: #0d0f0d;
  color: #c8cfc0;
  font-family: "Cascadia Code", "Sarasa Mono SC", Consolas, "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  display: flex;
  height: 100%;
  height: 100dvh;
  max-width: 100vw;
  overflow: hidden;
}

/* 手机顶栏:默认隐藏,窄屏显示 */
#mobile-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: #111411;
  border-bottom: 1px solid #2a2f28;
  flex-shrink: 0;
  z-index: 20;
}
#panel-toggle {
  flex-shrink: 0;
  background: #1c211b;
  color: #d9a441;
  border: 1px solid #3a4036;
  border-radius: 6px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  min-height: 40px;
  cursor: pointer;
}
#compact-stats {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  line-height: 1.3;
  color: #9aa894;
}
#compact-stats .chip {
  white-space: nowrap;
}
#compact-stats .chip b { color: #c8cfc0; font-weight: normal; }
#compact-stats .hp b { color: #d96b52; }
#compact-stats .caps b { color: #d9a441; }
#compact-stats .echo b { color: #a98fd9; }

#panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
  border: 0;
  padding: 0;
  cursor: pointer;
}

/* 左侧状态面板 */
#panel {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid #2a2f28;
  padding: 16px;
  background: #111411;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.panel-close {
  display: none;
  background: transparent;
  border: 1px solid #3a4036;
  color: #7d8a74;
  border-radius: 6px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
#panel h1 {
  font-size: 18px; color: #d9a441;
  letter-spacing: 4px; margin-bottom: 4px;
}
#panel .subtitle {
  font-size: 11px; color: #7d8a74; letter-spacing: 2px;
  margin-bottom: 14px; border-bottom: 1px dashed #3a4036; padding-bottom: 8px;
}
.stat-row { display: flex; justify-content: space-between; margin: 4px 0; gap: 8px; }
.stat-row .k { color: #7d8a74; flex-shrink: 0; }
.stat-row .v { text-align: right; word-break: break-all; }
.stat-hp .v { color: #d96b52; }
.stat-water .v { color: #6fb3c9; }
.stat-food .v { color: #c9a86f; }
.stat-ammo .v { color: #b0b8a8; }
.stat-caps .v { color: #d9a441; }
.stat-echo .v { color: #a98fd9; }
.stat-sep { border-top: 1px dashed #3a4036; margin: 10px 0; }

/* 右侧主区 */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
#log {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 28px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
#log p { margin-bottom: 10px; word-wrap: break-word; overflow-wrap: anywhere; }
#log .sys { color: #7d8a74; }
#log .story { color: #c8cfc0; }
#log .good { color: #8fc97a; }
#log .bad { color: #d96b52; }
#log .roll { color: #a98fd9; }
#log .title {
  color: #d9a441; font-weight: bold; margin-top: 14px;
  border-left: 3px solid #d9a441; padding-left: 10px;
}

/* 行动按钮区 */
#actions {
  border-top: 1px solid #2a2f28;
  padding: 14px 28px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; gap: 10px;
  background: #111411;
  min-height: 70px;
  flex-shrink: 0;
  max-height: 42vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#actions button {
  background: #1c211b; color: #c8cfc0;
  border: 1px solid #3a4036; border-radius: 4px;
  padding: 8px 16px; cursor: pointer;
  font-family: inherit; font-size: 14px;
  transition: border-color .15s, color .15s, background .15s;
  /* 触控友好最小高度 */
  min-height: 40px;
  text-align: left;
  max-width: 100%;
}
#actions button:hover:not(:disabled),
#actions button:focus-visible:not(:disabled) {
  border-color: #d9a441; color: #d9a441; background: #24291f;
  outline: none;
}
#actions button:active:not(:disabled) {
  background: #2a3226;
}
#actions button:disabled { opacity: .35; cursor: not-allowed; }

/* 遗物 / 创伤 / 任务 */
.relic { color: #d9a441; font-size: 13px; margin: 2px 0; cursor: help; }
.trauma { color: #d96b52; font-size: 13px; margin: 2px 0; cursor: help; }
.quest-title {
  color: #a98fd9; font-size: 12px; letter-spacing: 1px;
  margin: 4px 0 6px;
}
.quest-item {
  color: #9aa894; font-size: 11px; line-height: 1.45;
  margin: 2px 0; padding-left: 2px;
}

/* ========== 平板及以下 ========== */
@media (max-width: 900px) {
  #panel { width: 220px; padding: 12px; }
  #log { padding: 16px 18px; }
  #actions { padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* ========== 手机竖屏 ========== */
@media (max-width: 720px) {
  body { font-size: 14px; }
  body.panel-open { overflow: hidden; }

  #app {
    flex-direction: column;
  }

  #mobile-bar { display: flex; }

  #panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 300px);
    max-width: 100%;
    z-index: 50;
    border-right: 1px solid #3a4036;
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: none;
  }
  body.panel-open #panel {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.45);
  }
  .panel-close { display: inline-flex; align-items: center; justify-content: center; }

  #panel-backdrop {
    display: block;
  }
  body.panel-open #panel-backdrop {
    display: block;
  }
  #panel-backdrop[hidden] {
    display: none !important;
  }

  #main {
    flex: 1;
    min-height: 0;
  }

  #log {
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.65;
  }
  #log .title {
    margin-top: 10px;
    font-size: 15px;
  }

  #actions {
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    max-height: 38vh;
    /* 底部操作区更像工具栏 */
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
  }
  #actions button {
    /* 手机上一行一个更易点 */
    flex: 1 1 100%;
    width: 100%;
    min-height: 46px;
    padding: 12px 14px;
    font-size: 14px;
    border-radius: 8px;
    line-height: 1.35;
  }
}

/* 超窄屏再压一点 */
@media (max-width: 380px) {
  body { font-size: 13px; }
  #compact-stats { font-size: 11px; gap: 4px 8px; }
  #actions button { font-size: 13px; min-height: 44px; }
}

/* 横屏手机:侧栏仍可抽屉,主区多留高度 */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  #mobile-bar { padding: 4px 10px; }
  #actions {
    max-height: 32vh;
  }
  #actions button {
    flex: 1 1 calc(50% - 8px);
    width: auto;
    min-height: 40px;
    padding: 8px 10px;
  }
}
