:root {
  --bg: #03050a;
  --glass: rgba(9, 15, 27, 0.66);
  --glass-strong: rgba(8, 13, 24, 0.9);
  --edge: rgba(140, 200, 255, 0.16);
  --text: #e8f1ff;
  --muted: #93a7c2;
  --accent: #66e0ff;
  --accent-2: #ffd166;
  --good: #5dffa0;
  --warn: #ff7a6b;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); overflow: hidden; overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
body { position: fixed; inset: 0; }
canvas#gl, canvas#overlay { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
canvas#gl { z-index: 0; }
canvas#overlay { pointer-events: none; z-index: 1; }
video#cam { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: var(--accent); text-underline-offset: 3px; }

.glass {
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ---------- top bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: linear-gradient(180deg, rgba(3, 5, 10, 0.72), rgba(3, 5, 10, 0));
  pointer-events: none;
}
.topbar button { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-text { min-width: 0; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: 0.1em; line-height: 1.1; }
.brand-sub { color: var(--muted); font-size: 10.5px; letter-spacing: 0.08em; margin-top: 1px; }
.logo { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--accent); position: relative; flex: none; box-shadow: 0 0 16px rgba(102, 224, 255, 0.5); }
.logo span { position: absolute; inset: 9px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 12px var(--accent-2); }
.logo.big { width: 62px; height: 62px; margin: 0 auto 10px; }
.logo.big span { inset: 20px; }

.top-actions { display: flex; gap: 8px; align-items: center; }
.round {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--edge); backdrop-filter: blur(12px);
  font-size: 17px; transition: border-color 0.2s, background 0.2s, transform 0.1s;
}
.round.on { border-color: rgba(102, 224, 255, 0.7); box-shadow: 0 0 16px rgba(102, 224, 255, 0.35); }
.round:active { transform: scale(0.94); }

