/* スマホ巻尺 — 屋外でも読めるよう、文字は大きめ・色の差ははっきり */
:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #161b20;
  --sub: #55606b;
  --line: #cfd6dd;
  --dark: #1d2630;
  --yellow: #ffc400;
  --yellow-text: #161b20;
  --good: #0b6e4f;
  --good-bg: #e3f4ec;
  --warn: #8a5a00;
  --warn-bg: #fff2d6;
  --bad: #a3231b;
  --bad-bg: #fde5e2;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 17px;
  line-height: 1.6;
}

/* ---- 上の帯 ---- */
.top {
  flex: 0 0 auto;
  display: flex; align-items: baseline; gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: var(--dark); color: #fff;
}
.top h1 { font-size: 20px; margin: 0; }
.top .ver { font-size: 13px; color: #b9c3cc; }
.update-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; background: var(--yellow); color: var(--yellow-text); font-weight: 700;
}
.update-bar button {
  min-height: 44px; padding: 6px 14px; font-family: inherit; font-size: 16px; font-weight: 700;
  border: 0; border-radius: 10px; background: var(--dark); color: #fff;
}

/* ---- 真ん中（画面ごとに入れ替わる） ---- */
main { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.tab { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--sub); }
p { margin: 0 0 8px; }
.status { padding: 12px 14px; border-radius: 10px; background: #e8edf2; font-size: 16px; margin: 0 0 12px; }
.status.ok { background: var(--good-bg); color: var(--good); }
.status.ng { background: var(--bad-bg); color: var(--bad); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0 0 12px; }
details.card summary { font-weight: 700; font-size: 17px; cursor: pointer; min-height: 32px; }
details.card[open] summary { margin-bottom: 8px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0; min-width: 56px; min-height: 52px; padding: 8px 8px;
  font-family: inherit; font-size: 17px;
  border: 2px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
.seg button[aria-pressed="true"] { border-color: var(--dark); background: var(--dark); color: #fff; font-weight: 700; }
button.big {
  display: block; width: 100%; min-height: 68px; margin: 4px 0 14px;
  font-family: inherit; font-size: 23px; font-weight: 700;
  border: 0; border-radius: 12px; background: var(--yellow); color: var(--yellow-text);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .18);
}
button.big:disabled { background: #c4ccd3; color: #5f6a74; box-shadow: none; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
button.btn {
  min-height: 52px; padding: 8px 14px;
  font-family: inherit; font-size: 16px;
  border: 2px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
button.btn.primary { border-color: var(--yellow); background: var(--yellow); color: var(--yellow-text); font-weight: 700; }
button.btn.danger { color: var(--bad); }
button.btn.small { min-height: 44px; font-size: 14px; }
button.btn:disabled { color: #98a3ad; background: #f0f2f4; border-color: var(--line); }
.headline { font-size: 26px; font-weight: 700; margin: 0 0 4px; }
.note { color: var(--sub); font-size: 14px; }
.warn-note { color: var(--warn); font-size: 14px; }
.foot { color: var(--sub); font-size: 13px; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 16px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { text-align: center; width: 2.5em; }
th { color: var(--sub); font-size: 14px; font-weight: 600; }
td.empty, p.empty { color: var(--sub); text-align: center; }
td.diff { font-weight: 700; }
td.good { color: var(--good); background: var(--good-bg); }
td.warn { color: var(--warn); background: var(--warn-bg); }
td.bad { color: var(--bad); background: var(--bad-bg); }
#trial-summary { margin-top: 10px; font-size: 15px; }
#trial-summary p { margin: 0 0 4px; }
ol { margin: 0 0 8px; padding-left: 1.4em; }
li { margin: 0 0 6px; }
.seglines p { margin: 0 0 2px; font-size: 15px; }

/* 記録の一覧 */
.rec { border-top: 1px solid var(--line); padding: 10px 0 4px; }
.rec:first-child { border-top: 0; padding-top: 0; }
.rec .rec-name { font-weight: 700; }
.rec .rec-at { color: var(--sub); font-size: 13px; }
.rec .rec-head { font-size: 21px; font-weight: 700; margin: 2px 0; }

/* ---- 下の切り替え ---- */
.tabs {
  flex: 0 0 auto;
  display: flex;
  border-top: 1px solid var(--line);
  background: #fff;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1 1 0; min-height: 60px; padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: inherit; font-size: 22px; line-height: 1.1;
  border: 0; background: #fff; color: var(--sub);
}
.tabs button span { font-size: 13px; margin-top: 2px; }
.tabs button[aria-pressed="true"] { color: var(--text); font-weight: 700; box-shadow: inset 0 4px 0 var(--yellow); }

/* ---- 画面の定規 ---- */
main.ruler-mode { overflow: hidden; display: flex; flex-direction: column; }
main.ruler-mode #tab-ruler { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; max-width: none; width: 100%; padding: 0; }
.ruler-warn { margin: 0; padding: 8px 12px; background: var(--warn-bg); color: var(--warn); font-size: 14px; }
.ruler-help { margin: 0; padding: 8px 12px; background: #fffbe8; font-size: 14px; }
.ruler-wrap { position: relative; flex: 1 1 auto; min-height: 120px; background: #fffdf3; overflow: hidden; }
#ruler-canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; touch-action: none; }
.ruler-read {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  padding: 6px 14px; border-radius: 12px; background: rgba(29, 38, 48, .88); color: #fff;
  font-size: 34px; font-weight: 700; white-space: nowrap; pointer-events: none;
}
.ruler-read:empty { display: none; }
.ruler-panel { flex: 0 0 auto; padding: 8px 12px 10px; background: #fff; border-top: 1px solid var(--line); }
.ruler-panel .btns { margin-top: 0; }
.ruler-panel .btns + .btns { margin-top: 8px; }
.ruler-panel .btn { flex: 1 1 auto; }
.ruler-tip { font-size: 14px; color: var(--sub); margin: 0 0 6px; }
.calib-btns .btn { font-size: 22px; font-weight: 700; }

/* ---- お知らせ・コピーの箱 ---- */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: 84px; z-index: 20;
  padding: 12px 14px; border-radius: 10px; background: rgba(20, 24, 28, .92); color: #fff; font-size: 16px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.fallback {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(0, 0, 0, .45);
}
.fallback-inner { width: 100%; max-width: 520px; background: #fff; border-radius: 12px; padding: 14px; }
#fallback-area { width: 100%; font-family: ui-monospace, monospace; font-size: 14px; }

/* ---- カメラ（AR）の画面 ---- */
#ar-overlay {
  display: none; position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 40;
  background: transparent !important; color: #fff; font-family: inherit;
}
#ar-canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
#ar-top {
  position: absolute; left: 0; right: 0; top: 0; pointer-events: none;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: rgba(0, 0, 0, .6); font-size: 16px; line-height: 1.45;
}
#ar-top p { margin: 0 0 2px; }
#ar-top .mode { font-weight: 700; font-size: 16px; color: #ffe08a; }
#ar-top .bignum { font-size: 40px; font-weight: 800; line-height: 1.15; }
#ar-top .sub { font-size: 15px; color: #e2e8ee; }
#ar-top .warn { color: #ffd166; }
#ar-top .done { color: #8ff0b4; font-weight: 700; }
#ar-top .hint { color: #cfeedd; }
#ar-top .segs { white-space: pre-line; font-size: 15px; }
#ar-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, .5);
}
#ar-bottom .row { display: flex; gap: 8px; margin-top: 8px; }
#ar-bottom button {
  flex: 1 1 0; min-height: 56px; padding: 4px 2px; font-family: inherit; font-size: 16px; font-weight: 700;
  border: 0; border-radius: 10px; background: #fff; color: #111;
}
#ar-bottom button#ar-place { display: block; width: 100%; min-height: 66px; font-size: 23px; background: var(--yellow); color: #111; }
#ar-bottom button:disabled, #ar-bottom button#ar-place:disabled { background: #7b858e; color: #cfd6dd; }
