/* 页面 UI：黑底直角小字号（与调试面板同一套风格），半透明悬浮在画面上 */
:root {
  --ui-font-size: 12px;
  --panel-width: 380px;
  --panel-alpha: 0.9;
  --ui-bg: rgba(18, 18, 21, var(--panel-alpha));
  --ui-bg-solid: #141417;
  --ui-field: #2a2a30;
  --ui-field-hover: #34343b;
  --ui-fg: #e6e6e6;
  --ui-muted: #8d8d96;
  --ui-line: #34343a;
  --ui-accent: #4fb6f0;
  --ui-mod: #f0c75a;
  --ui-danger: #ff6b5e;
  --ui-ok: #5fd08a;
  --font: ui-monospace, 'SF Mono', Menlo, 'PingFang SC', 'Microsoft YaHei', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #f3efe6;
  color: var(--ui-fg);
  font: var(--ui-font-size) / 1.45 var(--font);
}

#view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  outline: none;
  touch-action: none;
}

button, select, input, textarea { font: inherit; color: inherit; border-radius: 0; }
button {
  border: 1px solid var(--ui-line);
  background: var(--ui-field);
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--ui-field-hover); border-color: #4a4a52; }
button.primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #08131b; }
button.danger { color: var(--ui-danger); }
button:disabled { opacity: 0.5; cursor: progress; }
[hidden] { display: none !important; }

/* ---------- 顶栏：标题、版本、服务器状态、帧率（浅色小徽章，不用黑底） ---------- */
#topbar {
  position: fixed;
  top: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
}
.tb-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.brand { font-weight: 700; white-space: nowrap; color: #222831; font-size: 13px; }
.badge {
  white-space: nowrap;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  color: #222831;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(0, 0, 0, 0.1);
  pointer-events: auto;
}
.srv { display: inline-flex; align-items: center; gap: 5px; }
.srv i { width: 7px; height: 7px; border-radius: 50%; background: #9aa0a6; display: inline-block; }
.srv.on i { background: #2e9d5c; }
.srv.off i { background: #d24a3c; }
.srv.off { color: #b03a2e; }
#fps:empty, body.no-fps #fps { display: none; }

#snapshot-banner {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ui-bg);
  color: var(--ui-mod);
  border: 1px solid var(--ui-mod);
  padding: 4px 10px;
  z-index: 5;
}
#snapshot-banner a { color: var(--ui-accent); }

#help {
  position: fixed;
  left: 8px;
  bottom: 8px;
  color: var(--ui-muted);
  background: var(--ui-bg);
  padding: 3px 8px;
  z-index: 4;
}
#help b { color: var(--ui-fg); font-weight: 600; }
body.no-help #help { display: none; }

/* 隐藏全部页面 UI（U） */
body.ui-hidden #topbar,
body.ui-hidden #help,
body.ui-hidden #snapshot-banner,
body.ui-hidden #log-drawer,
body.ui-hidden .p-panel,
body.ui-hidden .p-tip,
body.ui-hidden .biome-map { display: none !important; }

/* 调试：群系地图 */
.biome-map {
  position: fixed;
  left: 10px;
  top: 40px;
  z-index: 20;
  background: rgba(10, 10, 12, 0.88);
  padding: 6px;
  pointer-events: none;
}
.biome-map canvas { display: block; image-rendering: pixelated; }
.biome-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  max-width: 520px;
  margin-top: 6px;
  font-size: 11px;
  color: #e8e6e0;
}
.biome-legend i { display: inline-block; width: 9px; height: 9px; margin-right: 4px; vertical-align: -1px; }

/* ---------- 弹窗 / 抽屉 / 提示 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal-card {
  width: min(400px, calc(100vw - 32px));
  background: var(--ui-bg-solid);
  border: 1px solid var(--ui-line);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-card h3 { margin: 0; font-size: 1.1em; }
.modal-card label { display: flex; flex-direction: column; gap: 3px; color: var(--ui-muted); }
.modal-card input, .modal-card textarea {
  padding: 5px 7px;
  border: 1px solid var(--ui-line);
  background: var(--ui-field);
  resize: vertical;
  outline: none;
}
.modal-card input:focus, .modal-card textarea:focus { border-color: var(--ui-accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 6px; }
.muted { color: var(--ui-muted); margin: 0; }
.req, .error { color: var(--ui-danger); }
.error:empty { display: none; }

#log-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(360px, 100vw);
  background: var(--ui-bg);
  border-right: 1px solid var(--ui-line);
  z-index: 15;
  display: flex;
  flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--ui-line); }
.drawer-head h3 { margin: 0; font-size: 1.1em; }
#log-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.log-item { border: 1px solid var(--ui-line); background: rgba(255, 255, 255, 0.02); padding: 6px 8px; }
.log-item.current { border-color: var(--ui-accent); }
.log-head { display: flex; align-items: center; gap: 6px; }
.log-meta { color: var(--ui-muted); margin-top: 2px; }
.log-note { margin-top: 4px; white-space: pre-wrap; color: #c8c8cc; }
.log-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.log-actions:empty { display: none; }
.log-empty { color: var(--ui-muted); padding: 10px; text-align: center; }
.tag { background: var(--ui-accent); color: #08131b; padding: 0 5px; }

#toasts { position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; z-index: 30; pointer-events: none; }
.toast { background: var(--ui-bg-solid); border-left: 3px solid var(--ui-muted); color: var(--ui-fg); padding: 5px 10px; transition: opacity 0.4s; }
.toast-ok { border-left-color: var(--ui-ok); }
.toast-error { border-left-color: var(--ui-danger); }
.toast.out { opacity: 0; }

#boot-error {
  position: fixed;
  inset: 30% 10% auto;
  background: var(--ui-bg-solid);
  border: 1px solid var(--ui-danger);
  padding: 12px;
  white-space: pre-wrap;
  z-index: 40;
}

/* ---------- 参数面板 ---------- */
.p-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  width: var(--panel-width);
  max-height: calc(100vh - 20px);
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
  border: 1px solid #2c2c33;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 10;
  user-select: none;
  line-height: 1.5;
}
.p-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: grab;
  border-bottom: 1px solid var(--ui-line);
  background: rgba(255, 255, 255, 0.04);
  touch-action: none;
}
.p-head:active { cursor: grabbing; }
.p-head b { font-size: 1.08em; }
.p-head-ver { color: var(--ui-muted); }
.p-head-caret { margin-left: auto; width: 0; height: 0; border: 5px solid transparent; border-top-color: var(--ui-fg); transform: translateY(3px); }
.p-panel.collapsed .p-head-caret { transform: rotate(90deg) translateX(2px); }
.p-panel.collapsed .p-head { border-bottom: 0; }
.p-panel.collapsed .p-body { display: none; }
.p-body { display: flex; flex-direction: column; min-height: 0; }

