/* 税ピタ。色・書体・部品は docs/design.md 0-3。
   1画面目（375×667）の縦の割り付け: ヘッダー44 + 上8 + h1 30 + 8 + 計算のしかた44 + 8 + ラベル20 + 4 + 入力欄52 = 218（230以下）
   → 一文 6+20 → カード 8 + 枠1 + 余白16 → 主の行 ラベル16 + 数字42 = 327（330以下）。8%カードの下端は 558、逆算のときは 658（667以内） */

:root {
  color-scheme: light dark;
  --bg: #F2F4F3;
  --surface: #FFFFFF;
  --ink: #16201C;
  --ink-2: #56625C;
  --rule: #D9DFDC;
  --accent: #0F7B5F;
  --accent-weak: #E3F2EC;
  --on-accent: #FFFFFF;
  --warn-ink: #7A4F00;
  --warn-bg: #FFF3D6;
  --danger: #B3261E;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  --font-num: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  --fade: 150ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1513;
    --surface: #17201C;
    --ink: #E8EEEB;
    --ink-2: #A3B0AA;
    --rule: #2A3530;
    --accent: #4FC9A4;
    --accent-weak: #173A30;
    --on-accent: #0F1513;
    --warn-ink: #F2C46B;
    --warn-bg: #3A2E12;
    --danger: #F2827A;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.8 var(--font);
  overflow-wrap: anywhere;
}

a { color: var(--accent); text-underline-offset: 0.2em; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button, input { font: inherit; color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* 括弧の中など、途中で折り返したくない語句。320px 幅の h1 でも1行に収まる長さだけに使う */
.nowrap { white-space: nowrap; }

/* アイコン（インライン SVG。コピー・チェック・×） */
.copy svg, .field__clear svg, .line__del svg {
  display: block;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.copy .i-check, .field__clear svg, .line__del svg { stroke-width: 2; }

/* ---------- ヘッダー ---------- */
.site-header {
  height: 44px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.site-header__in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 712px;
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 43px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}
.logo__mark {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 16px;
  font-weight: 700;
}
.site-header__link {
  display: inline-flex;
  align-items: center;
  min-height: 43px;
  padding: 0 2px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.3;
}

/* ---------- 本体 ---------- */
.main { padding: 8px 16px 48px; }
.tool { max-width: 640px; margin: 0 auto; }

.page-title {
  margin: 0;
  font-size: 24px;
  line-height: 30px;
  font-weight: 700;
}

/* ---------- ラジオのセグメント（計算のしかた・端数・税率） ---------- */
.choice { min-width: 0; margin: 8px 0 0; padding: 0; border: 0; }
.choice__legend {
  padding: 0 0 4px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 20px;
}
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
}
.seg__item { position: relative; display: block; }
.seg__item input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.seg__item span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 8px;
  font-size: 15px;
  line-height: 1.3;
  text-align: center;
  transition: background-color var(--fade), color var(--fade);
}
.seg__item + .seg__item span { border-left: 1px solid var(--rule); }
.seg__item input:checked + span {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}
.seg__item input:focus-visible + span {
  box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 4px var(--surface);
}

/* ---------- 入力欄 ---------- */
.field { margin-top: 8px; }
.field__label {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 20px;
}
.field__box {
  display: flex;
  align-items: center;
  height: 52px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
  transition: border-color var(--fade), box-shadow var(--fade);
}
.field__box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.field__box.is-invalid { border-color: var(--danger); }
.field__input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 4px 0 12px;
  border: 0;
  background: transparent;
  font-family: var(--font-num);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.field__input:focus, .field__input:focus-visible { outline: none; }
.field__unit { padding-right: 12px; color: var(--ink-2); font-size: 18px; line-height: 1; }
.field__unit:has(+ .field__clear) { padding-right: 0; }
.field__clear {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  margin: 0 3px 0 4px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}
.field__box.is-empty .field__clear { visibility: hidden; }

.status {
  min-height: 20px;
  margin: 6px 0 0;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 20px;
}
.status.is-error { color: var(--danger); }

/* ---------- 結果のカード ---------- */
.card {
  margin-top: 8px;
  padding: 16px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
}
.card__head { margin: 0 0 4px; font-size: 14px; font-weight: 700; line-height: 20px; }

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 8px;
}
.row + .row { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--rule); }
.row__body { min-width: 0; container-type: inline-size; }
.row__label { display: block; color: var(--ink-2); font-size: 13px; line-height: 16px; }
.row__label .tag { margin-right: 6px; color: var(--ink); font-weight: 700; }
.row__value { display: block; white-space: nowrap; }
.yen { margin-left: 2px; color: var(--ink-2); font-weight: 500; }

