/* Connect Home round 4, H. Board. Brief: _dev/BRIEF-v4.md. Logic: home-h.js.
 * A board on fixed rows (--hb-row from assets/r4/cards.css) and one "Customise Home" dialog.
 * No jiggle, no rotation, no overshoot. Colour 120-160ms; transform and opacity 160-240ms; layout glides in JS. */

.hb { --gap: 1.1429rem; --ease-out: cubic-bezier(0.23, 1, 0.32, 1); display: flex; flex-direction: column; gap: 1.5rem; padding-bottom: 2rem; }

/* ------------------------------------------------------------------ board */
.hb-wrap { position: relative; }
.hb-board {
	position: relative; z-index: 1;
	display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: var(--hb-row);
	gap: var(--gap); align-items: stretch;
}
.hb-board.is-one { grid-template-columns: minmax(0, 1fr); }
.hb-fx { position: absolute; inset: 0; z-index: 0; pointer-events: none; }

.hb-slot { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; border-radius: 16px; }
.hb-slot > .r3-card { flex: 1; min-height: 0; height: 100%; }

/* a quiet ring when a hero count points here */
.hb-slot::after {
	content: ''; position: absolute; inset: -4px; border-radius: 20px; pointer-events: none;
	box-shadow: 0 0 0 2px color-mix(in oklab, var(--primary) 55%, transparent), 0 0 0 7px color-mix(in oklab, var(--primary) 10%, transparent);
	opacity: 0;
}
.hb-slot.hb-flash::after { animation: hb-flash 1.6s var(--ease-out); }
@keyframes hb-flash { 0% { opacity: 0; } 14% { opacity: 1; } 62% { opacity: 1; } 100% { opacity: 0; } }

/* the empty frame that morphs behind a card whose slot changes size on Save */
.hb-frame { position: absolute; left: 0; top: 0; background: var(--card); border: 1px solid var(--line); border-radius: 16px; will-change: transform; }

