/*
 * sim.css — カラーシミュレーションの見た目
 * セレクタはすべて .csim から始まり、ページのほかの部分の見た目は変えない。
 * サイト側のCSS（リセットCSSなど）から受ける影響は、必要な値をこちらで明示して抑えている。
 * 配色は先方サイトに合わせた（橙 #ff5500／緑 #21a751）。家を載せる台は、色を正しく見比べられるよう無彩色のグレーにしている。
 */
.csim {
  --ink: #22272b;
  --sub: #5a6268;
  --line: #d6dad8;
  --paper: #ffffff;
  --page-bg: #ffffff;     /* ページの地の色。サイトの背景色に合わせる */
  --mat: #f4f5f4;
  --stage-top: #f3f5f4;
  --stage-bottom: #dfe3e1;
  --brand: #ff5500;
  --brand-dark: #d94800;
  --ok: #1b8f45;
  --note: #fff4e0;
  --sticky-top: 0px;      /* サイトに固定ヘッダーがあるときは、その高さ */
  --stage-max: 40vh;      /* スマホで家の絵が占める高さの上限（svh が使えるブラウザでは下で svh に替える） */
  --bottom-safe: 0px;     /* サイトに画面下の固定ボタンがあるときは、その高さ */
  box-sizing: border-box;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 96px;
  color: var(--ink);
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
@supports (height: 1svh) { .csim { --stage-max: 40svh; } }
.csim *, .csim *::before, .csim *::after { box-sizing: border-box; }
.csim h1, .csim h2, .csim p { margin: 0; }
.csim button { font: inherit; color: inherit; cursor: pointer; -webkit-appearance: none; appearance: none; -webkit-tap-highlight-color: transparent; }
.csim [hidden] { display: none !important; }
/* キーボードで操作中の位置を示す枠。:focus-visible が使えない古いブラウザでは、常に枠を出す */
.csim :focus { outline: 3px solid #1c6fd6; outline-offset: 2px; }
.csim :focus:not(:focus-visible) { outline: none; }

.csim-head { margin-bottom: 14px; }
.csim-head h1 {
  font-weight: 700; font-size: 21px; line-height: 1.4; letter-spacing: .02em;
}
.csim-head p { color: var(--sub); font-size: 13.5px; margin-top: 4px; }

/* ---------- 家を見せる台 ---------- */
.csim-stage {
  position: sticky; top: var(--sticky-top); z-index: 5;
  margin: 0 -16px; padding: 0 16px 8px;
  background: var(--page-bg);
}
.csim-canvas {
  position: relative; overflow: hidden;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--stage-top) 0%, var(--stage-top) 38%, var(--stage-bottom) 100%);
}
.csim-svg { display: block; width: 100%; height: auto; max-height: var(--stage-max); touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.csim-svg [data-p] { cursor: pointer; }
.csim-svg .np { pointer-events: none; }
.csim-svg.is-drag { cursor: grabbing; }
/* 写真風の家（画像は 3:2）。縦が台の上限を超えるときは、空と道路の側を少し切って横長に見せる（1.8:1 まで。
   家は画像の高さの 15〜92% にあり、1.8:1・上下の切り方 60% なら 10〜93% が見えるので、屋根の先も基礎も切れない）。
   それでも収まらない低い画面では、写真を小さくして中央に置く（台の灰色の地は出さない） */
.csim-photo {
  position: relative; overflow: hidden; width: 100%; margin: 0 auto; aspect-ratio: 3 / 2; border-radius: inherit;
  max-height: var(--photo-max, var(--stage-max)); max-width: calc(var(--photo-max, var(--stage-max)) * 1.8); background: #dfe6ea;
}
.csim-canvas.is-photo { background: none; }
.csim-photo[hidden], .csim-pin[hidden], .csim-loading[hidden] { display: none; }
.csim-photo canvas { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 60%; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.csim-pin {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 0 0 1.5px #1f2428, inset 0 0 0 1.5px #1f2428; pointer-events: none;
}
.csim-pin::after { content: ""; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: #1f2428; }
.csim-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font-size: 13px; color: var(--sub); }
.csim-gl { width: 100%; aspect-ratio: 4 / 3; max-height: 46vh; touch-action: none; }
.csim-gl canvas { display: block; width: 100%; height: 100%; }
.csim-gl[hidden], .csim-turn[hidden] { display: none; }

@keyframes csim-pulse { 0%, 100% { opacity: 1; } 30% { opacity: .35; } 60% { opacity: 1; } 80% { opacity: .6; } }
.csim-svg[data-pulse="wall1"] [data-p="wall1"], .csim-svg[data-pulse="wall2"] [data-p="wall2"],
.csim-svg[data-pulse="roof"] [data-p="roof"], .csim-svg[data-pulse="soffit"] [data-p="soffit"],
.csim-svg[data-pulse="roof"] [data-p="fascia"], .csim-svg[data-pulse="roof"] [data-p="gutter"],
.csim-svg[data-pulse="door"] [data-p="door"], .csim-svg[data-pulse="base"] [data-p="base"] { animation: csim-pulse .75s ease-out; }

/* 見え方の切り替え（2D／3D）。家の絵に重ならないよう、絵の外（上）に置く */
.csim-viewsw { display: flex; width: -moz-fit-content; width: fit-content; margin: 0 0 6px; border: 1.5px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--paper); }
.csim-viewsw button { border: 0; background: transparent; min-width: 56px; min-height: 40px; padding: 4px 14px; font-size: 13px; font-weight: 700; text-align: center; border-left: 1px solid var(--line); }
.csim-viewsw button:first-child { border-left: 0; }
.csim-viewsw button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.csim-viewsw button:focus { outline-offset: -3px; }
.csim-turn {
  /* 家の絵に重ねず、絵のすぐ下に置く */
  display: flex; align-items: center; justify-content: center; gap: 4px; width: -moz-fit-content; width: fit-content; margin: 2px auto 8px;
  background: rgba(255, 255, 255, .92); border: 1px solid var(--line); border-radius: 999px; padding: 3px;
}
.csim-turn button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; display: grid; place-items: center; }
.csim-turn button:hover { background: var(--mat); }
.csim-turn svg { width: 20px; height: 20px; }
.csim-turn span { min-width: 7.5em; text-align: center; font-size: 13px; font-weight: 500; }

