:root {
  --dark: #3a3a3a;
  --bar: #333;
  --bg: #e9e9e9;
  --row: #f2f2f2;
  --line: #d6d6d6;
  --green: #1a9f1a;
  --track: #7c7c7c;
  --text: #222;
  --muted: #666;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); padding-bottom: env(safe-area-inset-bottom);
  background: #fff; color: var(--text);
  font: 14px/1.4 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, select, input { font: inherit; color: inherit; }

.top { max-width: 1320px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; }
.logo { font-weight: 800; font-size: 22px; letter-spacing: 1px; }
.logo span { margin-left: 6px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 2px; }
.top-r { display: flex; gap: 8px; align-items: center; }

.layout { max-width: 1320px; margin: 0 auto; padding: 0 16px 24px; display: grid; grid-template-columns: minmax(380px, 560px) 1fr; gap: 14px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.panel { background: var(--bg); border-radius: 6px; overflow: hidden; }
.phead { background: var(--dark); color: #fff; display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-weight: 700; font-size: 16px; }
.phead .ttl { flex: 1; }
.phead .ico { opacity: .9; }
.sec { background: var(--bar); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: 1px; padding: 2px 8px; }
.row { background: var(--row); padding: 8px 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid #fff; }
.row .lab { min-width: 70px; }
.row.col2 { display: grid; grid-template-columns: 90px 1fr 1fr; gap: 6px 12px; }
.opt { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.opt input { accent-color: #222; width: 16px; height: 16px; margin: 0; }

.btn, select.btn {
  background: #fff; border: 1px solid #bbb; border-radius: 4px; padding: 4px 10px; cursor: pointer; min-height: 30px;
  transition: background .12s;
}
.btn:hover { background: #f7f7f7; }
.btn.dark { color: #222; background: #fff; border-color: #fff; padding: 2px 10px; min-height: 26px; font-size: 13px; }
.btn.help, .help { border: 0; background: transparent; color: #fff; font-weight: 800; font-size: 14px; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; padding: 0; background: #fff; color: #333; }
select.btn { padding-right: 4px; max-width: 100%; }
select.btn.wide { min-width: 220px; }

.icon-lbl { width: 36px; height: 36px; flex: 0 0 36px; display: flex; align-items: center; justify-content: center; }
.icon-lbl svg { width: 34px; height: 34px; fill: #111; }
.numin { width: 62px; padding: 3px 6px; border: 1px solid #bbb; border-radius: 4px; background: #fff; text-align: center; }
.unit { color: #333; }

.sl { --th: 20px; flex: 1; min-width: 220px; position: relative; padding-bottom: 22px; }
.sl input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 12px; margin: 6px 0; border-radius: 6px; outline: none; cursor: pointer;
  background: linear-gradient(to right, var(--green) var(--p, 0%), var(--track) var(--p, 0%));
}
.sl input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: var(--th); height: var(--th); border-radius: 50%; background: var(--green); border: 2px solid #0e6a0e; }
.sl input[type=range]::-moz-range-thumb { width: calc(var(--th) - 4px); height: calc(var(--th) - 4px); border-radius: 50%; background: var(--green); border: 2px solid #0e6a0e; }
.sl input[type=range]:disabled { opacity: .45; cursor: not-allowed; }
.sl .ticks { position: absolute; left: 0; right: 0; top: 26px; height: 16px; font-size: 12px; color: #222; pointer-events: none; }
.sl .ticks i { position: absolute; font-style: normal; transform: translateX(-50%); white-space: nowrap; }

.fov-ctl { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.fov-ctl .btn { padding: 4px 8px; }

.simhead { padding: 6px 10px; background: var(--row); border-bottom: 1px solid #fff; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.simhead b { font-variant-numeric: tabular-nums; }
.stagewrap { padding: 10px; background: var(--row); }
.stage {
  --ar: 1.5; position: relative; overflow: hidden; margin: 0 auto; background: #556;
  aspect-ratio: var(--ar); width: min(100%, calc(70vh * var(--ar))); width: min(100%, calc(70dvh * var(--ar)));
  border: 3px solid #111;
}
.stage canvas { position: absolute; pointer-events: none; }
#glCanvas { display: none; left: 0; top: 0; width: 100%; height: 100%; }
body.gl3d #glCanvas { display: block; }
body.gl3d #bgCanvas, body.gl3d #bokehCanvas, body.gl3d .person, body.gl3d .plant { display: none !important; }
#bgCanvas { will-change: filter; }
.person { position: absolute; left: 50%; transform: translateX(-50%); aspect-ratio: 0.4; }
.plant { position: absolute; left: 7%; transform: translateX(-50%); aspect-ratio: 0.75; bottom: -2%; pointer-events: none; will-change: filter; }
.plant svg { width: 100%; height: 100%; display: block; overflow: visible; }
.blurs { display: flex; flex-direction: column; gap: 0; line-height: 1.35; }
.person svg { width: 100%; height: 100%; display: block; overflow: visible; }
.watermark { position: absolute; right: 8px; bottom: 6px; color: rgba(255,255,255,.7); font-size: 11px; text-shadow: 0 0 2px #000; pointer-events: none; }

.data { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.data div { padding: 6px 10px; background: var(--row); border-bottom: 1px solid #fff; border-right: 1px solid #fff; }
.data span { display: block; font-size: 12px; color: var(--muted); }
.data b { font-size: 16px; font-variant-numeric: tabular-nums; }

table.saved { width: 100%; border-collapse: collapse; background: var(--row); font-size: 13px; }
table.saved th { background: #dcdcdc; font-weight: 700; padding: 4px 6px; text-align: center; }
table.saved td { padding: 5px 6px; text-align: center; border-top: 1px solid #fff; cursor: pointer; }
table.saved tr:hover td { background: #fff; }
table.saved td.rm { cursor: pointer; font-weight: 800; }
table.saved td:first-child { text-align: left; }
.saved-foot { background: var(--row); padding: 8px 10px; }

.notes { max-width: 1320px; margin: 0 auto; padding: 8px 16px 40px; color: var(--muted); font-size: 12.5px; }
.notes h3 { color: var(--text); font-size: 14px; margin: 14px 0 4px; }
.notes code { background: #eee; padding: 1px 4px; border-radius: 3px; }

dialog { border: 0; border-radius: 8px; padding: 0; max-width: min(560px, 92vw); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dh { background: var(--dark); color: #fff; padding: 8px 14px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
dialog .db { padding: 14px; line-height: 1.6; }
dialog .db p { margin: 0 0 8px; }
dialog .dh button { background: none; border: 0; color: #fff; font-size: 20px; cursor: pointer; }

.adv-only { display: none; }
body.adv .adv-only { display: block; }
body.adv .data.adv-only { display: grid; }
.hidden { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 0 8px 20px; gap: 8px; }
  .top { padding: 6px 10px; }
  .col.simcol { order: -1; position: sticky; top: 0; z-index: 10; background: #fff; padding: 0 0 6px; }
  .stage { width: min(100%, calc(30vh * var(--ar))); width: min(100%, calc(30dvh * var(--ar))); border-width: 2px; }
  .simcol .stagewrap { padding: 4px; }
  .simcol .phead { display: none; }
  .simhead { padding: 4px 8px; gap: 2px 10px; font-size: 13px; flex-wrap: nowrap; justify-content: space-between; }
  .simhead select.btn { min-height: 32px; padding: 2px 4px; max-width: 110px; }
  .simcol .panel { border-radius: 0 0 6px 6px; }
  .sl { --th: 28px; min-width: 150px; flex-basis: 100%; padding-bottom: 24px; }
  .sl input[type=range] { height: 14px; margin: 9px 0; }
  .sl .ticks { top: 34px; font-size: 11px; }
  .row { padding: 8px; gap: 8px 10px; }
  .row.col2 { grid-template-columns: 74px 1fr 1fr; }
  select.btn.wide { min-width: 0; width: 100%; }
  .btn, select.btn { min-height: 40px; }
  .btn.dark { min-height: 32px; }
  .help { width: 30px; height: 30px; }
  .opt input { width: 20px; height: 20px; }
  .opt { min-height: 36px; }
  .numin { width: 74px; min-height: 38px; }
  .fov-ctl .btn { padding: 4px 10px; }
  table.saved td, table.saved th { padding: 8px 4px; font-size: 12px; }
  table.saved td.rm { font-size: 18px; width: 44px; }
  /* 16px 以上，防止 iOS Safari 聚焦输入框时自动放大页面 */
  input, select, .numin, select.btn { font-size: 16px; }
}
@media (max-width: 380px) { .top .logo span { display: none; } }
@media (hover: none) { .btn:hover { background: #fff; } }

.gl-loading { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; color: #fff; font-size: 14px; background: #556; z-index: 3; }
body.gl3d:not(.gl-ready) .gl-loading { display: flex; }
