/* bldg-ar — 測量の道具（ポール・三角点・目盛り）を下敷きにした表示 */
:root {
  --navy: #12324f;   /* 測量図の紺：文字・主要ボタン */
  --plate: #f3f6f8;  /* ラベル札の地色 */
  --pole: #e0362c;   /* 測量ポールの赤：引き出し線・方位の指標 */
  --green: #1e7f4f;  /* 駅 */
  --blue: #2c6db5;   /* 学校・病院・役所 */
  --olive: #66852a;  /* 公園・競技場 */
  --pencil: #56616e; /* 補足の文字 */
  --line: rgba(18, 50, 79, 0.18);
  --hud: rgba(18, 50, 79, 0.74);
  --font: "BIZ UDPGothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--pole); outline-offset: 2px; }

/* ---------- カメラと重ね描き ---------- */
#cam {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
}
#touch { position: fixed; inset: 0; z-index: 1; touch-action: none; }
#overlay { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
#marks { position: fixed; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }

#reticle {
  position: fixed; left: 50%; top: 50%; z-index: 4;
  width: 30px; height: 30px; margin: -15px 0 0 -15px;
  pointer-events: none;
  background:
    linear-gradient(#fff, #fff) center top / 2px 10px no-repeat,
    linear-gradient(#fff, #fff) center bottom / 2px 10px no-repeat,
    linear-gradient(#fff, #fff) left center / 10px 2px no-repeat,
    linear-gradient(#fff, #fff) right center / 10px 2px no-repeat;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.9));
}

/* ラベル：札（tag）・測量ポール（pole）・三角点（tri）の三点で一組 */
/* .mark は重なり順の基準を作らない（札がどの引き出し線よりも上に来るように） */
.mark { position: absolute; left: 0; top: 0; pointer-events: none; }
.mark[hidden] { display: none; }

.tag {
  --band: var(--navy);
  position: absolute; left: 0; top: 0; z-index: 2;
  display: grid; gap: 2px;
  width: max-content; max-width: 64vw;
  padding: 5px 10px 6px 13px;
  border: 0; border-radius: 2px;
  background: var(--plate) linear-gradient(var(--band), var(--band)) left / 4px 100% no-repeat;
  color: var(--navy);
  text-align: left;
  white-space: nowrap;
  box-shadow: 0 0 0 1px rgba(18, 50, 79, 0.25), 0 2px 7px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  will-change: transform;
}
.tag .nm { font-weight: 700; font-size: 15px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; }
.tag .sub { display: flex; gap: 7px; font-size: 12px; line-height: 1.2; color: var(--pencil); font-variant-numeric: tabular-nums; }
.tag .sub span + span { border-left: 1px solid var(--line); padding-left: 7px; }

.pole {
  position: absolute; left: -2px; top: 0; z-index: 1;
  width: 4px; height: 0;
  background: repeating-linear-gradient(to bottom, var(--pole) 0 7px, #fff 7px 14px);
  box-shadow: 0 0 0 0.75px rgba(0, 0, 0, 0.45);
  will-change: transform, height;
}
.tri {
  position: absolute; left: -7px; top: -7.4px; z-index: 1;
  will-change: transform;
  width: 14px; height: 12px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 12'%3E%3Cpath d='M7 1 13 11H1Z' fill='%23f3f6f8' stroke='%2312324f' stroke-width='1.4' stroke-linejoin='round'/%3E%3Ccircle cx='7' cy='7.4' r='1.6' fill='%2312324f'/%3E%3C/svg%3E") center / contain no-repeat;
}

.mark.c-tower .tag { --band: var(--pole); }
.mark.c-station .tag { --band: var(--green); }
.mark.c-school .tag, .mark.c-hospital .tag, .mark.c-public .tag { --band: var(--blue); }
.mark.c-park .tag, .mark.c-stadium .tag { --band: var(--olive); }
.mark.sel .tag { box-shadow: 0 0 0 2px var(--pole), 0 2px 7px rgba(0, 0, 0, 0.3); }

/* ---------- 画面上部・下部の表示 ---------- */
#hud {
  position: fixed; left: 0; right: 0; z-index: 5;
  top: calc(env(safe-area-inset-top, 0px) + 48px);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: 0 10px;
  pointer-events: none;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--hud); color: #fff;
  font-size: 12px; line-height: 1;
  padding: 7px 8px;
  border-radius: 2px;
  font-variant-numeric: tabular-nums;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.chip.warn { background: rgba(224, 54, 44, 0.9); }
.icon-btn {
  pointer-events: auto;
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; border-radius: 2px;
  background: var(--hud); color: #fff;
}

#foot {
  position: fixed; left: 0; right: 0; z-index: 5;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  display: flex; justify-content: space-between; align-items: flex-end; gap: 8px;
  padding: 0 10px;
  pointer-events: none;
}
#attrib {
  pointer-events: auto;
  font-size: 10px; line-height: 1.3;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 2px #000, 0 0 2px #000;
  text-decoration: none;
}
.actions { display: flex; gap: 6px; }
.pill {
  pointer-events: auto;
  border: 0; border-radius: 2px;
  background: var(--hud); color: #fff;
  font-weight: 700; font-size: 13px; line-height: 1;
  padding: 11px 12px;
}
.pill[aria-pressed="true"] { background: var(--plate); color: var(--navy); box-shadow: inset 4px 0 0 var(--pole); }

#toast {
  position: fixed; left: 50%; z-index: 6;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 66px);
  transform: translateX(-50%);
  width: max-content; max-width: min(92vw, 460px);
  padding: 10px 12px;
  border-radius: 2px;
  background: var(--plate); color: var(--navy);
  box-shadow: inset 4px 0 0 var(--navy), 0 4px 14px rgba(0, 0, 0, 0.35);
  font-size: 13px; line-height: 1.55;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
