/* 星络·空间 —— 星域绘制（无限网格画板） */

:root {
  --bg: #0b0d10;
  --surface: #111419;
  --surface-2: #151920;
  --surface-3: #1a1f27;
  --surface-4: #202631;
  --border: #232a33;
  --border-soft: #1b212a;
  --text: #e8eaee;
  --text-dim: #99a2b0;
  --text-faint: #6a7482;
  --accent: #7c9cff;
  --accent-dim: rgba(124, 156, 255, 0.14);
  --gold: #e8bd5c;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  /* 触屏上禁止页面橡皮筋回弹 */
  overscroll-behavior: none;
}

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.brand-mark {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 32%, #c9d7ff, var(--accent) 62%, #48548c);
  box-shadow: 0 0 12px rgba(124, 156, 255, 0.5);
}

/* ==================================================== 布局 */

.stars-body {
  height: 100vh;
  height: 100dvh;              /* 移动端地址栏收缩时不抖动 */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stars-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 54px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}

.stars-brand { display: flex; align-items: center; gap: 10px; }
.stars-brand .brand-name { font-size: 15px; font-weight: 600; letter-spacing: 0.5px; }

.stars-brand .brand-sub {
  padding-left: 10px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-faint);
}

.stars-tools { display: flex; align-items: center; gap: 8px; }

.stars-links { font-size: 13px; color: var(--text-dim); }
.stars-links a:hover { color: var(--accent); }

/* 颜色按钮 */

.color-btn,
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.color-btn:hover,
.tool-btn:hover { border-color: var(--accent); background: var(--surface-3); }

/* 工具栏复选框 */
.tool-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.tool-check:hover { border-color: var(--accent); background: var(--surface-3); }
.tool-check:has(input:checked) { color: var(--text); }

.tool-check input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 工具栏：笔头大小与类型 */

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color 0.15s ease;
}

.tool-group:hover { border-color: var(--accent); }

.tool-label {
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
}

.tool-divider {
  width: 1px;
  height: 15px;
  background: var(--border);
}

.tool-select {
  padding: 1px 2px;
  border: 0;
  color-scheme: dark;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tool-select:focus { outline: none; }

.tool-select option { background: var(--surface-2); color: var(--text); }

.brush-shape {
  padding: 3px 9px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.brush-shape:hover {
  background: var(--surface-3);
  color: var(--text);
}

.brush-shape.is-active {
  border-color: var(--accent);
  background: rgba(124, 156, 255, 0.16);
  color: var(--text);
}

.color-dot {
  width: 45px;
  height: 15px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: var(--accent);
}

.color-caret { font-size: 10px; color: var(--text-faint); }

.stars-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#board { display: block; cursor: crosshair; }
#board.is-grabbing { cursor: grabbing; }

/* 画布上的手势一律自己处理：禁掉浏览器滚动、双击缩放与长按系统菜单 */
#board,
#brush-layer {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* 笔头边框覆盖层，不接收鼠标事件 */
#brush-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.viewport-info,
.viewport-hint {
  position: absolute;
  bottom: 14px;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-4);
  color: #ffffff;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.viewport-info { left: 14px; }
.viewport-hint { right: 14px; }

/* 操作提示按指针类型切换：触屏不显示「左键 / Shift」这类文案 */
.hint-touch { display: none; }

/* ==================================================== 颜色浮动框 */

.palette {
  position: fixed;
  z-index: 300;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 10px 12px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.6);
}

.palette::-webkit-scrollbar { width: 8px; }
.palette::-webkit-scrollbar-thumb {
  border: 2px solid var(--surface);
  border-radius: 4px;
  background: var(--surface-4);
}

.palette.is-hidden { display: none; }

.palette-title {
  margin: 6px 2px;
  font-size: 11.5px;
  letter-spacing: 1px;
  color: var(--text-faint);
}

.palette-title:first-child { margin-top: 0; }

.palette-grid { display: grid; gap: 3px; }

.palette-swatch {
  width: 15px;
  height: 15px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.palette-swatch:hover {
  transform: scale(1.22);
  box-shadow: 0 0 0 2px rgba(124, 156, 255, 0.55);
  z-index: 2;
}

/* 触屏没有 hover，避免点选后色块停留在放大态 */
@media (hover: none) {
  .palette-swatch:hover { transform: none; box-shadow: none; }
}

.palette-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border-soft);
}