/* 数字の大きさ。--max まで大きくし、欄の幅に収まらない桁数なら小さくする。
   --w は桁数（data-len、カンマを含む文字数）ごとの字幅の合計を em で表したもの（数字 0.70em・カンマ 0.35em で見積もる。
   SF の太字の実測は数字 0.69em 以下・カンマ 0.35em 以下）。--unit-w は後ろの「円」の幅 */
.fit { --w: 11.9; font-size: var(--max); }
@supports (width: 1cqi) {
  .fit { font-size: min(var(--max), calc((100cqi - var(--unit-w)) / var(--w))); }
}
.fit[data-len="1"] { --w: 1; }
.fit[data-len="2"] { --w: 1.4; }
.fit[data-len="3"] { --w: 2.1; }
.fit[data-len="4"], .fit[data-len="5"] { --w: 3.15; }
.fit[data-len="6"] { --w: 3.85; }
.fit[data-len="7"] { --w: 4.55; }
.fit[data-len="8"], .fit[data-len="9"] { --w: 5.6; }
.fit[data-len="10"] { --w: 6.3; }
.fit[data-len="11"] { --w: 7; }
.fit[data-len="12"], .fit[data-len="13"] { --w: 8.05; }
.fit[data-len="14"] { --w: 8.75; }
.fit[data-len="15"] { --w: 9.45; }
.fit[data-len="16"], .fit[data-len="17"] { --w: 10.5; }
.fit[data-len="18"] { --w: 11.2; }

/* 主の行（10%・請求書の合計・食品の1%）、2番目のカードの主の行、消費税額などの行 */
.row--lead .row__value { height: 42px; line-height: 42px; }
.row--lead .fit { --max: 40px; --unit-w: 22px; font-weight: 700; }
.row--lead .yen { font-size: 18px; }

.row--second .row__value { height: 34px; line-height: 34px; }
.row--second .fit { --max: 28px; --unit-w: 20px; font-weight: 700; }
.row--second .yen { font-size: 16px; }

.row--sub .row__value { height: 22px; line-height: 22px; }
.row--sub .fit { --max: 16px; --unit-w: 18px; font-weight: 500; }
.row--sub .yen { font-size: 14px; }

/* ---------- コピーボタン ---------- */
.copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 84px;
  height: 44px;
  padding: 0 8px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--fade), color var(--fade);
}
.copy:disabled { color: var(--ink-2); opacity: 0.45; cursor: default; }
.copy__icon, .copy__text { display: grid; place-items: center; }
.copy__icon > *, .copy__text > * { grid-area: 1 / 1; }
.copy__done, .copy__fail { font-size: 11px; line-height: 13px; text-align: center; }
.copy .i-check, .copy .copy__done, .copy .copy__fail { visibility: hidden; }
.copy.is-copied { border-color: var(--accent); color: var(--accent); }
.copy.is-copied .i-copy, .copy.is-copied .copy__idle { visibility: hidden; }
.copy.is-copied .i-check, .copy.is-copied .copy__done { visibility: visible; }
.copy.is-failed { border-color: var(--danger); color: var(--danger); }
.copy.is-failed .copy__icon, .copy.is-failed .copy__idle { visibility: hidden; }
.copy.is-failed .copy__fail { visibility: visible; }
.copy--wide { width: 100%; margin-top: 12px; }
.copy--wide .copy__done, .copy--wide .copy__fail { font-size: 13px; line-height: 1; }

