/* 指尖玩具箱 · 玩具页通用外壳 */
:root {
  --bg: #06070b;
  --fg: #eef0f6;
  --muted: rgba(238, 240, 246, .62);
  --faint: rgba(238, 240, 246, .38);
  --glass: rgba(16, 18, 26, .58);
  --glass-strong: rgba(16, 18, 26, .86);
  --line: rgba(255, 255, 255, .13);
  --accent: #ffb86b;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}

/* ---------- 顶栏 ---------- */
.ui-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 20;
  transition: opacity .35s ease;
}
.ui-top > * { pointer-events: auto; }
body.ui-dim .ui-top, body.ui-dim .hint { opacity: .28; }
body.ui-hidden .ui-top, body.ui-hidden .hint, body.ui-hidden .panel { opacity: 0; pointer-events: none; }
body.ui-hidden .ui-top > * { pointer-events: none; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title {
  font-size: 15px; font-weight: 650; letter-spacing: .02em; white-space: nowrap;
  height: 40px; padding: 4px 14px 0; border-radius: 20px;
  background: var(--glass); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  display: flex; flex-direction: column; justify-content: center; padding-top: 0; line-height: 1.15;
}
.title small { display: block; font-weight: 450; font-size: 10.5px; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; margin-top: 1px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  height: 40px;
  min-width: 40px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s, transform .12s, border-color .2s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:hover { background: var(--glass-strong); border-color: rgba(255, 255, 255, .22); }
.btn:active { transform: scale(.94); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.icon { padding: 0; width: 40px; }
.btn.on { background: rgba(255, 184, 107, .22); border-color: rgba(255, 184, 107, .55); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- 底部提示 ---------- */
.hint {
  position: fixed;
  left: 50%;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 10px));
  transform: translate(-50%, 0);
  max-width: min(92vw, 560px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fg);
  text-align: center;
  z-index: 15;
  pointer-events: none;
  transition: opacity .6s ease, transform .6s ease;
}
.hint.gone { opacity: 0; transform: translate(-50%, 10px); }

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(.96);
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  font-size: 14px;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- 设置面板 ---------- */
.panel {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  top: calc(max(12px, env(safe-area-inset-top)) + 52px);
  width: 290px;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 16px;
  border-radius: 18px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
  z-index: 30;
  transform-origin: top right;
  transition: opacity .22s ease, transform .22s ease;
  font-size: 13px;
}
.panel[hidden] { display: block; opacity: 0; transform: scale(.96) translateY(-6px); pointer-events: none; visibility: hidden; }
.panel h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .1em; display: flex; justify-content: space-between; align-items: center; }
.panel .close { display: none; }

.ctl { margin: 12px 0; }
.ctl label, .ctl .lab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; color: var(--fg); margin-bottom: 7px; }
.ctl output { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.ctl input[type=range] { width: 100%; -webkit-appearance: none; appearance: none; height: 22px; background: transparent; margin: 0; touch-action: pan-x; }
.ctl input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .16); }
.ctl input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .16); }
.ctl input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 6px rgba(0, 0, 0, .4); }
.ctl input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 0; }
.ctl input[type=text] { width: 100%; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); color: var(--fg); padding: 0 10px; font: inherit; font-size: 14px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 1 auto;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .05);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.seg button:hover { background: rgba(255, 255, 255, .1); }
.seg button.sel { background: rgba(255, 184, 107, .2); border-color: rgba(255, 184, 107, .6); }

.toggle { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.toggle input { display: none; }
.toggle .sw { width: 38px; height: 22px; border-radius: 11px; background: rgba(255, 255, 255, .18); position: relative; transition: background .2s; flex: none; }
.toggle .sw::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + .sw { background: #f0a35b; }
.toggle input:checked + .sw::after { transform: translateX(16px); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .btn { height: 36px; font-size: 13px; border-radius: 11px; padding: 0 8px; }
.actions .btn.wide { grid-column: 1 / -1; }

.mobile-only { display: none; }
.keys { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--faint); font-size: 11.5px; line-height: 1.7; }
.keys kbd { font-family: inherit; font-size: 11px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); color: var(--muted); }

.nogl {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; color: var(--muted); font-size: 15px; line-height: 1.7; z-index: 5;
}

@media (max-width: 640px) {
  .btn { height: 38px; min-width: 38px; }
  .btn.icon { width: 38px; }
  .btn .lbl { display: none; }
  .btn.textual { padding: 0 12px; }
  .title { font-size: 14px; height: 38px; padding: 0 12px; }
  .tools { gap: 6px; }
  .panel {
    left: 0; right: 0; top: auto; bottom: 0;
    width: auto;
    max-height: 58%;
    border-radius: 20px 20px 0 0;
    padding: 12px 18px calc(18px + env(safe-area-inset-bottom));
    transform-origin: bottom center;
  }
  .panel[hidden] { transform: translateY(30px); }
  .panel .close { display: inline-flex; }
  .panel h3::before { content: ""; position: absolute; left: 50%; top: 6px; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: rgba(255, 255, 255, .25); }
  .keys { display: none; }
  .tools .opt { display: none; }
  .actions.mobile-only { display: grid; grid-template-columns: repeat(3, 1fr); padding-top: 12px; border-top: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .hint, .btn { transition: none; }
}

/* ---------- 底部工具条（材料、颜色等） ---------- */
.dock {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px));
  z-index: 18;
  display: flex;
  gap: 4px;
  padding: 5px;
  max-width: calc(100% - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 22px;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transition: opacity .35s ease;
}
.dock::-webkit-scrollbar { display: none; }
.dock button {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px 0 9px;
  border: 0;
  border-radius: 17px;
  background: transparent;
  color: var(--muted);
  font: 500 13px/1 var(--font);
  cursor: pointer;
  white-space: nowrap;
}
.dock button i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1px rgba(255, 255, 255, .2) inset; }
.dock button.on { background: rgba(255, 255, 255, .15); color: var(--fg); }
body.has-dock .hint { bottom: calc(max(14px, calc(env(safe-area-inset-bottom) + 8px)) + 56px); }
body.ui-hidden .dock { opacity: 0; pointer-events: none; }
