:root {
  --blue: #c9dfec;
  --line: #cfe0ea;
  --ink: #2b2b2b;
  --muted: #6b7680;
  --accent: #2f6f95;
  --rec: #d23b3b;
  --bg: #f6f8fa;
  --card: #fff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }

.banner {
  background: var(--blue);
  display: flex; align-items: center; gap: 16px;
  padding: calc(20px + env(safe-area-inset-top)) 20px 20px;
}
.star { width: 48px; height: 48px; flex: none; fill: var(--ink); }
.banner h1 {
  font-family: "SFMono-Regular", Menlo, Consolas, "Courier New", monospace;
  font-weight: 500; letter-spacing: .08em; font-size: clamp(18px, 4.5vw, 32px);
  margin: 0; flex: 1;
}
.banner-actions { display: flex; gap: 8px; }
.ghost {
  background: rgba(255,255,255,.6); border: 1px solid rgba(0,0,0,.12);
  border-radius: 8px; padding: 8px 12px; font-size: 14px;
}

.notice { background: #fff4d6; border-bottom: 1px solid #ecd9a0; padding: 12px 20px; font-size: 14px; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 16px; line-height: 1.4; }

.row {
  display: grid; grid-template-columns: 240px minmax(0, 1fr);
  background: var(--card); border: 1px solid var(--line); border-top: none;
}
.row:first-of-type { border-top: 1px solid var(--line); }
.hint + .row { border-top: 1px solid var(--line); margin-bottom: 16px; }
.hint + .row + .row { border-top: 1px solid var(--line); }
.label {
  padding: 16px; font-weight: 600; border-right: 1px solid var(--line); line-height: 1.35;
}
.label small { display: block; font-weight: 400; color: var(--muted); margin-top: 4px; }
.cell { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; justify-content: center; min-width: 0; }

.field { display: flex; align-items: center; gap: 8px; }
.field input, .field textarea {
  flex: 1; min-width: 0; width: 100%; font: inherit; font-size: 17px;
  border: 1px solid #d8e2e8; border-radius: 8px; padding: 10px 12px; background: #fbfdfe;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.field.live input, .field.live textarea { border-color: var(--rec); background: #fff7f7; }

.mic {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid #c4d6e1; background: #eef5f9;
  display: grid; place-items: center;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform .1s, background .15s;
}
.mic svg { width: 22px; height: 22px; fill: var(--accent); pointer-events: none; }
.mic.on { background: var(--rec); border-color: var(--rec); transform: scale(1.12); box-shadow: 0 0 0 6px rgba(210,59,59,.18); }
.mic.on svg { fill: #fff; }
.mic[disabled] { opacity: .35; }

.cell.name-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-content: center; }
.name-grid .tip { grid-column: 1 / -1; margin: 0; }
.sub label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.sub .field input { font-size: 16px; }
.tip { font-size: 12px; color: var(--muted); }

.choice-field { justify-content: space-between; flex-wrap: wrap; }
.seg, .checks { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.seg button, .checks button {
  border: 1px solid #c4d6e1; background: #fff; border-radius: 999px;
  padding: 10px 16px; font-size: 16px; min-height: 44px;
}
.seg button[aria-checked="true"], .checks button[aria-checked="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.checks button::before { content: "☐ "; }
.checks button[aria-checked="true"]::before { content: "☑ "; }

.meta { color: var(--muted); font-size: 13px; text-align: right; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px; justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.95); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.actionbar button {
  flex: 1; max-width: 260px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--accent); background: #fff; color: var(--accent); font-weight: 600;
}
.actionbar button:first-child { background: var(--accent); color: #fff; }

.listening {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 999px;
  display: flex; align-items: center; gap: 10px; font-size: 15px; z-index: 20;
  max-width: 90vw;
}
.listening .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: pulse 1s infinite; flex: none; }
#listeningText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes pulse { 50% { opacity: .3; } }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 20;
}

dialog { border: none; border-radius: 12px; padding: 16px; width: min(520px, 92vw); max-height: 80vh; }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.small { color: var(--muted); font-size: 13px; }
#historyList { list-style: none; padding: 0; margin: 0; }
#historyList li { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 10px 0; }
#historyList li .open { flex: 1; text-align: left; background: none; border: none; padding: 4px 0; }
#historyList li .open small { display: block; color: var(--muted); }
#historyList li .del { background: none; border: 1px solid #e3c4c4; color: var(--rec); border-radius: 6px; padding: 6px 10px; font-size: 13px; }
#historyList li.current .open { font-weight: 600; }

@media (max-width: 640px) {
  main { padding: 10px; }
  .row { grid-template-columns: 1fr; }
  .label { border-right: none; padding: 12px 14px 0; }
  .cell { padding: 8px 14px 14px; }
  .cell.name-grid { grid-template-columns: minmax(0, 1fr); }
  .star { width: 36px; height: 36px; }
}

/* ---------- print ---------- */
#printView { display: none; }
@media print {
  body { background: #fff; padding: 0; }
  .banner, main, .actionbar, .notice, .listening, .toast, dialog { display: none !important; }
  #printView { display: block; font-family: Georgia, serif; color: #000; }
  #printView .p-head { background: var(--blue); padding: 28px; display: flex; align-items: center; gap: 20px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printView .p-head h1 { font-family: "Courier New", monospace; font-weight: 500; letter-spacing: .08em; margin: 0; }
  #printView .p-caller { margin: 18px 4px; }
  #printView table { width: 100%; border-collapse: collapse; }
  #printView td { border: 1.5px solid var(--line); padding: 12px; vertical-align: top; font-size: 14px; }
  #printView td:first-child { width: 32%; font-family: Arial, sans-serif; font-weight: 600; }
  #printView .pn { display: grid; grid-template-columns: repeat(3, 1fr); }
  #printView .pn span { display: block; font-size: 11px; color: #555; }
  #printView .p-meta { font-size: 11px; color: #555; margin-top: 10px; }
}