/* ---------- 逆算の検算 ---------- */
.check {
  min-height: 42px;
  margin: 8px 0 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 21px;
}
[data-mode="excluded"] .check { display: none; }
/* 狭い画面では「1円ずれ」の文が3行になるので、3行分を確保してカードの高さを変えない */
@media (max-width: 359px) { .check { min-height: 63px; } }
.badge {
  display: inline-block;
  margin: 1px 6px 0 0;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 19px;
  vertical-align: top;
}
.badge--ok { background: var(--accent-weak); color: var(--accent); }
.badge--warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- 旧税率・関連リンク・注記 ---------- */
.old { margin-top: 16px; }
.old summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}
.note { margin: 8px 0 0; color: var(--ink-2); font-size: 13px; line-height: 1.7; }
.related { margin-top: 16px; font-size: 15px; line-height: 1.6; }
.related ul { margin: 0; padding: 0; list-style: none; }
.related a { display: inline-flex; align-items: center; min-height: 44px; }
.lead-note { margin: 8px 0 0; color: var(--ink-2); font-size: 14px; line-height: 1.7; }

/* ---------- 請求書の明細 ---------- */
.lines { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.line {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto 44px;
  grid-template-areas: "no box rate del";
  align-items: center;
  column-gap: 6px;
}
.line__no { grid-area: no; color: var(--ink-2); font-size: 13px; text-align: right; }
.line .field__box { grid-area: box; }
.line__rate { grid-area: rate; min-width: 0; margin: 0; padding: 0; border: 0; }
.line__rate .seg__item span { min-width: 52px; min-height: 42px; }
.line__del {
  grid-area: del;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}
.line__del:disabled { opacity: 0.35; cursor: default; }
@media (max-width: 439px) {
  .line {
    grid-template-columns: 24px minmax(0, 1fr) 44px;
    grid-template-areas: "no box del" ". rate .";
    row-gap: 4px;
  }
}
.add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  margin-top: 8px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  font-size: 15px;
  cursor: pointer;
}
.add:disabled { opacity: 0.45; cursor: default; }
.diffs { margin: 8px 0 0; padding: 0; list-style: none; color: var(--ink-2); font-size: 13px; line-height: 1.6; }
.diffs:empty { display: none; }

/* ---------- 解説 ---------- */
.explain { max-width: 680px; margin: 48px auto 0; }
.explain h2 { margin: 40px 0 0; font-size: 20px; line-height: 1.5; }
.explain h3 { margin: 28px 0 0; font-size: 17px; line-height: 1.5; }
.explain p, .explain ul, .explain ol, .explain table { margin: 12px 0 0; }
.explain table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.6; }
.explain th, .explain td { padding: 8px; border: 1px solid var(--rule); text-align: left; vertical-align: top; }
.explain td.num { text-align: right; white-space: nowrap; }
.explain code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.92em; }
.page { max-width: 680px; margin: 0 auto; }
.page .explain { margin-top: 16px; }
.crumbs { margin-bottom: 4px; }
.crumbs ol { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; color: var(--ink-2); font-size: 13px; line-height: 1.6; }
.crumbs li + li::before { content: "›"; margin-right: 4px; }
.meta { margin: 8px 0 0; color: var(--ink-2); font-size: 13px; }
.facts { margin: 12px 0 0; }
.facts div { display: grid; grid-template-columns: 7em minmax(0, 1fr); gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; }

/* ---------- フッター ---------- */
.site-footer { margin-top: 32px; border-top: 1px solid var(--rule); background: var(--surface); }
.site-footer__in { max-width: 712px; margin: 0 auto; padding: 16px 16px 32px; }
.site-footer__links { display: flex; flex-wrap: wrap; gap: 0 16px; margin: 0; padding: 0; list-style: none; font-size: 14px; line-height: 1.5; }
.site-footer__links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); }
.site-footer__copy { margin: 8px 0 0; color: var(--ink-2); font-size: 13px; }

/* ---------- PC ---------- */
@media (min-width: 768px) {
  .page-title { font-size: 28px; line-height: 36px; }
  .row--lead .row__value { height: 52px; line-height: 52px; }
  .row--lead .fit { --max: 48px; }
  .row--second .row__value { height: 38px; line-height: 38px; }
  .row--second .fit { --max: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
