/* 暖房費シミュレーター（皮算用と同じ配色・ライト／ダーク・スマホ対応） */

:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f3ede3;
  --text: #2b2420;
  --text-sub: #6b5f55;
  --line: #e2d8c9;
  --accent: #a4532b;
  --accent-soft: #f3e2d6;
  --warn: #b0451f;
  --warn-soft: #fbe6dc;
  --c0: #b0552a;
  --c1: #2f6f9a;
  --c2: #447a2d;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .07);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", Meiryo, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #272220;
    --surface-2: #211c19;
    --text: #efe7de;
    --text-sub: #b3a69a;
    --line: #3b332d;
    --accent: #e08a5c;
    --accent-soft: #3a2a21;
    --warn: #f09a72;
    --warn-soft: #3d241a;
    --c0: #e8895a;
    --c1: #6fb0dc;
    --c2: #94c46f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* ヘッダー */
.top { padding: 18px 0 8px; }
.top h1 { margin: 10px 0 2px; font-size: clamp(22px, 4.5vw, 30px); line-height: 1.3; letter-spacing: .02em; }
.lead { margin: 0; color: var(--text-sub); }
.top-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lang { display: inline-flex; align-items: center; gap: 4px; }
.lang select { width: auto; font-size: 13px; padding: 3px 6px; }
.price-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.price-head h2 { margin: 0; }
.cur { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-sub); }
.cur select { width: auto; font-size: 14px; padding: 3px 6px; }

/* カード */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 16px 0;
}
h2 { font-size: 17px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 15px; margin: 18px 0 4px; }
.num {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px; flex: none;
}
.sec-title { margin: 24px 0 4px; }
.sec-hint { margin: 0; }
.hint { font-size: 12.5px; color: var(--text-sub); margin: 10px 0 0; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: 1.15fr 1fr; } }

