/* ── 配色 ───────────────────────────────────────────────
   ライトを既定にし、ダークはシステムがダークのときか明示指定のときだけ。
   色は必ず素の :root で一度定義する（メディアクエリ内だけの定義を作らない）。 */
:root {
  color-scheme: light;
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --surface-2: #eceff5;
  --line:      #cfd6e2;
  --line-soft: #e3e8f0;
  --fg:        #0f1419;
  --fg-2:      #48525f;
  --fg-3:      #6a7483;
  --accent:    #1d4ed8;
  --accent-fg: #ffffff;
  --wait-fg:   #8a5a00;
  --wait-bg:   #fdf0d5;
  --err-fg:    #b3261e;
  --err-bg:    #fdeceb;
  --shadow:    0 1px 2px rgba(15, 20, 25, .06), 0 1px 3px rgba(15, 20, 25, .04);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #11151b;
    --surface:   #1a1f27;
    --surface-2: #232935;
    --line:      #39424f;
    --line-soft: #2b333f;
    --fg:        #f4f7fb;
    --fg-2:      #c2ccd9;
    --fg-3:      #8e99a8;
    --accent:    #8ab4ff;
    --accent-fg: #0b1220;
    --wait-fg:   #f0c274;
    --wait-bg:   #33280f;
    --err-fg:    #ff9b9b;
    --err-bg:    #3a1d1d;
    --shadow:    none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #11151b;
  --surface:   #1a1f27;
  --surface-2: #232935;
  --line:      #39424f;
  --line-soft: #2b333f;
  --fg:        #f4f7fb;
  --fg-2:      #c2ccd9;
  --fg-3:      #8e99a8;
  --accent:    #8ab4ff;
  --accent-fg: #0b1220;
  --wait-fg:   #f0c274;
  --wait-bg:   #33280f;
  --err-fg:    #ff9b9b;
  --err-bg:    #3a1d1d;
  --shadow:    none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.7 system-ui, -apple-system, "Segoe UI", "Noto Sans JP", sans-serif;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}
.grow { flex: 1; }
.dim { color: var(--fg-2); }
.small { font-size: 14px; }

/* ── 上部 ─────────────────────────────────────────── */

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 750; letter-spacing: .1em; }
.topbar .sub { color: var(--fg-3); font-size: 13px; }

.banner {
  padding: 10px 16px;
  background: var(--wait-bg);
  color: var(--wait-fg);
  font-size: 14px; line-height: 1.6;
  border-bottom: 1px solid var(--line);
}

/* ── ボタン ───────────────────────────────────────── */

button {
  font: inherit; font-size: 15px;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 14px;
  cursor: pointer;
  line-height: 1.3;
}
button:hover { background: var(--surface); }
button:active { transform: translateY(1px); }
button.primary, button.primary-sm {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-fg); font-weight: 650;
}
button.primary:hover, button.primary-sm:hover { filter: brightness(1.08); }
button.icon { padding: 8px 11px; font-size: 17px; }
button.chip { padding: 5px 11px; font-size: 13px; border-radius: 999px; }
button.ghost { background: transparent; }
button[disabled] { opacity: .4; cursor: default; }

textarea {
  width: 100%; font: inherit; color: var(--fg);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; resize: vertical; line-height: 1.7;
}
textarea::placeholder { color: var(--fg-3); }
textarea:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ── ターン ───────────────────────────────────────── */

.turns {
  flex: 1; overflow-y: auto;
  padding: 18px 14px 28px;
  display: flex; flex-direction: column; gap: 30px;
}
.turn { display: flex; flex-direction: column; gap: 12px; }

