*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
	--red: #D01012; --red-dark: #A50E0E; --yellow: #FFD700; --yellow-light: #FFF3B0;
	--blue: #006DB7; --green: #00852B; --bg: #F5F5F0; --card: #FFFFFF;
	--text: #1A1A1A; --text-light: #666; --border: #E0E0E0;
	--shadow: 0 2px 8px rgba(0,0,0,0.08); --radius: 10px;
}
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; padding-bottom: 4rem; }

/* Header */
.app-header { background: var(--red); color: #fff; padding: 0.75rem 1rem; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 12px rgba(208,16,18,0.3); }
.app-header h1 { font-size: 1.15rem; font-weight: 700; }
.header-row { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; }
.search-box { position: relative; flex: 1; }
.search-box input { width: 100%; padding: 0.45rem 0.7rem 0.45rem 2rem; border: none; border-radius: var(--radius); font-size: 0.85rem; background: rgba(255,255,255,0.2); color: #fff; outline: none; }
.search-box input::placeholder { color: rgba(255,255,255,0.6); }
.search-box input:focus { background: rgba(255,255,255,0.3); }
.search-box .ico { position: absolute; left: 0.6rem; top: 50%; transform: translateY(-50%); opacity: 0.6; font-size: 0.85rem; }

/* Tabs */
.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 4.75rem; z-index: 90; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab { flex: 1; padding: 0.6rem 0.25rem; text-align: center; font-size: 0.72rem; font-weight: 600; color: var(--text-light); border: none; background: none; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; transition: 0.2s; min-width: 0; }
.tab.active { color: var(--red); border-bottom-color: var(--red); }

.main { padding: 0.75rem; max-width: 840px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* Stats */
.stats-bar { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; overflow-x: auto; padding-bottom: 0.2rem; }
.stat-chip { background: var(--card); border-radius: 20px; padding: 0.3rem 0.65rem; font-size: 0.7rem; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); display: flex; align-items: center; gap: 0.3rem; }
.stat-chip .n { color: var(--red); font-size: 0.85rem; }

/* ── Theme browser ─────────────────────────────────────────── */
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.theme-card { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--card); box-shadow: var(--shadow); cursor: pointer; aspect-ratio: 4/3; display: flex; align-items: flex-end; transition: transform 0.15s; }
.theme-card:active { transform: scale(0.97); }
.theme-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.theme-card .overlay { position: relative; z-index: 1; width: 100%; padding: 0.5rem 0.6rem; background: linear-gradient(transparent, rgba(0,0,0,0.75)); color: #fff; }
.theme-card .t-name { font-weight: 700; font-size: 0.8rem; line-height: 1.2; }
.theme-card .t-meta { font-size: 0.65rem; opacity: 0.85; }
.theme-card .t-badge { position: absolute; top: 0.4rem; right: 0.4rem; background: var(--red); color: #fff; border-radius: 10px; padding: 0.1rem 0.45rem; font-size: 0.65rem; font-weight: 700; z-index: 2; }

/* ── Filter bar ────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; overflow-x: auto; padding-bottom: 0.2rem; -webkit-overflow-scrolling: touch; }
.filter-chip { background: var(--card); border: 1.5px solid var(--border); border-radius: 20px; padding: 0.3rem 0.7rem; font-size: 0.72rem; font-weight: 600; white-space: nowrap; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 0.3rem; }
.filter-chip.active { background: var(--red); color: #fff; border-color: var(--red); }
.filter-chip select { border: none; background: transparent; font: inherit; color: inherit; cursor: pointer; outline: none; padding-right: 0.2rem; }
.filter-chip.active select { color: #fff; }

.active-filters { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.6rem; }
.active-filter { background: var(--yellow-light); color: #856404; border-radius: 12px; padding: 0.2rem 0.55rem; font-size: 0.7rem; font-weight: 600; display: flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.active-filter .x { font-weight: 700; }

/* ── Location groups ───────────────────────────────────────── */
.location-group { margin-bottom: 1rem; }
.location-header { font-size: 0.8rem; font-weight: 700; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.03em; padding: 0.4rem 0; border-bottom: 2px solid var(--red); margin-bottom: 0.4rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.2rem; }
.location-badges { display: flex; gap: 0.3rem; }
.location-header .count { background: var(--red); color: #fff; border-radius: 10px; padding: 0.1rem 0.45rem; font-size: 0.65rem; }
.location-header .count.parts { background: var(--blue); }

/* ── Set cards ─────────────────────────────────────────────── */
.set-card { background: var(--card); border-radius: var(--radius); padding: 0.5rem 0.65rem; margin-bottom: 0.4rem; box-shadow: var(--shadow); cursor: pointer; transition: transform 0.15s; display: flex; align-items: center; gap: 0.6rem; }
.set-card:active { transform: scale(0.98); }
.set-thumb { width: 48px; height: 48px; border-radius: 6px; object-fit: contain; background: #f8f8f8; flex-shrink: 0; }
.set-thumb-empty { width: 48px; height: 48px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; background: #f0f0f0; flex-shrink: 0; }
.set-info { flex: 1; min-width: 0; }
.set-name { font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-number { color: var(--text-light); font-weight: 400; font-size: 0.72rem; }
.set-meta { font-size: 0.7rem; color: var(--text-light); margin-top: 0.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.children-badge { background: var(--blue); color: #fff; border-radius: 10px; padding: 0.12rem 0.45rem; font-size: 0.65rem; font-weight: 600; white-space: nowrap; flex-shrink: 0; }

/* ── Tree ──────────────────────────────────────────────────── */
.tree-node { margin-left: 0.85rem; }
.tree-node.level-0 { margin-left: 0; }
.tree-item { padding: 0.45rem 0.65rem; margin-bottom: 0.2rem; background: var(--card); border-radius: 8px; box-shadow: var(--shadow); cursor: pointer; display: flex; align-items: center; gap: 0.45rem; font-size: 0.8rem; flex-wrap: wrap; }
.tree-item .toggle { width: 1.1rem; height: 1.1rem; display: flex; align-items: center; justify-content: center; font-size: 0.65rem; color: var(--text-light); transition: transform 0.2s; flex-shrink: 0; }
.tree-item .toggle.open { transform: rotate(90deg); }
.level-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.level-dot.l0 { background: var(--red); } .level-dot.l1 { background: var(--blue); }
.level-dot.l2 { background: var(--green); } .level-dot.l3 { background: var(--yellow); border: 1px solid #ccc; }
.tree-name { flex: 1; min-width: 0; } .tree-name small { color: var(--text-light); }
.tree-loc { font-size: 0.65rem; color: var(--text-light); white-space: nowrap; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; display: flex; align-items: flex-end; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.25s; }
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal { background: var(--card); border-radius: 16px 16px 0 0; width: 100%; max-width: 500px; max-height: 85vh; overflow-y: auto; padding: 1.25rem; transform: translateY(100%); transition: transform 0.3s ease; }
.modal-overlay.open .modal { transform: translateY(0); }
.modal h2 { font-size: 1.05rem; margin-bottom: 0.6rem; display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.modal h2 .close-btn { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-light); line-height: 1; flex-shrink: 0; }
.detail-image { text-align: center; margin-bottom: 0.6rem; }
.detail-image img { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: 8px; background: #f8f8f8; }
.detail-pills { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.6rem; }
.pill { background: #f0f0f0; padding: 0.2rem 0.55rem; border-radius: 20px; font-size: 0.72rem; font-weight: 500; white-space: nowrap; }
.detail-path { font-size: 0.78rem; color: var(--text-light); padding: 0.45rem 0.65rem; background: var(--yellow-light); border-radius: 8px; margin-bottom: 0.4rem; }
.rb-link { display: inline-block; font-size: 0.78rem; color: var(--blue); text-decoration: none; margin: 0.4rem 0; font-weight: 600; }
.detail-children { margin-top: 0.65rem; }
.detail-children h3 { font-size: 0.82rem; color: var(--text-light); margin-bottom: 0.4rem; }
.set-card-mini { padding: 0.4rem 0.65rem; }

/* Form */
.form-group { margin-bottom: 0.65rem; }
.form-group label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-light); margin-bottom: 0.2rem; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 0.55rem 0.7rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: 0.88rem; font-family: inherit; outline: none; transition: border-color 0.2s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--red); }
.form-row { display: flex; gap: 0.65rem; }
.form-row .form-group { flex: 1; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; padding: 0.55rem 1rem; border: none; border-radius: 8px; font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: background 0.2s; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: #dc3545; color: #fff; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.72rem; }
.btn-block { width: 100%; }
.form-actions { display: flex; gap: 0.4rem; margin-top: 0.75rem; }
.form-actions .btn { flex: 1; }

.fab { position: fixed; bottom: 1.25rem; right: 1.25rem; width: 3rem; height: 3rem; border-radius: 50%; background: var(--red); color: #fff; border: none; font-size: 1.4rem; box-shadow: 0 4px 16px rgba(208,16,18,0.4); cursor: pointer; z-index: 50; display: flex; align-items: center; justify-content: center; transition: transform 0.2s; }
.fab:active { transform: scale(0.9); }
.empty { text-align: center; padding: 1.5rem 1rem; color: var(--text-light); font-size: 0.85rem; }
.search-results h2 { font-size: 0.95rem; margin-bottom: 0.6rem; color: var(--text-light); }

/* ── Size bar ──────────────────────────────────────────────── */
.size-legend { display: flex; gap: 0.3rem; margin-bottom: 0.6rem; }
.size-btn { flex: 1; text-align: center; padding: 0.35rem 0.2rem; border-radius: 8px; background: var(--card); border: 1.5px solid var(--border); font-size: 0.65rem; font-weight: 600; cursor: pointer; transition: 0.2s; }
.size-btn.active { background: var(--red); color: #fff; border-color: var(--red); }
.size-btn .sz-label { display: block; font-size: 0.6rem; color: var(--text-light); font-weight: 400; margin-top: 0.1rem; }
.size-btn.active .sz-label { color: rgba(255,255,255,0.8); }

@media (min-width: 500px) {
	.theme-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 600px) {
	.app-header { padding: 0.75rem 1.5rem; }
	.header-row { margin-top: 0; }
	.app-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
	.header-row { flex: 0 0 320px; }
	.main { padding: 1rem; }
	.modal { border-radius: 16px; margin-bottom: 2rem; }
	.set-thumb { width: 56px; height: 56px; }
}

/* ═══════════════════════════════════════════════════════════
   THEME SHOWCASE (LEGO Shop style)
   ═══════════════════════════════════════════════════════════ */
.theme-hero {
	background: var(--card);
	border-radius: 12px;
	overflow: hidden;
	margin-bottom: 0.75rem;
	box-shadow: 0 3px 12px rgba(0,0,0,0.1);
	cursor: pointer;
	transition: transform 0.15s;
}
.theme-hero:active { transform: scale(0.985); }

/* Mosaic: big image left + 2 stacked right */
.theme-mosaic {
	display: grid;
	grid-template-columns: 1.6fr 1fr;
	gap: 2px;
	aspect-ratio: 2/1;
	background: #f0f0f0;
}
.mosaic-main { overflow: hidden; }
.mosaic-main img { width: 100%; height: 100%; object-fit: contain; background: #f8f8f8; }
.mosaic-side { display: flex; flex-direction: column; gap: 2px; }
.mosaic-side img { flex: 1; width: 100%; object-fit: contain; background: #f8f8f8; min-height: 0; }

/* Single hero fallback */
.theme-single-hero { aspect-ratio: 2.2/1; overflow: hidden; background: #f8f8f8; display: flex; align-items: center; justify-content: center; }
.theme-single-hero img { max-width: 100%; max-height: 100%; object-fit: contain; }

.theme-hero-body { padding: 0.75rem 1rem; }
.theme-hero-title { font-size: 1.1rem; font-weight: 800; margin-bottom: 0.25rem; color: var(--text); }
.theme-hero-meta { display: flex; gap: 0.4rem; font-size: 0.75rem; color: var(--text-light); flex-wrap: wrap; }
.theme-hero-arrow { margin-top: 0.4rem; font-size: 0.8rem; font-weight: 600; color: var(--red); }

/* Others compact grid */
.others-title { font-size: 0.85rem; font-weight: 700; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.03em; margin: 1rem 0 0.5rem; padding-bottom: 0.3rem; border-bottom: 2px solid var(--border); }
.theme-compact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.theme-compact { background: var(--card); border-radius: 10px; box-shadow: var(--shadow); cursor: pointer; display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem; transition: transform 0.15s; overflow: hidden; }
.theme-compact:active { transform: scale(0.97); }
.theme-compact img { width: 44px; height: 44px; border-radius: 6px; object-fit: contain; background: #f8f8f8; flex-shrink: 0; }
.tc-empty { width: 44px; height: 44px; border-radius: 6px; background: #f0f0f0; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.tc-info { flex: 1; min-width: 0; }
.tc-name { font-weight: 600; font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-meta { font-size: 0.65rem; color: var(--text-light); }

/* ── Theme detail view ─────────────────────────────────────── */
.back-btn { background: none; border: none; font-size: 0.85rem; font-weight: 600; color: var(--red); cursor: pointer; padding: 0.4rem 0; margin-bottom: 0.5rem; }
.theme-detail-header { margin-bottom: 0.75rem; }
.theme-detail-header h2 { font-size: 1.25rem; font-weight: 800; margin-bottom: 0.4rem; }
.theme-detail-stats { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pill-theme { cursor: pointer !important; background: var(--red) !important; color: #fff !important; }
