/* 配色: 帳簿の紙・墨・青磁・朱。負数（△）だけが朱を使う */
:root {
  color-scheme: light dark;
  --bg: #f1f3ee;
  --surface: #fbfcf9;
  --text: #1b2226;
  --muted: #4f5b5f;
  --border: #b9c4bd;
  --rule: #dfe5df;
  --accent: #2b6b5e;
  --accent-soft: #e1ece8;
  --on-accent: #ffffff;
  --neg: #b8322a;
  --font: "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI",
    "Meiryo", "Noto Sans JP", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191b;
    --surface: #1b2124;
    --text: #e7ece9;
    --muted: #a2aeaa;
    --border: #3a4744;
    --rule: #2a3330;
    --accent: #6fc1ad;
    --accent-soft: #1e2e2a;
    --on-accent: #0d1f1a;
    --neg: #f08a80;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- ヘッダー・フッター ---- */
.site-header {
  display: flex; flex-wrap: wrap; gap: 0 24px; align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.logo { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; padding: 8px 0; }
.logo span { color: var(--accent); }
.site-header nav a, .site-footer nav a {
  display: inline-block; padding: 10px 8px;
  color: var(--muted); text-decoration: none; font-size: .95rem;
}
.site-header nav a:hover, .site-footer nav a:hover { color: var(--accent); }
/* 上の基本ルールより後ろに置く（同じ詳細度なので順序で上書きする） */
@media (max-width: 639px) {
  .site-header { position: static; }
  /* 4リンクが1行に収まるよう詰める（高さは40px以上を維持） */
  .site-header nav { width: 100%; display: flex; justify-content: space-between; }
  .site-header nav a { padding: 10px 4px; font-size: .85rem; white-space: nowrap; }
}
.site-footer {
  border-top: 1px solid var(--border); padding: 24px 20px; text-align: center;
  color: var(--muted); font-size: .9rem;
}

/* ---- ページ本体 ---- */
main { max-width: 880px; margin: 0 auto; padding: 24px 16px 64px; }
section[id] { scroll-margin-top: 72px; }
.hero h1 { font-size: clamp(1.5rem, 4.5vw, 2.2rem); line-height: 1.35; margin: 16px 0 8px; }
.lead { color: var(--muted); margin: 0 0 16px; max-width: 40em; }
.settings { margin: 0 0 20px; font-size: .9rem; color: var(--muted); }
.settings select {
  width: auto; padding: 6px 8px; font-size: .9rem; margin-left: 8px;
}

/* 副次セクション（履歴・早見表・FAQ など）: 面を持たず、上罫線だけ */
.card { margin: 0 0 24px; padding: 20px 0 4px; border-top: 1px solid var(--border); }
.card h2 { margin-top: 0; font-size: 1.25rem; }
.card p { max-width: 42em; }

/* 主役のパネル（変換ツール）: 唯一の「面」 */
.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 32px;
}

/* ---- フォーム ---- */
.input-row { display: flex; flex-wrap: wrap; gap: 16px; }
.input-wrap { flex: 1 1 320px; }
.unit-wrap { flex: 0 1 220px; }
label span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
input[type="text"], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1.05rem;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
input[type="text"]:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { font-variant-numeric: tabular-nums; font-size: .95rem; margin-top: 16px; }
.examples { margin: 12px 0 4px; color: var(--muted); font-size: .9rem; }
.examples button {
  font-family: inherit;
  border: 1px solid var(--border); background: var(--accent-soft); color: var(--text);
  border-radius: 4px; padding: 4px 12px; margin: 2px; cursor: pointer; font-size: .9rem;
}
.examples button:hover { border-color: var(--accent); }
.note { margin: 8px 0 0; font-size: .85rem; color: var(--muted); }

/* ---- 結果表示 ---- */
.main-result { padding: 16px 0 8px; }
.main-yen {
  font-size: clamp(1.8rem, 6vw, 3rem); font-weight: 700; line-height: 1.3;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.neg { color: var(--neg); }
.sub-results { color: var(--muted); display: flex; gap: 4px 20px; flex-wrap: wrap; margin-top: 4px; }

/* 位取り（兆・億・万・円）。縦罫は4桁ごとの区切りを表す */
.ledger { width: 100%; margin-top: 16px; border-collapse: collapse; table-layout: fixed;
  border-top: 2px solid var(--text); border-bottom: 1px solid var(--border); }
.ledger th, .ledger td {
  text-align: right; padding: 4px 12px; font-variant-numeric: tabular-nums;
}
.ledger th { font-size: .85rem; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--rule); }
.ledger td { font-size: clamp(1.15rem, 4.2vw, 1.7rem); font-weight: 600; overflow-wrap: anywhere; }
.ledger th + th, .ledger td + td { border-left: 1px solid var(--rule); }
.ledger td.zero { color: var(--muted); font-weight: 400; opacity: .55; }

.result-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0; }
.result-actions button {
  font-family: inherit;
  background: var(--accent); color: var(--on-accent);
  border: 1px solid var(--accent); border-radius: 6px;
  padding: 10px 18px; font-size: .95rem; cursor: pointer;
}
.result-actions button:hover { opacity: .88; }
.result-actions button.secondary { background: transparent; color: var(--accent); }
.result-actions button.secondary:hover { background: var(--accent-soft); opacity: 1; }

/* ---- 表 ---- */
.unit-table { width: 100%; border-collapse: collapse; }
.unit-table th, .unit-table td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px; text-align: left;
}
.unit-table th { font-weight: 600; color: var(--muted); font-size: .9rem; }
.unit-table td:nth-child(2) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.unit-table th:nth-child(2) { text-align: right; }
.unit-table.ref td:nth-child(2), .unit-table.ref th:nth-child(2) { text-align: left; font-weight: 400; }
.unit-table tbody tr[data-copy] { cursor: pointer; }
.unit-table tbody tr[data-copy]:hover { background: var(--accent-soft); }
/* 小数点の位置を行ごとにそろえる */
.n-frac { display: inline-block; min-width: calc(var(--frac, 0) * 1ch); text-align: left; }
.unit-table td.action { width: 1%; white-space: nowrap; text-align: right; }
.copy-mark {
  font: inherit; font-size: .8rem; background: none; border: 0; color: var(--muted);
  cursor: pointer; padding: 2px 6px; opacity: 0;
}
tr:hover .copy-mark, .copy-mark:focus-visible { opacity: 1; }
@media (hover: none) { .copy-mark { opacity: 1; } }
.hint { color: var(--muted); font-size: .85rem; }
.error { color: var(--neg); }
.table-scroll { overflow-x: auto; }

/* ---- 履歴・FAQ ---- */
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li { border-bottom: 1px solid var(--border); }
.history-list li > .hint { display: block; padding: 8px 2px; }
.history-item {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  width: 100%; padding: 10px 2px; text-align: left;
  font: inherit; color: inherit; background: none; border: 0; cursor: pointer;
}
.history-item:hover { background: var(--accent-soft); }
.history-list time { color: var(--muted); font-size: .85rem; }
details { border-bottom: 1px solid var(--border); padding: 10px 2px; }
summary { cursor: pointer; font-weight: 600; }

/* ---- トースト（操作への応答なので表示だけ動かす） ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translate(-50%, 8px);
  background: var(--text); color: var(--bg);
  padding: 10px 22px; border-radius: 6px; font-size: .95rem; z-index: 20;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast:empty { display: none; }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