/* 自定义 RGB 调色盘 */

.palette-custom {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.palette-custom .palette-foot {
  margin-top: 9px;
  padding-top: 0;
  border-top: 0;
}

.custom-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
}

.custom-chip {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.28);
  background: var(--accent);
}

.custom-code {
  flex: 0 0 auto;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  color: var(--text);
}

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

.custom-label {
  width: 10px;
  font-size: 12px;
  color: var(--text-faint);
}

.custom-num {
  width: 28px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text-dim);
}

.custom-row input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 4px;
  margin: 0;
  border: 0;
  border-radius: 2px;
  background: var(--surface-4);
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.custom-row input[type="range"]::-webkit-slider-thumb {
  width: 13px;
  height: 13px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

.custom-row input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

.palette-hex {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}

.palette-hex:focus { border-color: var(--accent); }

.palette-apply {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.palette-apply:hover { background: rgba(124, 156, 255, 0.22); }

/* ==================================================== 右键菜单与弹窗 */

/* 格子右键菜单 */

.cell-menu {
  position: fixed;
  z-index: 350;
  min-width: 172px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.58);
}

.cell-menu.is-hidden { display: none; }

.cell-menu-head {
  padding: 5px 9px 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.cell-menu-item {
  display: block;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.cell-menu-item:hover { background: var(--surface-4); }

.cell-menu-item:disabled {
  color: var(--text-faint);
  cursor: default;
}

.cell-menu-item:disabled:hover { background: transparent; }

.cell-menu-item.is-danger:hover {
  background: rgba(255, 107, 107, 0.16);
  color: #ffb4b4;
}

.cell-menu-sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--border-soft);
}

/* 像素画对话框 */

.pixel-row {
  display: flex;
  gap: 10px;
}

.pixel-row .modal-field {
  flex: 1 1 0;
  min-width: 0;
}

.pixel-file {
  padding: 7px 9px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.pixel-file::file-selector-button {
  margin-right: 10px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.pixel-file::file-selector-button:hover { background: var(--surface-4); }

.pixel-note {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-faint);
}

.pixel-state {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.pixel-state.is-error { color: #ffb4b4; }

/* 密语（写入 / 读取 / 解密） */

.secret-input {
  min-height: 108px;
  resize: vertical;
  line-height: 1.7;
}

.secret-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.secret-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.secret-color {
  width: 62px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}

.secret-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}

.secret-check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.secret-note,
.secret-warn {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.65;
}

.secret-note { color: var(--text-faint); }

.secret-warn {
  padding: 8px 10px;
  border: 1px solid rgba(232, 189, 92, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(232, 189, 92, 0.1);
  color: var(--gold);
}

.secret-state {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.secret-state.is-error { color: #ffb4b4; }

.modal.modal-wide { max-width: 460px; }

.modal-field.is-hidden { display: none; }

/* 弹窗层级：密语 < 帮助 < 秘钥 < UI.form/confirm < 提示框 */
#secret-modal { z-index: 410; }
#help-modal { z-index: 412; }
#key-modal { z-index: 420; }
#modal-root { z-index: 430; }
#alert-box { z-index: 440; }

/* 顶栏「使用方法」按钮 */

.help-btn {
  padding: 8px 18px;
  border: 1px solid rgba(96, 156, 255, 0.75);
  border-radius: 999px;
  background: linear-gradient(135deg, #2f6bff 0%, #7c9cff 48%, #ff4d5e 100%);
  color: #ffffff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  animation: help-breath 2.8s ease-in-out infinite;
}

.help-btn:hover { filter: brightness(1.1); }

/* 红蓝交替呼吸 */
@keyframes help-breath {
  0%, 100% {
    border-color: rgba(96, 156, 255, 0.85);
    box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.32), 0 6px 20px rgba(47, 107, 255, 0.6);
  }
  50% {
    border-color: rgba(255, 96, 110, 0.85);
    box-shadow: 0 0 0 8px rgba(255, 77, 94, 0.2), 0 6px 26px rgba(255, 77, 94, 0.7);
  }
}

/* 使用方法对话框 */

#help-modal .modal { max-width: 920px; }

.help-body {
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
  column-count: 2;
  column-gap: 30px;
}

.help-section {
  margin-bottom: 16px;
  break-inside: avoid;
}
.help-section:last-child { margin-bottom: 0; }

.help-section h4 {
  margin: 0 0 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.help-section ul {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.85;
  color: var(--text-dim);
}

.help-section li { margin-bottom: 2px; }

.help-key {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 12px;
}

.help-gold { color: var(--gold); }

.secret-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52vh;
  overflow-y: auto;
}

.secret-item {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #000000;
}

.secret-item.is-clickable { cursor: pointer; }
.secret-item.is-clickable:hover { border-color: var(--gold); }

.secret-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.secret-tag {
  padding: 2px 7px;
  border: 1px solid rgba(232, 189, 92, 0.34);
  border-radius: 999px;
  color: var(--gold);
  font-size: 11px;
}

.secret-body {
  font-size: 13.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.secret-body.is-locked { color: var(--gold); cursor: pointer; }

.secret-empty {
  padding: 22px 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-faint);
}

/* 通用弹窗（UI.form 与像素画对话框共用） */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 6, 9, 0.66);
  backdrop-filter: blur(2px);
}

.modal-root.is-hidden { display: none; }

.modal {
  width: 100%;
  max-width: 400px;
  padding: 22px 22px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal-title { margin: 0 0 14px; font-size: 15px; font-weight: 600; }

.modal-text {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-dim);
  word-break: break-word;
}

.modal-field { margin-bottom: 12px; }

.modal-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.modal-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.modal-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.modal-error {
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(255, 107, 107, 0.14);
  color: #ffb4b4;
  font-size: 12.5px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.btn-ghost {
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-ghost:hover { color: var(--text); background: var(--surface-3); }

.btn-solid {
  padding: 8px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #0b0d10;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-solid:hover { filter: brightness(1.08); }

.btn-solid:disabled {
  opacity: 0.6;
  cursor: default;
  filter: none;
}

/* ==================================================== 提示 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 56px;
  z-index: 500;
  transform: translateX(-50%);
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  font-size: 13px;
}

.toast.is-error {
  color: #ffb4b4;
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.14);
}

.toast.is-hidden { display: none; }

/* ==================================================== 小屏与触屏适配 */

/* 手机竖屏：顶栏折成两行，工具栏独占一行横向滑动 */
@media (max-width: 720px) {
  .stars-topbar {
    height: auto;
    min-height: 54px;
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 8px 10px;
  }

  .stars-brand .brand-sub { display: none; }

  /* 品牌与「返回首页」留在第一行，不参与挤压 */
  .stars-tools {
    order: 3;
    flex: 1 1 100%;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .stars-tools::-webkit-scrollbar { display: none; }
  .stars-tools > * { flex: 0 0 auto; }

  /* 操作提示挪到画布上方，避免和底部坐标栏重叠 */
  .viewport-info,
  .viewport-hint {
    left: 10px;
    right: 10px;
    font-size: 11.5px;
    text-align: center;
  }

  .viewport-info { bottom: 10px; }
  .viewport-hint { top: 10px; bottom: auto; }

  /* 调色板改为贴底抽屉；色板过宽时允许横向滚动 */
  .palette {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 8px;
    width: auto;
    max-height: 58dvh;
    overflow: auto;
  }

  .modal-root { padding: 12px; }
  .modal {
    max-width: none;
    max-height: 88dvh;
    overflow-y: auto;
  }
  /* 窄屏下使用方法改为单栏，滚动交给弹窗本身 */
  .help-body {
    column-count: 1;
    max-height: none;
    overflow: visible;
  }

  .cell-menu { max-width: calc(100vw - 16px); }
}

/* 触屏设备：放大触控目标、切换提示文案 */
@media (pointer: coarse) {
  .tool-btn,
  .color-btn,
  .tool-check,
  .tool-group,
  .cell-menu-item,
  .palette-apply { min-height: 40px; }

  .brush-shape { min-height: 32px; padding: 6px 12px; }
  .modal-input { min-height: 40px; }
  .color-dot { height: 18px; }

  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
}
