/* ==========================================================================
   Tool UI  (loaded on tool pages and wherever [ctb_tool] is used)
   Blue = things you touch. Green = things that are answers. Tool colour lives on the tile + panel edge.
   ========================================================================== */

.ctb-tool { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; align-items: start; }
.ctb-toolpage .ctb-tool + .ctb-ad--bottom { margin-top: 36px; }
.ctb-panel--result { align-self: stretch; }

/* ---------- Fields ---------- */
.ctb-field { margin-bottom: 26px; }
.ctb-field > label, .ctb-label { display: block; font-weight: 700; font-size: 1.08rem; margin: 0 0 9px; color: var(--ink); }
.ctb-field:last-child { margin-bottom: 0; }

.ctb-input {
	display: flex; align-items: center; gap: 8px; min-height: 62px; padding: 0 20px;
	background: var(--surface); border: 1.5px solid var(--line-2); border-radius: var(--r-sm);
	transition: border-color .15s, box-shadow .15s;
}
.ctb-input:focus-within { border-color: var(--blue); box-shadow: var(--focus); }
.ctb-input input, .ctb-input select {
	flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; outline: 0; padding: 12px 0;
	font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; color: var(--ink); -webkit-appearance: none; appearance: none;
	font-variant-numeric: tabular-nums;
}
.ctb-input input::placeholder { color: var(--line-2); font-weight: 500; }
.ctb-input__unit, .ctb-input__pre { color: var(--muted); font-size: 1.1rem; font-weight: 500; flex: none; }
.ctb-input__pre { font-size: 1.45rem; font-weight: 700; color: var(--ink-2); }
.ctb-input--sm { min-height: 54px; padding: 0 16px; }
.ctb-input--sm input, .ctb-input--sm select { font-size: 1.1rem; }
.ctb-input--select { position: relative; }
.ctb-input--select::after {
	content: ""; flex: none; width: 10px; height: 10px; margin-right: 4px;
	border-right: 2.5px solid var(--muted); border-bottom: 2.5px solid var(--muted); transform: translateY(-3px) rotate(45deg); pointer-events: none;
}
.ctb-input--select select { cursor: pointer; padding-right: 6px; }
.ctb-input select option { color: #0F172A; background: #fff; font-weight: 500; }

.ctb-hint { margin: 8px 0 0; color: var(--muted); font-size: 1rem; }
.ctb-hint strong { color: var(--ink); }
.ctb-note { color: var(--muted); font-size: .98rem; margin: 18px 0; }
.ctb-note--center { text-align: center; }
.ctb-fine { color: var(--muted); font-size: .85rem; margin: 18px 0 0; }
.ctb-muted { color: var(--muted); }

.ctb-textarea {
	width: 100%; resize: vertical; padding: 18px 20px; background: var(--surface); color: var(--ink);
	border: 1.5px solid var(--line-2); border-radius: var(--r-sm); font-size: 1.05rem; line-height: 1.6; outline: 0; margin-bottom: 18px;
	transition: border-color .15s, box-shadow .15s;
}
.ctb-textarea:focus { border-color: var(--blue); box-shadow: var(--focus); }
.ctb-textarea--tall { min-height: 340px; }
.ctb-field .ctb-textarea { margin-bottom: 0; }

.ctb-color { display: flex; align-items: center; min-height: 54px; padding: 8px 12px; background: var(--surface); border: 1.5px solid var(--line-2); border-radius: var(--r-sm); }
.ctb-color input { width: 100%; height: 34px; padding: 0; border: 0; background: none; cursor: pointer; }

/* ---------- Sliders ---------- */
.ctb-range {
	-webkit-appearance: none; appearance: none; display: block; width: 100%; height: 8px; margin: 18px 0 6px; border-radius: 99px; outline: 0;
	background: linear-gradient(90deg, var(--c, var(--blue)) var(--pct, 50%), var(--line) var(--pct, 50%));
}
.ctb-range::-webkit-slider-thumb {
	-webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; background: var(--c, var(--blue));
	border: 4px solid var(--surface); box-shadow: 0 2px 10px rgba(0, 0, 0, .28); cursor: grab; transition: transform .12s;
}
.ctb-range::-moz-range-thumb {
	width: 20px; height: 20px; border-radius: 50%; background: var(--c, var(--blue)); border: 4px solid var(--surface); box-shadow: 0 2px 10px rgba(0, 0, 0, .28); cursor: grab;
}
.ctb-range:active::-webkit-slider-thumb { transform: scale(1.12); cursor: grabbing; }
.ctb-range:focus-visible { box-shadow: var(--focus); }

/* ---------- Segmented control / tabs / checks ---------- */
.ctb-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 6px; margin-bottom: 26px; background: var(--surface-2); border-radius: var(--pill); }
.ctb-seg label { position: relative; display: block; text-align: center; border-radius: var(--pill); cursor: pointer; }
.ctb-seg input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.ctb-seg span { display: block; padding: 14px 10px; font-weight: 700; font-size: 1.15rem; color: var(--ink-2); border-radius: var(--pill); transition: background .15s, color .15s; }
.ctb-seg input:checked + span { background: var(--blue); color: #fff; box-shadow: 0 6px 16px rgba(42, 114, 229, .35); }
.ctb-seg input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }

.ctb-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 26px; }
.ctb-tab {
	padding: 10px 18px; border-radius: var(--pill); border: 1.5px solid var(--line-2); background: var(--surface);
	color: var(--ink-2); font-weight: 600; transition: background .15s, color .15s, border-color .15s;
}
.ctb-tab:hover { border-color: var(--blue); color: var(--blue); }
.ctb-tab[aria-selected="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }

.ctb-checks { display: grid; gap: 12px; margin-bottom: 26px; }
.ctb-check { display: flex; align-items: center; gap: 12px; font-weight: 500; cursor: pointer; margin-top: 14px; }
.ctb-checks .ctb-check { margin-top: 0; }
.ctb-check input { width: 22px; height: 22px; accent-color: var(--blue); flex: none; }

.ctb-more { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 18px; }
.ctb-more summary { cursor: pointer; font-weight: 700; color: var(--blue); list-style: none; display: flex; align-items: center; gap: 10px; }
.ctb-more summary::-webkit-details-marker { display: none; }
.ctb-more summary::before { content: "+"; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--blue-l); font-size: 1.1rem; line-height: 1; }
.ctb-more[open] summary::before { content: "\2212"; }
.ctb-more__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; margin-top: 20px; }
.ctb-more__grid--flush { margin-top: 0; }
.ctb-more__grid .ctb-field { margin-bottom: 20px; }
.ctb-span-2 { grid-column: span 2; }
.ctb-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ctb-hms { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.ctb-hms .ctb-input { padding: 0 14px; }
.ctb-hms input { text-align: center; font-size: 1.6rem; }

.ctb-actions { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 26px; }
.ctb-actions > .ctb-btn { flex: 1 1 180px; }
.ctb-actions--3 > .ctb-btn { flex: 1 1 120px; }

/* ---------- Result: big green banner (mortgage, percentage) ---------- */
.ctb-banner {
	text-align: center; color: #fff; padding: 28px 24px; border-radius: var(--r);
	background: linear-gradient(135deg, #27A056 0%, #1A7C3E 100%); box-shadow: 0 14px 32px rgba(30, 138, 69, .32);
}
.ctb-banner__num { display: flex; justify-content: center; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ctb-banner__num strong { font-size: clamp(2.5rem, 5.4vw, 3.9rem); font-weight: 800; letter-spacing: -.04em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.ctb-banner__num span { font-size: 1.5rem; font-weight: 700; opacity: .95; }
.ctb-banner__sub { margin-top: 6px; opacity: .95; font-size: 1.05rem; }

/* Donut */
.ctb-donut { position: relative; width: min(260px, 70%); margin: 30px auto 22px; aspect-ratio: 1; }
.ctb-donut svg { width: 100%; height: 100%; display: block; transform: none; }
.ctb-donut circle { transition: stroke-dasharray .4s ease, stroke-dashoffset .4s ease; }
.ctb-donut__c { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-weight: 700; font-size: .95rem; line-height: 1.25; padding: 0 30%; color: var(--ink); }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 9px; vertical-align: -1px; }
.dot--blue { background: var(--blue); } .dot--red { background: var(--red); } .dot--yellow { background: var(--yellow); } .dot--green { background: var(--green); }
.ctb-legend { list-style: none; margin: 0 0 24px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; font-size: .98rem; color: var(--ink-2); }
.ctb-legend strong { color: var(--ink); white-space: nowrap; }

.ctb-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 0 24px; }
.ctb-stats--2 { grid-template-columns: repeat(2, 1fr); }
.ctb-stats > div { background: var(--surface-2); border-radius: var(--r-sm); padding: 14px 16px; }
.ctb-stats dt { color: var(--muted); font-size: .85rem; font-weight: 600; margin: 0 0 2px; }
.ctb-stats dd { margin: 0; font-weight: 800; font-size: 1.2rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ---------- BMI ---------- */
.ctb-bmi { text-align: center; margin: 6px 0 34px; }
.ctb-hero-num { font-size: clamp(4rem, 9vw, 6.4rem); font-weight: 800; letter-spacing: -.05em; line-height: 1; margin-bottom: 20px; font-variant-numeric: tabular-nums; }
.ctb-badge { display: inline-block; padding: 12px 36px; border-radius: var(--pill); font-weight: 800; font-size: 1.6rem; letter-spacing: -.02em; background: var(--green); color: #fff; transition: background .25s; }
.ctb-badge.is-under { background: #1C9BF0; }
.ctb-badge.is-normal { background: var(--green); }
.ctb-badge.is-over { background: var(--yellow); color: var(--on-yellow); }
.ctb-badge.is-obese { background: var(--red); }

.ctb-gauge { margin: 0 0 12px; }
.ctb-gauge__bar {
	position: relative; height: 26px; border-radius: var(--pill);
	background: linear-gradient(90deg, #1C9BF0 0%, #1C9BF0 12%, #25A55C 26%, #25A55C 40%, #F7C400 55%, #F08A00 66%, #E5442D 80%, #B3261E 100%);
}
.ctb-gauge__pin {
	position: absolute; top: 50%; left: 30%; width: 24px; height: 24px; border-radius: 50%; background: var(--surface);
	border: 4px solid var(--ink); transform: translate(-50%, -50%); transition: left .4s cubic-bezier(.3, 1.3, .5, 1); box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
}
.ctb-gauge__labels { position: relative; height: 26px; list-style: none; margin: 10px 0 0; padding: 0; font-size: .92rem; color: var(--muted); }
.ctb-gauge__labels li { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ctb-gauge__labels li.is-on { color: var(--ink); font-weight: 800; }

.ctb-history { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }
.ctb-history h3 { font-size: 1rem; margin-bottom: 10px; }
.ctb-history ul { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 8px; }
.ctb-history li { display: flex; justify-content: space-between; gap: 12px; background: var(--surface-2); border-radius: 10px; padding: 10px 14px; font-size: .95rem; }
.ctb-history li small { color: var(--muted); white-space: nowrap; }

/* ---------- Converter ---------- */
.ctb-conv { position: relative; display: grid; gap: 14px; }
.ctb-conv__box { position: relative; background: var(--surface-2); border: 1.5px solid var(--line-2); border-radius: var(--r); padding: 18px 22px 22px; transition: border-color .15s, box-shadow .15s; }
.ctb-conv__box:focus-within { border-color: var(--blue); box-shadow: var(--focus); background: var(--surface); }
.ctb-conv__unit { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.ctb-conv__unit select {
	max-width: 100%; padding: 9px 38px 9px 18px; border-radius: var(--pill); border: 1.5px solid var(--line-2); background: var(--surface) no-repeat right 14px center / 12px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	-webkit-appearance: none; appearance: none; font-weight: 700; font-size: .98rem; cursor: pointer; color: var(--ink);
}
.ctb-conv__unit select option { color: #0F172A; background: #fff; }
.ctb-conv__val { display: block; width: 100%; border: 0; background: transparent; outline: 0; padding: 4px 0; font-size: clamp(1.8rem, 3.6vw, 2.6rem); font-weight: 700; letter-spacing: -.03em; color: var(--ink); font-variant-numeric: tabular-nums; }
.ctb-conv__swap {
	position: absolute; left: 50%; top: 50%; z-index: 2; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; border: 6px solid var(--surface);
	background: var(--blue); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 20px rgba(42, 114, 229, .4); transition: transform .25s;
}
.ctb-conv__swap:hover { background: var(--blue-d); }
.ctb-conv__swap.is-spin { transform: rotate(180deg); }
.ctb-conv--flat { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: end; }
.ctb-conv--flat .ctb-field { margin: 0; }
.ctb-conv__swap--inline { position: static; margin: 0 0 0 0; width: 54px; height: 54px; border-width: 0; }

.ctb-conv__result { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: clamp(1.6rem, 3.2vw, 2.4rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.15; margin: 10px 0 30px; }
.ctb-conv__result [data-out="line"] { border-bottom: 4px solid var(--green); padding-bottom: 6px; word-break: break-word; }
.ctb-tick { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--green); color: #fff; flex: none; }
.ctb-ratebox { text-align: center; padding: 20px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); margin: 0 0 24px; font-size: 1.1rem; }

/* ---------- Timer / stopwatch ---------- */
.ctb-clock { text-align: center; font-family: var(--mono); font-weight: 700; font-size: clamp(2.6rem, 6.4vw, 4.6rem); letter-spacing: -.04em; padding: 30px 0; font-variant-numeric: tabular-nums; }
.ctb-progress { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.ctb-progress i { display: block; height: 100%; width: 100%; background: var(--green); border-radius: 99px; transition: width .25s linear; }
.ctb-clock.is-done { color: var(--red); animation: ctb-blink 1s steps(2, start) 6; }
@keyframes ctb-blink { 50% { opacity: .25; } }
.ctb-empty-note { color: var(--muted); }
.ctb-tablewrap { overflow-x: auto; max-height: 420px; }
.ctb-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ctb-table th { text-align: left; font-size: .85rem; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.ctb-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-weight: 600; }
.ctb-table tr.is-best td { color: var(--green); }
.ctb-table tr.is-worst td { color: var(--red); }

/* ---------- Password ---------- */
.ctb-secret {
	font-family: var(--mono); font-size: clamp(1.2rem, 2.4vw, 1.7rem); font-weight: 700; word-break: break-all; text-align: center; line-height: 1.45;
	padding: 28px 22px; border-radius: var(--r); background: var(--surface-2); border: 1.5px dashed var(--line-2); margin-bottom: 20px; user-select: all;
}
.ctb-meter { height: 12px; border-radius: 99px; background: var(--line); overflow: hidden; }
.ctb-meter i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--red); transition: width .3s, background .3s; }

/* ---------- Word counter ---------- */
.ctb-bigstats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.ctb-bigstats > div { text-align: center; padding: 22px 12px; border-radius: var(--r); background: var(--blue-l); }
.ctb-bigstats strong { display: block; font-size: clamp(2.2rem, 4.6vw, 3.2rem); font-weight: 800; letter-spacing: -.04em; line-height: 1.05; color: var(--blue); font-variant-numeric: tabular-nums; }
[data-theme="dark"] .ctb-bigstats strong { color: #8DB8FF; }
.ctb-bigstats span { color: var(--ink-2); font-weight: 600; }
.ctb-top { margin: 0 0 24px; padding-left: 1.4em; display: grid; gap: 4px; }
.ctb-top li span { color: var(--muted); }

/* ---------- QR ---------- */
.ctb-qr { display: grid; place-items: center; min-height: 260px; padding: 20px; border-radius: var(--r); background: var(--surface-2); margin-bottom: 14px; overflow: hidden; }
.ctb-qr canvas, .ctb-qr img { max-width: 100%; height: auto !important; border-radius: 8px; }
.ctb-qr img { display: block; width: min(340px, 100%); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
	.ctb-tool { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
	.ctb-panel { padding: 26px 20px 24px; }
	.ctb-panel::before { left: 20px; right: 20px; }
	.ctb-legend, .ctb-stats { grid-template-columns: 1fr; }
	.ctb-more__grid { grid-template-columns: 1fr; }
	.ctb-span-2 { grid-column: auto; }
	.ctb-conv--flat { grid-template-columns: 1fr; }
	.ctb-conv__swap--inline { justify-self: center; transform: rotate(90deg); }
	.ctb-input input, .ctb-input select { font-size: 1.25rem; }
	.ctb-actions > .ctb-btn { flex-basis: 100%; }
	.ctb-actions--3 > .ctb-btn { flex-basis: 30%; padding: 0 10px; }
}