.csim-stagefoot { display: flex; align-items: flex-start; gap: 8px; padding-top: 4px; }
.csim-hint { flex: 1; min-height: 1.6em; font-size: 12.5px; color: var(--sub); }
/* 家の絵の下の小さな相談ボタン。サイト側に固定ボタンがあるスマホ表示（.csim--nobar）でだけ出す */
.csim .csim-mini { display: none; flex: none; min-height: 40px; padding: 4px 12px; border: 0; border-radius: 8px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 700; text-align: center; }
.csim-hint b { color: var(--ink); font-weight: 700; }

/* ---------- 操作パネル ---------- */
.csim-block { padding: 14px 0 4px; }
.csim-block h2 { font-size: 14px; font-weight: 700; margin-bottom: 8px; }

.csim-models { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.csim-model {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  padding: 6px 6px 8px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--paper); text-align: center;
}
.csim-model svg, .csim-model img { display: block; width: 100%; height: auto; border-radius: 6px; background: var(--mat); }
.csim-model b { font-size: 12.5px; font-weight: 700; line-height: 1.35; margin-top: 4px; }
.csim-model small { font-size: 11px; color: var(--sub); line-height: 1.35; }
.csim-model[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.csim-modelnote { font-size: 12px; color: var(--sub); margin-top: 6px; }
.csim-partnote { font-size: 12px; color: var(--sub); margin: 8px 0 0; }
.csim-partnote[hidden] { display: none; }

.csim-parts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.csim-part {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px 6px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--paper); min-height: 76px;
}
.csim-part i { display: block; width: 30px; height: 30px; border-radius: 7px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14); }
.csim-part b { font-size: 11.5px; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.csim-part small { font-size: 11px; color: var(--sub); line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.csim-part[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: var(--mat); }
.csim-part[aria-pressed="true"]::after {
  content: ""; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
}
.csim-part.is-off i { opacity: .35; }
.csim-part.is-off b, .csim-part.is-off small { color: #8b9297; }

.csim-tt { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-top: 10px; }
.csim-tt-label { font-size: 12.5px; font-weight: 700; }
.csim-seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--paper); }
.csim-seg button { border: 0; background: transparent; text-align: center; padding: 7px 11px; font-size: 13px; min-height: 44px; border-left: 1px solid var(--line); }
.csim-seg button:first-child { border-left: 0; }
.csim-seg button[aria-pressed="true"] { background: var(--ink); color: #fff; font-weight: 700; }

.csim-now { font-size: 13px; margin: -2px 0 8px; display: flex; align-items: center; gap: 8px; }
.csim-now i { flex: none; width: 22px; height: 22px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14); }
.csim-now b { font-weight: 700; }

/* 色見本カード：上が色、下に番号と色名 */
.csim-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 7px; }
/* align-items: stretch は必須。Safari は button の初期値が flex-start で、指定しないと色の帯（i）の幅が 0 になり、色が出ない */
.csim-chip {
  position: relative; display: flex; flex-direction: column; align-items: stretch; padding: 0; text-align: left;
  border: 1px solid var(--line); border-radius: 7px; background: var(--paper); overflow: hidden;
}
.csim-chip i { display: block; width: 100%; height: 42px; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .08); }
.csim-chip span { display: block; padding: 4px 5px 6px; font-size: 12px; line-height: 1.3; min-height: 38px; word-break: break-all; }
.csim-chip span b { display: block; font-size: 13px; font-weight: 700; }
.csim-chip[aria-pressed="true"] { outline: 2.5px solid var(--ink); outline-offset: 1px; }
.csim-chip[aria-pressed="true"]::after {
  content: ""; position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M4.5 9.4l3 3 6-6.4' fill='none' stroke='%2322272b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px no-repeat;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18);
}
.csim-palnote { font-size: 11.5px; color: var(--sub); margin-top: 8px; }

