:root {
  --fg: #d8dde6;
  --dim: #7d8794;
  --line: rgba(200, 210, 230, 0.18);
  --panel: rgba(8, 10, 16, 0.34);
  --accent: #9fc2ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-rows: 1fr auto;
}

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

/* ---------------- 顶部 ---------------- */
header {
  position: absolute;
  top: 22px;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
}

header .title {
  font-size: 13px;
  letter-spacing: 0.35em;
  color: var(--dim);
  text-transform: uppercase;
}

header #clock {
  margin-top: 6px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: #eef2f8;
  text-shadow: 0 0 18px rgba(170, 200, 255, 0.35);
}

header .subtitle {
  margin-top: 4px;
  font-size: 11px;
  color: rgba(125, 135, 148, 0.8);
  letter-spacing: 0.18em;
}

/* ---------------- 面板通用 ---------------- */
.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  min-width: 210px;
  font-size: 12px;
  line-height: 1.7;
}

.panel-title {
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.22em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.dim {
  color: var(--dim);
}

.row {
  white-space: nowrap;
}

/* ---------------- 状态 ---------------- */
#status-panel {
  left: 3.5vw;
  top: 46%;
  transform: translateY(-50%);
  min-width: 250px;
}

#civ-status {
  font-size: 14px;
  letter-spacing: 0.08em;
  color: #e8edf5;
}

#civ-status.alive {
  color: #b9e6c2;
  text-shadow: 0 0 14px rgba(140, 230, 170, 0.45);
}

#civ-status.dead {
  color: #98a2b0;
}

/* ---------------- 日志 ---------------- */
#log-panel {
  left: 3.5vw;
  bottom: 7vh;
  width: 330px;
  max-height: 240px;
  overflow: hidden;
}

.civ-live {
  margin: 2px 0 6px;
  line-height: 1.5;
}

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

.log-item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: #b8c2cf;
}

/* 新日志从顶部滑入，旧条目被挤出（滚动感） */
.log-item.log-new {
  animation: log-slide 0.5s cubic-bezier(0.25, 0.8, 0.35, 1);
}

@keyframes log-slide {
  from {
    opacity: 0;
    transform: translateY(-14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.log-item .log-year {
  color: var(--dim);
  font-family: Consolas, monospace;
  margin-right: 8px;
}

.log-item.born {
  color: #b9e6c2;
}

.log-item.destroyed {
  color: #e8b6b6;
}

@keyframes log-in {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------------- 排行榜 ---------------- */
#rank-panel {
  right: 3.5vw;
  bottom: 7vh;
  width: 250px;
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rank-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: #c3ccd8;
  font-variant-numeric: tabular-nums;
}

.rank-row .rank-no {
  color: var(--dim);
  width: 28px;
  flex: none;
}

.rank-row .rank-life {
  font-family: Consolas, monospace;
  color: #dfe7f1;
}

.rank-row .rank-event {
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  flex: 1;
}

#rank-summary {
  margin-top: 6px;
  font-size: 11px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

/* ---------------- 工具栏 ---------------- */
#toolbar {
  position: absolute;
  top: 20px;
  right: 3vw;
  display: flex;
  gap: 8px;
}

button {
  pointer-events: auto;
  background: rgba(20, 26, 38, 0.7);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 12px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-family: inherit;
}

button:hover {
  border-color: rgba(159, 194, 255, 0.55);
  background: rgba(30, 40, 60, 0.8);
}

button:active {
  transform: translateY(1px);
}

footer {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: rgba(125, 135, 148, 0.7);
  letter-spacing: 0.1em;
  pointer-events: none;
}

/* ---------------- 浮层 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.hidden {
  display: none !important;
}

.dialog {
  width: min(640px, 92vw);
  max-height: 82vh;
  background: rgba(12, 15, 22, 0.96);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.dialog.wide {
  width: min(980px, 96vw);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--dim);
}

.dialog-head .close {
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
  color: var(--dim);
}

.dialog-body {
  padding: 16px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.7;
}

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

/* ---------------- 参数面板 ---------------- */
.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 18px;
  font-family: Consolas, monospace;
  font-size: 11px;
  color: #b6c0cc;
}

.param-grid .k {
  color: var(--dim);
}

.admin-title {
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.2em;
  margin-bottom: 8px;
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

input[type="password"],
input[type="number"],
select,
textarea {
  background: rgba(8, 10, 16, 0.8);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--fg);
  padding: 6px 9px;
  font-size: 12px;
  font-family: Consolas, monospace;
  outline: none;
}

input[type="number"] {
  width: 76px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(159, 194, 255, 0.6);
}

textarea {
  width: 100%;
  height: 220px;
  resize: vertical;
  line-height: 1.5;
  margin-top: 4px;
}

/* ---------------- 历史面板 ---------------- */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin-bottom: 10px;
}

.filter-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--dim);
  font-size: 12px;
}

.filter-row input[type="number"] {
  width: 88px;
}

#history-stats {
  margin-bottom: 8px;
  font-size: 11px;
}

.table-wrap {
  max-height: 46vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(200, 210, 230, 0.07);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: rgba(16, 20, 30, 0.98);
  color: var(--dim);
  font-weight: normal;
  letter-spacing: 0.08em;
  z-index: 1;
}

td.num {
  font-family: Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

tr:hover td {
  background: rgba(159, 194, 255, 0.05);
}

#history-more {
  margin-top: 8px;
  font-size: 11px;
}

/* ---------------- 天体悬停信息 ---------------- */
.tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  padding: 8px 10px;
  border: 1px solid rgba(159, 194, 255, 0.28);
  border-radius: 6px;
  background: rgba(10, 14, 22, 0.88);
  backdrop-filter: blur(4px);
  font-size: 12px;
  line-height: 1.55;
  color: #cfd8e6;
  white-space: nowrap;
  font-family: Consolas, monospace;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.tooltip .tip-coord {
  color: #9fb6d8;
}

.tooltip .tip-name {
  color: #ffffff;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
}

.tooltip .tip-sub {
  color: #8b97a8;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ---------------- 移动端 ---------------- */
@media (max-width: 900px) {
  #status-panel {
    top: auto;
    bottom: 32vh;
    transform: none;
    left: 3vw;
    font-size: 11px;
    min-width: 0;
  }
  #log-panel {
    width: 60vw;
    bottom: 16vh;
  }
  #rank-panel {
    width: 44vw;
    bottom: 16vh;
    right: 3vw;
  }
  footer {
    display: none;
  }
  header #clock {
    font-size: 20px;
  }
}
