/* ==========================================================
 * Mars Game - 火星求生 样式
 * ========================================================== */

:root {
  --bg: #14100e;
  --bg-panel: #1e1815;
  --bg-panel-2: #262019;
  --bg-hover: #322a21;
  --border: #3d332a;
  --border-light: #57493b;
  --text: #e8ddd0;
  --text-dim: #a3948a;
  --text-faint: #6e6258;
  --accent: #d96f32;        /* 火星橙 */
  --accent-bright: #ff8c48;
  --good: #7dc95e;
  --bad: #e05555;
  --gold: #e8c46a;
  --night-blue: #5b7fb5;
  --radius: 8px;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% -10%, #2a1c14 0%, transparent 55%),
                    radial-gradient(ellipse at 90% 110%, #1c1424 0%, transparent 50%);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  user-select: none;
}

#app {
  display: grid;
  grid-template-columns: clamp(200px, 20vw, 280px) 1fr clamp(240px, 23vw, 330px);
  gap: 10px;
  height: 100vh;
  padding: 10px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: bold;
  color: var(--accent-bright);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
  letter-spacing: 1px;
  flex-shrink: 0;
}

.panel-title-icon svg, .tab-icon svg, .btn-icon svg {
  width: 16px; height: 16px; display: block;
}
.panel-title-icon svg { width: 18px; height: 18px; }

.hidden { display: none !important; }

/* ---------------- 按钮 ---------------- */
.btn {
  font-family: var(--font);
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border-light); background: var(--bg-panel-2); }

.btn-primary { border-color: var(--accent); color: var(--accent-bright); }
.btn-primary:hover { background: #3a2416; }

.btn-icon svg { width: 15px; height: 15px; }

/* ================= 左侧：资源（单行紧凑） ================= */
.resource-list {
  padding: 8px 10px;
  overflow-y: auto;
  flex-shrink: 0;
}

.res-line {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  margin-bottom: 4px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.res-line .res-icon svg { width: 15px; height: 15px; display: block; flex-shrink: 0; }
.res-line .res-name {
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 52px;
}
.res-line .res-rate {
  font-size: 10px;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.res-line .res-bar {
  flex: 1;
  height: 5px;
  min-width: 24px;
  background: #171310;
  border-radius: 3px;
  overflow: hidden;
}
.res-line .res-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 3px;
  transition: width .3s linear;
}
.res-line .res-amt {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.rate-pos { color: var(--good) !important; }
.rate-neg { color: var(--bad) !important; }
.rate-zero { color: var(--text-faint) !important; }

/* ---- 左侧：建筑数量区 ---- */
.sub-title {
  font-size: 11px;
  color: var(--text-faint);
  padding: 6px 12px 4px;
  border-top: 1px solid var(--border);
  letter-spacing: 2px;
  flex-shrink: 0;
}
.building-list {
  padding: 0 10px 10px;
  overflow-y: auto;
  flex: 1;
}
.b-line {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin-bottom: 3px;
  border-radius: var(--radius);
}
.b-line .res-icon svg { width: 14px; height: 14px; display: block; color: var(--text-dim); }
.b-line .res-name { font-size: 12px; color: var(--text-dim); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-count { font-size: 12px; color: var(--gold); font-weight: bold; font-variant-numeric: tabular-nums; }

/* ================= 中间：Tabs ================= */
#tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel-2);
  flex-shrink: 0;
}
.tab-btn {
  position: relative;
  font-family: var(--font);
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 2px;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: color .12s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent-bright); border-bottom-color: var(--accent); }
.tab-icon svg { width: 17px; height: 17px; display: block; }

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  min-width: 17px; height: 17px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

.tab-page { display: none; flex: 1; min-height: 0; overflow: hidden; }
.tab-page.active { display: flex; flex-direction: column; }

/* ---------------- 知识 Tab ---------------- */
.knowledge-hint {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#tech-tree-wrap {
  position: relative;
  flex: 1;
  overflow: auto;
}

#tech-edges {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
}

#tech-nodes {
  position: relative;
}

