:root {
  --ink: #111827; --sub: #6B7280; --line: #E5E7EB; --bg: #F5F6F8; --card: #fff;
  --accent: #2563EB; --accent-soft: #EAF1FF;
  --glass: rgba(17, 24, 39, .72);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
a { color: inherit; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.link { color: var(--accent); font-weight: 600; }
.sm { font-size: 13px; }
.btn-ghost { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: #fff; }

/* ---------- 홈 ---------- */
#home { max-width: 520px; margin: 0 auto; padding: 0 16px calc(24px + var(--safe-b)); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; background: var(--bg); }
.unit-pill { display: inline-flex; background: #E9EBEF; border-radius: 999px; padding: 3px; }
.unit-pill button { min-width: 42px; padding: 6px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--sub); }
.unit-pill button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.notice { margin: 4px 0 8px; padding: 12px 14px; border-radius: 12px; background: #FFF7E6; color: #8A5300; font-size: 14px; }
.notice.ok { background: var(--accent-soft); color: var(--accent); }
.notice-btn { display: block; width: 100%; margin-top: 10px; padding: 11px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 700; text-align: center; text-decoration: none; }
.notice .diag { display: block; margin-top: 8px; font-size: 11px; opacity: .7; }

.sec { display: flex; justify-content: space-between; align-items: baseline; margin: 24px 2px 10px; font-size: 15px; color: var(--sub); font-weight: 700; }

.modes { display: grid; gap: 10px; }
.mode { display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; transition: transform .1s, border-color .15s; }
.mode:active { transform: scale(.985); border-color: var(--accent); }
.mode .ico { flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px;
  background: var(--accent-soft); color: var(--accent); }
.mode .ico svg { width: 28px; height: 28px; }
.mode .txt { display: flex; flex-direction: column; }
.mode b { font-size: 17px; }
.mode small { color: var(--sub); font-size: 13px; }
.mode.off { opacity: .55; }

.records { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.records:empty { display: none; }
.records li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.records li:first-child { border-top: 0; }
.records .rv { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.records .rm { color: var(--sub); font-size: 12px; }
.records .rx { margin-left: auto; color: #9CA3AF; padding: 6px; }
.records .rx svg { width: 18px; height: 18px; }
.records .tag { flex: none; font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 2px 7px; }
.empty { margin: 0; padding: 18px; text-align: center; color: var(--sub); font-size: 14px; background: var(--card); border: 1px dashed var(--line); border-radius: 16px; }

.tips { margin: 0; padding: 14px 14px 14px 34px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; font-size: 14px; color: #374151; }
.tips li + li { margin-top: 4px; }
.foot { margin-top: 28px; font-size: 12px; color: var(--sub); text-align: center; }
.foot p { margin: 6px 0; }

/* ---------- 광고 자리: 광고 코드를 넣기 전에는 보이지 않음. 주소 끝에 ?adpreview 를 붙이면 자리 표시 ---------- */
.ad { margin: 20px 0 0; text-align: center; }
.ad:empty { display: none; }
.ad iframe { display: block; width: 100%; border: 0; }
.ad-note { margin: 0 0 6px; font-size: 11px; line-height: 1.4; color: #9CA3AF; text-align: left; }
body.adpreview .ad:empty { display: grid; place-items: center; height: 100px; border: 1px dashed #C7CBD3; border-radius: 12px; color: #9CA3AF; font-size: 13px; }
body.adpreview .ad:empty::before { content: "광고 영역 (" attr(data-slot) ")"; }

/* ---------- PC 안내 ---------- */
#pc { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 32px 16px; }
.pc-card { width: 100%; max-width: 440px; padding: 36px 32px; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 24px; }
.pc-card .brand { justify-content: center; }
.pc-card h1 { margin: 18px 0 8px; font-size: 24px; letter-spacing: -.02em; }
.pc-card p { margin: 0; color: var(--sub); font-size: 15px; }
.qr { width: 200px; height: 200px; margin: 24px auto 12px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; }
.qr img, .qr svg { width: 100%; height: 100%; display: block; }
.pc-url { display: flex; gap: 8px; justify-content: center; align-items: center; font-size: 13px; color: var(--sub); word-break: break-all; }
.pc-req { margin: 20px 0 16px; padding: 12px 16px; list-style: none; background: var(--bg); border-radius: 12px; font-size: 13px; color: #374151; text-align: left; }
.pc-req li::before { content: "✓  "; color: var(--accent); font-weight: 700; }
#pc .ad { width: 100%; max-width: 728px; }

/* ---------- AR 화면 ---------- */
#ar { position: fixed; inset: 0; color: #fff; user-select: none; -webkit-user-select: none; }
#ar svg { stroke-width: 2.2; }
.round { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--glass); backdrop-filter: blur(8px); }
.round:disabled { opacity: .35; }
.ar-top { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; align-items: center; gap: 12px; }
.ar-top b { font-size: 19px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.chip { margin-left: auto; padding: 5px 12px; border-radius: 999px; background: var(--glass); font-size: 14px; font-weight: 600; }

.status { position: absolute; top: 78px; left: 14px; right: 14px; padding: 12px 14px 10px; border-radius: 18px; background: var(--glass); backdrop-filter: blur(8px); }
.st-msg { font-size: 15px; font-weight: 600; }
.steps { display: flex; margin: 10px 0 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { flex: 1; position: relative; padding-top: 18px; font-size: 12px; text-align: center; color: rgba(255,255,255,.5); }
.steps li::before { content: ""; position: absolute; top: 2px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); }
.steps li::after { content: ""; position: absolute; top: 7px; left: calc(50% + 9px); right: calc(-50% + 9px); height: 2px; background: rgba(255,255,255,.25); }
.steps li:last-child::after { display: none; }
.steps li.on { color: #fff; }
.steps li.on::before { background: var(--accent); border-color: #fff; }
.steps li.on::after { background: var(--accent); }

.result { position: absolute; top: 178px; left: 14px; right: 14px; padding: 12px 14px; border-radius: 18px; background: var(--glass); backdrop-filter: blur(8px); text-align: center; }
.r-main { display: flex; justify-content: center; align-items: baseline; gap: 6px; }
#rVal { font-size: 46px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
#rUnit { font-size: 18px; opacity: .8; }
.r-sub { font-size: 13px; opacity: .85; font-variant-numeric: tabular-nums; }
.r-sub:empty { display: none; }
.r-sub .tot { color: #9DBBFF; font-weight: 700; }

.cross { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none; }
.cross::before, .cross::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 3px rgba(0,0,0,.6); }
.cross::before { left: 10px; top: 0; width: 2px; height: 22px; }
.cross::after { top: 10px; left: 0; height: 2px; width: 22px; }

.lbl { position: absolute; transform: translate(-50%, -150%); padding: 4px 9px; border-radius: 8px; background: rgba(17,24,39,.85);
  font-size: 14px; font-weight: 700; white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; }
.lbl.live { background: var(--accent); }

.ar-bottom { position: absolute; left: 14px; right: 14px; bottom: calc(18px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 16px; }
.unit-pill.dark { background: var(--glass); backdrop-filter: blur(8px); }
.unit-pill.dark button { color: rgba(255,255,255,.7); }
.unit-pill.dark button.on { background: #fff; color: var(--ink); }
.controls { display: flex; align-items: center; justify-content: center; gap: 36px; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 4px solid #fff; padding: 5px; box-shadow: 0 0 0 1px rgba(0,0,0,.18), 0 2px 10px rgba(0,0,0,.25); }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--accent); transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.shutter:disabled { opacity: .4; }
.toast { position: absolute; left: 50%; bottom: 220px; transform: translateX(-50%); padding: 10px 16px; border-radius: 999px; background: #fff; color: var(--ink); font-weight: 700; font-size: 14px; }

/* ---------- 센서·화면 도구 카드 ---------- */
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tool-card { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 16px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; transition: transform .1s, border-color .15s; }
.tool-card:active { transform: scale(.98); border-color: var(--accent); }
.tool-card .ico { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 8px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.tool-card b { font-size: 16px; }
.tool-card small { color: var(--sub); font-size: 12.5px; line-height: 1.4; }

.round.light { background: #fff; border: 1px solid var(--line); width: 44px; height: 44px; }

/* ---------- 수평계 ---------- */
.tool-view { min-height: 100dvh; max-width: 520px; margin: 0 auto; padding: 0 16px calc(24px + var(--safe-b)); display: flex; flex-direction: column; }
.tool-top { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.tool-top b { font-size: 19px; flex: 1; }
.lv-read { margin-top: 24px; text-align: center; font-size: 72px; font-weight: 800; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; transition: color .2s; }
.lv-read .deg { font-size: 40px; vertical-align: top; margin-left: 2px; color: var(--sub); }
.lv-sub { margin-top: 8px; text-align: center; color: var(--sub); font-size: 14px; font-variant-numeric: tabular-nums; }
.lv-stage { flex: 1; display: grid; place-items: center; padding: 24px 0; }
.lv-disc { position: relative; width: min(78vw, 300px); aspect-ratio: 1; border-radius: 50%; background: #fff; border: 1px solid var(--line); }
.lv-disc .ring { position: absolute; inset: 0; margin: auto; border-radius: 50%; border: 1.5px solid #D1D5DB; }
.lv-disc .r1 { width: 26%; height: 26%; border-color: var(--accent); }
.lv-disc .r2 { width: 62%; height: 62%; }
.lv-disc .hair { position: absolute; background: #E5E7EB; }
.lv-disc .h { left: 6%; right: 6%; top: 50%; height: 1px; }
.lv-disc .v { top: 6%; bottom: 6%; left: 50%; width: 1px; }
.bubble { position: absolute; left: 50%; top: 50%; width: 22%; aspect-ratio: 1; border-radius: 50%; background: rgba(37,99,235,.18); border: 2px solid var(--accent);
  transform: translate(-50%, -50%); will-change: transform; }
.lv-vial { position: relative; width: min(84vw, 340px); height: 64px; border-radius: 32px; background: #fff; border: 1px solid var(--line); }
.lv-vial.vertical { width: 64px; height: min(60vh, 340px); }
.lv-vial .mark { position: absolute; inset: 0; margin: auto; width: 64px; height: 100%; border-left: 1.5px solid var(--accent); border-right: 1.5px solid var(--accent); }
.lv-vial.vertical .mark { width: 100%; height: 64px; border: 0; border-top: 1.5px solid var(--accent); border-bottom: 1.5px solid var(--accent); }
.lv-vial .bubble { width: 52px; }
.lv-ok .lv-read, .lv-ok .lv-read .deg { color: var(--accent); }
.lv-ok .bubble { background: var(--accent); }
.lv-hint { margin: 0; text-align: center; color: var(--sub); font-size: 14px; }

/* ---------- 화면 자 ---------- */
#ruler { position: fixed; inset: 0; background: #fff; touch-action: none; user-select: none; -webkit-user-select: none; }
#rCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.r-read { position: absolute; left: 50%; top: 44%; transform: translateX(-50%); text-align: center; pointer-events: none; white-space: nowrap;
  padding: 6px 14px; border-radius: 14px; background: rgba(255,255,255,.85); }
.r-read b { display: block; font-size: 44px; font-weight: 800; letter-spacing: -.03em; color: var(--accent); font-variant-numeric: tabular-nums; }
.r-read small { color: var(--sub); font-size: 14px; font-variant-numeric: tabular-nums; }
.r-bar { position: absolute; left: 70px; right: 12px; bottom: calc(14px + var(--safe-b)); display: flex; align-items: center; gap: 10px; }
.r-help { flex: 1; font-size: 12px; color: var(--sub); line-height: 1.35; }
.r-cal { position: absolute; inset: 0; background: rgba(255,255,255,.96); display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 24px 16px calc(16px + var(--safe-b)); }
.r-card { display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 13px; text-align: center; font-weight: 600; }
.r-cal-panel { width: 100%; max-width: 420px; }
.r-cal-panel p { margin: 0 0 10px; font-size: 14px; text-align: center; color: #374151; }
.r-cal-row { display: flex; align-items: center; gap: 10px; }
.r-cal-row input { flex: 1; accent-color: var(--accent); }
.sm-round { width: 40px !important; height: 40px !important; font-size: 22px; font-weight: 600; }
