/* 星海纪年 —— 深空终端风格。单一深色主题（有意为之）。
   布局：顶栏资源 / 左侧导航 / 中间视图 / 右侧大纲与消息 */
:root {
  --bg: #090d13;
  --bg2: #0f151e;
  --panel: #131b26;
  --panel2: #18222f;
  --line: #243244;
  --line2: #31445b;
  --fg: #d3dce6;
  --dim: #7e8da1;
  --faint: #4d5c70;
  --amber: #e9b44c;
  --amber2: #b98a2e;
  --cyan: #63c7d6;
  --good: #7cc36e;
  --bad: #e0675a;
  --warn: #e4a645;
  --mono: "Cascadia Mono", "Sarasa Mono SC", "Noto Sans Mono CJK SC", "Consolas", "MS Gothic", monospace;
  --sans: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
  --fs: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: var(--fs)/1.5 var(--sans); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a, .link { color: var(--cyan); cursor: pointer; text-decoration: none; }
a:hover, .link:hover { text-decoration: underline; }
.mono { font-family: var(--mono); }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.amber { color: var(--amber); }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.hidden { display: none !important; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; text-wrap: balance; }
h2 { font-size: 18px; color: var(--amber); letter-spacing: 0.04em; }
h3 { font-size: 15px; color: var(--fg); }
h4 { font-size: 13px; color: var(--dim); text-transform: none; letter-spacing: 0.06em; }
pre { margin: 0; font-family: var(--mono); line-height: 1.15; }
:focus-visible { outline: 1px solid var(--amber); outline-offset: 1px; }

.btn { background: var(--panel2); border: 1px solid var(--line2); color: var(--fg); padding: 3px 10px; cursor: pointer; border-radius: 2px; white-space: nowrap; }
.btn:hover { border-color: var(--amber2); color: var(--amber); }
.btn:disabled, .btn.disabled { opacity: 0.4; cursor: default; color: var(--dim); border-color: var(--line); }
.btn.primary { border-color: var(--amber2); color: var(--amber); }
.btn.small { padding: 0 6px; font-size: 12px; }
.btn.on { background: #2a2310; border-color: var(--amber); color: var(--amber); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.sep { border-top: 1px dashed var(--line); margin: 8px 0; }
.tag { display: inline-block; border: 1px solid var(--line2); padding: 0 6px; font-size: 12px; border-radius: 2px; color: var(--dim); }
.tag.good { border-color: #3e6a37; color: var(--good); }
.tag.bad { border-color: #6a3530; color: var(--bad); }
.tag.amber { border-color: var(--amber2); color: var(--amber); }
.box { border: 1px solid var(--line); background: var(--panel); padding: 10px 12px; }
.box.tight { padding: 6px 8px; }
.box-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
table.t { border-collapse: collapse; width: 100%; }
table.t td, table.t th { padding: 2px 8px 2px 0; text-align: left; vertical-align: top; }
table.t th { color: var(--dim); font-weight: normal; font-size: 12px; border-bottom: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; }
table.t tr.hl td { background: #1a2433; }
.bar { height: 6px; background: var(--bg2); border: 1px solid var(--line); position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--amber2); }
.bar.cyan > i { background: #3d8c99; }
.bar.good > i { background: #4f8a45; }
.bar.bad > i { background: #9a4239; }
.scroll { overflow: auto; }

/* ───── 屏幕 ───── */
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; }

/* 主菜单 */
#menu { flex-direction: column; align-items: center; justify-content: center; gap: 22px; background: radial-gradient(ellipse at 50% 40%, #142030 0%, var(--bg) 70%); }
#menu canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#menu .logo { position: relative; color: var(--amber); font-size: 12px; text-align: center; text-shadow: 0 0 12px rgba(233, 180, 76, 0.25); }
#menu .sub { position: relative; color: var(--dim); letter-spacing: 0.3em; font-size: 13px; }
#menu .menu-btns { position: relative; display: flex; flex-direction: column; gap: 8px; width: 240px; }
#menu .menu-btns .btn { padding: 8px; font-size: 15px; text-align: left; }
#menu .menu-btns .btn::before { content: '› '; color: var(--faint); }

/* 设置/设计器 */
.page { flex-direction: column; width: 100%; height: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.page-body { flex: 1; overflow: auto; padding: 16px; }
.page-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--bg2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 18px; }
.field { display: flex; flex-direction: column; gap: 2px; }
.field label { font-size: 12px; color: var(--dim); }
.field select, .field input[type=text], .field input[type=number], textarea { background: var(--bg2); border: 1px solid var(--line2); padding: 4px 6px; }
.field input[type=range] { accent-color: var(--amber); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.card { border: 1px solid var(--line); background: var(--panel); padding: 8px 10px; cursor: pointer; position: relative; }
.card:hover { border-color: var(--line2); }
.card.sel { border-color: var(--amber); background: #1d1a12; }
.card.na { opacity: 0.45; }
.card .c-title { color: var(--fg); font-weight: 600; }
.card .c-text { font-size: 12px; color: var(--dim); }
.card .c-cost { position: absolute; right: 8px; top: 6px; font-family: var(--mono); font-size: 12px; }

.designer { display: grid; grid-template-columns: 170px 1fr 300px; height: 100%; }
.designer .tabs { border-right: 1px solid var(--line); padding: 10px 0; background: var(--bg2); }
.designer .tabs .tab { padding: 6px 16px; cursor: pointer; color: var(--dim); border-left: 2px solid transparent; }
.designer .tabs .tab.on { color: var(--amber); border-left-color: var(--amber); background: var(--panel); }
.designer .tabs .tab .err { color: var(--bad); }
.designer .d-main { overflow: auto; padding: 16px; }
.designer .d-side { border-left: 1px solid var(--line); overflow: auto; padding: 14px; background: var(--bg2); }
.portrait { font-family: var(--mono); line-height: 1.1; white-space: pre; padding: 6px 8px; background: #0a0f15; border: 1px solid var(--line); display: inline-block; }
.flag { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 20px; font-size: 14px; border: 1px solid rgba(255,255,255,0.15); }
.flag.big { width: 64px; height: 44px; font-size: 30px; }

/* ───── 游戏界面 ───── */
#game { flex-direction: column; }
#top { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); background: var(--bg2); min-height: 40px; }
#top .t-empire { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-right: 1px solid var(--line); cursor: pointer; }
#top .t-res { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; padding: 4px 12px; flex: 1; min-width: 0; }
#top .res { display: inline-flex; align-items: baseline; gap: 4px; cursor: default; white-space: nowrap; font-size: 13px; }
#top .res .ic { width: 14px; text-align: center; }
#top .res .inc { font-size: 11px; }
#top .t-time { display: flex; align-items: center; gap: 6px; padding: 0 12px; border-left: 1px solid var(--line); }
#top .date { font-family: var(--mono); font-size: 15px; color: var(--amber); min-width: 92px; }
#top .spd { cursor: pointer; font-family: var(--mono); color: var(--faint); padding: 0 1px; }
#top .spd.on { color: var(--amber); }
#top .pause { font-family: var(--mono); font-size: 12px; border: 1px solid var(--line2); padding: 0 6px; cursor: pointer; }
#top .pause.paused { color: var(--bad); border-color: #6a3530; }

#mid { flex: 1; display: flex; min-height: 0; }
#nav { width: 92px; border-right: 1px solid var(--line); background: var(--bg2); display: flex; flex-direction: column; padding: 6px 0; overflow: auto; }
#nav .n { padding: 6px 10px; cursor: pointer; color: var(--dim); border-left: 2px solid transparent; font-size: 13px; display: flex; justify-content: space-between; }
#nav .n:hover { color: var(--fg); }
#nav .n.on { color: var(--amber); border-left-color: var(--amber); background: var(--panel); }
#nav .n .k { color: var(--faint); font-family: var(--mono); font-size: 11px; }
#nav .n .alert { color: var(--bad); }
#nav .n.locked { color: var(--faint); }
#view { flex: 1; min-width: 0; overflow: auto; position: relative; }
#view.map { overflow: hidden; }
.view-pad { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
#side { width: 260px; border-left: 1px solid var(--line); background: var(--bg2); display: flex; flex-direction: column; min-height: 0; }
#outliner { flex: 1; overflow: auto; padding: 6px 8px; font-size: 12px; }
#outliner .o-h { color: var(--dim); margin-top: 6px; cursor: pointer; user-select: none; }
#outliner .o-i { display: flex; justify-content: space-between; gap: 6px; padding: 1px 0 1px 8px; cursor: pointer; }
#outliner .o-i:hover { background: var(--panel); }
#outliner .o-i .st { color: var(--faint); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
#msgs { height: 38%; border-top: 1px solid var(--line); overflow: auto; padding: 6px 8px; font-size: 12px; }
#msgs .m { padding: 2px 0; border-bottom: 1px dotted #1c2735; cursor: pointer; }
#msgs .m .d { color: var(--faint); font-family: var(--mono); margin-right: 4px; }
#msgs .m.good { color: #a8d79c; }
#msgs .m.bad { color: #eb9a90; }
#msgs .m.warn { color: #ecc27c; }
#msgs .m.event { color: #9fd9e3; }
#msgs .m.research { color: #b6c8f0; }

/* 地图 */
#mapwrap { position: absolute; inset: 0; }
#mapcv { width: 100%; height: 100%; display: block; cursor: grab; }
#mapinfo { position: absolute; right: 10px; top: 10px; width: 300px; max-height: calc(100% - 20px); overflow: auto; }
#maptools { position: absolute; left: 10px; top: 10px; display: flex; gap: 4px; flex-wrap: wrap; max-width: 60%; }
#maphint { position: absolute; left: 10px; bottom: 10px; color: var(--dim); font-size: 12px; background: rgba(9,13,19,0.8); padding: 4px 8px; }
#tip { position: fixed; z-index: 50; pointer-events: none; background: #0c1219; border: 1px solid var(--line2); padding: 6px 8px; font-size: 12px; max-width: 380px; display: none; white-space: pre-wrap; box-shadow: 0 4px 18px rgba(0,0,0,0.5); }

/* 星系页 */
.sysview { position: relative; min-height: 100%; }
.sysview .starbg { position: absolute; right: 24px; top: 20px; font-family: var(--mono); line-height: 1.05; white-space: pre; opacity: 0.55; pointer-events: none; font-size: 13px; }
.sysview .view-pad { position: relative; }
.body-row { display: grid; grid-template-columns: 48px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); align-items: center; }
.body-row:hover { background: rgba(24, 34, 47, 0.6); }
.pp { image-rendering: pixelated; display: block; }

/* 星球页 */
.planet-head { display: grid; grid-template-columns: 96px 1fr auto; gap: 14px; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.slot { border: 1px solid var(--line); padding: 4px 8px; background: var(--bg2); display: flex; justify-content: space-between; gap: 6px; align-items: center; font-size: 13px; min-height: 30px; }
.slot.empty { color: var(--faint); border-style: dashed; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.dist { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px 10px; align-items: center; }

/* 科研 */
.rcol { display: flex; flex-direction: column; gap: 8px; }
.tcard { border: 1px solid var(--line); background: var(--panel); padding: 8px 10px; cursor: pointer; }
.tcard:hover { border-color: var(--amber2); }
.tcard.cur { border-color: var(--amber); }
.tcard.rare { box-shadow: inset 2px 0 0 #8a6fd6; }
.tcard.perm { box-shadow: inset 2px 0 0 var(--amber); }
.tcard .tn { font-weight: 600; }
.tcard .tm { font-size: 12px; color: var(--dim); }

/* 事件弹窗 */
#modal { position: fixed; inset: 0; background: rgba(4, 7, 11, 0.72); display: none; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
#modal.on { display: flex; }
.ev { width: min(620px, 100%); max-height: 90vh; overflow: auto; background: var(--panel); border: 1px solid var(--amber2); box-shadow: 0 0 0 1px #000, 0 10px 40px rgba(0,0,0,0.6); }
.ev .ev-h { padding: 8px 14px; border-bottom: 1px solid var(--line); color: var(--amber); font-size: 16px; display: flex; justify-content: space-between; }
.ev .ev-art { padding: 10px 14px; color: var(--cyan); background: #0a0f15; border-bottom: 1px solid var(--line); font-size: 13px; overflow: auto; }
.ev .ev-t { padding: 12px 14px; white-space: pre-wrap; line-height: 1.7; }
.ev .ev-help { margin: 0 14px 12px; padding: 6px 10px; background: #0d141c; border-left: 2px solid var(--line2); color: var(--dim); font-size: 12px; line-height: 1.7; white-space: pre-wrap; }
.ev .ev-help b { color: var(--fg); font-weight: normal; }
.ev .ev-o { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.ev .ev-o .btn { text-align: left; padding: 6px 10px; white-space: normal; }
.ev .ev-o .btn .tip { display: block; font-size: 12px; color: var(--dim); }
.dlg { width: min(720px, 100%); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line2); }
.dlg .ev-t { white-space: normal; }

.toast { position: fixed; left: 50%; top: 52px; transform: translateX(-50%); background: #2a1d12; border: 1px solid var(--warn); color: var(--warn); padding: 6px 14px; z-index: 60; font-size: 13px; }

@media (max-width: 900px) {
  #side { display: none; }
  .designer { grid-template-columns: 110px 1fr; }
  .designer .d-side { display: none; }
  /* 星图：信息面板放到底部，不挡住地图中间 */
  #mapinfo { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 45%; }
  #maptools { max-width: calc(100% - 20px); }
}
/* 触屏设备：没有鼠标悬停，星图底部的鼠标操作提示不显示 */
@media (pointer: coarse) {
  #maphint { display: none; }
}
/* 手机竖屏：整个页面转 90°，横过来拿就是横屏（ui_setup.js 的 UI.applyRotate 加 html.rot） */
html.rot body { position: fixed; top: 0; left: var(--rh); width: var(--rw); height: var(--rh); transform-origin: 0 0; transform: rotate(90deg); }
/* 不让浏览器缩放页面：双击放大、双指缩放（星图画布自己处理手势） */
html, body { touch-action: pan-x pan-y; }
button, .btn, [data-act] { touch-action: manipulation; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.card.newcard { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 140px; border: 2px dashed var(--line2); color: var(--dim); }
.card.newcard:hover { border-color: var(--amber); color: var(--amber); }
.card.newcard .plus { font-size: 54px; line-height: 1; font-weight: 300; }
.card.newcard.small { min-height: 100px; }
