/* ===== iPhone 版（縦画面・HUD） ===== */
:root {
  --bg: #02070a;
  --panel: rgba(6, 22, 30, 0.72);
  --line: rgba(94, 234, 255, 0.35);
  --line-soft: rgba(94, 234, 255, 0.16);
  --cyan: #5eeaff;
  --text: #d9f7ff;
  --muted: #7fb3c2;
  --warn: #ffc267;
  --danger: #ff7b7b;
  --ok: #6ff0b0;
  --font: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  --display: "Avenir Next", "Futura", -apple-system, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: radial-gradient(120% 70% at 50% 35%, #05161d 0%, var(--bg) 62%);
  color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
.svg-defs { position: absolute; width: 0; height: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ===== メイン ===== */
.app { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto auto auto auto; padding: calc(var(--st) + 8px) 16px calc(var(--sb) + 10px); }
.top { display: flex; justify-content: space-between; align-items: flex-start; }
.clock { display: grid; line-height: 1.1; }
.clock span { font-family: var(--display); font-size: 30px; font-weight: 500; text-shadow: 0 0 12px rgba(94,234,255,.45); font-variant-numeric: tabular-nums; }
.clock small { color: var(--muted); font-size: 12px; margin-top: 2px; }
.top-right { display: grid; justify-items: end; gap: 4px; }
.badge { font-size: 11px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.flat { border-color: rgba(111,240,176,.45); color: var(--ok); }
.badge.mock { border-color: rgba(255,194,103,.5); color: var(--warn); }
.wx { font-size: 12px; color: var(--muted); }

.stage { position: relative; min-height: 0; }
.rings { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mark {
  text-align: center; font-family: var(--display); font-weight: 600; font-size: clamp(30px, 10vw, 44px);
  letter-spacing: .3em; padding-left: .3em; color: #e9fdff;
  text-shadow: 0 0 6px rgba(94,234,255,.9), 0 0 24px rgba(94,234,255,.5);
}
.status { text-align: center; color: var(--muted); font-size: 13px; min-height: 1.6em; margin: 4px 0 8px; }

/* 字幕（話したとき・回答のときだけ出る） */
.sub {
  min-height: 0; max-height: 30vh; overflow-y: auto; margin-bottom: 10px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 0 14px rgba(94,234,255,.18), inset 0 0 18px rgba(94,234,255,.05);
  transition: opacity .3s, transform .3s; -webkit-user-select: text; user-select: text;
}
.sub.closed { opacity: 0; transform: translateY(10px); pointer-events: none; }
.line { margin: 0; display: grid; gap: 1px; }
.line + .line { margin-top: 8px; }
.line .who { font-size: 11px; letter-spacing: .12em; color: var(--muted); }
.line.user .txt { color: #bfefff; font-size: 16px; }
.line.ai .txt { color: #fff; font-size: 17px; text-shadow: 0 0 10px rgba(94,234,255,.3); }
.line .placeholder { color: var(--muted); }
.line .part.todo { opacity: .45; }
.line.ai.thinking .txt::after { content: "…"; animation: pulse 1s infinite; }
.sub-open { margin-top: 10px; width: 100%; padding: 10px; border-radius: 10px; border: 1px solid rgba(255,194,103,.5); background: rgba(255,194,103,.12); color: var(--warn); font-weight: 600; }
@keyframes pulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* 下のボタン */
.bar { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.round { position: relative; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: rgba(4,18,26,.7); border: 1px solid var(--line-soft); color: var(--muted); }
.round svg { width: 22px; height: 22px; }
.round:active { color: var(--cyan); border-color: var(--line); }
.round .dot { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.mic {
  position: relative; width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; color: var(--cyan);
  background: radial-gradient(circle, rgba(94,234,255,.18) 0 50%, rgba(4,18,26,.8) 51%);
  border: 2px solid rgba(94,234,255,.6); box-shadow: 0 0 0 6px rgba(94,234,255,.07), 0 0 22px rgba(94,234,255,.35);
}
.mic::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; border: 2px dashed rgba(94,234,255,.35); animation: spin 14s linear infinite; }
.mic svg { width: 36px; height: 36px; }
.mic .i-stop { display: none; }
body[data-voice="listening"] .mic, body[data-voice="speaking"] .mic, body[data-voice="thinking"] .mic {
  color: #fff; border-color: #ff8a8a; box-shadow: 0 0 0 6px rgba(255,120,120,.12), 0 0 26px rgba(255,120,120,.5);
}
body[data-voice="listening"] .mic .i-mic, body[data-voice="speaking"] .mic .i-mic, body[data-voice="thinking"] .mic .i-mic { display: none; }
body[data-voice="listening"] .mic .i-stop, body[data-voice="speaking"] .mic .i-stop, body[data-voice="thinking"] .mic .i-stop { display: block; }
.mic:disabled { opacity: .4; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== シート ===== */
.scrim { position: fixed; inset: 0; z-index: 10; background: rgba(0,4,6,.6); }
.sheet {
  position: fixed; z-index: 11; left: 0; right: 0; bottom: 0; max-height: 70vh;
  background: #04131a; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 6px 16px calc(var(--sb) + 14px); display: flex; flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0,0,0,.6); animation: up .22s ease;
}
.sheet.tall { max-height: 88vh; height: 88vh; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: rgba(127,179,194,.4); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; -webkit-user-select: text; user-select: text; flex: 1; }
.x { background: none; border: none; color: var(--cyan); font-size: 15px; padding: 6px 2px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line); background: rgba(94,234,255,.06); font-weight: 600; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: linear-gradient(180deg, rgba(94,234,255,.38), rgba(34,211,238,.25)); border-color: var(--cyan); color: #fff; }
.btn.danger { border-color: rgba(255,123,123,.5); color: var(--danger); background: rgba(255,123,123,.08); width: 100%; margin-top: 14px; }
.btn:disabled { opacity: .45; }

.type-form { display: grid; gap: 10px; }
.type-form textarea { width: 100%; background: rgba(94,234,255,.05); border: 1px solid var(--line-soft); border-radius: 12px; padding: 10px 12px; font-size: 16px; resize: none; -webkit-user-select: text; user-select: text; }
.attach { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--cyan); background: rgba(94,234,255,.08); border-radius: 10px; padding: 6px 10px; }
.attach button { background: none; border: none; color: var(--muted); }

.row-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.row-toggle span { display: grid; }
.row-toggle small { color: var(--muted); font-size: 12px; }
.row-toggle input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--cyan); }
.row-toggle select { background: rgba(94,234,255,.06); border: 1px solid var(--line-soft); border-radius: 8px; padding: 6px 8px; }
.info { margin-top: 12px; font-size: 13px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* 履歴 */
.h-item { padding: 10px 12px; border-radius: 12px; margin-bottom: 8px; font-size: 14px; }
.h-item.user { background: rgba(94,234,255,.14); border: 1px solid var(--line); margin-left: 15%; }
.h-item.ai { background: rgba(255,255,255,.03); border: 1px solid var(--line-soft); margin-right: 10%; }
.h-item.prop { background: rgba(255,194,103,.08); border: 1px solid rgba(255,194,103,.35); margin-right: 10%; }
.h-item .meta { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.h-item button { margin-top: 6px; background: none; border: none; color: var(--warn); font-weight: 600; padding: 0; }
.empty { color: var(--muted); font-size: 14px; text-align: center; margin-top: 30px; }

/* 提案 */
.p-status { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line-soft); color: var(--muted); }
.p-status.pending_approval { color: var(--warn); border-color: rgba(255,194,103,.45); background: rgba(255,194,103,.1); }
.p-status.executed { color: var(--ok); border-color: rgba(111,240,176,.45); background: rgba(111,240,176,.1); }
.p-status.rejected, .p-status.failed { color: var(--danger); }
.p-sec { margin: 12px 0; }
.p-sec h3 { font-size: 13px; color: var(--cyan); margin: 0 0 6px; font-weight: 600; }
.p-concl { background: rgba(94,234,255,.06); border: 1px solid var(--line-soft); border-radius: 12px; padding: 10px 12px; }
.p-concl b { display: block; margin-bottom: 4px; }
.p-conf { font-size: 12px; color: var(--muted); }
.opt { border: 1px solid var(--line-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.opt.rec { border-color: var(--cyan); background: rgba(94,234,255,.07); }
.opt-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.opt-head em { font-style: normal; color: var(--cyan); white-space: nowrap; }
.opt-desc { color: var(--muted); font-size: 13px; margin: 2px 0 4px; }
.opt-meta { font-size: 12px; color: var(--text); }
.rec-tag { font-size: 11px; background: var(--cyan); color: #00222a; border-radius: 4px; padding: 0 6px; margin-left: 6px; }
.p-list { margin: 0; padding-left: 1.2em; font-size: 14px; }
.p-crit { border-left: 3px solid var(--warn); padding-left: 10px; }
.p-action input, .p-action textarea { width: 100%; background: rgba(94,234,255,.05); border: 1px solid var(--line-soft); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; font-size: 15px; }
.p-action textarea { min-height: 110px; resize: vertical; }
.p-gate { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.p-result { margin-top: 8px; color: var(--ok); font-size: 14px; word-break: break-all; }
.p-result.err { color: var(--danger); }
.p-note { font-size: 12px; color: var(--muted); }

/* ===== ペアリング ===== */
.pair { position: fixed; inset: 0; overflow-y: auto; padding: calc(var(--st) + 40px) 24px calc(var(--sb) + 30px); text-align: center; }
.pair-logo { border-radius: 20px; box-shadow: 0 0 30px rgba(94,234,255,.35); }
.pair h1 { font-size: 22px; margin: 18px 0 10px; }
.pair-steps { text-align: left; color: var(--muted); font-size: 14px; padding-left: 1.3em; margin: 0 0 18px; }
.pair-steps b { color: var(--text); }
.pair-form { display: grid; gap: 10px; }
.pair-form > * { width: 100%; min-width: 0; }
.pair-form input { text-align: center; font-size: 22px; letter-spacing: .15em; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(94,234,255,.05); text-transform: uppercase; -webkit-user-select: text; user-select: text; }
.pair-form #pairName { font-size: 15px; letter-spacing: normal; text-transform: none; }
.pair-msg { min-height: 1.5em; color: var(--warn); }
.pair-note { font-size: 12px; color: var(--muted); }

/* 通知 */
.toasts { position: fixed; z-index: 30; top: calc(var(--st) + 10px); left: 12px; right: 12px; display: grid; gap: 8px; pointer-events: none; }
.toast { background: rgba(4,18,26,.95); border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px; font-size: 14px; animation: up .2s ease; }
.toast.error { border-color: rgba(255,123,123,.6); color: #ffd6d6; }

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