/* 蜡烛厂模拟器 — 移动优先。
 *
 * 和站里另外三个 viewer 不同,这一份没有 `min-width: 1040px`。那三个是把桌面版
 * 缩到手机上,这一个是从手机往上长:竖屏时画面在上、控制面板是可以拉起的底部抽屉,
 * 到 900px 宽才变成左右分栏。理由很简单 —— 这个页面的访问者多数在手机上。
 */

:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --ink: #eef4f8;
  --muted: #8da0ad;
  --dim: #6f8491;
  --panel: rgba(11, 17, 22, 0.96);
  --line: rgba(177, 207, 224, 0.15);
  --accent: #48b7eb;
  --accent-ink: #06202c;
  --good: #6fd7a4;
  --sheet: 44vh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #090f14;
  color: var(--ink);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 40% 38%, rgba(67, 98, 116, 0.2), transparent 46%),
    #090f14;
}

/* ---- 顶栏 ------------------------------------------------------------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 15, 20, 0.92);
  z-index: 3;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--dim);
  font-size: 9px;
  font-weight: 760;
  letter-spacing: 0.15em;
}

h1 { margin: 0; font-size: 16px; font-weight: 620; letter-spacing: 0.01em; }

.status-pill {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid rgba(105, 206, 153, 0.24);
  border-radius: 999px;
  color: #9ad8b8;
  background: rgba(39, 107, 73, 0.12);
  font-size: 10px;
  font-weight: 640;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-pill span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--good); box-shadow: 0 0 8px var(--good);
}

/* ---- 画面 ------------------------------------------------------------- */

.viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: none;
}

#scene { display: block; width: 100%; height: 100%; }

.hud {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.hud-card {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(9, 15, 20, 0.78);
  backdrop-filter: blur(6px);
}
.hud-card b {
  display: block;
  font-size: 19px;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.hud-card i {
  display: block;
  margin-top: 1px;
  color: var(--dim);
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.hud-card.target b { color: var(--accent); }
.hud-card.hit b { color: var(--good); }

.hint {
  position: absolute;
  left: 12px; bottom: 10px;
  color: var(--dim);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  justify-items: center;
  background: #090f14;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transition: opacity 0.4s ease;
  z-index: 2;
}
.loading[hidden] { display: none; }
.loading span {
  width: 26px; height: 26px;
  border: 2px solid rgba(72, 183, 235, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 控制面板:竖屏是底部抽屉 ----------------------------------------- */

.panel {
  flex: 0 0 auto;
  max-height: var(--sheet);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  gap: 16px;
  z-index: 4;
}

/* 抽屉收起时只留下第一屏,由 viewer-host.js 切换 data-open */
@media (max-width: 899px) {
  .panel { max-height: 40vh; }
  .panel[data-open="false"] { max-height: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; border-top-color: transparent; }
  .panel-toggle { display: block; }
}

.panel-toggle {
  display: none;
  position: absolute;
  right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9, 15, 20, 0.9);
  font-size: 12px;
  font-weight: 620;
  z-index: 5;
}

.section-label {
  margin: 0 0 8px;
  color: var(--dim);
  font-size: 9px;
  font-weight: 760;
  letter-spacing: 0.15em;
}

.field { display: grid; gap: 7px; }
.field + .field { margin-top: 12px; }

.field label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.field output {
  color: var(--ink);
  font-size: 15px;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: rgba(177, 207, 224, 0.2);
}
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 2px; background: rgba(177, 207, 224, 0.2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -9px;
  border: 0; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border: 0; border-radius: 50%;
  background: var(--accent);
}

.segmented { display: flex; gap: 6px; }
.segmented button {
  flex: 1 1 0;
  padding: 9px 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 13px;
  font-weight: 600;
}
.segmented button[aria-pressed="true"] {
  border-color: rgba(72, 183, 235, 0.5);
  background: rgba(72, 183, 235, 0.14);
  color: #cbeaff;
}

.fact {
  margin: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ---- 结果卡 ----------------------------------------------------------- */

.results { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.result {
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}
.result b {
  display: block;
  font-size: 21px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.result b small { font-size: 12px; font-weight: 560; color: var(--muted); }
.result i {
  display: block;
  margin-top: 3px;
  color: var(--dim);
  font-size: 10px;
  font-style: normal;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.result.wide { grid-column: 1 / -1; }
.result.tank { border-color: rgba(72, 183, 235, 0.34); background: rgba(72, 183, 235, 0.08); }

.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
}
.note strong { color: var(--ink); font-weight: 640; }

/* 结果卡下面的免责说明。左边一道竖线,让它读作「这里有个前提」而不是又一行结果 ——
   人看完那几个数字最容易做的事,就是把它当成自己的方案。 */
.caveat {
  margin: 10px 0 0;
  padding-left: 9px;
  border-left: 2px solid rgba(72, 183, 235, 0.34);
  color: var(--dim);
  font-size: 11.5px;
  line-height: 1.55;
}

/* ---- 按钮 ------------------------------------------------------------- */

.wide-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 13.5px;
  font-weight: 640;
}
.wide-button.primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}
.wide-button.quote {
  border-color: rgba(111, 215, 164, 0.4);
  background: rgba(111, 215, 164, 0.12);
  color: #b6f0d3;
}
.wide-button + .wide-button { margin-top: 8px; }
.wide-button .icon { font-size: 12px; }

/* ---- 页脚 ------------------------------------------------------------- */

footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 14px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 9.5px;
  letter-spacing: 0.05em;
  background: rgba(9, 15, 20, 0.9);
}
#passLabel { font-weight: 700; letter-spacing: 0.12em; white-space: nowrap; }

/* ---- 无 WebGL 回退 ---------------------------------------------------- */

.viewer-fallback {
  display: grid;
  gap: 14px;
  place-content: center;
  height: 100%;
  padding: 24px;
  text-align: center;
}
.viewer-fallback img { width: min(100%, 460px); border-radius: 12px; }
.viewer-fallback h2 { margin: 0; font-size: 17px; }
.viewer-fallback p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
body.no-webgl { overflow: auto; }

/* ---- 宽屏:左右分栏 --------------------------------------------------- */

@media (min-width: 900px) {
  :root { font-size: 15px; }
  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 356px;
    grid-template-rows: 62px minmax(0, 1fr) 32px;
  }
  .topbar { grid-column: 1 / -1; padding: 0 20px; }
  .viewport { grid-column: 1; grid-row: 2; }
  .panel {
    grid-column: 2; grid-row: 2;
    max-height: none;
    border-top: 0;
    border-left: 1px solid var(--line);
    padding: 18px;
  }
  footer { grid-column: 1 / -1; grid-row: 3; }
  .panel-toggle { display: none !important; }
  h1 { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .loading span { animation: none; }
}