#toast.show { opacity: 1; }

/* ---------- 下から出る面（詳細・設定） ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-height: 84vh; overflow: auto;
  background: var(--plate); color: var(--navy);
  border-top: 3px solid var(--navy);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: rise 0.18s ease-out;
}
.sheet[hidden] { display: none; }
@keyframes rise { from { transform: translateY(16px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheet-body { max-width: 560px; margin: 0 auto; padding: 16px 18px 18px; }
.sheet h2 { font-size: 21px; line-height: 1.35; margin: 0 0 12px; overflow-wrap: anywhere; }

.detail-cat { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font-size: 13px; color: var(--pencil); }
.detail-cat::before { content: ""; width: 10px; height: 10px; background: var(--band, var(--navy)); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0 0 12px; }
.facts div { border-left: 2px solid var(--line); padding-left: 9px; }
.facts dt { font-size: 12px; color: var(--pencil); }
.facts dd { margin: 2px 0 0; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.help { font-size: 12.5px; line-height: 1.6; color: var(--pencil); margin: 0 0 12px; }

.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; padding: 0 14px;
  border: 1.5px solid var(--navy); border-radius: 2px;
  background: transparent; color: var(--navy);
  font-weight: 700; font-size: 14px;
  text-decoration: none;
}
.btn.primary { background: var(--navy); color: #fff; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}
.row.col { flex-direction: column; align-items: stretch; gap: 10px; }
.row-label { display: block; font-weight: 700; font-size: 15px; }
.row-label output { font-weight: 400; color: var(--pencil); margin-left: 6px; font-variant-numeric: tabular-nums; }
.row-help { display: block; margin-top: 3px; font-size: 12px; line-height: 1.5; color: var(--pencil); }

.stepper { display: flex; align-items: center; flex: none; }
.stepper button {
  width: 40px; height: 40px;
  border: 1.5px solid var(--navy); border-radius: 2px;
  background: transparent; color: var(--navy);
  font-size: 18px; font-weight: 700;
}
.stepper output { min-width: 58px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.seg { display: flex; flex: none; border: 1.5px solid var(--navy); border-radius: 2px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--navy); padding: 9px 10px; font-weight: 700; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--navy); color: #fff; }

.calib { display: flex; flex-wrap: wrap; gap: 8px; }

.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; position: relative;
  width: 48px; height: 28px; margin: 0;
  border-radius: 14px;
  background: #c3ccd4;
  transition: background 0.15s;
}
.switch::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch:checked { background: var(--navy); }
.switch:checked::before { transform: translateX(20px); }

.credits { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.credits h3 { margin: 0 0 6px; font-size: 13px; }
.credits ul { margin: 0; padding-left: 1.1em; display: grid; gap: 3px; }
.credits li { font-size: 12px; line-height: 1.55; color: var(--pencil); }
.credits a { color: var(--navy); }
.diag { margin: 0 0 4px; font-size: 12px; line-height: 1.55; color: var(--pencil); overflow-wrap: anywhere; }
.diag.warn-text { color: #b0261d; }

input[type="range"] { width: 100%; accent-color: var(--navy); }
select { max-width: 60vw; padding: 8px; border: 1.5px solid var(--navy); border-radius: 2px; background: #fff; }

/* ---------- 開始画面 ---------- */
#start {
  position: fixed; inset: 0; z-index: 30;
  overflow: auto;
  display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 28px) 22px calc(env(safe-area-inset-bottom, 0px) + 28px);
  background: var(--navy); color: #fff;
}
#start[hidden] { display: none; }
#dial {
  position: fixed; left: 50%; top: 22%;
  width: min(150vw, 900px);
  transform: translate(-50%, -50%);
  opacity: 0.17;
  pointer-events: none;
}
.start-body { position: relative; width: 100%; max-width: 30em; }
#start h1 { margin: 0 0 14px; font-size: 46px; line-height: 1.05; font-weight: 700; letter-spacing: 0.01em; }
/* 縮尺記号のように寝かせた測量ポール */
#start h1::after {
  content: ""; display: block;
  width: 160px; height: 7px; margin-top: 12px;
  background: repeating-linear-gradient(90deg, var(--pole) 0 20px, #fff 20px 40px);
}
.lead { margin: 0 0 22px; font-size: 17px; line-height: 1.65; font-weight: 700; }
.uses { list-style: none; margin: 0 0 22px; padding: 0; display: grid; gap: 12px; }
.uses li { padding-left: 12px; border-left: 3px solid rgba(255, 255, 255, 0.35); font-size: 14px; line-height: 1.6; }
.uses strong { display: block; }
.warn { margin: 0 0 16px; padding: 10px 12px; background: var(--pole); font-weight: 700; font-size: 13px; line-height: 1.5; }
.start-btn {
  width: 100%; padding: 17px 16px;
  border: 0; border-radius: 2px;
  background: var(--plate); color: var(--navy);
  box-shadow: inset 7px 0 0 var(--pole);
  font-size: 18px; font-weight: 700;
}
.start-btn:disabled { opacity: 0.6; }
.note { margin: 14px 0 0; font-size: 12.5px; line-height: 1.65; color: rgba(255, 255, 255, 0.8); }

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  #toast, .switch, .switch::before { transition: none; }
}