/* ---------- current model card */
.now-card {
  position: fixed; z-index: 15; top: calc(62px + var(--safe-t)); left: 12px; right: 12px;
  padding: 13px 15px 12px; pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 17, 30, 0.78), rgba(8, 13, 24, 0.5));
}
.now-card button { pointer-events: auto; }
.now-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cat {
  display: inline-block; font-size: 10.5px; letter-spacing: 0.14em;
  color: var(--accent); border: 1px solid rgba(102, 224, 255, 0.32);
  padding: 2px 9px; border-radius: 99px; background: rgba(102, 224, 255, 0.07);
}
.ghost { color: var(--muted); font-size: 12px; padding: 2px 4px; }
.ghost:hover { color: var(--text); }
.now-card h1 { margin: 7px 0 2px; font-size: 25px; line-height: 1.15; letter-spacing: 0.02em; font-weight: 800; }
.fact { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.now-status { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.k { color: var(--muted); font-size: 10.5px; letter-spacing: 0.1em; }
.pill {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 99px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.1);
  letter-spacing: 0.03em; white-space: nowrap;
}
.pill[data-state="sphere"] { color: var(--accent); border-color: rgba(102, 224, 255, 0.5); background: rgba(102, 224, 255, 0.09); }
.pill[data-state="formed"] { color: var(--good); border-color: rgba(93, 255, 160, 0.5); background: rgba(93, 255, 160, 0.08); }
.pill[data-state="dissolve"] { color: var(--warn); border-color: rgba(255, 122, 107, 0.5); background: rgba(255, 122, 107, 0.08); }
.pill.pose { color: #cfe0f7; }

/* ---------- catalog */
.catalog {
  position: fixed; z-index: 12; left: 0; right: 0;
  bottom: calc(84px + var(--safe-b));
  display: flex; flex-direction: column; gap: 6px; padding: 0 0 4px;
}
.tabs, .chips {
  display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; overflow-y: hidden;
  padding: 0 12px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tabs { scroll-snap-type: x proximity; }
.tab {
  flex: none; font-size: 11.5px; padding: 6px 11px; border-radius: 99px;
  background: rgba(8, 13, 24, 0.5); border: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--muted); backdrop-filter: blur(10px); scroll-snap-align: start;
}
.tab.active { color: #fff; border-color: rgba(102, 224, 255, 0.55); background: rgba(102, 224, 255, 0.14); }
.chip {
  flex: none; white-space: nowrap; font-size: 12px; padding: 6px 11px; border-radius: 99px;
  background: rgba(8, 13, 24, 0.55); border: 1px solid rgba(255, 255, 255, 0.09);
  display: inline-flex; align-items: center; gap: 6px; backdrop-filter: blur(10px);
  transition: border-color 0.15s, background 0.15s;
}
.chip[hidden] { display: none; }
.chip i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; box-shadow: 0 0 8px currentColor; flex: none; }
.chip.active { background: rgba(102, 224, 255, 0.16); border-color: var(--accent); color: #fff; }

/* ---------- action bar */
.actions {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
  padding: 6px 6px calc(6px + var(--safe-b));
  border-radius: 18px 18px 0 0; border-bottom: 0;
  background: var(--glass-strong);
}
.actions button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 54px; border-radius: 12px; transition: background 0.15s, transform 0.1s;
}
.actions button span { font-size: 21px; line-height: 1; }
.actions button small { font-size: 10.5px; color: var(--muted); letter-spacing: 0.08em; }
.actions button:active { background: rgba(102, 224, 255, 0.12); transform: scale(0.97); }

/* ---------- sheets */
.backdrop {
  position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(2px); animation: fadeIn 0.2s ease;
}
.backdrop[hidden] { display: none; }
.sheet {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
  max-height: 82dvh; overflow: hidden; display: flex; flex-direction: column;
  border-radius: 22px 22px 0 0; border-bottom: 0;
  background: var(--glass-strong);
  padding-bottom: var(--safe-b);
  animation: sheetIn 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet[hidden] { display: none; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px 11px; border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.sheet-head b { font-size: 15px; letter-spacing: 0.04em; }
.sheet-body { padding: 14px 18px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-body section + section { margin-top: 16px; }
.status .row { display: flex; justify-content: space-between; align-items: center; margin: 7px 0; }
.pill.pose { text-transform: none; }

.sensitivity { margin-top: 14px; }
.sensitivity-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sensitivity select {
  max-width: 150px; padding: 6px 9px; border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px; background: #101826; color: var(--text); font: inherit; font-size: 12px;
}
.sensitivity .hint { margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.meter { margin-top: 12px; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.meter-head b { font-size: 13px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: rgba(255, 255, 255, 0.08); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width 0.08s linear; }
.explode input[type="range"] { width: 100%; accent-color: var(--accent-2); }
.explode .hint { color: var(--muted); font-size: 11px; margin-top: 2px; }
.guide { list-style: none; padding: 0; margin: 6px 0 0; }
.guide li {
  display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: center;
  padding: 7px 8px; border-radius: 10px; font-size: 12.5px; color: var(--muted);
  transition: background 0.2s, color 0.2s;
}
.guide li .e { font-size: 18px; text-align: center; }
.guide li b { color: var(--text); font-weight: 650; }
.guide li.hot { background: rgba(102, 224, 255, 0.1); color: var(--text); box-shadow: inset 0 0 0 1px rgba(102, 224, 255, 0.25); }
.hint { color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.privacy { margin-top: 14px; }

/* ---------- tools */
#stats { font-size: 11px; color: var(--muted); padding: 8px 10px; line-height: 1.55; background: rgba(255, 255, 255, 0.035); border-radius: 10px; font-variant-numeric: tabular-nums; }
#stats b { color: var(--text); font-weight: 650; }
.tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 12px; }
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 62px; border-radius: 12px; background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09); transition: background 0.15s, border-color 0.15s;
}
.tool span { font-size: 19px; line-height: 1; }
.tool small { font-size: 10.5px; color: var(--muted); }
.tool.on { border-color: rgba(102, 224, 255, 0.55); background: rgba(102, 224, 255, 0.1); }
.tool:active { transform: scale(0.97); }

/* ---------- part card */
.part-card {
  position: fixed; z-index: 45; left: 10px; right: 10px; bottom: calc(78px + var(--safe-b));
  max-height: 52dvh; overflow-y: auto; padding: 14px 15px; font-size: 13px;
  border-radius: 18px; background: var(--glass-strong);
  animation: sheetIn 0.24s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.part-card[hidden], .quiz[hidden] { display: none; }
.part-card .phead { display: flex; align-items: center; gap: 8px; }
.part-card .swatch { width: 11px; height: 11px; border-radius: 50%; box-shadow: 0 0 10px currentColor; flex: none; }
.part-card .pname { font-weight: 800; font-size: 17px; flex: 1; }
.part-card .pinfo { margin: 8px 0 5px; line-height: 1.5; }
.part-card .pmodel, .part-card .phint { color: var(--muted); font-size: 11px; line-height: 1.4; }
.part-card .pactions { display: flex; gap: 7px; margin: 10px 0 7px; }
.part-card .pactions button {
  flex: 1; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px; padding: 8px; font-size: 12px;
}
.part-card.pulled { border-color: rgba(255, 159, 67, 0.7); box-shadow: 0 0 26px rgba(255, 159, 67, 0.25); }
.x { background: transparent; border: none; color: var(--muted); font-size: 15px; padding: 4px 6px; line-height: 1; }
.x:hover { color: var(--text); }

/* ---------- quiz */
.quiz {
  position: fixed; z-index: 32; left: 50%; top: calc(66px + var(--safe-t)); transform: translateX(-50%);
  width: min(420px, calc(100vw - 24px)); padding: 12px 42px 12px 16px;
  text-align: center; background: var(--glass-strong);
  animation: dropIn 0.25s ease;
}
.quiz .q { font-weight: 800; font-size: 18px; }
.quiz .qs { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.quiz .qf { margin-top: 6px; font-size: 12.5px; line-height: 1.4; }
.quiz-on .now-card { display: none; }
.quiz.good { border-color: rgba(93, 255, 160, 0.6); }
.quiz.bad { border-color: rgba(255, 122, 107, 0.6); }
.quiz .x { position: absolute; right: 8px; top: 8px; }
.rec { color: #ff5a5a; font-weight: 700; }

/* ---------- titles, toast */
.big-title { display: none; }
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(192px + var(--safe-b));
  transform: translate(-50%, 8px); max-width: calc(100vw - 32px);
  background: rgba(8, 14, 24, 0.92); border: 1px solid var(--edge);
  padding: 9px 16px; border-radius: 99px; font-size: 12.5px; line-height: 1.35;
  opacity: 0; transition: opacity 0.22s, transform 0.22s; pointer-events: none;
  text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- start overlay */
.start {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 14px;
  background: radial-gradient(ellipse at 50% 35%, rgba(24, 48, 82, 0.6), rgba(0, 0, 0, 0.9));
  overflow-y: auto;
}
.start[hidden] { display: none; }
.start-card {
  width: min(560px, 100%); max-height: calc(100dvh - 28px); overflow-y: auto;
  padding: 24px 20px calc(22px + var(--safe-b)); text-align: center;
  background: rgba(8, 13, 24, 0.86);
}
.start-card h1 { margin: 2px 0 4px; font-size: 31px; letter-spacing: 0.12em; font-weight: 800; }
.start-card p { color: var(--muted); margin: 0 0 10px; line-height: 1.6; font-size: 13px; }
.start-card .lead { color: var(--accent-2); font-size: 14px; letter-spacing: 0.04em; margin-bottom: 12px; }
.steps { text-align: left; color: var(--muted); line-height: 1.6; margin: 4px 0 16px; padding-left: 20px; font-size: 13px; }
.steps li { margin-bottom: 5px; }
.steps b { color: var(--text); }
.start-buttons { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }
.start-buttons button {
  padding: 12px 20px; font-size: 14.5px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.14);
}
.start-buttons .primary {
  background: linear-gradient(90deg, rgba(102, 224, 255, 0.4), rgba(255, 209, 102, 0.34));
  border-color: rgba(102, 224, 255, 0.7); font-weight: 700;
}
.start-msg { min-height: 1.4em; margin-top: 11px !important; color: var(--accent-2) !important; font-size: 12px !important; }
.start-card .privacy { font-size: 11px; margin: 8px 0 0; }

button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes sheetIn { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes dropIn { from { transform: translate(-50%, -8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- tablets and desktop */
@media (min-width: 720px) {
  .now-card { right: auto; width: 370px; left: 20px; }
  .catalog { align-items: center; }
  .tabs, .chips { justify-content: center; flex-wrap: wrap; overflow: visible; padding: 0 20px; }
  .actions { left: 50%; right: auto; transform: translateX(-50%); width: min(560px, calc(100vw - 40px)); border-radius: 18px; bottom: 14px; padding-bottom: 6px; }
  .catalog { bottom: 96px; }
  .toast { bottom: 108px; }
  .part-card { left: auto; right: 20px; bottom: 90px; width: 340px; }
}

@media (min-width: 1000px) {
  .topbar { padding: 18px 24px; }
  .brand-name { font-size: 20px; }
  .now-card { top: 88px; left: 28px; width: 390px; padding: 16px 18px; }
  .now-card h1 { font-size: 29px; }
  .fact { font-size: 12.5px; }
  .catalog { bottom: 24px; left: 50%; transform: translateX(-50%); width: min(1080px, calc(100vw - 40px)); }
  .actions { left: auto; right: 28px; transform: none; width: 380px; bottom: 88px; border-radius: 16px; }
  .toast { bottom: 170px; }
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%);
    width: min(560px, calc(100vw - 40px)); max-height: 82vh; border-radius: 20px;
    padding-bottom: 0; animation: modalIn 0.22s ease;
  }
  .sheet-head { padding: 16px 20px 12px; }
  .sheet-body { padding: 16px 20px 22px; }
  .part-card { bottom: 176px; right: 28px; animation: none; }
  .quiz { top: 80px; }
}
@keyframes modalIn { from { transform: translate(-50%, -47%); opacity: 0; } to { transform: translate(-50%, -50%); opacity: 1; } }

@media (max-height: 660px) {
  .start-card { padding-top: 16px; }
  .start-card h1 { font-size: 26px; }
  .start-card .steps { font-size: 12px; line-height: 1.5; }
  .start-card p { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
