:root {
  --bg: #0b0f16;
  --bg-2: #10161f;
  --panel: #141b25;
  --panel-2: #1a2331;
  --border: #24303f;
  --border-2: #2f3d4f;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4f8cff;
  --accent-hi: #6ea0ff;
  --danger: #ff5c5c;
  --ok: #3fb950;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

/* 组件类里的 display 会盖掉 UA 的 [hidden]，这里统一兜底 */
[hidden] { display: none !important; }

/* 键盘操作时要有清晰的焦点指示 */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
#view:focus-visible, #view:focus { outline: none; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, p, ol, dl, dd, dt { margin: 0; }

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(180deg, #151d28, #111823);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: #fff;
  font-size: 20px;
  flex: 0 0 auto;
}

.brand-text { min-width: 0; }
.brand-text h1 { font-size: 16px; font-weight: 650; letter-spacing: .2px; }
.brand-text p { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* ---------- buttons ---------- */

.btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #23303f; border-color: #3b4c60; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  border-color: #3b74e0;
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: linear-gradient(180deg, #7fb0ff, #5b93ff); border-color: #4d84f0; }
.btn-block { width: 100%; padding: 11px 14px; font-size: 14px; }
.btn.on { background: rgba(79,140,255,.18); border-color: var(--accent); color: var(--accent-hi); }

/* ---------- dropdown menu ---------- */

.menu-wrap { position: relative; display: inline-flex; }

.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 252px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  box-shadow: 0 14px 38px rgba(0, 0, 0, .55);
}
.menu button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background .12s;
}
.menu button:hover { background: rgba(79, 140, 255, .16); }
.menu .m-sub { font-size: 11px; color: var(--muted); }

/* ---------- layout ---------- */

.app-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 264px;
}

.panel {
  background: var(--panel);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }

.group { display: flex; flex-direction: column; gap: 9px; }

.group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.value {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-hi);
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.hint { font-size: 11.5px; color: var(--muted); line-height: 1.6; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1 1 0; min-width: 0; }
.row-3 > * { font-size: 12px; padding: 7px 6px; }

.row-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row-grid .btn { font-size: 12px; padding: 7px 6px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .015);
  font-size: 12.5px;
  cursor: pointer;
  line-height: 1.45;
}
.check:hover { border-color: var(--border-2); }
.check input { margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--accent); }

