:root {
  --ink: #dbe4ff;
  --ink-dim: #8b97b8;
  --gold: #e8c37a;
  --gold-soft: #f3dcae;
  --cyan: #57e0e6;
  --violet: #a97cff;
  --ember: #ff8a4c;
  --panel: rgba(9, 13, 28, 0.78);
  --panel-line: rgba(120, 150, 220, 0.28);
  --panel-line-hot: rgba(232, 195, 122, 0.55);
  --font: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #01020a;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: minmax(260px, 300px) 1fr minmax(240px, 300px);
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "banner banner banner"
    "top top top"
    "left mid right"
    "bottom bottom bottom";
  gap: 10px;
  padding: 10px;
}

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

/* ---------- 降级横幅 ---------- */
.banner {
  grid-area: banner;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 138, 76, 0.55);
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(90, 30, 10, 0.92), rgba(40, 16, 40, 0.86));
  color: #ffe6d2;
  font-size: 13px;
  letter-spacing: 0.02em;
  box-shadow: 0 0 24px rgba(255, 120, 40, 0.25);
}
.banner.hidden { display: none; }
.banner-tag {
  flex: none;
  padding: 2px 9px;
  border-radius: 4px;
  background: rgba(255, 138, 76, 0.22);
  border: 1px solid rgba(255, 138, 76, 0.7);
  color: #ffcfae;
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- 顶栏 ---------- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  margin-top: 0;
  background: linear-gradient(180deg, rgba(6, 10, 24, 0.92), rgba(6, 10, 24, 0.68));
  border: 1px solid var(--panel-line);
  border-top: 2px solid var(--panel-line-hot);
  border-radius: 8px;
  backdrop-filter: blur(6px);
}

.brand { display: flex; flex-direction: column; line-height: 1.15; padding-right: 16px; border-right: 1px solid var(--panel-line); }
.brand-mark {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--gold-soft);
  text-shadow: 0 0 18px rgba(232, 195, 122, 0.45);
}
.brand-sub { font-size: 11px; color: var(--ink-dim); letter-spacing: 0.24em; margin-top: 3px; }

.resources { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; }
.res {
  position: relative;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  padding: 5px 12px;
  min-width: 122px;
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  background: rgba(14, 20, 42, 0.6);
}
.res-icon { font-size: 13px; grid-row: 1 / span 2; }
.res-name { font-size: 11px; color: var(--ink-dim); letter-spacing: 0.12em; }
.res-value { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; transition: color 0.35s ease; }
.res-value.bump { animation: resPulse 0.65s ease; }
@keyframes resPulse {
  0% { transform: scale(1); }
  28% { transform: scale(1.2); color: #ffffff; text-shadow: 0 0 14px currentColor; }
  100% { transform: scale(1); }
}
.res-value.spend { color: var(--ember) !important; }
.res-delta {
  position: absolute;
  right: 8px;
  top: -3px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #8df0a8;
  text-shadow: 0 0 10px rgba(80, 240, 140, 0.6);
  pointer-events: none;
  animation: resFloat 1s ease forwards;
}
.res-delta.neg { color: #ff9a7a; text-shadow: 0 0 10px rgba(255, 120, 80, 0.6); }
@keyframes resFloat {
  0% { opacity: 0; transform: translateY(6px); }
  25% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-16px); }
}
.res-rate { grid-column: 2; font-size: 10px; color: var(--ink-dim); }
.res-energy .res-icon, .res-energy .res-value { color: var(--cyan); }
.res-alloy .res-icon, .res-alloy .res-value { color: var(--gold); }
.res-manpower .res-icon, .res-manpower .res-value { color: var(--ember); }

.turnbox { display: flex; align-items: center; gap: 12px; padding-left: 16px; border-left: 1px solid var(--panel-line); }
.turn-label { font-size: 11px; color: var(--ink-dim); letter-spacing: 0.2em; }
.turn-value { font-size: 24px; font-weight: 800; color: var(--gold-soft); font-variant-numeric: tabular-nums; min-width: 34px; text-align: center; }