.csim-notes { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--note); font-size: 13.5px; line-height: 1.65; font-weight: 500; }
.csim-notes p + p { margin-top: 6px; }
.csim-notes p { padding-left: 1.1em; text-indent: -1.1em; }
.csim-notes p::before { content: "※"; }

.csim-sets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.csim-set { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--paper); text-align: left; min-height: 48px; }
.csim-set i { flex: none; display: flex; width: 44px; height: 30px; border-radius: 6px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14); }
.csim-set i u { flex: 1; text-decoration: none; }
.csim-set b { font-size: 12px; font-weight: 700; line-height: 1.3; }

.csim-actions { margin-top: 18px; }
.csim .csim-cta {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 54px; padding: 10px 16px;
  border: 0; border-radius: 10px; background: var(--brand); color: #fff !important; font-size: 19px; line-height: 1.3; font-weight: 700; text-align: center; text-decoration: none; letter-spacing: .04em;
}
.csim .csim-cta:hover { background: var(--brand-dark); }
.csim-subactions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 9px; }
.csim-subactions button, .csim-dialog-actions button {
  text-align: center; min-height: 44px; padding: 6px 4px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--paper); font-size: 12.5px; font-weight: 500;
}
.csim-subactions button:hover, .csim-dialog-actions button:hover { border-color: var(--ink); }

/* スマホでは画面下に相談ボタンを固定 */
.csim-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line); }
.csim-bar .csim-cta { min-height: 50px; }

