:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --text: #17212b;
  --muted: #5d6b78;
  --line: #dde3e8;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3f1;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --warn-soft: #fff5d6;
  --warn-ink: #7a5200;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161b;
    --surface: #1a232b;
    --text: #e8eef2;
    --muted: #9aa8b4;
    --line: #2c3842;
    --accent: #2bb3a6;
    --accent-ink: #06211e;
    --accent-soft: #16332f;
    --danger: #ff7b6b;
    --danger-soft: #3a1d1a;
    --warn-soft: #3a3013;
    --warn-ink: #f2d27a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); }

.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.appbar h1 {
  flex: 1; margin: 0; padding: 0 8px;
  font-size: 18px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: var(--line); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 60px; font-size: 18px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.btn.text-danger { color: var(--danger); }

.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; min-width: 0; }
.row.wrap { flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2, .section-title {
  margin: 0 0 8px; font-size: 15px; font-weight: 700; color: var(--muted);
}
.section-title { margin: 24px 4px 8px; }

.hint { margin: 6px 0; font-size: 13px; color: var(--muted); }
.notice {
  padding: 10px 12px; border-radius: 10px;
  background: var(--warn-soft); color: var(--warn-ink); font-size: 14px;
}
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--accent-soft); color: var(--accent); }

/* 一覧 */
.meeting-list { list-style: none; margin: 0; padding: 0; }
.meeting-list li + li { margin-top: 8px; }
.meeting-item {
  display: block; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: inherit; text-decoration: none;
}
.meeting-item:active { background: var(--accent-soft); }
.meeting-item .title { font-weight: 700; overflow-wrap: anywhere; }
.meeting-item .meta { margin-top: 4px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--line); color: var(--text);
}
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge.rec { background: var(--danger-soft); color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

.rec-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--danger-soft); color: var(--danger); font-weight: 700; text-decoration: none;
}

/* 録音 */
.rec-panel { text-align: center; padding: 28px 16px; }
.rec-timer { font-size: 56px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 1px; line-height: 1.1; }
.rec-state { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--danger); margin-bottom: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
.saved-box {
  margin: 18px auto 0; padding: 12px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.saved-box small { display: block; font-weight: 500; color: var(--muted); }

/* 詳細 */
.title-input {
  width: 100%; padding: 8px 10px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--text);
  font: inherit; font-size: 20px; font-weight: 700;
}
.title-input:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.detail-meta { padding: 0 10px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.progress { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress.indeterminate > i { width: 35%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
.transcript { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.transcript .ts { display: block; margin-top: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.transcript .ts:first-child { margin-top: 0; }
.transcript .silent { color: var(--muted); font-size: 13px; }
.summary h3 { margin: 16px 0 6px; font-size: 16px; }
.summary h3:first-child { margin-top: 0; }
.summary ul { margin: 0; padding-left: 22px; }
.summary p { margin: 6px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

/* 設定シート */
.sheet {
  width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px);
  padding: 0; border: 0; border-radius: 18px;
  background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet form { padding: 20px; }
.sheet h2 { margin: 0 0 12px; font-size: 20px; }
.sheet h3 { margin: 20px 0 4px; font-size: 15px; }
.sheet label { display: block; margin: 12px 0 4px; font-size: 14px; font-weight: 600; }
.sheet input, .sheet select {
  width: 100%; min-height: 46px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit;
}
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px;
  background: #17212b; color: #fff; font-size: 14px; z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}

/* キーの状態・折りたたみ・発行者用エリア */
.key-status { margin: 8px 0 4px; font-weight: 700; }
.key-status.ok { color: var(--accent); }
.fold { margin-top: 12px; }
.fold > summary { padding: 8px 0; font-size: 13px; color: var(--muted); cursor: pointer; }
.fold.issuer { margin-top: 28px; padding-top: 8px; border-top: 1px solid var(--line); }
.masked { -webkit-text-security: disc; }
.sheet textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 13px; word-break: break-all; resize: vertical;
}
.qr { display: block; width: min(260px, 100%); height: auto; margin: 12px auto 4px; border-radius: 8px; image-rendering: pixelated; }
.qr[hidden] { display: none; }

/* 文字起こし失敗時の詳細（配布元へそのまま伝えられる形で見せる） */
.error-detail-head { margin-top: 10px; font-size: 12px; font-weight: 600; }
.error-detail {
  margin: 6px 0 8px; padding: 8px 10px; border-radius: 8px;
  background: rgba(255, 255, 255, .7); color: #1f2937;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
}
#last-error { margin-bottom: 12px; }