.p-panel button { padding: 4px 10px; border-color: #44444d; background: #2e2e35; }
.p-panel button:hover { background: #3a3a43; border-color: #5a5a66; }
.p-panel button.primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #061620; font-weight: 600; }
.p-panel button.primary:hover { filter: brightness(1.1); }
.p-quick { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--ui-line); }
.p-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.p-actions button { flex: 1 1 auto; }
.p-main button { flex: 1 1 0; padding: 6px 4px; }
.p-minor button { color: #c4c4cc; padding: 3px 6px; }
.p-status { display: flex; align-items: center; gap: 8px; }
.p-dirty { color: var(--ui-muted); }
.p-dirty.dirty { color: var(--ui-mod); }
.p-dirty.dirty::before { content: ''; display: inline-block; width: 7px; height: 7px; background: var(--ui-mod); margin-right: 6px; }
.p-panel button.p-link { padding: 0 4px; border: 0; background: none; color: var(--ui-accent); text-decoration: underline; }
.p-plist { display: flex; flex-direction: column; gap: 4px; padding: 2px 10px 4px 16px; }
.p-plist > .p-note { padding: 0 0 4px; }
.p-pcard { display: flex; align-items: center; gap: 8px; padding: 5px 7px; border: 1px solid var(--ui-line); border-radius: 4px; }
.p-pcard.active { border-color: var(--ui-accent); background: rgba(79, 182, 240, 0.08); }
.p-pcard-text { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.p-pcard-text span { color: var(--ui-muted); font-size: 0.92em; }
.p-note { color: var(--ui-muted); margin: 0; }
.p-search, .p-panel select, .p-panel input[type='number'], .p-panel input[type='text'] {
  background: #26262c;
  border: 1px solid #3c3c45;
  padding: 3px 6px;
  outline: none;
  min-width: 0;
  color: var(--ui-fg);
}
.p-search:focus, .p-panel input:focus, .p-panel select:focus { border-color: var(--ui-accent); }

.p-tabs { display: flex; border-bottom: 1px solid var(--ui-line); }
.p-panel .p-tabs button { flex: 1; border: 0; border-right: 1px solid var(--ui-line); background: transparent; padding: 6px 2px; color: var(--ui-muted); }
.p-panel .p-tabs button:last-child { border-right: 0; }
.p-panel .p-tabs button:hover { color: var(--ui-fg); background: rgba(255, 255, 255, 0.04); }
.p-panel .p-tabs button.active { color: var(--ui-fg); background: #2a2a31; box-shadow: inset 0 -2px 0 var(--ui-accent); font-weight: 600; }
.p-panel.searching .p-tabs { display: none; }

.p-content { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.p-content::-webkit-scrollbar { width: 8px; }
.p-content::-webkit-scrollbar-thumb { background: #4a4a54; }
.p-tab-title { display: none; padding: 5px 10px; color: var(--ui-accent); border-bottom: 1px solid var(--ui-line); }
.p-panel.searching .p-tab-title { display: block; }

.p-sec { border-bottom: 1px solid var(--ui-line); }
.p-sec-head { display: flex; align-items: center; gap: 7px; padding: 6px 10px; cursor: pointer; font-weight: 600; color: #ececf0; }
.p-sec-head:hover { background: rgba(255, 255, 255, 0.05); }
.p-caret { width: 0; height: 0; border: 4px solid transparent; border-left-color: var(--ui-muted); margin-right: -2px; }
.p-sec.open .p-caret { transform: rotate(90deg) translateX(2px); }
.p-count { margin-left: auto; color: var(--ui-mod); font-weight: 400; }
.p-sec-body { display: none; padding: 0 0 6px; }
.p-sec.open .p-sec-body, .p-panel.searching .p-sec-body { display: block; }

.p-row { display: grid; grid-template-columns: 40% 1fr 18px; align-items: center; gap: 8px; padding: 2px 6px 2px 16px; min-height: 26px; border-left: 2px solid transparent; }
.p-row:hover { background: rgba(255, 255, 255, 0.06); }
.p-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #dcdce2; }
.p-row.is-mod { border-left-color: var(--ui-mod); background: rgba(240, 199, 90, 0.07); }
.p-row.is-mod .p-label { color: var(--ui-mod); }
.p-regen { font-style: normal; color: var(--ui-muted); margin-left: 3px; }
.p-ctl { display: flex; align-items: center; gap: 5px; min-width: 0; }
.p-ctl select { width: 100%; }
.p-panel .p-reset { visibility: hidden; padding: 0; border: 0; background: none; color: var(--ui-muted); width: 18px; }
.p-row.is-mod .p-reset { visibility: visible; }
.p-panel .p-reset:hover { color: var(--ui-fg); background: none; }

.p-panel input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 18px;
  margin: 0;
  background: linear-gradient(var(--ui-accent), var(--ui-accent)) 0 50% / var(--pct, 0%) 100% no-repeat, #2b2b32;
  border: 1px solid #3c3c45;
  cursor: ew-resize;
}
.p-row.is-mod input[type='range'] { background: linear-gradient(var(--ui-mod), var(--ui-mod)) 0 50% / var(--pct, 0%) 100% no-repeat, #2b2b32; }
.p-panel input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 3px; height: 18px; background: #fff; }
.p-panel input[type='range']::-moz-range-thumb { width: 3px; height: 18px; background: #fff; border: 0; border-radius: 0; }
.p-panel input[type='range']:hover { filter: brightness(1.12); }
.p-num { width: 60px; text-align: right; -moz-appearance: textfield; }
.p-num::-webkit-inner-spin-button, .p-num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.p-panel input[type='color'] { width: 30px; height: 20px; padding: 0; border: 1px solid #3c3c45; background: none; cursor: pointer; }
.p-panel input[type='color']::-webkit-color-swatch-wrapper { padding: 0; }
.p-panel input[type='color']::-webkit-color-swatch { border: 0; border-radius: 0; }
.p-hex { flex: 1; }
.p-check { display: inline-flex; cursor: pointer; }
.p-check input { display: none; }
.p-check span { width: 16px; height: 16px; background: #26262c; border: 1px solid #50505a; }
.p-check input:checked + span { background: var(--ui-accent); border-color: var(--ui-accent); box-shadow: inset 0 0 0 3px #26262c; }
.p-row.is-mod .p-check input:checked + span { background: var(--ui-mod); border-color: var(--ui-mod); }
.p-sec-body > .p-actions, .p-sec-body > .p-keys { padding: 5px 10px 5px 16px; }
.p-sec-body .p-note { padding: 3px 10px 3px 16px; }
.p-keys div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--ui-muted); }
.p-keys kbd { font: inherit; color: var(--ui-fg); }

.p-tip {
  position: fixed;
  z-index: 50;
  width: 260px;
  background: var(--ui-bg-solid);
  border: 1px solid var(--ui-line);
  border-left: 2px solid var(--ui-accent);
  padding: 7px 9px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  line-height: 1.5;
}
.p-tip b { color: var(--ui-fg); }
.p-tip-meta { color: var(--ui-muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

@media (max-width: 720px) {
  #help { display: none; }
  .p-panel { width: calc(100vw - 16px); top: auto; bottom: 8px; max-height: 60vh; }
}

.biome-map canvas { cursor: crosshair; pointer-events: auto; }
.biome-hint { color: #d8d8de; font-size: 11px; padding: 3px 2px 0; }
.biome-info { color: #ffe9a8; font: 12px/1.4 ui-monospace, Menlo, monospace; padding: 2px 2px 0; }
.biome-tip { position: fixed; z-index: 40; pointer-events: none; background: rgba(10, 10, 12, 0.92); color: #ececf0; font-size: 12px; line-height: 1.5; padding: 4px 8px; border: 1px solid #34343a; border-radius: 3px; white-space: nowrap; }
.biome-tip b { color: #ffe9a8; }
.biome-tip span { color: #8d8d96; }
/* 整个页面不能框选文字（输入框除外） */
html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }

.p-debug { display: block; }
.p-mode {
  font: inherit;
  font-weight: 700;
  color: inherit;
  opacity: 0.55;
  background: transparent;
  border: none;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.p-mode.active { opacity: 1; background: rgba(255, 255, 255, 0.14); }
.p-body-pane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.p-body-pane[hidden], .p-debug[hidden] { display: none; }

/* 调试面板「时间与天气」 */
.sky-bar { display: flex; flex-direction: column; gap: 6px; padding: 2px 0 6px; font-size: 12px; }
.sky-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.sky-row input[type='range'] { flex: 1; min-width: 100px; }
.sky-row select, .sky-row button {
  font-size: 12px;
  background: #2c2f38;
  color: #eceef2;
  border: 1px solid #4a4e5a;
  border-radius: 4px;
}
.sky-row select { padding: 1px 2px; }
.sky-row button { min-width: 24px; padding: 1px 4px; }
.sky-clock { font-variant-numeric: tabular-nums; min-width: 38px; }
.sky-moon, .sky-status { opacity: 0.85; }
.sky-forecast { opacity: 0.8; line-height: 1.5; }
.sky-dial { display: block; width: 148px; height: 68px; image-rendering: pixelated; border-radius: 4px; }

/* 1.4.0：局内操作说明画在像素画布上（ui/screens/gameHud.js），DOM 版不显示 */
body.game-ui #help { display: none; }

/* 正式模式：没有开发用的顶栏、面板与操作说明，画面铺满 */
body.release #topbar, body.release #help, body.release #snapshot-banner { display: none !important; }
html, body { overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; }