/* ---------- tools ---------- */

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.tool {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.tool .ico { font-size: 14px; line-height: 1; }
.tool:hover { background: #23303f; }
.tool.active {
  background: rgba(79,140,255,.16);
  border-color: var(--accent);
  color: var(--accent-hi);
  box-shadow: inset 0 0 0 1px rgba(79,140,255,.25);
}

/* ---------- segmented ---------- */

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button {
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.seg button:hover { background: #23303f; }
.seg button.active {
  background: rgba(79,140,255,.16);
  border-color: var(--accent);
  color: var(--accent-hi);
  font-weight: 600;
}

/* ---------- inputs ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #26313f;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0b0f16;
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: #26313f; }
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2px solid #0b0f16;
}

select {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- key/value ---------- */

.kv { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.kv > div { display: flex; justify-content: space-between; gap: 10px; }
.kv dt { color: var(--muted); flex: 0 0 auto; }
.kv dd {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.steps { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.85; }

/* ---------- stage ---------- */

.stage-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-2);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(79,140,255,.06), transparent 70%),
    var(--bg-2);
}
.stage.dragover { box-shadow: inset 0 0 0 2px var(--accent); }

/* 单张页是 #view，批量页是 #bView —— 两个都要 touch-action: none，
   否则手机上拖拽会变成滚动页面 / 双指缩放页面，而不是画选区 */
.stage > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cursor-ring {
  position: absolute;
  border: 1.5px solid rgba(255,255,255,.85);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,.55), inset 0 0 0 1px rgba(0,0,0,.4);
  will-change: transform, width, height;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
  color: var(--muted);
}
.ph-icon {
  font-size: 40px;
  opacity: .35;
  margin-bottom: 4px;
}
.ph-title { font-size: 15px; color: #b9c5d4; }
.ph-sub { font-size: 12.5px; max-width: 380px; }

.ph-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  pointer-events: auto;
}

.ph-steps {
  display: flex;
  gap: 22px;
  margin: 26px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: ph;
}
.ph-steps li {
  position: relative;
  padding-top: 28px;
  font-size: 12px;
  color: var(--muted);
  counter-increment: ph;
  white-space: nowrap;
}
.ph-steps li::before {
  content: counter(ph);
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(79, 140, 255, .18);
  color: var(--accent-hi);
  font-size: 11px;
  font-weight: 600;
}

/* 未载入图片时把两个侧栏压暗，让视线落在中间的入口上 */
body.is-empty .panel { opacity: .5; }
.panel { transition: opacity .2s; }

/* ---------- 折叠面板 ---------- */

.adv {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .015);
}
.adv > summary {
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::after { content: '▾'; float: right; }
.adv[open] > summary::after { content: '▴'; }
.adv > summary:hover { color: var(--text); }
.adv-body {
  padding: 4px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.busy {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(8, 12, 18, .68);
  backdrop-filter: blur(2px);
  font-size: 13px;
  z-index: 5;
}
.busy .btn { margin-left: 6px; }

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.22);
  border-top-color: var(--accent-hi);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.statusbar .spacer { flex: 1 1 auto; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(24, 33, 45, .96);
  border: 1px solid var(--border-2);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  z-index: 50;
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ---------- 触摸设备 ---------- */

/* 涂抹时别让页面跟着回弹/下拉刷新 */
.stage-wrap { overscroll-behavior: contain; }

@media (hover: none) and (pointer: coarse) {
  /* 按钮上的双击不再触发页面缩放，避免连点两次就放大整页 */
  .btn, .tool, .seg button, .adv > summary, .check, .menu button { touch-action: manipulation; }
  .menu button { padding: 11px 10px; font-size: 13.5px; }
  .hint { font-size: 12px; }
}

/* ---------- responsive ---------- */

/* 平板：两侧栏折成横向自适应的一排 */
@media (max-width: 1080px) {
  .app-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(240px, 1fr) auto; }
  .panel { flex-direction: row; flex-wrap: wrap; gap: 16px; }
  .panel-left { border-right: none; border-bottom: 1px solid var(--border); }
  .panel-right { border-left: none; border-top: 1px solid var(--border); }
  .group { flex: 1 1 200px; }
}

/* 手机：预览区优先、整页可滚、控件放大到适合手指 */
@media (max-width: 760px) {
  html, body { height: auto; }
  body {
    overflow: auto;
    -webkit-text-size-adjust: 100%;
  }

  .app-header { flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 15px; }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .header-actions .btn, .menu-wrap, .menu-wrap > .btn { width: 100%; }
  .menu { left: 0; right: auto; width: 100%; min-width: 0; }

  .app-body { display: flex; flex-direction: column; min-height: 0; }
  .stage-wrap { order: -1; flex: 0 0 auto; height: 54vh; border-bottom: 1px solid var(--border); }
  .panel { flex-direction: column; max-height: none; overflow: visible; padding: 14px 12px; }
  .group { flex: none; }
  .panel-left { border-right: none; border-bottom: 1px solid var(--border); }
  .panel-right { border-left: none; }

  /* 手指比鼠标粗得多，所有可点元素都要放大 */
  .btn { padding: 11px 12px; font-size: 13.5px; }
  .tool { padding: 13px 6px; font-size: 13px; }
  .seg button { padding: 12px 6px; font-size: 13px; }
  .row-grid .btn, .row-3 > * { padding: 11px 6px; font-size: 12.5px; }
  .adv > summary { padding: 12px 10px; }

  input[type="range"] { height: 34px; }
  input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; }
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -8px; }
  input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }

  .statusbar { padding: 8px 12px; }
  .ph-steps { gap: 14px; margin-top: 20px; }
  .ph-steps li { font-size: 11.5px; }
}
