/* Base */
:root{
	/* MTG color palette (approx from provided values) */
	--banner-h: 52px;
	--sidebar-w: 260px;
	--green-main: rgb(0,115,62);
	--green-light: rgb(196,211,202);
	--blue-main: rgb(14,104,171);
	--blue-light: rgb(179,206,234);
	--red-main: rgb(211,32,42);
	--red-light: rgb(235,159,130);
	--white-main: rgb(249,250,244);
	--white-light: rgb(248,231,185);
	--black-main: rgb(21,11,0);
	--black-light: rgb(166,159,157);
	--bg: #0f0f10;
	--panel: #1a1b1e;
	--text: #e8e8e8;
	--muted: #b6b8bd;
	--border: #2a2b2f;
	--ring: #60a5fa; /* focus ring */
	--ok: #16a34a; /* success */
	--warn: #f59e0b; /* warning */
	--err: #ef4444; /* error */
	/* Surface overrides for specific regions (default to panel) */
	--surface-banner: var(--panel);
	--surface-banner-text: var(--text);
	--surface-sidebar: var(--panel);
	--surface-sidebar-text: var(--text);
}

/* Light blend between Slate and Parchment (leans gray) */
[data-theme="light-blend"]{
	--bg: #e8e2d0;               /* blend of slate (#dedfe0) and parchment (#f8e7b9), 60/40 gray */
	--panel: #ffffff;            /* crisp panels for readability */
	--text: #0b0d12;
	--muted: #6b655d;            /* slightly warm muted */
	--border: #d6d1c7;           /* neutral warm-gray border */
	/* Slightly darker banner/sidebar for separation */
	--surface-banner: #1a1b1e;
	--surface-sidebar: #1a1b1e;
	--surface-banner-text: #e8e8e8;
	--surface-sidebar-text: #e8e8e8;
}

