/* style.css — 箱の型紙メーカー専用
   色はサイト共通の CSS 変数（--fg / --bg / --card / --muted / --muted-fg / --border / --primary / --accent）を使い、
   ライト・ダークの切り替えに追従する。書体はサイト共通の指定を継承する。 */

.bm-wrap {
  --bm-ink: hsl(var(--fg));
  --bm-ink2: hsl(var(--muted-fg));
  --bm-hair: hsl(var(--border));
  --bm-card: hsl(var(--card));
  --bm-soft: hsl(var(--muted));
  --bm-accent: hsl(var(--primary));
  --bm-input: hsl(var(--primary));      /* 寸法の目安の1行目（内寸＝入力値）の文字色。プリセットの選択中と同じ青 */
  --bm-bad: #d6453d;
  --bm-body: #d9bb8e;
  --bm-lid: #a4b6c8;
  --bm-radius: 10px;
  color: var(--bm-ink);
  font-variant-numeric: tabular-nums;
}
/* 寸法の目安の1行目の青は、ダークでは灰色の枠の上で読みやすい明るい青にする（サイト共通の common/style.css がダークで使っている色） */
.dark .bm-wrap { --bm-bad: #f87171; --bm-input: #60a5fa; }
.bm-wrap [hidden] { display: none !important; }
/* 書体だけを受け継ぐ（:where で詳細度を 0 にし、各部品の文字の大きさの指定を上書きしない） */
.bm-wrap :where(input, button) { font-family: inherit; color: inherit; }
.bm-wrap button { cursor: pointer; }
.bm-wrap button:disabled { cursor: not-allowed; }
.bm-sp { flex: 1; }

/* ---------- タイトル ---------- */
.bm-head { padding: .5rem 0 1.25rem; }
.bm-head h1 {
  font-size: clamp(1.6rem, 3.6vw, 2.25rem); font-weight: 800; letter-spacing: -.01em; line-height: 1.25; margin: 0;
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--accent)));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.bm-copy { margin: .35rem 0 0; font-size: 1.125rem; font-weight: 700; }
.bm-sub { margin: .15rem 0 0; font-size: .9375rem; color: var(--bm-ink2); }
.bm-noscript { padding: 1rem; border: 1px solid var(--bm-bad); border-radius: var(--bm-radius); }

