:root {
  --bg: #f3f0e9;
  --paper: rgba(255, 255, 250, .74);
  --ink: #282a29;
  --muted: #6e716f;
  --line: #d8d3c8;
  --teal: #14b8a6;
  --teal-dark: #0e7f73;
  --teal-soft: rgba(20, 184, 166, .10);
  --danger: #9a4b4b;
  --warn: #a8641f;
  --shadow: 0 18px 60px rgba(35, 32, 28, .09);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 0%, rgba(20, 184, 166, .12), transparent 32rem),
    linear-gradient(180deg, #faf8f1 0%, var(--bg) 100%);
  background-color: var(--bg);
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  font-size: 16px;
}

button, input, textarea, select { font: inherit; font-size: 16px; }

[hidden] { display: none !important; }

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 28px 16px calc(48px + env(safe-area-inset-bottom));
}

.hero { padding: 18px 2px 14px; }
.eyebrow {
  margin: 0 0 8px;
  font: 12px/1.4 var(--mono);
  letter-spacing: .18em;
  color: var(--teal-dark);
}
.ver { color: var(--muted); letter-spacing: .08em; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(30px, 9vw, 48px); letter-spacing: .04em; font-weight: 500; }
h2 { margin: 0; font-size: 14px; letter-spacing: .16em; font-family: var(--mono); font-weight: 600; }
.lead { color: var(--muted); line-height: 1.8; margin-bottom: 0; }

.panel {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.summary-head {
  list-style: none;
  cursor: pointer;
  margin-bottom: 0;
}
.summary-head::-webkit-details-marker { display: none; }
.summary-head h2::before {
  content: "+ ";
  color: var(--teal-dark);
}
details[open] > .summary-head { margin-bottom: 14px; }
details[open] > .summary-head h2::before { content: "− "; }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 6px rgba(20, 184, 166, .12);
}
.status-dot.busy { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .25; }
}

textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .62);
  color: var(--ink);
  outline: none;
}
textarea { padding: 14px; resize: vertical; line-height: 1.8; min-height: 130px; }
input, select { padding: 12px; min-height: 46px; }
textarea:focus, input:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, .12); }

.field-label { margin-top: 14px; margin-bottom: 7px; color: var(--muted); font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .55);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.chip[aria-checked="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.controls-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }

.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.button-row.tight { margin-top: 10px; }
button, .file-btn {
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  cursor: pointer;
  color: var(--ink);
  background: #ece6da;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button:active, .file-btn:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--teal); color: #fff; }
.primary.wide { flex: 1; }
.ghost { background: #ece6da; }
.danger { background: #f2dedc; color: var(--danger); }
.small { padding: 7px 12px; font-size: 13px; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; font-size: 16px; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.result-status {
  line-height: 1.8;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .46);
  border: 1px dashed var(--line);
}
.result-status.empty { color: var(--muted); }
.result-status.error { white-space: pre-wrap; word-break: break-word; color: var(--danger); border-color: #e3c4c0; background: #fbf1ef; }
.result-status.done { display: none; }

.facts-box {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--teal-soft);
  font-size: 13px;
  line-height: 1.7;
}
.facts-box .facts-title { font: 11px/1.4 var(--mono); letter-spacing: .14em; color: var(--teal-dark); margin-bottom: 4px; }
.facts-box ul { margin: 0; padding-left: 1.2em; }

.candidates { display: grid; gap: 14px; }

.candidate {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, .55);
}
.candidate-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.candidate-label { font: 12px/1.4 var(--mono); letter-spacing: .14em; color: var(--teal-dark); }
.candidate-label b { font-family: ui-serif, "Hiragino Mincho ProN", serif; letter-spacing: .04em; color: var(--ink); font-weight: 600; margin-left: 6px; }
.count { font: 12px/1.4 var(--mono); color: var(--muted); white-space: nowrap; }
.count.over { color: var(--danger); font-weight: 700; }

.candidate textarea.post {
  min-height: 120px;
  background: rgba(255, 255, 255, .8);
  line-height: 1.85;
  resize: none;
  overflow: hidden;
}

.candidate .button-row { margin-top: 10px; }

.candidate details.memo { margin-top: 10px; font-size: 13px; color: var(--muted); }
.candidate details.memo summary { cursor: pointer; font: 12px/1.6 var(--mono); letter-spacing: .1em; }
.candidate details.memo div { margin-top: 6px; line-height: 1.7; }

.refine-row { display: none; gap: 8px; margin-top: 10px; }
.refine-row.open { display: flex; }
.refine-row input { flex: 1; }

.coined-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.coined-box .coined-title { font: 12px/1.4 var(--mono); letter-spacing: .14em; color: var(--teal-dark); margin-bottom: 8px; }
.coined-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .5);
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.6;
}
.coined-item .arrow { color: var(--muted); margin: 0 4px; }

.small-note { color: var(--muted); font-size: 12px; line-height: 1.7; }
.message { margin: 10px 0 0; font-size: 13px; color: var(--teal-dark); min-height: 1em; }
.message.error { color: var(--danger); }
.backup-note { margin: 8px 0 0; color: var(--warn); }

.lock-form { display: flex; gap: 10px; }
.lock-form input { flex: 1; }

.lexicon-list { display: grid; gap: 10px; margin-top: 12px; }
.lexicon-list.empty { color: var(--muted); font-size: 14px; }
.lexicon-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px;
  background: rgba(255, 255, 255, .48);
}
.card-title { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 8px; }
.term { font-weight: 700; }
.card-meta { color: var(--muted); font-size: 13px; line-height: 1.7; word-break: break-all; }
.lexicon-form { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; margin: 12px 0; }
.lexicon-form button { grid-column: span 2; }

.setting-row { margin-bottom: 4px; }

.footer { padding: 28px 0 0; text-align: center; color: var(--muted); font: 12px/1.6 var(--mono); letter-spacing: .18em; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 10;
}
.toast.show { opacity: .92; transform: translate(-50%, 0); }

@media (max-width: 700px) {
  .app-shell { padding-inline: 16px; }
  .panel { padding: 15px; border-radius: 18px; }
  .lexicon-form { grid-template-columns: 1fr; }
  .lexicon-form button { grid-column: auto; }
}