[data-theme="dark"]{
	--bg: #0f0f10;
	--panel: #1a1b1e;
	--text: #e8e8e8;
	--muted: #b6b8bd;
	--border: #2a2b2f;
}
[data-theme="high-contrast"]{
	--bg: #000;
	--panel: #000;
	--text: #fff;
	--muted: #e5e7eb;
	--border: #fff;
	--ring: #ff0;
}
[data-theme="cb-friendly"]{
	/* Tweak accents for color-blind friendliness */
	--green-main: #2e7d32; /* darker green */
	--red-main: #c62828;   /* deeper red */
	--blue-main: #1565c0;  /* balanced blue */
}
*{box-sizing:border-box}
html{height:100%; overflow-x:hidden; overflow-y:hidden; max-width:100vw;}
body {
	font-family: system-ui, Arial, sans-serif;
	margin: 0;
	color: var(--text);
	background: var(--bg);
	display: flex;
	flex-direction: column;
	height: 100%;
	width: 100%;
	overflow-x: hidden;
	overflow-y: auto;
}
/* Honor HTML hidden attribute across the app */
[hidden] { display: none !important; }
/* Accessible focus ring for keyboard navigation */
.focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
/* Top banner */
.top-banner{ position:sticky; top:0; z-index:10; background: var(--surface-banner); color: var(--surface-banner-text); border-bottom:1px solid var(--border); }
.top-banner{ min-height: var(--banner-h); }
.top-banner .top-inner{ margin:0; padding:.5rem 0; display:grid; grid-template-columns: var(--sidebar-w) 1fr; align-items:center; width:100%; box-sizing:border-box; }
.top-banner .top-inner > div{ min-width:0; }
@media (max-width: 1100px){
	.top-banner .top-inner{ grid-auto-rows:auto; }
	.top-banner .top-inner select{ max-width:140px; }
}
.top-banner h1{ font-size: 1.1rem; margin:0; padding-left: 1rem; }
.banner-status{ color: var(--muted); font-size:.9rem; text-align:left; padding-left: 1.5rem; padding-right: 1.5rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:100%; min-height:1.2em; }
.banner-status.busy{ color:#fbbf24; }
.health-dot{ width:10px; height:10px; border-radius:50%; display:inline-block; background:#10b981; box-shadow:0 0 0 2px rgba(16,185,129,.25) inset; }
.health-dot[data-state="bad"]{ background:#ef4444; box-shadow:0 0 0 2px rgba(239,68,68,.3) inset; }

/* Layout */
.layout{ display:grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); flex: 1 0 auto; }
.sidebar{
	background: var(--surface-sidebar);
	color: var(--surface-sidebar-text);
	border-right: 1px solid var(--border);
	padding: 1rem;
	position: fixed;
	top: var(--banner-h);
	left: 0;
	bottom: 0;
	overflow: auto;
	width: var(--sidebar-w);
	z-index: 9; /* below the banner (z=10) */
	box-shadow: 2px 0 10px rgba(0,0,0,.18);
	display: flex;
	flex-direction: column;
}
.content{ padding: 1.25rem 1.5rem; grid-column: 2; min-width: 0; }

/* Collapsible sidebar behavior */
body.nav-collapsed .layout{ grid-template-columns: 0 minmax(0, 1fr); }
body.nav-collapsed .sidebar{ transform: translateX(-100%); visibility: hidden; }
body.nav-collapsed .content{ grid-column: 2; }
body.nav-collapsed .top-banner .top-inner{ grid-template-columns: auto 1fr; }
body.nav-collapsed .top-banner .top-inner{ padding-left: .5rem; padding-right: .5rem; }
/* Smooth hide/show on mobile while keeping fixed positioning */
.sidebar{ transition: transform .2s ease-out, visibility .2s linear; }

/* Mobile tweaks */
@media (max-width: 900px){
	:root{ --sidebar-w: 240px; }
	.top-banner .top-inner{ grid-template-columns: 1fr; row-gap: .35rem; padding:.4rem 15px !important; }
	.banner-status{ padding-left: .5rem; }
	.layout{ grid-template-columns: 0 1fr; }
	.sidebar{ transform: translateX(-100%); visibility: hidden; }
	body:not(.nav-collapsed) .layout{ grid-template-columns: var(--sidebar-w) 1fr; }
	body:not(.nav-collapsed) .sidebar{ transform: translateX(0); visibility: visible; }
	.content{ padding: .9rem .6rem; max-width: 100vw; box-sizing: border-box; overflow-x: hidden; }
	.top-banner{ box-shadow:0 2px 6px rgba(0,0,0,.4); }
	/* Spacing tweaks: tighter left, larger gaps between visible items */
	.top-banner .top-inner > div{ gap: 25px !important; }
	.top-banner .top-inner > div:first-child{ padding-left: 0 !important; }
	/* Mobile: show only Menu, Title, and Theme selector */
	#btn-open-permalink{ display:none !important; }
	#banner-status{ display:none !important; }
	#health-dot{ display:none !important; }
	.top-banner #theme-reset{ display:none !important; }
}

/* Additional mobile spacing for bottom floating controls */
@media (max-width: 720px) {
	.content { 
		padding-bottom: 6rem !important; /* Extra bottom padding to account for floating controls */
	}
}

.brand h1{ display:none; }
.mana-dots{ display:flex; gap:.35rem; margin-bottom:.5rem; }
.mana-dots .dot{ width:12px; height:12px; border-radius:50%; display:inline-block; border:1px solid rgba(0,0,0,.35); box-shadow:0 1px 2px rgba(0,0,0,.3) inset; }
.dot.green{ background: var(--green-main); }
.dot.blue{ background: var(--blue-main); }
.dot.red{ background: var(--red-main); }
.dot.white{ background: var(--white-light); border-color: rgba(0,0,0,.2); }
.dot.black{ background: var(--black-light); }

.nav{ display:flex; flex-direction:column; gap:.35rem; }
.nav a{ color: var(--surface-sidebar-text); text-decoration:none; padding:.4rem .5rem; border-radius:6px; border:1px solid transparent; }
.nav a:hover{ background: color-mix(in srgb, var(--surface-sidebar) 85%, var(--surface-sidebar-text) 15%); border-color: var(--border); }

/* Sidebar theme controls anchored at bottom */
.sidebar .nav { flex: 1 1 auto; }
.sidebar-theme { margin-top: auto; padding-top: .75rem; border-top: 1px solid var(--border); }
.sidebar-theme-label { display:block; color: var(--surface-sidebar-text); font-size: 12px; opacity:.8; margin: 0 0 .35rem .1rem; }
.sidebar-theme-row { display:flex; align-items:center; gap:.5rem; }
.sidebar-theme-row select { background: var(--panel); color: var(--text); border:1px solid var(--border); border-radius:6px; padding:.3rem .4rem; }
.sidebar-theme-row .btn-ghost { background: transparent; color: var(--surface-sidebar-text); border:1px solid var(--border); }

/* Simple two-column layout for inspect panel */
.two-col { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
.two-col .grow { min-width: 0; }
.card-preview img { width: 100%; height: auto; border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.35); border:1px solid var(--border); background: var(--panel); }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* Left-rail variant puts the image first */
.two-col.two-col-left-rail{ grid-template-columns: 320px 1fr; }
/* Ensure left-rail variant also collapses to 1 column on small screens */
@media (max-width: 900px){
	.two-col.two-col-left-rail{ grid-template-columns: 1fr; }
	/* So the commander image doesn't dominate on mobile */
	.two-col .card-preview{ max-width: 360px; margin: 0 auto; }
	.two-col .card-preview img{ width: 100%; height: auto; }
}
.card-preview.card-sm{ max-width:200px; }

/* Buttons, inputs */
button{ background: var(--blue-main); color:#fff; border:none; border-radius:6px; padding:.45rem .7rem; cursor:pointer; }
button:hover{ filter:brightness(1.05); }
/* Anchor-style buttons */
.btn{ display:inline-block; background: var(--blue-main); color:#fff; border:none; border-radius:6px; padding:.45rem .7rem; cursor:pointer; text-decoration:none; line-height:1; }
.btn:hover{ filter:brightness(1.05); text-decoration:none; }
.btn.disabled, .btn[aria-disabled="true"]{ opacity:.6; cursor:default; pointer-events:none; }
label{ display:inline-flex; flex-direction:column; gap:.25rem; margin-right:.75rem; }
.color-identity{ display:inline-flex; align-items:center; gap:.35rem; }
.color-identity .mana + .mana{ margin-left:4px; }
.mana{ display:inline-block; width:16px; height:16px; border-radius:50%; border:1px solid var(--border); box-shadow:0 0 0 1px rgba(0,0,0,.25) inset; }
.mana-W{ background:#f9fafb; border-color:#d1d5db; }
.mana-U{ background:#3b82f6; border-color:#1d4ed8; }
.mana-B{ background:#111827; border-color:#1f2937; }
.mana-R{ background:#ef4444; border-color:#b91c1c; }
.mana-G{ background:#10b981; border-color:#047857; }
.mana-C{ background:#d3d3d3; border-color:#9ca3af; }
select,input[type="text"],input[type="number"]{ background: var(--panel); color:var(--text); border:1px solid var(--border); border-radius:6px; padding:.35rem .4rem; }
fieldset{ border:1px solid var(--border); border-radius:8px; padding:.75rem; margin:.75rem 0; }
small, .muted{ color: var(--muted); }
.partner-preview{ border:1px solid var(--border); border-radius:8px; background: var(--panel); padding:.75rem; margin-bottom:.5rem; }
.partner-preview[hidden]{ display:none !important; }
.partner-preview__header{ font-weight:600; }
.partner-preview__layout{ display:flex; gap:.75rem; align-items:flex-start; flex-wrap:wrap; }
.partner-preview__art{ flex:0 0 auto; }
.partner-preview__art img{ width:140px; max-width:100%; border-radius:6px; box-shadow:0 4px 12px rgba(0,0,0,.35); }
.partner-preview__details{ flex:1 1 180px; min-width:0; }
.partner-preview__role{ margin-top:.2rem; font-size:12px; color:var(--muted); letter-spacing:.04em; text-transform:uppercase; }
.partner-preview__pairing{ margin-top:.35rem; }
.partner-preview__themes{ margin-top:.35rem; font-size:12px; }
.partner-preview--static{ margin-bottom:.5rem; }
.partner-card-preview img{ box-shadow:0 4px 12px rgba(0,0,0,.3); }

/* Toasts */
.toast-host{ position: fixed; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast{ background: rgba(17,24,39,.95); color:#e5e7eb; border:1px solid var(--border); border-radius:10px; padding:.5rem .65rem; box-shadow: 0 8px 24px rgba(0,0,0,.35); transition: transform .2s ease, opacity .2s ease; }
.toast.hide{ opacity:0; transform: translateY(6px); }
.toast.success{ border-color: rgba(22,163,74,.4); }
.toast.error{ border-color: rgba(239,68,68,.45); }
.toast.warn{ border-color: rgba(245,158,11,.45); }

/* Skeletons */
[data-skeleton]{ position: relative; }
[data-skeleton].is-loading > :not([data-skeleton-placeholder]){ opacity: 0; }
[data-skeleton-placeholder]{ display:none; pointer-events:none; }
[data-skeleton].is-loading > [data-skeleton-placeholder]{ display:flex; flex-direction:column; opacity:1; }
[data-skeleton][data-skeleton-overlay="false"]::after,
[data-skeleton][data-skeleton-overlay="false"]::before{ display:none !important; }
[data-skeleton]::after{
	content: '';
	position: absolute; inset: 0;
	border-radius: 8px;
	background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.08), rgba(255,255,255,0.04));
	background-size: 200% 100%;
	animation: shimmer 1.1s linear infinite;
	display: none;
}
[data-skeleton].is-loading::after{ display:block; }
[data-skeleton].is-loading::before{
	content: attr(data-skeleton-label);
	position:absolute;
	top:50%;
	left:50%;
	transform:translate(-50%, -50%);
	color: var(--muted);
	font-size:.85rem;
	text-align:center;
	line-height:1.4;
	max-width:min(92%, 360px);
	padding:.3rem .5rem;
	pointer-events:none;
	z-index:1;
	filter: drop-shadow(0 2px 4px rgba(15,23,42,.45));
}
[data-skeleton][data-skeleton-label=""]::before{ content:''; }
@keyframes shimmer{ 0%{ background-position: 200% 0; } 100%{ background-position: -200% 0; } }

/* Banner */
.banner{ background: linear-gradient(90deg, rgba(0,0,0,.25), rgba(0,0,0,0)); border: 1px solid var(--border); border-radius: 10px; padding: 2rem 1.6rem; margin-bottom: 1rem; box-shadow: 0 8px 30px rgba(0,0,0,.25) inset; }
.banner h1{ font-size: 2rem; margin:0 0 .35rem; }
.banner .subtitle{ color: var(--muted); font-size:.95rem; }

/* Home actions */
.actions-grid{ display:grid; grid-template-columns: repeat( auto-fill, minmax(220px, 1fr) ); gap: .75rem; }
.action-button{ display:block; text-decoration:none; color: var(--text); border:1px solid var(--border); background: var(--panel); padding:1.25rem; border-radius:10px; text-align:center; font-weight:600; }
.action-button:hover{ border-color: color-mix(in srgb, var(--border) 70%, var(--text) 30%); background: color-mix(in srgb, var(--panel) 80%, var(--text) 20%); }
.action-button.primary{ background: linear-gradient(180deg, rgba(14,104,171,.25), rgba(14,104,171,.05)); border-color: #274766; }

/* Card grid for added cards (responsive, compact tiles) */
.card-grid{
	display:grid;
	grid-template-columns: repeat(auto-fill, minmax(170px, 170px)); /* ~160px image + padding */
	gap: .5rem;
	margin-top:.5rem;
	justify-content: start; /* pack as many as possible per row */
	/* Prevent scroll chaining bounce that can cause flicker near bottom */
	overscroll-behavior: contain;
	content-visibility: auto;
	contain: layout paint;
	contain-intrinsic-size: 640px 420px;
}
@media (max-width: 420px){
	.card-grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.card-tile{ width: 100%; }
	.card-tile img{ width: 100%; max-width: 160px; margin: 0 auto; }
}
.card-tile{
	width:170px;
	position: relative;
	background: var(--panel);
	border:1px solid var(--border);
	border-radius:6px;
	padding:.25rem .25rem .4rem;
	text-align:center;
}
.card-tile.game-changer{ border-color: var(--red-main); box-shadow: 0 0 0 1px rgba(211,32,42,.35) inset; }
.card-tile.locked{
	/* Subtle yellow/goldish-white accent for locked cards */
	border-color: #f5e6a8; /* soft parchment gold */
	box-shadow: 0 0 0 2px rgba(245,230,168,.28) inset;
}
.card-tile.must-include{
	border-color: rgba(74,222,128,.85);
	box-shadow: 0 0 0 1px rgba(74,222,128,.32) inset, 0 0 12px rgba(74,222,128,.2);
}
.card-tile.must-exclude{
	border-color: rgba(239,68,68,.85);
	box-shadow: 0 0 0 1px rgba(239,68,68,.35) inset;
	opacity: .95;
}
.card-tile.must-include.must-exclude{
	border-color: rgba(249,115,22,.85);
	box-shadow: 0 0 0 1px rgba(249,115,22,.4) inset;
}
.card-tile img{ width:160px; height:auto; border-radius:6px; box-shadow: 0 6px 18px rgba(0,0,0,.35); background:#111; }
.card-tile .name{ font-weight:600; margin-top:.25rem; font-size:.92rem; }
.card-tile .reason{ color:var(--muted); font-size:.85rem; margin-top:.15rem; }

.must-have-controls{
	display:flex;
	justify-content:center;
	gap:.35rem;
	flex-wrap:wrap;
	margin-top:.35rem;
}
.must-have-btn{
	border:1px solid var(--border);
	background:rgba(30,41,59,.6);
	color:#f8fafc;
	font-size:11px;
	text-transform:uppercase;
	letter-spacing:.06em;
	padding:.25rem .6rem;
	border-radius:9999px;
	cursor:pointer;
	transition: all .18s ease;
}
.must-have-btn.include[data-active="1"], .must-have-btn.include:hover{
	border-color: rgba(74,222,128,.75);
	background: rgba(74,222,128,.18);
	color: #bbf7d0;
	box-shadow: 0 0 0 1px rgba(16,185,129,.25);
}
.must-have-btn.exclude[data-active="1"], .must-have-btn.exclude:hover{
	border-color: rgba(239,68,68,.75);
	background: rgba(239,68,68,.18);
	color: #fecaca;
	box-shadow: 0 0 0 1px rgba(239,68,68,.25);
}
.must-have-btn:focus-visible{
	outline:2px solid rgba(59,130,246,.6);
	outline-offset:2px;
}
.card-tile.must-exclude .must-have-btn.include[data-active="0"],
.card-tile.must-include .must-have-btn.exclude[data-active="0"]{
	opacity:.65;
}

.group-grid{ content-visibility: auto; contain: layout paint; contain-intrinsic-size: 540px 360px; }
.alt-list{ list-style:none; padding:0; margin:0; display:grid; gap:.25rem; content-visibility: auto; contain: layout paint; contain-intrinsic-size: 320px 220px; }

/* Shared ownership badge for card tiles and stacked images */
.owned-badge{
	position:absolute;
	top:6px;
	left:6px;
	background:rgba(17,24,39,.9);
	color:#e5e7eb;
	border:1px solid var(--border);
	border-radius:12px;
	font-size:12px;
	line-height:18px;
	height:18px;
	min-width:18px;
	padding:0 6px;
	text-align:center;
	pointer-events:none;
	z-index:2;
}

/* Step 1 candidate grid (200px-wide scaled images) */
.candidate-grid{
	display:grid;
	grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
	gap:.75rem;
}
.candidate-tile{
	background: var(--panel);
	border:1px solid var(--border);
	border-radius:8px;
	padding:.4rem;
}
.candidate-tile .img-btn{ display:block; width:100%; padding:0; background:transparent; border:none; cursor:pointer; }
.candidate-tile img{ width:100%; max-width:200px; height:auto; border-radius:8px; box-shadow:0 6px 18px rgba(0,0,0,.35); background: var(--panel); display:block; margin:0 auto; }
.candidate-tile .meta{ text-align:center; margin-top:.35rem; }
.candidate-tile .name{ font-weight:600; font-size:.95rem; }
.candidate-tile .score{ color:var(--muted); font-size:.85rem; }

/* Deck summary: highlight game changers */
.game-changer { color: var(--green-main); }
.stack-card.game-changer { outline: 2px solid var(--green-main); }

/* Image button inside card tiles */
.card-tile .img-btn{ display:block; padding:0; background:transparent; border:none; cursor:pointer; width:100%; }

/* Stage Navigator */
.stage-nav { margin:.5rem 0 1rem; }
.stage-nav ol { list-style:none; padding:0; margin:0; display:flex; gap:.35rem; flex-wrap:wrap; }
.stage-nav .stage-link { display:flex; align-items:center; gap:.4rem; background: var(--panel); border:1px solid var(--border); color:var(--text); border-radius:999px; padding:.25rem .6rem; cursor:pointer; }
.stage-nav .stage-item.done .stage-link { opacity:.75; }
.stage-nav .stage-item.current .stage-link { box-shadow: 0 0 0 2px rgba(96,165,250,.4) inset; border-color:#3b82f6; }
.stage-nav .idx { display:inline-grid; place-items:center; width:20px; height:20px; border-radius:50%; background:#1f2937; font-size:12px; }
.stage-nav .name { font-size:12px; }

/* Build controls sticky box tweaks */
.build-controls { 
	position: sticky; 
	top: calc(var(--banner-offset, 48px) + 6px); 
	z-index: 100;
	background: linear-gradient(180deg, rgba(15,17,21,.98), rgba(15,17,21,.92));
	backdrop-filter: blur(8px);
	border: 1px solid var(--border);
	border-radius: 10px;
	margin: 0.5rem 0;
	box-shadow: 0 4px 12px rgba(0,0,0,.25);
}

@media (max-width: 1024px){
	:root { --banner-offset: 56px; }
	.build-controls { 
		position: fixed !important; /* Fixed to viewport instead of sticky */
		bottom: 0 !important; /* Anchor to bottom of screen */
		left: 0 !important;
		right: 0 !important;
		top: auto !important; /* Override top positioning */
		border-radius: 0 !important; /* Remove border radius for full width */
		margin: 0 !important; /* Remove margins for full edge-to-edge */
		padding: 0.5rem !important; /* Reduced padding */
		box-shadow: 0 -6px 20px rgba(0,0,0,.4) !important; /* Upward shadow */
		border-left: none !important;
		border-right: none !important;
		border-bottom: none !important; /* Remove bottom border */
		background: linear-gradient(180deg, rgba(15,17,21,.99), rgba(15,17,21,.95)) !important;
		z-index: 1000 !important; /* Higher z-index to ensure it's above content */
	}
}
@media (min-width: 721px){
	:root { --banner-offset: 48px; }
}

/* Progress bar */
.progress { position: relative; height: 10px; background: var(--panel); border:1px solid var(--border); border-radius: 999px; overflow: hidden; }
.progress .bar { position:absolute; left:0; top:0; bottom:0; width: 0%; background: linear-gradient(90deg, rgba(96,165,250,.6), rgba(14,104,171,.9)); }
.progress.flash { box-shadow: 0 0 0 2px rgba(245,158,11,.35) inset; }

/* Chips */
.chip { display:inline-flex; align-items:center; gap:.35rem; background: var(--panel); border:1px solid var(--border); color:var(--text); border-radius:999px; padding:.2rem .55rem; font-size:12px; }
.chip .dot { width:8px; height:8px; border-radius:50%; background:#6b7280; }

/* Cards toolbar */
.cards-toolbar{ display:flex; flex-wrap:wrap; gap:.5rem .75rem; align-items:center; margin:.5rem 0 .25rem; }
.cards-toolbar input[type="text"]{ min-width: 220px; }
.cards-toolbar .sep{ width:1px; height:20px; background: var(--border); margin:0 .25rem; }
.cards-toolbar .hint{ color: var(--muted); font-size:12px; }

/* Collapse groups and reason toggle */
.group{ margin:.5rem 0; }
.group-header{ display:flex; align-items:center; gap:.5rem; }
.group-header h5{ margin:.4rem 0; }
.group-header .count{ color: var(--muted); font-size:12px; }
.group-header .toggle{ margin-left:auto; background: color-mix(in srgb, var(--panel) 80%, var(--text) 20%); color: var(--text); border:1px solid var(--border); border-radius:6px; padding:.2rem .5rem; font-size:12px; cursor:pointer; }
.group-grid[data-collapsed]{ display:none; }
.hide-reasons .card-tile .reason{ display:none; }
.card-tile.force-show .reason{ display:block !important; }
.card-tile.force-hide .reason{ display:none !important; }
.btn-why{ background: color-mix(in srgb, var(--panel) 80%, var(--text) 20%); color: var(--text); border:1px solid var(--border); border-radius:6px; padding:.15rem .4rem; font-size:12px; cursor:pointer; }
.chips-inline{ display:flex; gap:.35rem; flex-wrap:wrap; align-items:center; }
.chips-inline .chip{ cursor:pointer; user-select:none; }

/* Inline error banner */
.inline-error-banner{ background: color-mix(in srgb, var(--panel) 85%, #b91c1c 15%); border:1px solid #b91c1c; color:#b91c1c; padding:.5rem .6rem; border-radius:8px; margin-bottom:.5rem; }
.inline-error-banner .muted{ color:#fda4af; }

/* Alternatives panel */
.alts ul{ list-style:none; padding:0; margin:0; }
.alts li{ display:flex; align-items:center; gap:.4rem; }
/* LQIP blur/fade-in for thumbnails */
img.lqip { filter: blur(8px); opacity: .6; transition: filter .25s ease-out, opacity .25s ease-out; }
img.lqip.loaded { filter: blur(0); opacity: 1; }

/* Respect reduced motion: avoid blur/fade transitions for users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
	* { scroll-behavior: auto !important; }
	img.lqip { transition: none !important; filter: none !important; opacity: 1 !important; }
}

/* Virtualization wrapper should mirror grid to keep multi-column flow */
.virt-wrapper { display: grid; }

/* Mobile responsive fixes for horizontal scrolling issues */
@media (max-width: 768px) {
	/* Prevent horizontal overflow */
	html, body { 
		overflow-x: hidden !important; 
		width: 100% !important;
		max-width: 100vw !important;
	}

	/* Test hand responsive adjustments */
	#test-hand{ --card-w: 170px !important; --card-h: 238px !important; --overlap: .5 !important; }

	/* Modal & form layout fixes (original block retained inside media query) */
	/* Fix modal layout on mobile */
	.modal { 
		padding: 10px !important; 
		box-sizing: border-box;
	}
	.modal-content { 
		width: 100% !important;
		max-width: calc(100vw - 20px) !important;
		box-sizing: border-box !important;
		overflow-x: hidden !important;
	}
	/* Force single column for include/exclude grid */
	.include-exclude-grid { display: flex !important; flex-direction: column !important; gap: 1rem !important; }
	/* Fix basics grid */
	.basics-grid { grid-template-columns: 1fr !important; gap: 1rem !important; }
	/* Ensure all inputs and textareas fit properly */
	.modal input,
	.modal textarea,
	.modal select { width: 100% !important; max-width: 100% !important; box-sizing: border-box !important; min-width: 0 !important; }
	/* Fix chips containers */
	.modal [id$="_chips_container"] { max-width: 100% !important; overflow-x: hidden !important; word-wrap: break-word !important; }
	/* Ensure fieldsets don't overflow */
	.modal fieldset { max-width: 100% !important; box-sizing: border-box !important; overflow-x: hidden !important; }
	/* Fix any inline styles that might cause overflow */
	.modal fieldset > div,
	.modal fieldset > div > div { max-width: 100% !important; overflow-x: hidden !important; }
}

@media (max-width: 640px){
	#test-hand{ --card-w: 150px !important; --card-h: 210px !important; }
	/* Generic stack shrink */
	.stack-wrap:not(#test-hand){ --card-w: 150px; --card-h: 210px; }
}

@media (max-width: 560px){
	#test-hand{ --card-w: 140px !important; --card-h: 196px !important; padding-bottom:.75rem; }
	#test-hand .stack-grid{ display:flex !important; gap:.5rem; grid-template-columns:none !important; overflow-x:auto; padding-bottom:.25rem; }
	#test-hand .stack-card{ flex:0 0 auto; }
	.stack-wrap:not(#test-hand){ --card-w: 140px; --card-h: 196px; }
}

@media (max-width: 480px) {
	.modal-content {
		padding: 12px !important;
		margin: 5px !important;
	}
	
	.modal fieldset {
		padding: 8px !important;
		margin: 6px 0 !important;
	}
	
	/* Enhanced mobile build controls */
	.build-controls {
		flex-direction: column !important;
		gap: 0.25rem !important; /* Reduced gap */
		align-items: stretch !important;
		padding: 0.5rem !important; /* Reduced padding */
	}
	
	/* Two-column grid layout for mobile build controls */
	.build-controls {
		display: grid !important;
		grid-template-columns: 1fr 1fr !important; /* Two equal columns */
		grid-gap: 0.25rem !important;
		align-items: stretch !important;
	}
	
	.build-controls form {
		display: contents !important; /* Allow form contents to participate in grid */
		width: auto !important;
	}
	
	.build-controls button {
		flex: none !important;
		padding: 0.4rem 0.5rem !important; /* Much smaller padding */
		font-size: 12px !important; /* Smaller font */
		min-height: 36px !important; /* Smaller minimum height */
		line-height: 1.2 !important;
		width: 100% !important; /* Full width within grid cell */
		box-sizing: border-box !important;
		white-space: nowrap !important;
		display: flex !important;
		align-items: center !important;
		justify-content: center !important;
	}
	
	/* Hide non-essential elements on mobile to keep it clean */
	.build-controls .sep, 
	.build-controls .replace-toggle,
	.build-controls label[style*="margin-left"] {
		display: none !important;
	}
	
	.build-controls .sep {
		display: none !important; /* Hide separators on mobile */
	}
}

/* Desktop sizing for Test Hand */
@media (min-width: 900px) {
	#test-hand { --card-w: 280px !important; --card-h: 392px !important; }
}

/* Analytics accordion styling */
.analytics-accordion {
	transition: all 0.2s ease;
}

.analytics-accordion summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.analytics-accordion summary:hover {
	background: #1f2937;
	border-color: #374151;
}

.analytics-accordion summary:active {
	transform: scale(0.99);
}

.analytics-accordion[open] summary {
	border-bottom-left-radius: 0;
	border-bottom-right-radius: 0;
	margin-bottom: 0;
}

.analytics-accordion .analytics-content {
	animation: accordion-slide-down 0.3s ease-out;
}

@keyframes accordion-slide-down {
	from {
		opacity: 0;
		transform: translateY(-8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.analytics-placeholder .skeleton-pulse {
	animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
	0% { background-position: -200% 0; }
	100% { background-position: 200% 0; }
}

/* Ideals Slider Styling */
.ideals-slider {
	-webkit-appearance: none;
	appearance: none;
	height: 6px;
	background: var(--border);
	border-radius: 3px;
	outline: none;
}

.ideals-slider::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 18px;
	height: 18px;
	background: var(--ring);
	border-radius: 50%;
	cursor: pointer;
	transition: all 0.15s ease;
}

.ideals-slider::-webkit-slider-thumb:hover {
	transform: scale(1.15);
	box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.2);
}

.ideals-slider::-moz-range-thumb {
	width: 18px;
	height: 18px;
	background: var(--ring);
	border: none;
	border-radius: 50%;
	cursor: pointer;
	transition: all 0.15s ease;
}

.ideals-slider::-moz-range-thumb:hover {
	transform: scale(1.15);
	box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.2);
}

.slider-value {
	display: inline-block;
	padding: 0.25rem 0.5rem;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 4px;
}