/* ---------- 作業台 ---------- */
.bm-app { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.bm-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.bm-card {
  background: var(--bm-card); border: 1px solid var(--bm-hair); border-radius: var(--bm-radius);
  padding: 18px 18px 16px; min-width: 0;
}
.bm-card-title { font-size: 1rem; font-weight: 700; margin: 0 0 12px; display: flex; align-items: baseline; gap: 8px; }
.bm-card-note { font-size: .75rem; font-weight: 500; color: var(--bm-ink2); }
@media (max-width: 900px) {
  .bm-app { display: flex; flex-direction: column; gap: 16px; }
  .bm-col { display: contents; }
  .bm-view { order: 1; }
  .bm-controls { order: 2; }
  .bm-netcard { order: 3; }
  .bm-output { order: 4; }
  .bm-card { padding: 14px 14px 12px; }
}

/* ---------- 用途プリセット ---------- */
.bm-presets { margin-bottom: 14px; }
.bm-presets-label { display: block; font-size: .75rem; color: var(--bm-ink2); margin-bottom: 6px; }
.bm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.bm-chip {
  border: 1px solid var(--bm-hair); background: var(--bm-card); border-radius: 999px;
  padding: 5px 12px; font-size: .8125rem; line-height: 1.3; transition: border-color .15s, background .15s;
}
.bm-chip:hover { border-color: var(--bm-accent); }
.bm-chip[aria-pressed="true"] { background: var(--bm-accent); border-color: var(--bm-accent); color: #fff; }
.bm-chip:focus-visible { outline: 2px solid var(--bm-accent); outline-offset: 2px; }

/* ---------- 入力欄 ---------- */
.bm-field { padding: 8px 0 6px; border-top: 1px solid var(--bm-hair); }
.bm-field:first-of-type { border-top: 0; }
.bm-field-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bm-field-sub { margin-top: 6px; }
.bm-flabel { font-size: .9375rem; font-weight: 700; }
.bm-flabel-sub { font-size: .8125rem; font-weight: 500; color: var(--bm-ink2); }
.bm-num { display: inline-flex; align-items: baseline; gap: 4px; }
.bm-num input {
  width: 5.2em; text-align: right; font-size: 1.0625rem; font-weight: 700; padding: 4px 8px;
  border: 1px solid var(--bm-hair); border-radius: 6px; background: hsl(var(--bg));
}
.bm-num input:focus { outline: none; border-color: var(--bm-accent); box-shadow: 0 0 0 3px hsl(var(--primary) / .15); }
.bm-num input:disabled { opacity: .55; }
.bm-field.has-error .bm-num input { border-color: var(--bm-bad); box-shadow: 0 0 0 3px rgba(214, 69, 61, .15); }
.bm-unit { font-size: .8125rem; color: var(--bm-ink2); }
.bm-range { width: 100%; margin: 8px 0 2px; accent-color: hsl(var(--primary)); height: 22px; }
.bm-range:disabled { opacity: .45; }
.bm-hint { font-size: .75rem; color: var(--bm-ink2); margin: 2px 0 0; line-height: 1.5; }
.bm-error { font-size: .8125rem; color: var(--bm-bad); margin: 6px 0 0; line-height: 1.55; font-weight: 500; }
.bm-note { font-size: .8125rem; color: var(--bm-ink2); margin: 10px 0 0; line-height: 1.6; }
.bm-status { font-size: .8125rem; color: var(--bm-ink2); margin: 8px 0 0; min-height: 1.2em; }

/* 寸法の目安：見出し（右端に単位）の下に、項目名の列と数値の列を揃えて3行で並べる。1行目（内寸）は入力値なので青。
   行が増えても枠が高くなりすぎないよう、行の高さと行どうしのすき間を詰める */
.bm-outer { margin: 12px 0 0; padding: 10px 12px; background: var(--bm-soft); border-radius: 8px; line-height: 1.35; }
.bm-outer-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 0 0 4px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.bm-outer-unit { font-size: .6875rem; font-weight: 500; color: var(--bm-ink2); }
.bm-outer dl { display: grid; grid-template-columns: max-content 1fr; column-gap: 12px; row-gap: 2px; align-items: baseline; margin: 0; }
.bm-outer dl > div { display: contents; }
.bm-outer dt { font-size: .75rem; color: var(--bm-ink2); white-space: nowrap; }
.bm-outer dd { margin: 0; font-size: .875rem; font-weight: 600; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.bm-outer .bm-outer-in dt, .bm-outer .bm-outer-in dd { color: var(--bm-input); }

.bm-details { margin-top: 12px; border-top: 1px solid var(--bm-hair); padding-top: 10px; }
.bm-details summary { cursor: pointer; font-size: .875rem; font-weight: 600; padding: 4px 0; }
.bm-details summary:focus-visible { outline: 2px solid var(--bm-accent); outline-offset: 2px; border-radius: 4px; }
.bm-details-body { padding-top: 4px; }
.bm-details-body .bm-field:first-child { border-top: 0; }

.bm-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

/* ---------- ボタン ---------- */
.bm-btn-primary {
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border: 0; border-radius: 8px; font-weight: 700; font-size: 1rem; color: #fff;
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--accent)));
  box-shadow: 0 6px 18px -8px hsl(var(--primary) / .6); transition: transform .15s, box-shadow .15s, opacity .15s;
}
.bm-btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 22px -10px hsl(var(--primary) / .7); }
.bm-btn-primary:disabled { opacity: .45; box-shadow: none; }
.bm-btn-primary:focus-visible { outline: 3px solid hsl(var(--primary) / .45); outline-offset: 2px; }
.bm-btn-ghost {
  border: 1px solid var(--bm-hair); background: transparent; border-radius: 6px; padding: 6px 12px; font-size: .8125rem;
}
.bm-btn-ghost:hover { border-color: var(--bm-ink2); }
.bm-btn-small {
  border: 1px solid var(--bm-hair); background: var(--bm-card); border-radius: 6px; padding: 4px 10px; font-size: .75rem; white-space: nowrap;
}
.bm-btn-small:hover { border-color: var(--bm-accent); color: var(--bm-accent); }
.bm-btn-ghost:focus-visible, .bm-btn-small:focus-visible { outline: 2px solid var(--bm-accent); outline-offset: 2px; }

