:root {
  --bg: #ffffff;
  --card: #ffffff;
  --text: #2e2e36;
  --muted: #5d5d66;
  --line: #ddd6c4;
  --primary: #2b3478;
  --start: #1d7a3e;
  --end: #c8261c;
  --light: #f6c445;
  --pale: #fdf0c4;
  --warn-bg: #fff4d6;
  --warn-line: #a87b00;
  --error-bg: #fde7e5;
  --mock-bg: #ece3ff;
  --mock-line: #5b3cc4;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  font-size: 17px;
  line-height: 1.6;
}

header {
  background: var(--primary);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}

h1 { margin: 0; font-size: 20px; }
h1 small { font-size: 13px; font-weight: normal; opacity: 0.85; }
h2 { font-size: 18px; margin: 0 0 8px; }
h2 small, h3 small { font-size: 13px; font-weight: normal; color: var(--muted); }
h3 { font-size: 16px; margin: 16px 0 4px; }

.badge { margin: 2px 0 0; font-size: 13px; opacity: 0.9; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px calc(32px + env(safe-area-inset-bottom));
}

section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin: 12px 0;
}

.banner {
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0;
  border: 2px solid;
  font-size: 16px;
}
.banner strong { display: block; }
.banner-error { background: var(--error-bg); border-color: var(--end); color: #5c0f0a; }
.banner-warn { background: var(--warn-bg); border-color: var(--warn-line); color: #4a3700; }
.banner-mock { background: var(--mock-bg); border-color: var(--mock-line); color: #2c1a73; }

.call { text-align: center; }

.status { font-size: 26px; font-weight: bold; margin: 4px 0 0; min-height: 1.6em; }
.substatus { margin: 0 0 10px; color: var(--muted); min-height: 1.6em; font-variant-numeric: tabular-nums; }

button {
  font: inherit;
  border-radius: 10px;
  border: 2px solid var(--primary);
  background: #fff;
  color: var(--primary);
  padding: 10px 14px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: 0.45; cursor: default; }

.big {
  display: block;
  width: 100%;
  min-height: 132px;
  font-size: 34px;
  font-weight: bold;
  color: #fff;
  border: none;
  border-radius: 20px;
  letter-spacing: 0.05em;
}
.big.start { background: var(--start); }
.big.end { background: var(--end); }
.big:active:not(:disabled) { filter: brightness(0.88); }

.secondary { width: 100%; margin-top: 8px; }
.danger { border-color: var(--end); color: var(--end); }

.hint { font-size: 14px; color: var(--muted); margin: 8px 0 0; }

.markers { display: flex; gap: 8px; }
.markers button { flex: 1; font-size: 15px; border-color: var(--warn-line); color: #4a3700; background: var(--warn-bg); }

.row { display: flex; gap: 8px; }
.row button { flex: 1; font-size: 15px; }

.log, .history { list-style: none; margin: 0; padding: 0; }
.log li { padding: 8px 10px; border-radius: 10px; margin: 6px 0; overflow-wrap: anywhere; }
.log .who { display: block; font-size: 13px; color: var(--muted); }
.log .ai { background: #e6f1f8; margin-right: 12%; }
.log .visitor { background: #f0f0ee; margin-left: 12%; }
.log .note { background: var(--warn-bg); font-size: 14px; }
.log .flag { display: inline-block; font-size: 12px; background: var(--warn-line); color: #fff; border-radius: 6px; padding: 0 6px; margin-left: 6px; }
.log .pending { color: var(--muted); font-style: italic; }

.partial { color: var(--muted); font-size: 15px; min-height: 1.6em; margin: 4px 0 0; }

.end-reason { font-weight: bold; margin: 0; }

.summary {
  white-space: pre-wrap;
  font: inherit;
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 0;
  overflow-wrap: anywhere;
}

.metrics { width: 100%; border-collapse: collapse; font-size: 15px; }
.metrics th, .metrics td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; vertical-align: top; }
.metrics th { font-weight: normal; color: var(--muted); width: 46%; }
.metrics td { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metrics .alert { color: var(--end); font-weight: bold; }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--primary); padding: 6px 0; }
.notes dt { font-weight: bold; margin-top: 10px; }
.notes dd { margin: 0; font-size: 14px; color: var(--muted); }

fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 10px; padding: 8px 10px; min-width: 0; }
legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
.radio, .check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; }
.radio input, .check input { width: 24px; height: 24px; margin: 2px 0 0; flex: none; }
.inline { display: block; font-size: 15px; padding: 6px 0; }
.inline input { width: 5.5em; }
.block { display: block; margin: 10px 0; font-size: 15px; }
input[type="text"], input[type="number"], select {
  font: inherit;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
.block input, .block select { display: block; width: 100%; margin-top: 4px; }

.history li { border-top: 1px solid var(--line); padding: 8px 0; font-size: 15px; }
.history li:first-child { border-top: none; }
.history .meta { color: var(--muted); font-size: 13px; }
.history pre { white-space: pre-wrap; font: inherit; font-size: 14px; margin: 4px 0 0; overflow-wrap: anywhere; }
.history .empty { color: var(--muted); }

/* 訪問履歴 */
.visit { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; background: #fff; }
.visit.review { border-color: var(--warn-line); background: var(--warn-bg); }
.visit-head { display: flex; gap: 6px; margin-bottom: 6px; }
.tag { display: inline-block; font-size: 13px; border-radius: 6px; padding: 1px 8px; background: #e6e6e3; color: #333; }
.tag-review { background: var(--warn-line); color: #fff; font-weight: 700; }
.visit-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.visit-table th { text-align: left; vertical-align: top; white-space: nowrap; padding: 3px 10px 3px 0; font-weight: 600; color: var(--muted); width: 1%; }
.visit-table td { padding: 3px 0; overflow-wrap: anywhere; }
.visit h4 { margin: 10px 0 4px; font-size: 15px; }
.visit .concerns { margin: 0; padding-left: 20px; font-size: 15px; }
.visit .concerns ul { list-style: none; padding-left: 0; margin: 2px 0 6px; }
.visit .quote { color: #444; font-size: 14px; overflow-wrap: anywhere; }
.visit .muted, .muted { color: var(--muted); font-size: 14px; }
.visit .alert { color: #a33; font-weight: 600; }
.visit-notes { font-size: 14px; color: var(--muted); padding-left: 20px; }

/* リリース版: 親の画面では、テスト用の表示を隠して開始ボタンを中心にする */
body.parent .devonly { display: none !important; }
.pair input#pairCode { font-size: 1.8rem; letter-spacing: 0.2em; text-align: center; width: 100%; padding: 0.4em; box-sizing: border-box; }
.pair .consent { margin: 1em 0; }
.pair-more { margin-top: 1.5em; }
.device-info { text-align: center; }
button.small { font-size: 0.9rem; padding: 0.4em 0.8em; }

/* ---------- 画面デザイン: 案1「玄関灯」（2026-12-03 オーナー決定） ----------
   待機中は「① 通話 → ② 緑のボタン」と緑の丸い「おまかせ」を1つのまとまりにする（電話をかける緑、終わるは赤）。応対中は画面全体が玄関灯の黄色になる。
   応対を終わるボタンは、会話の吹き出しと見分けられるよう、下の帯に小さな赤い丸ボタンで置く。 */
body.parent header { background: transparent; color: var(--text); padding: calc(18px + env(safe-area-inset-top)) 22px 0; text-align: center; }
body.parent h1 { font-size: 17px; font-weight: 700; }
body.parent h1 small { display: none; }
body.parent main { padding: 8px 18px calc(40px + env(safe-area-inset-bottom)); }
body.parent section { background: transparent; border: 0; border-radius: 0; padding: 0; margin: 18px 0; }
body.parent .call { text-align: left; }
body.parent .status { font-size: 30px; font-weight: 800; line-height: 1.35; margin: 8px 4px 0; }
body.parent .substatus { margin: 0 4px 6px; }

/* 待機中: 紺の丸いボタン */
body.parent .big.start {
  width: min(270px, 74vw); height: min(270px, 74vw); min-height: 0;
  margin: 18px auto 0; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: clamp(30px, 9vw, 38px); font-weight: 800; line-height: 1.3; letter-spacing: 0.04em;
}
body.parent #pairSection .big.start { width: 100%; height: auto; min-height: 88px; border-radius: 999px; font-size: 26px; }
/* 待機中: 「① 通話 → ② 緑のボタン → 緑の丸」を1つのまとまりにして、画面の真ん中あたりに置く */
body.parent:not(.in-call) .call { min-height: calc(100svh - 150px); display: flex; flex-direction: column; justify-content: center; }
body.parent:not(.in-call) .status { font-size: 18px; font-weight: 700; color: var(--muted); }
body.parent .substatus:empty { display: none; }
.steps { list-style: none; margin: 18px 4px 0; padding: 0; }
.steps li { display: flex; align-items: center; gap: 12px; font-size: 21px; font-weight: 700; line-height: 1.4; }
.steps .num { display: inline-grid; place-content: center; width: 32px; height: 32px; border-radius: 50%; background: var(--text); color: #fff; font-size: 17px; font-weight: 800; flex: none; }
.steps .intercom { width: 40px; height: 56px; flex: none; }
.steps mark { background: var(--light); color: var(--text); padding: 0 10px; border-radius: 999px; font-weight: 800; }
.steps .arrow { width: 0; height: 0; margin: 8px 0 8px 5px; border: 11px solid transparent; border-top: 14px solid var(--line); border-bottom: 0; }
body:not(.parent) .steps .intercom { display: none; }
body.parent .device-info { text-align: left; border-top: 2px solid var(--line); padding-top: 14px; margin-top: 34px; }
body.parent .hint { font-size: 16px; }

/* 応対中: 画面全体を黄色にする */
body.parent.in-call { background: var(--light); }
body.parent.in-call .status { font-size: 30px; }
body.parent .status, body.parent .log li { word-break: auto-phrase; }
body.parent.in-call #deviceSection { display: none; }
body.parent.in-call main { padding-bottom: calc(130px + env(safe-area-inset-bottom)); }
body.parent #logSection h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* 会話の吹き出し: 訪問者は左に白、AIは右に紺 */
body.parent .log li { font-size: 21px; line-height: 1.6; padding: 14px 18px; margin: 12px 0; }
body.parent .log .who { font-size: 15px; font-weight: 700; color: inherit; opacity: .8; }
body.parent .log .visitor { background: #fff; margin: 12px 14% 12px 0; border-radius: 22px 22px 22px 4px; }
body.parent .log .ai { background: var(--primary); color: #fff; margin: 12px 0 12px 14%; border-radius: 22px 22px 4px 22px; }
body.parent .log .note { background: rgba(255,255,255,.6); border-radius: 12px; font-size: 16px; }
body.parent .log .pending { color: inherit; opacity: .7; }
/* 話している途中のスマホの言葉: 最初から紺の吹き出しの中に出す（文字が届く前は「…」） */
body.parent .partial { scroll-margin-bottom: calc(130px + env(safe-area-inset-bottom)); min-height: 0; margin: 0; }
body.parent .partial:not(:empty), body.parent.in-call.ai-speaking .partial:empty {
  background: var(--primary); color: #fff; margin: 12px 0 12px 14%; padding: 14px 18px;
  border-radius: 22px 22px 4px 22px; font-size: 21px; line-height: 1.6; word-break: auto-phrase;
}
body.parent .partial:not(:empty)::before, body.parent.in-call.ai-speaking .partial:empty::before {
  content: "スマホ"; display: block; font-size: 15px; font-weight: 700; opacity: .8;
}
body.parent.in-call.ai-speaking .partial:empty::after { content: "…"; }

/* 応対中: 上の状態の表示（話している人・経過時間）は固定し、会話だけを流す */
body.parent.in-call .call {
  position: sticky; top: 0; z-index: 4; background: var(--light);
  margin: 0 -18px; padding: 10px 18px 8px; border-bottom: 2px solid rgba(46,46,54,.2);
}

/* 応対を終わる: 線で分けた下の帯に、小さな赤い丸ボタン */
body.parent.in-call::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; /* 固定した上の表示（4）より下、会話より上 */
  height: calc(104px + env(safe-area-inset-bottom));
  background: var(--light); border-top: 2px solid rgba(46,46,54,.35);
}
body.parent .big.end {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: auto; min-height: 0; height: 64px; padding: 0 30px;
  border-radius: 999px; font-size: 22px; font-weight: 800; letter-spacing: 0; white-space: nowrap;
}
.hangup { width: 38px; height: 38px; fill: currentColor; flex: none; }
.talk { display: block; width: 84px; height: 56px; margin: 0 auto 6px; fill: currentColor; }
.talk .wave { fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; }
body:not(.parent) .talk { display: none; }
.big.end .hangup { display: inline-block; vertical-align: middle; }

/* 応対のあと */
body.parent #resultSection { border-top: 2px solid var(--line); padding-top: 16px; }
body.parent .visit { border-width: 2px; border-radius: 14px; }
body.parent .visit.review { background: var(--pale); border-color: var(--light); }
body.parent .tag-review { background: var(--primary); }
body.parent .banner { border-radius: 14px; }