.btn-turn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #0a1206;
  padding: 9px 18px;
  border: 1px solid rgba(255, 226, 160, 0.8);
  border-radius: 5px;
  background: linear-gradient(180deg, #f6dd9e, #d9ae57);
  cursor: pointer;
  box-shadow: 0 0 18px rgba(232, 195, 122, 0.35);
}
.btn-turn:hover { background: linear-gradient(180deg, #fff0c4, #e8c37a); }
.btn-turn:active { transform: translateY(1px); }

/* ---------- 情报面板 ---------- */
#infopanel {
  grid-area: right;
  align-self: start;
  padding: 12px 14px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  font-size: 12px;
  min-height: 220px;
}
.panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--gold);
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--panel-line);
}
.panel-title.small { font-size: 11px; letter-spacing: 0.18em; padding-bottom: 5px; margin-bottom: 7px; }
.sel-empty { color: var(--ink-dim); line-height: 1.9; text-align: center; padding: 26px 0; font-size: 12px; }
.hint-dim { font-size: 11px; opacity: 0.7; }
.sel-body.hidden, .sel-empty.hidden { display: none; }
.sel-name { font-size: 17px; font-weight: 800; color: var(--gold-soft); letter-spacing: 0.06em; margin-bottom: 9px; text-shadow: 0 0 14px rgba(232,195,122,0.35); }
.sel-row { display: flex; justify-content: space-between; padding: 3px 0; color: var(--ink-dim); }
.sel-row .v { color: var(--ink); font-weight: 600; }
.sel-section { margin: 10px 0 4px; font-size: 11px; color: var(--violet); letter-spacing: 0.14em; border-top: 1px dashed var(--panel-line); padding-top: 8px; }
.btn-sub {
  width: 100%;
  margin-top: 12px;
  padding: 7px;
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--cyan);
  background: rgba(87, 224, 230, 0.08);
  border: 1px solid rgba(87, 224, 230, 0.45);
  border-radius: 5px;
  cursor: pointer;
}
.btn-sub:hover { background: rgba(87, 224, 230, 0.18); }
.sel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
.sel-actions .btn-sub { margin-top: 0; }

/* ---------- 胜利结算 ---------- */
.victory {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(20, 26, 60, 0.72), rgba(1, 2, 10, 0.92));
  backdrop-filter: blur(3px);
}
.victory.hidden { display: none; }
.victory-card {
  width: min(480px, 88vw);
  padding: 26px 30px 22px;
  text-align: center;
  background: linear-gradient(180deg, rgba(12, 18, 40, 0.96), rgba(8, 11, 26, 0.96));
  border: 1px solid var(--panel-line-hot);
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(232, 195, 122, 0.22);
  animation: victoryIn 0.4s ease;
}
@keyframes victoryIn { from { opacity: 0; transform: translateY(18px) scale(0.97); } to { opacity: 1; transform: none; } }
.victory-tag { font-size: 11px; letter-spacing: 0.36em; color: var(--ink-dim); }
.victory-title { font-size: 30px; font-weight: 800; letter-spacing: 0.24em; color: var(--gold-soft); margin: 6px 0 4px; text-shadow: 0 0 26px rgba(232, 195, 122, 0.5); }
.victory-name { font-size: 18px; font-weight: 700; letter-spacing: 0.1em; margin-bottom: 6px; }
.victory-reason { font-size: 12px; color: var(--ink-dim); line-height: 1.7; margin-bottom: 14px; }
.victory-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; margin-bottom: 18px; font-size: 12px; }
.victory-grid .vgrow { display: flex; justify-content: space-between; padding: 5px 9px; border: 1px solid var(--panel-line); border-radius: 5px; background: rgba(14, 20, 42, 0.55); }
.victory-actions { display: flex; gap: 10px; justify-content: center; }
.victory-actions .btn-turn, .victory-actions .btn-sub { width: auto; margin-top: 0; padding: 9px 22px; }

/* ---------- 左列（性能 / 阵营 / 战报） ---------- */
#leftcol {
  grid-area: left;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

#perf, #factions, #fleets, #eventlog {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  font-size: 12px;
  width: 100%;
}

