/* ガラリ・制気口サイズ計算機（スマホを先に考えた作り。夜の表示にも対応） */

:root {
	--bg: #f2f4f7;
	--card: #ffffff;
	--ink: #1c2530;
	--muted: #5a6573;
	--line: #d6dce4;
	--field: #ffffff;
	--accent: #1f5fa8;
	--accent-ink: #ffffff;
	--accent-weak: #e7eef8;
	--ok: #2e7d32;
	--ok-bg: #e8f5e9;
	--ng: #c62828;
	--ng-bg: #fdecea;
	--warn-bg: #fff4e0;
	--warn-line: #f0a020;
	--top: #1b2a4a;
	--top-ink: #ffffff;
	--top-muted: #b8c4d8;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #11161c;
		--card: #1a2129;
		--ink: #e4e9ef;
		--muted: #9aa5b1;
		--line: #2e3946;
		--field: #131920;
		--accent: #7fb0f0;
		--accent-ink: #0d1a2b;
		--accent-weak: #1c2b3f;
		--ok: #81c784;
		--ok-bg: #17301c;
		--ng: #ff8a80;
		--ng-bg: #3a1d1d;
		--warn-bg: #33281a;
		--warn-line: #c98a20;
		--top: #0d1522;
		--top-ink: #e4e9ef;
		--top-muted: #8d9bb0;
		color-scheme: dark;
	}
}

:root[data-theme="dark"] {
	--bg: #11161c;
	--card: #1a2129;
	--ink: #e4e9ef;
	--muted: #9aa5b1;
	--line: #2e3946;
	--field: #131920;
	--accent: #7fb0f0;
	--accent-ink: #0d1a2b;
	--accent-weak: #1c2b3f;
	--ok: #81c784;
	--ok-bg: #17301c;
	--ng: #ff8a80;
	--ng-bg: #3a1d1d;
	--warn-bg: #33281a;
	--warn-line: #c98a20;
	--top: #0d1522;
	--top-ink: #e4e9ef;
	--top-muted: #8d9bb0;
	color-scheme: dark;
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	background: var(--bg);
	color: var(--ink);
	font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic UI", Meiryo, sans-serif;
	font-size: 16px;
	line-height: 1.6;
	-webkit-text-size-adjust: 100%;
}

svg {
	width: 20px;
	height: 20px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	flex: none;
}

[hidden] {
	display: none !important;
}

/* アプリの中では、ファイルを扱うボタンと重なる見出しを出さない */
[data-app] .web-only,
[data-app] .top__title {
	display: none !important;
}

/* ---------- 上の帯 ---------- */

.top {
	background: var(--top);
	color: var(--top-ink);
}

.top__inner {
	max-width: 760px;
	margin: 0 auto;
	padding: 16px 16px 12px;
}

[data-app] .top__inner {
	padding: 8px 12px;
}

.top__eyebrow {
	color: var(--top-muted);
	font-size: 12px;
	letter-spacing: 0.05em;
}

.top h1 {
	font-size: 22px;
	line-height: 1.4;
	margin-bottom: 10px;
}

.toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.tbtn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 40px;
	padding: 6px 12px;
	border: 1px solid rgba(255, 255, 255, 0.28);
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.08);
	color: inherit;
	font: inherit;
	font-size: 14px;
	text-decoration: none;
	cursor: pointer;
}

.tbtn:hover {
	background: rgba(255, 255, 255, 0.18);
}

/* ---------- 本文 ---------- */

.page {
	max-width: 760px;
	margin: 0 auto;
	padding: 16px 16px 40px;
}

.sec-title {
	font-size: 19px;
	margin: 8px 0 4px;
	padding-left: 10px;
	border-left: 5px solid var(--accent);
}

.sec-lead {
	color: var(--muted);
	font-size: 14px;
	margin-bottom: 12px;
}

.card {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 12px;
	margin-bottom: 14px;
}

.calc {
	padding: 14px;
}

.calc__head {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 12px;
}

.calc__name {
	flex: 1;
	min-width: 0;
	border: none;
	border-bottom: 2px solid var(--line);
	background: transparent;
	color: var(--ink);
	font: inherit;
	font-size: 20px;
	font-weight: 700;
	padding: 4px 2px;
}

.calc__name:focus {
	outline: none;
	border-bottom-color: var(--accent);
}

.calc__delete {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: transparent;
	color: var(--ng);
	cursor: pointer;
}

.calc__delete:disabled {
	color: var(--muted);
	opacity: 0.45;
	cursor: default;
}

/* 入力欄 */
.fields {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
	margin-bottom: 12px;
}