/* ------------------------------------------------------------------ header button */
.hb-hbtn { cursor: pointer; transition: background-color 140ms ease-out, border-color 140ms ease-out, color 140ms ease-out, transform 160ms var(--ease-out); }
.hb-hbtn.btn-outline:hover:not(:disabled) { background: var(--subtle); border-color: rgba(16, 17, 25, 0.22); }
.hb-hbtn.btn-ghost:hover:not(:disabled) { background: var(--subtle); color: var(--fg); }
.hb-hbtn.btn-primary:hover:not(:disabled) { background: color-mix(in oklab, var(--primary) 88%, #000); }
.hb-hbtn:active:not(:disabled) { transform: scale(0.97); }
.hb-hbtn:disabled { cursor: default; opacity: 0.5; }
.hb-hbtn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.hb-hbtn .ic { color: var(--muted-fg); }
.hb-hbtn.btn-primary .ic { color: currentColor; }

/* ------------------------------------------------------------------ dialog shell */
html.hb-locked { overflow: hidden; }
.hb-dlg-bg { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 2rem 1rem; background: rgba(0, 6, 37, 0.32); }
.hb-dlg {
	width: min(880px, 100%); max-height: calc(100dvh - 4rem); display: flex; flex-direction: column;
	background: var(--card); border-radius: 16px; box-shadow: 0 24px 64px -16px rgba(0, 6, 37, 0.35), 0 0 0 1px rgba(16, 17, 25, 0.06);
	overflow: hidden;
}
.hb-dlg h2 { font-family: var(--font-display); font-size: 1.1429rem; font-weight: 600; letter-spacing: -0.012em; color: var(--ats-title); }
.hb-dlg-h { display: flex; align-items: flex-start; gap: 1rem; padding: 1.125rem 1.25rem 1rem; border-bottom: 1px solid var(--line); }
.hb-dlg-h > div { flex: 1; min-width: 0; }
.hb-dlg-h p { margin-top: 0.25rem; font-size: var(--text-sm); color: var(--muted-fg); }
.hb-dlg-x { margin: -0.25rem -0.375rem 0 0; }
.hb-dlg .hb-dlg-x { width: 32px; height: 32px; } /* 8px of hover fill round the 16px icon */
.hb-dlg-b { flex: 1; min-height: 0; overflow: auto; padding: 1.25rem; }
.hb-dlg-f { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; padding: 0.875rem 1.25rem; border-top: 1px solid var(--line); }
.hb-dlg-f .hc-reset { margin-right: auto; margin-left: -0.5rem; padding-inline: 0.625rem; }

/* ------------------------------------------------------------------ Customise Home */
.hc-b { display: grid; grid-template-columns: minmax(0, 1fr) 17.5rem; gap: 1.5rem; align-items: start; }
.hc-cap { margin: 0 0 0.5rem; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em; color: var(--muted-fg); }

.hc-list { position: relative; margin: 0; padding: 0.25rem; list-style: none; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.hc-row {
	position: relative; display: flex; align-items: center; gap: 0.625rem; min-height: 3.75rem;
	padding: 8px; border-radius: 9px; background: var(--card);
	transition: background-color 140ms ease-out;
	user-select: none; -webkit-user-select: none;
}
.hc-row + .hc-row::before, .hc-ph + .hc-row::before, .hc-row + .hc-ph::before { content: ''; position: absolute; left: 0.75rem; right: 0.75rem; top: 0; height: 1px; background: var(--line); }
.hc-row:hover { background: var(--subtle); }
.hc-row:hover::before, .hc-row:hover + .hc-row::before { opacity: 0; }
.hc-row.is-lifted { background: var(--card); box-shadow: 0 14px 32px -12px rgba(16, 17, 25, 0.28), 0 0 0 1px var(--line); will-change: transform; cursor: grabbing; }
.hc-row.is-lifted::before { opacity: 0; }
.hc-row.is-landing { transition: box-shadow 320ms var(--ease-out); box-shadow: 0 0 0 0 rgba(16, 17, 25, 0); }
.hc-ph { position: relative; box-sizing: border-box; list-style: none; border-radius: 9px; border: 1.5px dashed color-mix(in oklab, var(--primary) 40%, transparent); background: color-mix(in oklab, var(--primary) 4%, transparent); }

.hc-grip {
	flex: none; display: grid; place-items: center; width: 32px; height: 36px; border-radius: 7px;
	color: var(--muted-fg); cursor: grab; touch-action: none;
	transition: background-color 140ms ease-out, color 140ms ease-out;
}
.hc-grip:hover { background: color-mix(in oklab, var(--fg) 6%, transparent); color: var(--fg); }
.hc-grip:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.hc-row:not(.is-lifted) { cursor: grab; }
.hc-ic { flex: none; display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 9px; background: var(--tint); color: var(--primary); transition: opacity 160ms ease-out, filter 160ms ease-out; }
.hc-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.0625rem; transition: opacity 160ms ease-out; }
.hc-tx b { font-size: var(--text-sm); font-weight: 600; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-tx small { font-size: var(--text-xs); line-height: 1.4; color: var(--muted-fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-row.is-hidden .hc-tx, .hc-row.is-hidden .hc-seg { opacity: 0.5; }
.hc-row.is-hidden .hc-ic { opacity: 0.55; filter: grayscale(1); }

/* the size control: two glyphs drawn to scale on the 3 x 2 grid */
.hc-seg { flex: none; display: inline-flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--subtle); box-shadow: inset 0 0 0 1px var(--line); transition: opacity 160ms ease-out; }
.hc-seg [role='radio'] {
	display: grid; place-items: center; width: 40px; height: 30px; border-radius: 7px; cursor: pointer; color: var(--muted-fg);
	transition: background-color 140ms ease-out, color 140ms ease-out, box-shadow 140ms ease-out;
}
.hc-seg [role='radio']:hover { color: var(--fg); background: color-mix(in oklab, var(--card) 60%, transparent); }
.hc-seg [role='radio'][aria-checked='true'] { background: var(--card); color: var(--primary); box-shadow: 0 1px 2px rgba(16, 17, 25, 0.1), 0 0 0 1px var(--line); }
.hc-seg [role='radio']:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.hc-gl-o { fill: currentColor; opacity: 0.22; }
.hc-gl-i { fill: currentColor; }

/* the show/hide switch */
.hc-sw { flex: none; position: relative; width: 36px; height: 22px; border-radius: 999px; background: var(--line-2); cursor: pointer; transition: background-color 160ms ease-out; }
.hc-sw[aria-checked='true'] { background: var(--primary); }
.hc-sw-k { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16, 17, 25, 0.2); transition: transform 200ms var(--ease-out); }
.hc-sw[aria-checked='true'] .hc-sw-k { transform: translateX(14px); }
.hc-sw[aria-disabled='true'] { cursor: default; opacity: 0.6; }
.hc-sw:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.hc-sw:active:not([aria-disabled='true']) .hc-sw-k { width: 19px; }
.hc-sw[aria-checked='true']:active:not([aria-disabled='true']) .hc-sw-k { transform: translateX(11px); }

.hc-more { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: var(--muted-fg); cursor: pointer; transition: background-color 140ms ease-out, color 140ms ease-out; }
.hc-more:hover { background: color-mix(in oklab, var(--fg) 6%, transparent); color: var(--fg); }
.hc-more:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* the mini-map: the board at true proportions */
.hc-map { position: sticky; top: 0; }
.hc-mm { position: relative; width: 100%; transition: height 300ms var(--ease-out); }
.hc-mb {
	position: absolute; overflow: hidden; border-radius: 6px;
	background: var(--card); border: 1px solid var(--line-2); box-shadow: 0 1px 2px rgba(16, 17, 25, 0.05);
	transition: border-color 160ms ease-out;
}
.hc-mb::after { content: ''; position: absolute; left: 7px; right: 7px; top: 26px; height: 5px; border-radius: 3px; background: var(--subtle); box-shadow: 0 10px 0 var(--subtle), 0 20px 0 var(--subtle); }
.hc-mb-t { position: relative; z-index: 1; display: flex; align-items: center; gap: 4px; padding: 6px 7px 0; font-size: 10.5px; font-weight: 600; line-height: 1.2; color: var(--fg-2); white-space: nowrap; }
.hc-mb-t .ic { flex: none; color: var(--primary); }
.hc-mb-t span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hc-mb.is-tiny .hc-mb-t .ic { display: none; }
.hc-mb-x {
	position: absolute; top: 0; right: 0; bottom: 0; z-index: 2; pointer-events: none;
	background: repeating-linear-gradient(135deg, color-mix(in oklab, var(--primary) 10%, transparent) 0 3px, transparent 3px 7px);
	border-left: 1px dashed color-mix(in oklab, var(--primary) 35%, transparent);
}
.hc-mb:not(.is-wide) .hc-mb-x { display: none; }
.hc-mb.is-wide { border-color: color-mix(in oklab, var(--primary) 35%, var(--line-2)); }
.hc-notes { margin: 0.75rem 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.25rem; }
.hc-notes li { display: flex; align-items: flex-start; gap: 0.375rem; font-size: var(--text-xs); line-height: 1.4; color: var(--muted-fg); }
.hc-notes .ic { flex: none; margin-top: 2px; color: var(--primary); }

body.hb-grabbing, body.hb-grabbing * { cursor: grabbing !important; user-select: none; }

.hb-tip-sub { display: block; color: rgba(255, 255, 255, 0.7); }

/* ------------------------------------------------------------------ narrow: map on top, then a sheet */
@media (max-width: 900px) {
	.hc-b { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
	.hc-map { position: static; order: -1; }
	.hc-mm { max-width: 22rem; }
}
@media (max-width: 760px) {
	.cs-actions { flex-wrap: wrap; justify-content: flex-end; row-gap: 0.5rem; min-width: 0; max-width: 100%; }
	.hb { gap: 1.25rem; }
	.hb-dlg-bg { place-items: end stretch; padding: 1rem 0 0; }
	.hb-dlg { width: 100%; max-height: calc(100dvh - 1rem); border-radius: 16px 16px 0 0; }
	.hc-tx small, .hc-ic { display: none; }
	.hc-row { gap: 0.5rem; }
	.hb-dlg-f .hc-reset span { display: none; }
	/* 44px touch targets without changing the look: an invisible hit area round each control */
	.hc-grip, .hc-seg [role='radio'], .hc-more, .hb-dlg-f .hc-reset { position: relative; }
	.hc-grip::after, .hc-seg [role='radio']::after, .hc-sw::after, .hc-more::after, .hb-dlg-f .hc-reset::after { content: ''; position: absolute; }
	.hc-grip::after { inset: -4px -6px; }
	.hc-seg [role='radio']::after { inset: -7px -2px; }
	.hc-sw::after { inset: -11px -4px; }
	.hc-more::after { inset: -6px -6px -6px -4px; }
	.hb-dlg-f .hc-reset::after { inset: -5px -3px; }
}

@media (prefers-reduced-motion: reduce) {
	.hc-sw-k, .hc-mm, .hc-row.is-landing { transition: none; }
}
