/* 骨格: 本の目次（1行に1語・右端に事実の件数）。色: DESIGN.md §3「生成り」。語と見出しだけ明朝 */
:root {
  --bg: #F4F0E8;
  --surface: #FFFDF8;
  --line: #E4DDD0;
  --text: #2B2620;
  --sub: #6E665A;
  --accent: #A14B26;
  --weak: #F6E6DC;
  --on: #FFFFFF;
  --sans: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --serif: "Hiragino Mincho ProN", "Noto Serif JP", "Yu Mincho", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.75;
  letter-spacing: .02em;
}
button, input { font: inherit; letter-spacing: inherit; color: inherit; }
[hidden] { display: none !important; }

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

/* 上: 名前と入力欄 */
.brand { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; color: var(--sub); }
.brand b { font-family: var(--serif); font-size: 16px; color: var(--text); letter-spacing: .08em; }
.entry { margin-top: 16px; display: flex; align-items: center; border-bottom: 2px solid var(--text); }
.entry input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  font-family: var(--serif); font-size: 20px; line-height: 1.5; padding: 10px 0;
}
.entry input::placeholder { color: var(--sub); }
.entry button {
  border: 0; background: transparent; color: var(--accent); font-size: 22px;
  min-width: 48px; min-height: 48px; cursor: pointer;
}
.entry:focus-within { border-bottom-color: var(--accent); }
.flash { min-height: 1.5em; margin: 8px 0 0; font-size: 14px; color: var(--sub); line-height: 1.5; }

/* 一覧（目次） */
.group { font-family: var(--serif); font-size: 14px; color: var(--sub); margin: 20px 0 4px; }
.item { border-bottom: 1px solid var(--line); }
.line {
  display: flex; align-items: baseline; gap: 12px; width: 100%;
  min-height: 52px; padding: 12px 0; border: 0; background: none; text-align: left; cursor: pointer;
}
.word { flex: 1; font-family: var(--serif); font-size: 18px; line-height: 1.5; overflow-wrap: anywhere; }
.num { font-size: 16px; color: var(--sub); font-variant-numeric: tabular-nums; min-width: 1.5em; text-align: right; white-space: nowrap; }
.num.wait { font-size: 14px; }
.item.open .word { font-weight: 700; }
.item.hit { animation: hit 1.2s ease-out; }
@keyframes hit { from { background: var(--weak); } to { background: transparent; } }

.body { padding: 0 0 16px; }
.facts { margin: 0; padding: 0; list-style: none; counter-reset: f; }
.facts li { position: relative; padding-left: 28px; margin: 0 0 12px; counter-increment: f; }
.facts li::before {
  content: counter(f); position: absolute; left: 0; top: 0;
  color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums;
}
/* Wikipedia へのリンク。右の余白（22px）の最後の行の高さに置き、文の流れに入れない＝行を増やさない */
.facts li { padding-right: 22px; }
.wiki {
  position: absolute; right: -6px; bottom: 1px;
  padding: 6px; color: var(--sub);
}
.wiki svg { display: block; width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.wiki:hover, .wiki:focus-visible { color: var(--accent); }.note { font-size: 14px; line-height: 1.6; color: var(--sub); margin: -4px 0 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-left: 28px; }
.link {
  border: 0; background: none; padding: 8px 0; min-height: 44px; cursor: pointer;
  font-size: 14px; color: var(--accent);
}
.link.quiet { color: var(--sub); }

.cands { list-style: none; margin: 4px 0 8px 28px; padding: 0; border-top: 1px solid var(--line); }
.cands li { border-bottom: 1px solid var(--line); }
.cands button {
  display: block; width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  padding: 10px 0;
}
.cands b { display: block; font-family: var(--serif); font-weight: 400; font-size: 16px; line-height: 1.5; }
.cands span {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  font-size: 14px; color: var(--sub); line-height: 1.5;
}

.empty { color: var(--sub); margin-top: 32px; }

/* ログイン */
.login { margin-top: 32px; }
.login input {
  display: block; width: 100%; padding: 12px; margin: 12px 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 16px;
}
.login button {
  min-height: 48px; padding: 0 24px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--on); font-weight: 700; cursor: pointer;
}
.error { color: var(--accent); font-size: 14px; }

/* PC: 名前と入力欄を左に残す（本の目次の片側固定） */
@media (min-width: 960px) {
  .app {
    max-width: 1040px; display: grid; grid-template-columns: 320px 1fr; gap: 64px;
    padding-top: 48px;
  }
  .side { position: sticky; top: 48px; align-self: start; }
  .login { grid-column: 2; }
}