.tech-node {
  position: absolute;
  width: 190px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: default;
  transition: border-color .15s, box-shadow .15s;
}
.tech-node:hover { border-color: var(--accent); }

.tech-node .tn-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
.tech-node .tn-icon svg { width: 22px; height: 22px; display: block; }
.tech-node .tn-name { font-weight: bold; font-size: 14px; }

.tech-node .tn-desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 8px;
}

.tech-node.unlocked {
  border-color: var(--good);
  background: #1d2617;
}
.tech-node.unlocked .tn-name { color: var(--good); }
.tech-node.unlocked .tn-state { color: var(--good); }

.tech-node.available {
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(217, 111, 50, .25);
}
.tech-node.available .tn-name { color: var(--accent-bright); }

.tech-node.locked { opacity: .75; }
.tech-node.locked .tn-icon svg { filter: grayscale(1) opacity(.6); }
.tech-node .tn-state { font-size: 12px; color: var(--text-faint); }

.tech-node .tn-unlock-btn {
  width: 100%;
  justify-content: center;
}

/* ---------------- 营地 Tab ---------------- */
.camp-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.camp-info { font-size: 13px; color: var(--text-dim); }
.camp-info b { color: var(--text); font-weight: normal; }

#camp-grid {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 10), 52px);
  grid-auto-rows: 52px;
  gap: 4px;
  align-content: start;
}

.camp-cell {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: background .1s, border-color .1s;
}
.camp-cell:hover { border-color: var(--border-light); }

.camp-cell.empty::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.camp-cell.empty:hover {
  border-color: var(--accent);
  background: #2c2018;
}

.camp-cell .cell-icon svg { width: 26px; height: 26px; display: block; }
.camp-cell .cell-label {
  font-size: 10px;
  color: var(--text-dim);
  line-height: 1;
  white-space: nowrap;
}

.camp-cell.building-plot {
  background: #2b2318;
  border-color: #6e5433;
}
.camp-cell.building-plot .cell-icon svg { color: var(--gold); }
.camp-cell.building-lumbermill {
  background: #2a2119;
  border-color: #7a5a3a;
}
.camp-cell.building-lumbermill .cell-icon svg { color: #d09055; }
.camp-cell.building-granary {
  background: #2e2417;
  border-color: #8a6a34;
}
.camp-cell.building-granary .cell-icon svg { color: #e0b45c; }

/* ---------------- 建造菜单（点击地块弹出） ---------------- */
.build-menu {
  position: fixed;
  z-index: 100;
  min-width: 280px;
  max-width: 350px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .55);
  padding: 6px;
}

.bm-head {
  padding: 6px 8px 7px;
  font-size: 12px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.bm-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  color: var(--text);
  font-family: var(--font);
}
.bm-option:hover:not(:disabled) { background: var(--bg-hover); }
.bm-option:disabled { opacity: .45; cursor: not-allowed; }

.bm-icon svg { width: 26px; height: 26px; display: block; color: var(--accent-bright); }
.bm-demolish .bm-icon svg { color: var(--bad); }

.bm-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bm-name { font-weight: bold; font-size: 13px; }
.bm-desc { font-size: 11px; color: var(--text-dim); line-height: 1.4; }

.bm-cost {
  text-align: right;
  font-weight: bold;
  font-size: 13px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.bm-cur { font-size: 10px; color: var(--text-faint); font-weight: normal; }

.bm-divider {
  border-top: 1px solid var(--border);
  margin: 5px 2px 2px;
  padding: 5px 8px 2px;
  font-size: 11px;
  color: var(--text-faint);
}
.bm-empty { padding: 10px; font-size: 12px; color: var(--text-faint); }

/* ==========================================================
 * 自适应布局
 * ========================================================== */

/* 中窄屏：侧栏收窄（由 clamp 完成），矮屏压缩纵向留白 */
@media (max-height: 640px) and (min-width: 981px) {
  .panel-title { padding: 8px 12px; font-size: 14px; }
  .time-display { padding: 8px 12px; }
  .controls { padding: 8px 12px; }
  .res-line { padding: 4px 8px; margin-bottom: 3px; }
}

/* 窄屏（平板竖屏 / 手机横屏）：单列堆叠，中间游戏区置顶 */
@media (max-width: 980px) {
  html, body { overflow: auto; }
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    height: auto;
    min-height: 100vh;
  }
  #panel-center { order: -1; min-height: 72vh; }
  #panel-resources { order: 0; }
  #panel-right { order: 1; }

  /* 资源卡横排铺满 */
  .resource-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 8px;
  }
  .res-line { margin-bottom: 0; }

  /* 右栏时间区紧凑化 */
  .time-display { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .time-line1 { flex: 1 1 auto; }
  .day-progress { flex: 1 1 100%; margin-top: 8px; }
  .log-title { margin-top: 0; }
  .log-list { max-height: 240px; }
}

/* 小屏：格子与字号缩小 */
@media (max-width: 600px) {
  #app { padding: 6px; gap: 6px; }
  #camp-grid {
    grid-template-columns: repeat(var(--cols, 10), 38px);
    grid-auto-rows: 38px;
    gap: 3px;
    padding: 8px;
  }
  .camp-cell .cell-label { font-size: 8px; }
  .camp-cell .cell-icon svg { width: 20px; height: 20px; }
  .build-menu { min-width: 240px; max-width: calc(100vw - 16px); }
}