.csim-modal {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 12px;
  background: rgba(20, 24, 27, .55);
}
.csim-modal[hidden] { display: none; }
.csim-dialog {
  position: relative; width: 100%; max-width: 560px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: auto;
  border-radius: 14px; padding: 20px 18px 18px; background: var(--paper); color: var(--ink);
}
.csim-dialog:focus { outline: none; }
.csim .csim-img { display: block; width: 100%; height: auto; margin: 10px 0 12px; border: 1px solid var(--line); border-radius: 8px; -webkit-touch-callout: default; }
.csim-dialog h2 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.csim-dialog p { font-size: 13px; color: var(--sub); }
.csim-dialog pre {
  margin: 10px 0; padding: 12px; max-height: 32vh; overflow: auto; white-space: pre-wrap; word-break: break-all;
  background: var(--mat); border-radius: 8px; font: inherit; font-size: 12.5px; line-height: 1.7; color: var(--ink);
}
.csim-dialog-note { margin-bottom: 12px; }
.csim-dialog-note p { font-size: 12.5px; padding-left: 1.1em; text-indent: -1.1em; }
.csim-dialog-note p::before { content: "※"; }
.csim-dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.csim-dialog-actions .csim-cta { grid-column: 1 / -1; }

.csim-toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-safe) + 76px); z-index: 1100; transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px); padding: 9px 16px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.csim-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* スマホ幅：相談ボタンは画面下の固定ボタンに任せる（同じボタンを2つ並べない） */
@media (max-width: 899px) {
  .csim-actions .csim-cta { display: none; }
  .csim-subactions { margin-top: 0; }
}
@media (max-width: 479px) {
  .csim-sets { grid-template-columns: 1fr; }
}

/* サイト側に画面下の固定ボタンがある場合（fixedBar: false）：こちらの固定ボタンは出さず、ページ内の相談ボタンを使う */
.csim--nobar { padding-bottom: 32px; }
.csim--nobar .csim-bar { display: none; }
.csim--nobar .csim-actions .csim-cta { display: flex; }
.csim--nobar .csim-subactions { margin-top: 9px; }
.csim--nobar .csim-toast { bottom: calc(var(--bottom-safe) + 16px); }
@media (max-width: 899px) { .csim--nobar .csim-mini { display: inline-flex; align-items: center; } }

/* ---------- PC幅 ---------- */
@media (min-width: 900px) {
  .csim { padding: 28px 24px 48px; font-size: 15px; }
  .csim-head h1 { font-size: 27px; }
  .csim-head p { font-size: 14.5px; }
  .csim-grid { display: grid; grid-template-columns: minmax(0, 1.22fr) minmax(360px, 1fr); gap: 28px; align-items: start; }
  .csim-stage { top: calc(var(--sticky-top) + 16px); margin: 0; padding: 0; }
  .csim-svg { max-height: min(74vh, calc(100vh - var(--sticky-top) - var(--bottom-safe) - 96px)); }
  .csim-gl { max-height: min(74vh, calc(100vh - var(--sticky-top) - var(--bottom-safe) - 96px)); }
  .csim-photo { --photo-max: min(74vh, calc(100vh - var(--sticky-top) - var(--bottom-safe) - 96px)); }
  .csim-canvas { border-radius: 16px; }
  .csim-stagefoot { padding-top: 8px; }
  .csim-hint { font-size: 13px; }
  .csim-block:first-child { padding-top: 0; }
  .csim-part { min-height: 82px; }
  .csim-part b { font-size: 12.5px; }
  .csim-part small { font-size: 11.5px; }
  .csim-chips { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .csim-bar { display: none; }
  .csim-toast { bottom: calc(var(--bottom-safe) + 28px); }
}
@media (prefers-reduced-motion: reduce) {
  .csim-svg [data-p] { animation: none !important; }
  .csim-toast { transition: none; }
}