/* 入力欄 */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 12px; }
.f { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--text-sub); }
.f.wide { grid-column: span 2; }
.fields > .f { justify-content: space-between; } /* ラベルが2行になっても入力欄の高さをそろえる */
.fh { font-size: 11px; opacity: .85; }
.in { display: flex; align-items: center; gap: 6px; }
.u { font-size: 12.5px; color: var(--text-sub); white-space: nowrap; }
input[type="number"], select {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; min-width: 0; width: 100%;
}
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
select { cursor: pointer; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.chk input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

.demand {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft);
}
.demand strong { font-size: 18px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.demand .in { width: 120px; }

/* 暖房の3枠 */
.slots { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 860px) { .slots { grid-template-columns: repeat(3, 1fr); } }
.slot { border-top: 4px solid var(--cc); display: flex; flex-direction: column; gap: 10px; }
.slot .fields { grid-template-columns: 1fr 1fr; }
.slot .fields .chk { grid-column: 1 / -1; }
.slot .fields.presets { grid-template-columns: 1fr; }
.slot-head { display: flex; align-items: center; gap: 8px; }
.slot-head select { font-weight: 700; }
.c0 { --cc: var(--c0); }
.c1 { --cc: var(--c1); }
.c2 { --cc: var(--c2); }
.dot {
  display: inline-grid; place-items: center; flex: none;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--cc); color: #fff; font-size: 12px; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .dot { color: #1b1714; } }
.slot-sum {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto;
  padding-top: 10px; border-top: 1px dashed var(--line);
}
.slot-sum div { display: flex; flex-direction: column; }
.slot-sum span { font-size: 12px; color: var(--text-sub); }
.slot-sum strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.slot-eff { margin: 0; font-size: 12px; color: var(--text-sub); }
.slot.warn .slot-eff { color: var(--warn); }

/* 結果 */
.result-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.result-head h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--surface-2); }
.seg button {
  font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--text-sub);
  padding: 4px 12px; border-radius: 999px; cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button[aria-checked="true"] { color: #1b1714; } }
.verdict { font-size: 16px; font-weight: 600; margin: 14px 0 10px; }

.bars { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 200px) 1fr auto; align-items: center; gap: 10px; }
.bar-name { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.bar-track { height: 22px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--cc); border-radius: 6px; transition: width .25s ease; }
.bar-val { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 84px; text-align: right; }
.tag {
  font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: #fff; margin-left: 2px;
}
.tag-warn { background: var(--warn-soft); color: var(--warn); }
@media (prefers-color-scheme: dark) { .tag:not(.tag-warn) { color: #1b1714; } }
@media (max-width: 560px) {
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-name { grid-column: 1 / -1; }
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
.tbl thead th { text-align: right; font-size: 13px; white-space: nowrap; }
.tbl thead th .dot { margin-right: 4px; }
.tbl tbody th { text-align: left; font-weight: 500; color: var(--text-sub); white-space: nowrap; }
.tbl tr.em td { font-size: 16px; font-weight: 700; }
.tbl td.is-best { background: var(--accent-soft); }
#tbl { min-width: 560px; }
.tbl.small { max-width: 560px; }
.tbl.small th, .tbl.small td { text-align: left; }

.notes { margin: 12px 0 0; padding-left: 1.2em; font-size: 13px; color: var(--text-sub); }
.notes li { margin: 4px 0; }
.notes li.warn { color: var(--warn); }

.explain { font-size: 14px; }
.explain ol, .explain ul { padding-left: 1.3em; }
.explain p { margin: 4px 0 8px; }

.foot { color: var(--text-sub); font-size: 13px; padding-bottom: 32px; }
.unit-sel { width: auto; padding: 4px 4px; font-size: 13px; }

/* 免責事項・利用条件 */
.legal-short { font-size: 12.5px; color: var(--text-sub); margin: 12px 0 0; }
dialog.legal {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0 20px 20px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog.legal::backdrop { background: rgba(0, 0, 0, .45); }
.legal-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--surface); padding: 16px 0 8px; }
.legal-head h2 { margin: 0; }
.legal-close { font: inherit; font-size: 22px; line-height: 1; border: 0; background: transparent; color: var(--text-sub); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.legal-close:hover { background: var(--surface-2); color: var(--text); }
.legal-body { font-size: 14px; }
.legal-body h4 { margin: 16px 0 4px; font-size: 14.5px; }
.legal-body p { margin: 0 0 6px; }
.foot-links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: -6px 0 0; }

/* 入力の不備 */
input.bad { border-color: var(--warn); background: var(--warn-soft); }
/* 狭い画面：説明の表の見出しは折り返す。期間ボタンも折り返す */
.tbl.small th { white-space: normal; }
.seg { flex-wrap: wrap; }
@media (max-width: 380px) {
  .seg button { padding: 4px 9px; }
  .fields { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .f.wide { grid-column: 1 / -1; }
}

/* スマホの結果バー（幅の広い画面では出さない） */
.mbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
}
.mbar[hidden] { display: none; }
.mbar-text { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; line-height: 1.4; }
.mbar-go {
  flex: none; padding: 8px 14px; border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 700; text-decoration: none; min-height: 40px; display: inline-flex; align-items: center;
}
@media (prefers-color-scheme: dark) { .mbar-go { color: #1b1714; } }
@media (min-width: 860px) { .mbar { display: none !important; } }

/* スマホ：入力時に拡大されないよう16px以上、指で押しやすい大きさに */
@media (max-width: 859px) {
  body { padding-bottom: 72px; }
  input[type="number"], select { font-size: 16px; min-height: 44px; }
  .lang select, .cur select, .unit-sel { font-size: 16px; min-height: 40px; }
  .chk { min-height: 40px; }
  .chk input { width: 22px; height: 22px; }
  .seg button { min-height: 40px; font-size: 14px; }
  .card { padding: 14px; }
  .legal-short a, .foot a { display: inline-block; padding: 6px 0; }
  .kz-home { padding-top: 6px; padding-bottom: 6px; }
  /* 表は1列目を固定して横に送れるように */
  #tbl th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
}
.faq h3 { margin: 16px 0 2px; font-size: 15px; }
.faq p { margin: 0 0 6px; font-size: 14px; }

/* 翻訳ファイルを読めなかったときのお知らせ */
.load-error { margin: 0; padding: 10px 16px; background: var(--warn-soft); color: var(--warn); font-size: 14px; text-align: center; }
/* 部屋の広さ：換算表示（＝19.4 m² など）は入力欄の下に重ねて、隣の「建物」と高さをそろえる */
.f:has(#areaAlt) { position: relative; margin-bottom: 14px; }
#areaAlt { position: absolute; left: 0; top: 100%; white-space: nowrap; }
.fields > .f:has(#build) { align-self: start; }