.field--wide {
	grid-column: 1 / -1;
}

.field {
	display: block;
	min-width: 0;
}

.field__label {
	display: block;
	color: var(--muted);
	font-size: 13px;
	margin-bottom: 2px;
}

.field__box {
	display: flex;
	align-items: center;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--field);
	padding-right: 10px;
}

.field__box:focus-within {
	border-color: var(--accent);
	box-shadow: 0 0 0 2px var(--accent-weak);
}

.field__box input {
	flex: 1;
	min-width: 0;
	border: none;
	background: transparent;
	color: var(--ink);
	font: inherit;
	font-size: 20px;
	font-variant-numeric: tabular-nums;
	padding: 8px 10px;
	outline: none;
}

.field__unit {
	color: var(--muted);
	font-size: 14px;
	white-space: nowrap;
}

.field__error {
	display: block;
	color: var(--ng);
	font-size: 12px;
	line-height: 1.4;
	margin-top: 2px;
}

.field__error:empty {
	display: none;
}

.field--error .field__box {
	border-color: var(--ng);
}

/* 結果の表 */
.result {
	width: 100%;
	border-collapse: collapse;
	font-variant-numeric: tabular-nums;
}

.result th,
.result td {
	padding: 7px 6px;
	border-top: 1px solid var(--line);
	vertical-align: middle;
}

.result th {
	text-align: left;
	font-weight: 500;
	font-size: 15px;
}

.result .num {
	text-align: right;
	font-size: 18px;
	font-weight: 700;
	white-space: nowrap;
}

.result .unit {
	width: 3.6em;
	color: var(--muted);
	font-size: 14px;
	white-space: nowrap;
}

.result__judge td {
	text-align: right;
}

.result__main {
	background: var(--ok-bg);
}

.result__sub th,
.result__sub .num {
	color: var(--muted);
	font-size: 14px;
	font-weight: 400;
}

.chip {
	display: inline-block;
	min-width: 64px;
	padding: 3px 14px;
	border-radius: 999px;
	background: var(--line);
	color: var(--ink);
	font-size: 18px;
	font-weight: 700;
	text-align: center;
}

.chip--ok {
	background: var(--ok);
	color: var(--card);
}

.chip--ng {
	background: var(--ng);
	color: var(--card);
}

.calc__note {
	color: var(--muted);
	font-size: 13px;
	text-align: right;
	margin-top: 4px;
}

.calc__note:empty {
	display: none;
}

.add-btn {
	display: block;
	width: 100%;
	min-height: 52px;
	margin-bottom: 28px;
	border: 2px dashed var(--accent);
	border-radius: 12px;
	background: var(--accent-weak);
	color: var(--accent);
	font: inherit;
	font-size: 17px;
	font-weight: 700;
	cursor: pointer;
}

/* ---------- 補助ツール ---------- */

.tool summary {
	display: flex;
	align-items: center;
	min-height: 56px;
	padding: 10px 14px;
	font-size: 17px;
	font-weight: 700;
	cursor: pointer;
	list-style: none;
}

.tool summary::-webkit-details-marker {
	display: none;
}

.tool summary::after {
	content: "";
	width: 10px;
	height: 10px;
	margin-left: auto;
	border-right: 2px solid var(--muted);
	border-bottom: 2px solid var(--muted);
	transform: rotate(45deg) translate(-2px, -2px);
	transition: transform 0.15s;
}

.tool[open] summary::after {
	transform: rotate(-135deg) translate(-2px, -2px);
}

.tool__body {
	padding: 4px 14px 14px;
	border-top: 1px solid var(--line);
	padding-top: 12px;
}

.switch {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 44px;
	margin-bottom: 8px;
	font-size: 15px;
	cursor: pointer;
}

.switch input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.switch__track {
	position: relative;
	width: 44px;
	height: 26px;
	border-radius: 999px;
	background: var(--line);
	transition: background 0.15s;
	flex: none;
}

.switch__track::after {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
	transition: transform 0.15s;
}

.switch input:checked + .switch__track {
	background: var(--accent);
}

.switch input:checked + .switch__track::after {
	transform: translateX(18px);
}