/* ================= 右侧 ================= */
.time-display {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.time-line1 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.time-phase-icon svg { width: 20px; height: 20px; display: block; }
#time-phase-text { font-weight: bold; width: 34px; }
.time-phase-day #time-phase-text { color: var(--gold); }
.time-phase-night #time-phase-text { color: var(--night-blue); }
#time-year-day {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.day-progress {
  height: 5px;
  background: #171310;
  border-radius: 3px;
  margin-top: 10px;
  overflow: hidden;
}
.day-progress > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--night-blue), var(--gold), var(--night-blue));
  border-radius: 3px;
}

.controls {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.btn-control { min-width: 76px; justify-content: center; }
.btn-control.paused {
  color: var(--gold);
  border-color: var(--gold);
  background: #33291a;
}
.speed-group {
  display: flex;
  gap: 4px;
  flex: 1;
}
.btn-speed { flex: 1; justify-content: center; padding: 7px 4px; }
.btn-speed.active {
  color: var(--accent-bright);
  border-color: var(--accent);
  background: #3a2416;
}

/* ================= 中间：仓库页 ================= */
.tab-btn.hidden { display: none; }

.warehouse-list {
  padding: 16px 20px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}
.wh-head {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
  line-height: 1.6;
}
.wh-line {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.wh-line .res-icon svg { width: 18px; height: 18px; display: block; flex-shrink: 0; }
.wh-name { font-weight: bold; min-width: 48px; flex-shrink: 0; }
.wh-max {
  color: var(--text-dim);
  font-size: 12px;
  flex: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.wh-btn { font-size: 12px; padding: 6px 10px; white-space: nowrap; flex-shrink: 0; }
.wh-btn:disabled { opacity: .45; cursor: not-allowed; }

.log-title { margin-top: auto; }
.log-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.log-item {
  font-size: 12px;
  line-height: 1.55;
  padding: 5px 8px;
  border-left: 2px solid var(--border-light);
  background: rgba(255,255,255,.02);
  border-radius: 0 4px 4px 0;
  color: var(--text-dim);
  animation: logIn .25s ease;
}
@keyframes logIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: none; }
}
.log-item .log-time {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  margin-right: 6px;
  font-size: 11px;
}
.log-item.info    { border-left-color: var(--text-faint); }
.log-item.good    { border-left-color: var(--good); color: #b9d8a8; }
.log-item.warn    { border-left-color: var(--gold); color: #e3d2a2; }
.log-item.bad     { border-left-color: var(--bad); color: #dda4a4; }
.log-item.system  { border-left-color: var(--accent); color: var(--accent-bright); }

/* ---------------- 滚动条 ---------------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 5px;
  border: 2px solid var(--bg-panel);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
