:root {
  --line: #e5e7eb;
  --accent: #1e3a8a;
  --ink: #111827;
  --muted: #6b7280;
  --bg: #ffffff;
  --soft: #f9fafb;
  --danger: #b91c1c;
  --ok: #047857;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.7;
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 1.05rem; margin: 0; font-weight: 600; }
h2 { font-size: 0.95rem; margin: 0 0 8px; font-weight: 600; }

.muted { color: var(--muted); font-size: 0.85rem; margin: 4px 0 10px; }
.lead { color: var(--muted); font-size: 0.85rem; padding: 12px 16px 0; margin: 0; }

/* ログイン */
.login-body { display: grid; place-items: center; min-height: 100dvh; background: var(--soft); }
.login-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 24px; width: min(340px, 88vw); text-align: center;
}
.login-card input {
  width: 100%; padding: 12px; margin: 8px 0; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px;
}
.error { color: var(--danger); font-size: 0.85rem; margin: 6px 0; }

/* ヘッダー */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(255,255,255,0.96);
  backdrop-filter: blur(8px); z-index: 20;
}
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.topbar-actions form { margin: 0; }

.banner {
  margin: 0; padding: 8px 16px; background: #fffbeb;
  border-bottom: 1px solid #fde68a; font-size: 0.8rem; color: #92400e;
}

/* タブ */
.tabs {
  display: flex; border-bottom: 1px solid var(--line);
  position: sticky; top: 49px; background: #fff; z-index: 19;
}
.tab {
  flex: 1; padding: 12px 4px; border: 0; background: none;
  font: inherit; font-size: 0.9rem; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer;
}
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.panel { display: none; }
.panel.is-active { display: block; }

/* カード */
.card {
  margin: 12px 16px; padding: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
}

textarea {
  width: 100%; padding: 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--soft); resize: vertical;
}

/* ボタン */
button { font: inherit; cursor: pointer; }

.primary {
  width: 100%; padding: 13px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 0.95rem;
}
.ghost {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--muted); font-size: 0.8rem;
}

.rec-btn {
  width: 100%; padding: 15px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 0.95rem;
}
.rec-btn.small { width: auto; padding: 9px 18px; font-size: 0.85rem; }
.rec-btn.is-rec { background: var(--danger); }
.rec-btn:disabled { background: #9ca3af; }

.hold-btn {
  width: 100%; padding: 26px; border: 2px dashed var(--line); border-radius: 12px;
  background: var(--soft); color: var(--ink); font-weight: 600;
  /* 押しっぱなし中に画面が動くと録音が切れるため、この要素のジェスチャーを止める */
  touch-action: none; -webkit-user-select: none; user-select: none;
}
.hold-btn.is-rec { background: var(--danger); color: #fff; border-color: var(--danger); }

/* レベルメーター */
.meter {
  height: 6px; background: var(--soft); border-radius: 3px;
  overflow: hidden; margin: 10px 0 6px; display: none;
}
.meter.is-on { display: block; }
.meter span {
  display: block; height: 100%; width: 0%;
  background: var(--ok); transition: width 0.08s linear;
}

/* 結果 */
.result-line { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; min-height: 1.2em; }
.result-line.is-error { color: var(--danger); }

.output {
  margin-top: 8px; padding: 12px; border-radius: 8px;
  background: var(--soft); font-size: 0.9rem; white-space: pre-wrap;
  word-break: break-word; min-height: 1em;
}
.output:empty { display: none; }
.output.is-error { color: var(--danger); background: #fef2f2; font-size: 0.8rem; }
.output-empty { color: var(--muted); font-size: 0.85rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* エンジン結果 */
.eng-row { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.eng-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 6px; flex-wrap: wrap;
}
.eng-name { font-weight: 600; font-size: 0.88rem; }
.eng-stat { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.eng-text { font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; }
.eng-text.is-error { color: var(--danger); font-size: 0.8rem; }

.hist-item { border-top: 1px solid var(--line); padding: 10px 0; }
.hist-meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.hist-line { font-size: 0.82rem; margin: 2px 0; word-break: break-word; }
.hist-line b { font-weight: 600; }

/* チェックボックス */
fieldset.engines { border: 0; padding: 0; margin: 0 0 12px; }
fieldset.engines legend { font-size: 0.8rem; color: var(--muted); padding: 0; margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: 0.9rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.check small { color: var(--muted); font-size: 0.75rem; margin-left: 8px; }

/* 項目ごと録音 */
.slot {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.slot:first-of-type { border-top: 0; }
.slot-label { font-size: 0.88rem; font-weight: 600; flex: 1; }
.slot .output { flex-basis: 100%; margin-top: 0; }

/* 端末情報シート */
.sheet {
  position: fixed; inset: 0; background: rgba(17,24,39,0.45);
  display: grid; place-items: end center; z-index: 50;
}
.sheet[hidden] { display: none; }
.sheet-inner {
  background: #fff; width: 100%; max-height: 82dvh; overflow-y: auto;
  border-radius: 14px 14px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
#device-list { margin: 0 0 14px; font-size: 0.82rem; }
#device-list dt { color: var(--muted); font-size: 0.75rem; margin-top: 8px; }
#device-list dd { margin: 0; word-break: break-all; font-variant-numeric: tabular-nums; }