.switch input:focus-visible + .switch__track {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.hint {
	color: var(--muted);
	font-size: 13px;
	margin: 6px 0 10px;
}

.seg {
	display: inline-flex;
	border: 1px solid var(--accent);
	border-radius: 10px;
	overflow: hidden;
	margin-bottom: 10px;
}

.seg button {
	min-height: 40px;
	padding: 6px 14px;
	border: none;
	background: transparent;
	color: var(--accent);
	font: inherit;
	font-size: 14px;
	cursor: pointer;
}

.seg button + button {
	border-left: 1px solid var(--accent);
}

.seg button[aria-pressed="true"] {
	background: var(--accent);
	color: var(--accent-ink);
	font-weight: 700;
}

.table-wrap {
	overflow-x: auto;
	border: 1px solid var(--line);
	border-radius: 10px;
}

.cand {
	width: 100%;
	border-collapse: collapse;
	font-size: 14px;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.cand th,
.cand td {
	padding: 7px 8px;
	text-align: right;
}

.cand th {
	background: var(--accent-weak);
	font-size: 12px;
	font-weight: 700;
	line-height: 1.3;
	white-space: normal;
	vertical-align: bottom;
}

.cand th small {
	display: block;
	font-weight: 400;
	color: var(--muted);
}

.cand td {
	border-top: 1px solid var(--line);
}

.cand .row--ok {
	background: var(--ok-bg);
}

.cand .row--ng {
	background: var(--ng-bg);
}

.cand .judge {
	font-weight: 700;
	text-align: center;
}

.cand .row--ok .judge {
	color: var(--ok);
}

.cand .row--ng .judge {
	color: var(--ng);
}

.empty {
	padding: 16px 0;
	color: var(--muted);
	text-align: center;
}

.mini-result {
	margin-bottom: 10px;
}

.formula {
	padding: 10px 12px;
	border-radius: 10px;
	background: var(--bg);
	color: var(--muted);
	font-size: 13px;
}

.formula p + p {
	margin-top: 4px;
}

/* ---------- 下 ---------- */

.foot {
	margin-top: 28px;
	padding-top: 14px;
	border-top: 1px solid var(--line);
	color: var(--muted);
	font-size: 13px;
}

.foot__copy {
	margin-top: 6px;
}

/* ---------- 使い方 ---------- */

dialog {
	width: min(680px, calc(100% - 24px));
	max-height: calc(100% - 32px);
	margin: auto;
	padding: 0;
	border: none;
	border-radius: 14px;
	background: var(--card);
	color: var(--ink);
}

dialog::backdrop {
	background: rgba(0, 0, 0, 0.5);
}

.help {
	padding: 0 18px 20px;
	font-size: 15px;
}

.help__head {
	position: sticky;
	top: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 0 10px;
	background: var(--card);
	border-bottom: 1px solid var(--line);
}

.help__head h2 {
	font-size: 19px;
	color: var(--accent);
}

.help__close {
	width: 44px;
	height: 44px;
	border: none;
	border-radius: 10px;
	background: transparent;
	color: var(--ink);
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
}

.help h3 {
	margin: 16px 0 6px;
	font-size: 16px;
	color: var(--accent);
}

.help ul {
	padding-left: 1.2em;
}

.help li + li {
	margin-top: 4px;
}

.help .disclaimer {
	margin-top: 18px;
	padding: 4px 14px 12px;
	border-left: 4px solid var(--warn-line);
	border-radius: 8px;
	background: var(--warn-bg);
}

.help .disclaimer h3 {
	color: var(--ng);
}

.help .disclaimer p + p {
	margin-top: 6px;
}

/* ---------- 広い画面 ---------- */

@media (min-width: 640px) {
	.top h1 {
		font-size: 26px;
	}

	.fields--calc,
	.fields--3 {
		grid-template-columns: repeat(3, 1fr);
	}

	.fields--calc .field--wide {
		grid-column: auto;
	}

	.fields:not(.fields--calc):not(.fields--3) {
		grid-template-columns: repeat(4, 1fr);
	}

	.calc {
		padding: 18px 20px;
	}
}

/* ---------- 印刷（計算の一覧だけを出す） ---------- */

.print-only {
	display: none;
}

@media print {
	:root {
		--bg: #ffffff;
		--card: #ffffff;
		--ink: #000000;
		--muted: #444444;
		--line: #999999;
		--field: #ffffff;
		--ok: #2e7d32;
		--ok-bg: #ffffff;
		--ng: #c62828;
		color-scheme: light;
	}

	.top,
	.tools,
	.add-btn,
	.sec-lead,
	.calc__delete {
		display: none !important;
	}

	.print-only {
		display: block;
	}

	.print-head {
		margin-bottom: 10px;
	}

	.page {
		max-width: none;
		padding: 0;
	}

	.calc {
		break-inside: avoid;
		border-color: #999;
	}

	.fields--calc {
		grid-template-columns: repeat(5, 1fr);
	}

	.fields--calc .field--wide {
		grid-column: auto;
	}

	.field__box input {
		font-size: 15px;
	}

	.chip--ok,
	.chip--ng {
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}
}