.qmeta { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.qmeta .tag {
  font-size: 12px; color: var(--accent); font-weight: 600;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 2px 10px;
}
.qmeta .progress {
  margin-left: auto; font-size: 13px; color: var(--fg-2);
  font-variant-numeric: tabular-nums;
}
.turn .q {
  margin: 0; font-size: 19px; font-weight: 700; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}

.cards { display: grid; gap: 12px; }
@media (min-width: 860px) {
  .cards { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
}

/* ── カード ───────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--p, var(--line));
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card.slim { background: transparent; box-shadow: none; border-color: var(--line-soft); }

.crow {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; row-gap: 8px;
  padding: 11px 14px;
  min-height: 46px;
}
.card:not(.slim) .crow { border-bottom: 1px solid var(--line-soft); }

.pname {
  font-weight: 700; font-size: 15px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
}
.pname::before {
  content: "";
  width: 10px; height: 10px; border-radius: 3px;
  background: var(--p, var(--fg-3));
}
.pmode {
  font-size: 12px; color: var(--fg-2); white-space: nowrap;
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 7px;
}

.pill { font-size: 13px; white-space: nowrap; padding: 2px 10px; border-radius: 999px; }
.pill.idle { color: var(--fg-2); }
.pill.wait { color: var(--wait-fg); background: var(--wait-bg); }
.pill.err  { color: var(--err-fg);  background: var(--err-bg); }

.cacts { display: flex; gap: 7px; flex-wrap: wrap; }
.cacts button { font-size: 14px; padding: 7px 12px; }
.cacts.bottom { padding: 11px 14px 13px; border-top: 1px solid var(--line-soft); }

.cnote { padding: 0 14px 12px; font-size: 14px; line-height: 1.6; }
.cnote.err { color: var(--err-fg); }

.body {
  padding: 14px;
  font-size: 17px; line-height: 1.9;
  white-space: pre-wrap; word-break: break-word;
}
/* 畳むときも文字は薄くしない。読めない文字を出すくらいなら切る。 */
.body.clamped {
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical;
  overflow: hidden;
}
button.more {
  display: block; width: 100%;
  background: transparent; border: 0;
  border-top: 1px solid var(--line-soft); border-radius: 0;
  color: var(--accent); font-size: 14px; font-weight: 600; padding: 11px;
}
button.more:hover { background: var(--surface-2); }

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

/* ── 入力欄 ───────────────────────────────────────── */

.empty { padding: 44px 22px; color: var(--fg-2); }
.empty h2 { font-size: 18px; margin: 0 0 12px; color: var(--fg); font-weight: 700; }
.empty p { margin: 0 0 9px; font-size: 16px; }

.composer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 14px 15px;
  display: flex; flex-direction: column; gap: 10px;
}
.composer-row { display: flex; align-items: center; gap: 10px; }
#mic-state { font-size: 13px; color: var(--fg-3); }

/* ── ダイアログ ───────────────────────────────────── */

dialog {
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; max-width: min(580px, 92vw); width: 100%;
  box-shadow: 0 20px 60px rgba(10, 15, 25, .28);
}
dialog::backdrop { background: rgba(15, 20, 30, .5); }
dialog h2 { margin: 0 0 10px; font-size: 18px; }
dialog > form > p.dim { margin: 0 0 14px; font-size: 15px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 18px 0 0; }

.preview {
  max-height: 160px; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 12px;
  font-size: 14px; line-height: 1.7; white-space: pre-wrap; margin: 0 0 14px;
}
.pick-options { display: flex; flex-direction: column; gap: 8px; }
.pick-options button { text-align: left; padding: 12px 14px; font-weight: 600; }
.pick-options .sub {
  display: block; font-size: 13px; color: var(--fg-2);
  font-weight: 400; margin-top: 3px;
}

.pset { border: 1px solid var(--line); border-radius: 11px; padding: 14px; margin-bottom: 12px; }
.pset > .head {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 4px; font-weight: 700; font-size: 16px;
}
.pset label { display: block; font-size: 14px; color: var(--fg-2); margin: 11px 0 4px; }
.pset input, .pset select {
  width: 100%; font: inherit; font-size: 15px; color: var(--fg);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px;
}
.pset input[type="checkbox"] { width: auto; }
.cnote.warn { color: var(--wait-fg); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(112px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex; align-items: center; gap: 12px;
  max-width: min(560px, 92vw);
  padding: 11px 14px;
  background: var(--fg); color: var(--bg);
  border-radius: 10px; font-size: 14.5px;
  box-shadow: 0 8px 28px rgba(10, 15, 25, .35);
}
.toast button {
  background: transparent; color: var(--bg);
  border: 1px solid currentColor; border-radius: 7px;
  padding: 4px 10px; font-size: 13px; opacity: .85;
}
.toast button:hover { background: transparent; opacity: 1; }
.cnote { color: var(--fg-2); }

.meter {
  font-size: 13px; color: var(--fg-2);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; white-space: nowrap;
}
.pricerow { display: flex; gap: 8px; }
