/*
  VOICE  : 落ち着いた道具。編みながら片手で使える、はっきりした数字
  IDEA   : 日本の編み図用紙（方眼）。結果は編み図に書き込む形で見せる
  PICTURE: 結果欄は方眼の紙。割り出しは階段状の編み地の線、ゲージは10cm四方の試し編み
  COLOUR : 白と藍（主）、方眼の淡い青（補助）、茜（強調は結果の数字だけ）
  TYPE   : 端末の日本語ゴシック。数字は等幅の数字（tabular-nums）
  LAYOUT : 1カラム、最大760px。入力 → 結果 → 説明の順。600px以下は全幅
*/
:root {
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #0f1626);
  --paper: light-dark(#f5f8fc, #152038);
  --grid: light-dark(#dde6f2, #22325a);
  --ink: light-dark(#1b2333, #e8edf6);
  --muted: light-dark(#566176, #a6b1c7);
  --indigo: light-dark(#23407a, #9db9f2);
  --band: light-dark(#23407a, #13244a);
  --accent: light-dark(#b8392a, #ff9580);
  --line: light-dark(#d3dae6, #2c3a5e);
  --field: light-dark(#ffffff, #0c1322);
  --focus: light-dark(#2f6fe0, #8fb4ff);
  --radius: 10px;
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

* { box-sizing: border-box; min-width: 0; }
html { scroll-padding-top: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.75 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic', Meiryo, system-ui, sans-serif;
  overflow-x: clip;
}
a { color: var(--indigo); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ヘッダー・フッター */
.site-header { background: var(--band); color: #fff; }
.site-header .inner, .site-footer .inner, main {
  max-width: 760px; margin: 0 auto; padding-inline: max(4vw, 16px);
}
.site-header .inner { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px; padding-block: 12px; }
.site-name { color: #fff; font-weight: 700; font-size: 18px; text-decoration: none; letter-spacing: 0.02em; }
.site-nav { display: flex; flex-wrap: wrap; gap: 0 16px; font-size: 14px; }
.site-nav a { color: #dfe8fb; text-decoration: none; padding-block: 6px; }
.site-nav a[aria-current='page'] { color: #fff; border-bottom: 2px solid #fff; }
.site-footer { margin-top: 64px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.site-footer .inner { padding-block: 24px 40px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-bottom: 8px; }

/* 見出しと本文 */
main { padding-top: 20px; }
.breadcrumb { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.breadcrumb a { color: var(--muted); }
h1 { font-size: clamp(26px, 5vw, 34px); line-height: 1.3; margin: 0 0 8px; text-wrap: balance; }
h2 { font-size: 22px; line-height: 1.4; margin: 48px 0 12px; padding-bottom: 6px; border-bottom: 2px solid var(--grid); }
h3 { font-size: 17px; margin: 28px 0 8px; }
.lead { color: var(--muted); margin: 0 0 20px; }
p, li { max-width: 70ch; }
.note { font-size: 14px; color: var(--muted); }

/* 計算カード */
.tool { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); margin: 0 0 20px; overflow: hidden; }
.tool > .tool-head { padding: 14px 16px 0; }
.tool-head h2 { margin: 0; padding: 0; border: 0; font-size: 18px; }
.tool-head p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); gap: 12px 14px; padding: 14px 16px; }
.field label, .field .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.field .unit-wrap { display: flex; align-items: center; gap: 6px; }
.field .unit { font-size: 14px; color: var(--muted); white-space: nowrap; }
input[type='number'], input[type='text'], select {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--field); border: 1px solid var(--line); border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
input[type='number'] { text-align: right; }
input:focus, select:focus { border-color: var(--focus); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 14px; border: 0; margin: 0; }
.choices legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 4px; float: left; width: 100%; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 6px 14px; border: 1px solid var(--line);
  border-radius: 999px; font-size: 14px; background: var(--field); cursor: pointer;
}
.choice input:checked + span { background: var(--indigo); color: var(--bg); border-color: var(--indigo); font-weight: 600; }
.choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; padding: 0 16px 14px; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--indigo); }

/* 結果欄：方眼の紙 */
.result {
  padding: 16px; border-top: 1px solid var(--line);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 16px 16px;
  font-variant-numeric: tabular-nums;
}
.result .big { font-size: clamp(28px, 7vw, 40px); font-weight: 700; color: var(--accent); line-height: 1.2; }
.result .big small { font-size: 16px; color: var(--ink); font-weight: 600; margin-left: 4px; }
.result .sub { margin: 4px 0 0; font-size: 15px; }
.result .rows { display: grid; gap: 6px 16px; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.result .item { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.result .item .k { font-size: 13px; color: var(--muted); }
.result .item .v { font-size: 22px; font-weight: 700; }
.result .item .v.accent { color: var(--accent); }
.result .error { color: var(--accent); font-weight: 600; margin: 0; }
.result ul { margin: 8px 0 0; padding-left: 1.2em; }

/* 割り出し：編み図の表記 */
.notation-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; align-items: center; }
.notation { margin: 0; padding: 12px 16px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; list-style: none; }
.notation li { font-size: clamp(24px, 6vw, 32px); font-weight: 700; line-height: 1.5; color: var(--accent); letter-spacing: 0.04em; }
.notation li.flat { color: var(--ink); font-size: 20px; }
.notation-caption { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.slope { width: 100%; height: auto; display: block; }
.slope .edge { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.slope .fabric { fill: var(--grid); opacity: 0.6; }
.slope .tick { stroke: var(--line); }
.slope text { fill: var(--muted); font-size: 11px; }
.slope text.lab { fill: var(--ink); font-size: 12px; font-weight: 700; }
.seq { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 0; padding: 0; list-style: none; }
.seq li { min-width: 36px; text-align: center; padding: 2px 6px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; }
.seq li.act { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 700; }

/* ゲージ：10cm四方 */
.swatch-wrap { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; align-items: center; padding: 0 16px 14px; }
.swatch { width: 120px; height: 120px; display: block; }
.swatch .bg { fill: var(--paper); stroke: none; }
.swatch .frame { fill: none; stroke: var(--indigo); stroke-width: 2; }
.swatch line { stroke: var(--grid); stroke-width: 1; }
.swatch text { fill: var(--muted); font-size: 10px; }

/* 表 */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 15px; font-variant-numeric: tabular-nums; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
th { font-size: 14px; color: var(--muted); font-weight: 600; background: var(--paper); }
td.num, th.num { text-align: right; white-space: nowrap; }

/* 説明・FAQ */
.formula { background: var(--paper); border-left: 4px solid var(--indigo); padding: 10px 14px; border-radius: 0 8px 8px 0; font-variant-numeric: tabular-nums; }
details { border-bottom: 1px solid var(--line); padding: 10px 0; }
summary { cursor: pointer; font-weight: 600; min-height: 32px; }
details p { margin: 8px 0 0; }

/* トップページ */
.hero { padding: 8px 0 8px; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); margin-top: 16px; }
.card { display: block; text-decoration: none; color: inherit; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: var(--bg); }
.card:hover { border-color: var(--indigo); }
.card .t { font-weight: 700; font-size: 18px; color: var(--indigo); }
.card .d { font-size: 14px; color: var(--muted); margin-top: 4px; }
.card .ex { margin-top: 10px; font-size: 22px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.privacy-badge { display: inline-block; margin-top: 8px; font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; }

@media (max-width: 600px) {
  .notation-wrap { grid-template-columns: 1fr; }
  .swatch-wrap { grid-template-columns: 96px minmax(0, 1fr); }
  .swatch { width: 96px; height: 96px; }
  h2 { font-size: 20px; }
}
@media (prefers-reduced-motion: no-preference) {
  .result .big, .notation li { transition: color 0.2s; }
}

/* ボタン・余白 */
.note.pad { padding: 0 16px 14px; margin: 0; }
button { font: inherit; }
.reset, .btn {
  min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--field); color: var(--ink); cursor: pointer; font-size: 15px;
}
.reset:hover, .btn:hover { border-color: var(--indigo); }
.btn.primary { background: var(--indigo); color: var(--bg); border-color: var(--indigo); font-weight: 600; }
.copy-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 0; border: 0; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.parts { display: grid; gap: 8px; padding: 0 16px 14px; }
.part { display: grid; grid-template-columns: 4.5em repeat(3, minmax(0, 1fr)); gap: 8px; align-items: end; }
.part .name { font-size: 14px; font-weight: 600; padding-bottom: 10px; }
.part label { font-size: 12px; color: var(--muted); display: block; }
.match-table td:first-child { white-space: nowrap; }
.diff { font-size: 13px; color: var(--muted); }
.result table { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.nw { white-space: nowrap; }
/* 段数カウンター */
.counter-main { display: grid; grid-template-columns: 1fr minmax(0, 1.4fr) 1fr; gap: 10px; align-items: center; padding: 14px 16px; }
.counter-main .count { text-align: center; }
.counter-main .count input { width: 100%; text-align: center; font-size: clamp(44px, 14vw, 72px); font-weight: 700; color: var(--accent); border: 0; background: transparent; font-variant-numeric: tabular-nums; padding: 0; }
.counter-main .count .label { font-size: 13px; color: var(--muted); }
.counter-btn { min-height: 88px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font-size: 32px; font-weight: 700; cursor: pointer; touch-action: manipulation; }
.counter-btn.plus { background: var(--indigo); color: var(--bg); border-color: var(--indigo); font-size: 40px; }
.counter-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.result .flag { display: inline-block; background: var(--accent); color: var(--bg); font-weight: 700; border-radius: 6px; padding: 2px 10px; margin: 0 0 6px; }
.site-footer .footer-tools { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.footer-tools a[aria-current='page'] { font-weight: 700; color: var(--ink); }
