:root {
  --bg: #f7f7f5; --fg: #1f1f1d; --sub: #6b6b66; --me: #ebebe7; --line: #e2e2dd;
  --btn: #ffffff; --btn-line: #dcdcd6; --dark: #2a2a28; --dark-fg: #ffffff; --accent: #c2410c; --warn: #b42318;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1b; --fg: #ededea; --sub: #a3a39d; --me: #2f2f2d; --line: #333331;
    --btn: #262625; --btn-line: #3a3a38; --dark: #ededea; --dark-fg: #1c1c1b; --accent: #fb923c; --warn: #f97066;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1c1b; --fg: #ededea; --sub: #a3a39d; --me: #2f2f2d; --line: #333331;
  --btn: #262625; --btn-line: #3a3a38; --dark: #ededea; --dark-fg: #1c1c1b; --accent: #fb923c; --warn: #f97066;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 17px; line-height: 1.7; display: flex; flex-direction: column;
  overflow: hidden; overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.round {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--btn-line); background: var(--btn);
  display: inline-flex; align-items: center; justify-content: center; padding: 0; flex: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.round svg { width: 22px; height: 22px; }
svg[hidden], [hidden] { display: none !important; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 6px;
}
header h1 { font-size: 16px; font-weight: 600; margin: 0; color: var(--sub); letter-spacing: .05em; }
#log {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 24px;
  width: 100%; max-width: 720px; margin: 0 auto;
}
.msg { margin: 14px 0; white-space: pre-wrap; word-break: break-word; }
.msg.me { display: flex; justify-content: flex-end; }
.msg.me span { background: var(--me); border-radius: 22px; padding: 9px 18px; max-width: 82%; }
.msg.me.interim span { color: var(--sub); }
.msg.ai { padding-right: 8%; }
.msg.ai.wait { color: var(--sub); }
.msg.sys { color: var(--sub); font-size: 14px; text-align: center; }
.msg.err { color: var(--warn); font-size: 15px; }
.msg .tools { margin-top: 4px; }
.msg .tools button {
  border: 1px solid var(--btn-line); background: var(--btn); border-radius: 16px; font-size: 13px;
  padding: 3px 12px; color: var(--sub);
}
.empty { color: var(--sub); text-align: center; margin-top: 30vh; font-size: 15px; }
footer { padding: 4px 16px calc(env(safe-area-inset-bottom) + 14px); width: 100%; max-width: 720px; margin: 0 auto; }
#status { text-align: center; color: var(--sub); font-size: 14px; min-height: 22px; margin-bottom: 6px; }
#textrow { display: none; gap: 8px; margin-bottom: 10px; }
#textrow.show { display: flex; }
#textrow input {
  flex: 1; min-width: 0; font-size: 17px; padding: 10px 14px; border-radius: 22px;
  border: 1px solid var(--btn-line); background: var(--btn); color: var(--fg);
}
#textrow button { border: 0; border-radius: 22px; padding: 0 16px; background: var(--dark); color: var(--dark-fg); }
.micwrap { display: flex; justify-content: center; margin-bottom: 12px; }
#mic {
  width: 78px; height: 78px; border-radius: 50%; border: 1px solid var(--btn-line); background: var(--btn);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 10px rgba(0,0,0,.08);
  position: relative;
}
#mic svg { width: 32px; height: 32px; }
#mic.listening { background: var(--accent); border-color: var(--accent); color: #fff; }
#mic.listening::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--accent);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse { from { opacity: .8; transform: scale(.92); } to { opacity: 0; transform: scale(1.25); } }
@media (prefers-reduced-motion: reduce) { #mic.listening::after { animation: none; opacity: .5; } }
.bar { display: flex; align-items: center; gap: 10px; }
.bar .grow { flex: 1; }
#speed {
  height: 46px; border-radius: 23px; border: 1px solid var(--btn-line); background: var(--btn);
  padding: 0 16px; display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums;
}
#mute.on { color: var(--warn); }
#end { background: var(--dark); color: var(--dark-fg); border-color: var(--dark); }
/* 設定 */
#settings {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); display: none; align-items: flex-end; justify-content: center;
  z-index: 10;
}
#settings.show { display: flex; }
#settings .sheet {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px); max-height: 92vh; overflow-y: auto;
}
@media (min-width: 700px) { #settings { align-items: center; } #settings .sheet { border-radius: 18px; } }
.sheet h2 { font-size: 18px; margin: 0 0 12px; }
.sheet label { display: block; font-size: 14px; color: var(--sub); margin: 14px 0 4px; }
.sheet input[type=url], .sheet input[type=password] {
  width: 100%; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--btn-line);
  background: var(--btn); color: var(--fg);
}
.sheet .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.sheet .row button { border-radius: 10px; padding: 10px 14px; border: 1px solid var(--btn-line); background: var(--btn); }
.sheet .row button.primary { background: var(--dark); color: var(--dark-fg); border-color: var(--dark); }
.sheet .check { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 15px; color: var(--fg); }
.sheet .check input { width: 20px; height: 20px; }
.sheet .note { font-size: 13px; color: var(--sub); margin-top: 10px; }
#setmsg { font-size: 14px; margin-top: 10px; min-height: 20px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