/* ---------- 阵营态势 ---------- */
.faction-list { display: flex; flex-direction: column; gap: 5px; }
.faction-row {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 5px;
  border: 1px solid transparent;
}
.faction-row.is-player { border-color: rgba(232, 195, 122, 0.45); background: rgba(232, 195, 122, 0.07); }
.faction-row.dead { opacity: 0.42; }
.faction-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.faction-name { color: var(--ink); font-weight: 600; letter-spacing: 0.04em; white-space: nowrap; }
.faction-tag { font-size: 9px; padding: 1px 5px; border-radius: 3px; border: 1px solid var(--panel-line); color: var(--ink-dim); }
.faction-tag.player { color: #0a1206; background: var(--gold); border-color: var(--gold-soft); font-weight: 700; }
.faction-tag.ai { color: var(--cyan); }
.faction-cut { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.faction-bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: rgba(120,150,220,0.14); overflow: hidden; }
.faction-bar > i { display: block; height: 100%; border-radius: 2px; transition: width 0.5s ease; }
.faction-foot { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--panel-line); color: var(--ink-dim); font-size: 11px; }

/* ---------- 舰队列表 ---------- */
.fleet-list { display: flex; flex-direction: column; gap: 5px; max-height: 168px; overflow-y: auto; }
.fleet-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 5px;
  border: 1px solid var(--panel-line);
  background: rgba(14, 20, 42, 0.5);
  cursor: pointer;
}
.fleet-row:hover { border-color: var(--panel-line-hot); }
.fleet-row.is-player { border-color: rgba(232, 195, 122, 0.4); }
.fleet-row.selected { border-color: var(--cyan); background: rgba(87, 224, 230, 0.12); box-shadow: 0 0 12px rgba(87, 224, 230, 0.2); }
.fleet-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.fleet-row-body { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.fleet-row-top { color: var(--ink); font-weight: 600; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-row-sub { color: var(--ink-dim); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-tag { font-size: 9px; padding: 1px 5px; border-radius: 3px; border: 1px solid var(--panel-line); color: var(--ink-dim); }
.fleet-tag.player { color: #0a1206; background: var(--gold); border-color: var(--gold-soft); font-weight: 700; }
.fleet-tag.ai { color: var(--cyan); }
.fleet-foot { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--panel-line); color: var(--ink-dim); font-size: 11px; }

/* ---------- 船坞建造 ---------- */
.ship-btns { display: flex; flex-direction: column; gap: 6px; }
.ship-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--gold-soft);
  background: rgba(232, 195, 122, 0.08);
  border: 1px solid rgba(232, 195, 122, 0.42);
  border-radius: 5px;
  cursor: pointer;
}
.ship-btn:hover:not(:disabled) { background: rgba(232, 195, 122, 0.2); }
.ship-btn:disabled { opacity: 0.42; cursor: not-allowed; }
.ship-name { font-weight: 700; letter-spacing: 0.06em; }
.ship-cost { font-size: 10px; color: var(--ink-dim); white-space: nowrap; }
.build-queue { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.queue-row { display: flex; justify-content: space-between; padding: 3px 7px; font-size: 11px; color: var(--ink); background: rgba(87, 224, 230, 0.07); border: 1px solid var(--panel-line); border-radius: 4px; }
.queue-turns { color: var(--cyan); }
.queue-empty { font-size: 11px; color: var(--ink-dim); padding: 3px 0; }
.yard-hint { margin-top: 10px; font-size: 11px; color: var(--ink-dim); border-top: 1px dashed var(--panel-line); padding-top: 8px; }
.yard-hint.hidden, #yard-section.hidden { display: none; }
.fleet-tip { font-size: 11px; color: var(--ink-dim); line-height: 1.6; margin-top: 6px; padding: 6px 8px; border: 1px dashed var(--panel-line); border-radius: 5px; }

/* ---------- 遭遇占位弹窗 ---------- */
.encounter {
  position: fixed;
  inset: 0;
  z-index: 65;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 42%, rgba(60, 18, 24, 0.7), rgba(1, 2, 10, 0.92));
  backdrop-filter: blur(3px);
}
.encounter.hidden { display: none; }
.encounter-card {
  width: min(460px, 88vw);
  padding: 24px 28px 20px;
  background: linear-gradient(180deg, rgba(30, 14, 22, 0.96), rgba(10, 12, 28, 0.96));
  border: 1px solid rgba(255, 138, 76, 0.6);
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(255, 120, 60, 0.24);
  animation: victoryIn 0.35s ease;
}
.encounter-tag { font-size: 11px; letter-spacing: 0.32em; color: var(--ember); }
.encounter-title { font-size: 24px; font-weight: 800; letter-spacing: 0.14em; color: #ffd9b8; margin: 6px 0 4px; text-shadow: 0 0 22px rgba(255, 138, 76, 0.5); }
.encounter-sub { font-size: 12px; color: var(--ink); line-height: 1.7; margin-bottom: 14px; }
.encounter-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; margin-bottom: 14px; font-size: 12px; }
.encounter-grid .vgrow { display: flex; justify-content: space-between; padding: 5px 9px; border: 1px solid rgba(255, 138, 76, 0.3); border-radius: 5px; background: rgba(40, 16, 20, 0.5); }
.encounter-note { font-size: 11px; color: var(--ink-dim); margin-bottom: 16px; }
.encounter-actions { display: flex; gap: 10px; justify-content: center; }
.encounter-actions .btn-turn, .encounter-actions .btn-sub { width: auto; margin-top: 0; padding: 9px 22px; }

/* ---------- 战报 ---------- */
.event-log { display: flex; flex-direction: column; gap: 3px; max-height: 132px; overflow: hidden; font-size: 11px; line-height: 1.5; color: var(--ink-dim); }
.event-log .ev { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-log .ev-player { color: var(--gold-soft); }
.event-log .ev-home { color: var(--ember); font-weight: 700; }
.event-log .ev-turn { color: var(--cyan); letter-spacing: 0.1em; margin-top: 3px; }

/* ---------- 阶段提示 ---------- */
.phasebox { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; padding: 0 4px; min-width: 108px; }
.phase-label { font-size: 10px; color: var(--ink-dim); letter-spacing: 0.2em; }
.phase-name { font-size: 14px; font-weight: 700; color: var(--cyan); letter-spacing: 0.06em; }
.phase-name.busy { color: var(--ember); }
.phase-timer { font-size: 10px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.perf-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.perf-grid .k { color: var(--ink-dim); }
.perf-grid .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.perf-grid .v.mode { color: var(--cyan); }
.perf-grid .v.mode.degraded { color: var(--ember); }
.quality { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--panel-line); }
.quality .k { color: var(--ink-dim); }
.qbtns { display: flex; gap: 5px; }
.qbtn {
  font-family: var(--font);
  font-size: 11px;
  padding: 4px 11px;
  color: var(--ink-dim);
  background: rgba(20, 28, 54, 0.8);
  border: 1px solid var(--panel-line);
  border-radius: 4px;
  cursor: pointer;
}
.qbtn:hover { color: var(--ink); border-color: var(--panel-line-hot); }
.qbtn.active { color: #0a1206; background: linear-gradient(180deg, #f6dd9e, #d9ae57); border-color: var(--gold-soft); font-weight: 700; }

/* ---------- 底部 ---------- */
#hintbar {
  grid-area: bottom;
  justify-self: start;
  align-self: end;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 7px 14px;
  font-size: 11px;
  color: var(--ink-dim);
  background: rgba(6, 10, 24, 0.7);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  letter-spacing: 0.04em;
}
#hintbar b { color: var(--gold); font-weight: 600; }

#statsbar {
  grid-area: bottom;
  justify-self: end;
  align-self: end;
  display: flex;
  gap: 16px;
  padding: 7px 14px;
  font-size: 11px;
  color: var(--ink-dim);
  background: rgba(6, 10, 24, 0.7);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 载入 ---------- */
#loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: radial-gradient(circle at 50% 45%, #0a1030 0%, #01020a 70%);
  z-index: 50;
  transition: opacity 0.6s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.load-core {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7e0 0%, #e8c37a 30%, rgba(169, 124, 255, 0.4) 60%, transparent 72%);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.86); opacity: 0.75; }
  50% { transform: scale(1.1); opacity: 1; }
}
.load-text { font-size: 13px; letter-spacing: 0.36em; color: var(--gold-soft); }

@media (max-width: 980px) {
  #hud { grid-template-columns: 1fr; grid-template-areas: "top" "mid" "bottom"; }
  #leftcol, #infopanel { position: fixed; }
  #leftcol { left: 10px; top: 96px; width: 240px; }
  #infopanel { right: 10px; top: 96px; width: 240px; }
  #hintbar { display: none; }
}