/* 切り替え（ラジオを並べたもの） */
.bm-seg { display: inline-flex; background: var(--bm-soft); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.bm-seg label { position: relative; }
.bm-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.bm-seg span { display: block; padding: 4px 10px; border-radius: 6px; font-size: .8125rem; cursor: pointer; color: var(--bm-ink2); white-space: nowrap; }
.bm-seg input:checked + span { background: var(--bm-card); color: var(--bm-ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.bm-seg input:focus-visible + span { outline: 2px solid var(--bm-accent); outline-offset: 1px; }
.bm-seg input:disabled + span { opacity: .5; cursor: not-allowed; }
.bm-seg-sm span { padding: 3px 9px; font-size: .75rem; }
/* ふたの表示の切り替えに付ける「ふた：」（ラベルとボタンは折り返しても離れない） */
.bm-lidctl { display: inline-flex; align-items: center; gap: 6px; }
.bm-seg-label { font-size: .8125rem; font-weight: 600; color: var(--bm-ink2); white-space: nowrap; }

/* ---------- 3D ---------- */
.bm-view-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.bm-view-head .bm-card-title { margin: 0; }
.bm-stage {
  position: relative; height: 380px; border-radius: 8px; overflow: hidden; touch-action: none;
  background: radial-gradient(120% 90% at 50% 20%, hsl(var(--bg)), hsl(var(--muted)));
  border: 1px solid var(--bm-hair);
}
.bm-stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.bm-stage canvas:active { cursor: grabbing; }
.bm-3d-labels { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.bm-3d-label {
  position: absolute; left: 0; top: 0; white-space: nowrap; font-size: .75rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px; background: hsl(var(--card) / .88); border: 1px solid var(--bm-hair);
  color: var(--bm-ink2); visibility: hidden; transition: background .15s, color .15s;
}
.bm-3d-label.is-active { background: var(--bm-accent); color: #fff; border-color: var(--bm-accent); font-weight: 700; }
.bm-3d-label.is-active::before { content: "▶ "; font-size: .625rem; }
.bm-3d-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; pointer-events: none;
  padding: 8px 14px; border-radius: 8px; background: rgba(15, 15, 20, .72); color: #fff; font-size: .8125rem;
  opacity: 0; transition: opacity .2s; white-space: nowrap;
}
.bm-3d-hint.is-on { opacity: 1; }
/* 「ドラッグで回転」のバッジ：3D 枠の下部中央に重ねる。クリックやドラッグは下の 3D に通す（pointer-events: none）。
   最初の操作で薄くなって消える（is-hidden）。矢印はゆっくり左右に揺らす（動きを減らす設定のときは揺らさない）。
   縦に長い箱では寸法ラベルが枠の下端に来るため、ラベル（z-index 2）より下に置き、重なってもラベルの数値を読めるようにする */
.bm-3d-badge {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 1; pointer-events: none;
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px 6px 11px; border-radius: 999px;
  background: rgba(15, 15, 20, .6); color: #fff; font-size: .8125rem; font-weight: 600; line-height: 1.2; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18); transition: opacity .35s ease, visibility 0s linear .35s;
}
.dark .bm-3d-badge { box-shadow: 0 0 0 1px rgba(255, 255, 255, .14), 0 2px 10px rgba(0, 0, 0, .3); }
.bm-3d-badge.is-hidden { opacity: 0; visibility: hidden; }
.bm-3d-badge-icon { display: block; flex: none; animation: bm-rock 2.4s ease-in-out infinite; }
@keyframes bm-rock { 0%, 100% { transform: rotate(-14deg); } 50% { transform: rotate(14deg); } }
@media (prefers-reduced-motion: reduce) {
  .bm-3d-badge-icon { animation: none; }
}
.bm-fallback {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; margin: 0; font-size: .875rem; color: var(--bm-ink2); line-height: 1.7;
}
.bm-view-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
@media (max-width: 900px) {
  .bm-stage { height: 290px; }
}

/* ---------- 展開図 ---------- */
.bm-netbox {
  position: relative; height: 460px; border: 1px solid var(--bm-hair); border-radius: 8px; overflow: hidden;
  background: hsl(var(--bg));
}
.bm-net { width: 100%; height: 100%; display: block; }
.bm-netinfo { font-size: .8125rem; font-weight: 600; margin: 8px 0 4px; }
@media (max-width: 900px) {
  .bm-netbox { height: 360px; }
}
.bm-net .bm-paper { fill: hsl(var(--card)); stroke: none; }
.bm-net .bm-cut { fill: none; stroke: var(--bm-ink); stroke-width: 1.4px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.bm-net .bm-fold { stroke: var(--bm-ink); stroke-width: 1.1px; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.bm-net .bm-tab { stroke: none; }
.bm-net .bm-hatch-line { stroke: hsl(var(--muted-fg) / .7); stroke-width: .35; }
.bm-net .bm-target { fill: hsl(var(--primary) / .06); stroke: hsl(var(--muted-fg)); stroke-width: 1px; stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; }
.bm-net .bm-label { fill: var(--bm-ink2); text-anchor: middle; }
.bm-net .bm-sym { fill: var(--bm-ink); text-anchor: middle; font-weight: 700; }
.bm-net .bm-sym-target { fill: var(--bm-ink2); }
.bm-net .bm-tile { fill: none; stroke: hsl(var(--primary) / .75); stroke-width: 1.2px; stroke-dasharray: 8 5; vector-effect: non-scaling-stroke; }
.bm-net .bm-strip { fill: hsl(var(--primary) / .08); stroke: none; }
.bm-net .bm-tile-label { fill: hsl(var(--primary)); font-weight: 700; }
.bm-net .bm-dim line { stroke: hsl(var(--muted-fg)); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.bm-net .bm-dim text { fill: hsl(var(--muted-fg)); text-anchor: middle; }
.bm-net .bm-arrow { fill: hsl(var(--muted-fg)); }
.bm-net .bm-dim.is-active line { stroke: hsl(var(--primary)); stroke-width: 2px; }
.bm-net .bm-dim.is-active text { fill: hsl(var(--primary)); font-weight: 700; }

.bm-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 6px; padding: 0 !important; font-size: .75rem; color: var(--bm-ink2); }
.bm-legend li { display: flex; align-items: center; gap: 6px; margin: 0 !important; }
.bm-legend i { display: inline-block; width: 22px; height: 10px; }
.bm-legend .lg-cut { border-top: 2px solid var(--bm-ink); height: 0; }
.bm-legend .lg-fold { border-top: 2px dashed var(--bm-ink); height: 0; }
.bm-legend .lg-tab { background: repeating-linear-gradient(45deg, hsl(var(--muted-fg) / .6) 0 1px, transparent 1px 4px); border: 1px solid hsl(var(--muted-fg) / .5); }
.bm-legend .lg-target { border: 1.5px dotted hsl(var(--muted-fg)); }
.bm-legend .lg-tile { border: 1.5px dashed hsl(var(--primary) / .75); }

/* ---------- 用意するもの・PDF ---------- */
.bm-materials { list-style: none; margin: 0; padding: 0 !important; display: grid; gap: 10px; }
.bm-materials li { display: grid; grid-template-columns: 7.2em minmax(0, 1fr); gap: 10px; align-items: baseline; margin: 0 !important; }
.bm-mk { font-size: .8125rem; color: var(--bm-ink2); line-height: 1.4; }
.bm-mv { font-size: .875rem; line-height: 1.5; min-width: 0; }
.bm-mv b { font-size: 1.0625rem; font-weight: 700; }
.bm-mv small { display: block; font-size: .75rem; color: var(--bm-ink2); }
.bm-mv .bm-fit { color: hsl(var(--primary)); font-weight: 600; }
.bm-tools { font-size: .8125rem; }
.bm-pdf { margin-top: 16px; }
.bm-pdf-note { font-size: .75rem; color: var(--bm-ink2); margin: 8px 0 0; line-height: 1.6; }

/* ---------- 解説・ヘルプ ---------- */
.bm-help { margin-top: 3rem; max-width: 52rem; line-height: 1.85; font-size: .9375rem; }
.bm-help h2 { font-size: 1.25rem; font-weight: 700; margin: 2.25rem 0 .75rem; padding-bottom: .35rem; border-bottom: 1px solid var(--bm-hair); }
.bm-help h2:first-child { margin-top: 0; }
.bm-help h3 { font-size: 1rem; font-weight: 700; margin: 1.25rem 0 .35rem; }
.bm-help p { margin: 0 0 .75rem; }
.bm-help ul, .bm-help ol { margin: 0 0 .75rem; }
.bm-help table { width: 100%; border-collapse: collapse; font-size: .875rem; margin: .5rem 0 0; }
.bm-help th, .bm-help td { border: 1px solid var(--bm-hair); padding: .45rem .6rem; text-align: left; vertical-align: top; }
.bm-help th { background: var(--bm-soft); font-weight: 600; }
.bm-substitute { border: 1px solid var(--bm-hair); border-radius: 8px; padding: .6rem .9rem; background: var(--bm-card); }
.bm-substitute summary { cursor: pointer; font-weight: 600; }
.bm-substitute[open] summary { margin-bottom: .5rem; }
.bm-howto { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; align-items: start; }
.bm-howto-fig { margin: 0; padding: 12px; border: 1px solid var(--bm-hair); border-radius: 8px; background: var(--bm-card); }
.bm-howto-svg svg { width: 100%; height: auto; display: block; }
.bm-howto-fig figcaption { font-size: .75rem; color: var(--bm-ink2); line-height: 1.6; margin-top: 8px; }
.bm-credit { font-size: .8125rem; color: var(--bm-ink2); }
.bm-credit a { color: hsl(var(--primary)); }
@media (max-width: 760px) {
  .bm-howto { grid-template-columns: 1fr; }
  .bm-howto-fig { max-width: 320px; }
  .bm-help table { font-size: .8125rem; }
}

/* サイト共通の余白を狭い画面で詰める（横にはみ出さないように） */
@media (max-width: 640px) {
  .bm-wrap.fullwidth-container { padding: 0 1rem !important; }
}
