/* Snap Bricks — a 3D brick builder in a dark hardware-style panel; follows the site / Remix variables. */
.sb {
  position: relative; outline: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column; gap: 14px; box-sizing: border-box;
  background: linear-gradient(180deg, var(--bg3, #18181e), var(--bg2, #121216));
  border: 1px solid var(--line, #232329); border-radius: 24px; padding: 16px;
  box-shadow: 0 30px 80px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.05);
  color: var(--ink, #f4f4f1); font-family: inherit; font-size: 14px;
}
.sb *, .sb *::before, .sb *::after { box-sizing: border-box; }
.sb button, .sb a.sb-btn { font-family: inherit; color: inherit; cursor: pointer; text-transform: none; letter-spacing: normal; margin: 0; min-height: 0; line-height: 1.1; }
.sb [hidden] { display: none !important; }
.sb svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sb svg .f { fill: currentColor; stroke: none; }

/* top strip: brand, tools, display */
.sb-top { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(170px, 260px); gap: 14px; align-items: center; }
.sb-brand { display: flex; flex-direction: column; line-height: 1.1; }
.sb-brand b { font-size: 19px; font-weight: 900; letter-spacing: .08em; white-space: nowrap; }
.sb-brand span { font-size: 10px; letter-spacing: .2em; color: var(--mute, #9a9aa3); margin-top: 4px; white-space: nowrap; }
.sb-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
.sb-sep { width: 1px; height: 34px; background: var(--line, #232329); margin: 0 4px; }
.sb-tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 52px; height: 52px; padding: 5px 6px;
  border-radius: 13px; border: 1px solid var(--line, #232329); background: var(--bg, #0b0b0d);
  box-shadow: 0 3px 0 rgba(0,0,0,.35); transition: transform .08s, background .15s, border-color .15s;
}
.sb-tool span { font-size: 10.5px; font-weight: 700; letter-spacing: .02em; color: var(--mute, #9a9aa3); }
.sb-tool:hover { border-color: var(--acc, #ff4d2e); }
.sb-tool:active { transform: translateY(2px); box-shadow: none; }
.sb-tool.on { background: var(--acc, #ff4d2e); border-color: var(--acc, #ff4d2e); color: #fff; }
.sb-tool.on span { color: #fff; }
.sb-lcd {
  min-width: 0; background: #07090a; border-radius: 12px; padding: 9px 13px; border: 1px solid #000;
  box-shadow: inset 0 2px 10px rgba(0,0,0,.8), 0 1px 0 rgba(255,255,255,.05);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--acc, #ff4d2e);
}
.sb-lcd-main { font-size: 14px; font-weight: 700; letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 0 10px color-mix(in srgb, var(--acc, #ff4d2e) 60%, transparent); }
.sb-lcd-sub { font-size: 11.5px; opacity: .82; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.3em; }

/* body: parts | stage | colors & camera */
.sb-body { display: grid; grid-template-columns: 252px minmax(0, 1fr) 236px; gap: 14px; height: min(80vh, 780px); min-height: 540px; }
.sb-left, .sb-right { min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 14px; padding-right: 2px; scrollbar-width: thin; scrollbar-color: var(--line, #232329) transparent; }
.sb-sec { display: flex; flex-direction: column; gap: 8px; }
.sb-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sb-lbl { font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--mute, #9a9aa3); }
.sb-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sb-chip, .sb-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line, #232329); background: var(--bg, #0b0b0d);
  font-size: 12.5px; font-weight: 700; text-decoration: none; transition: border-color .15s, background .15s;
}
.sb-chip:hover, .sb-btn:hover { border-color: var(--acc, #ff4d2e); }
.sb-chip.on { background: var(--acc, #ff4d2e); border-color: var(--acc, #ff4d2e); color: #fff; }
.sb-btn { background: var(--acc, #ff4d2e); border-color: var(--acc, #ff4d2e); color: #fff !important; justify-content: center; }
.sb-btn:hover { filter: brightness(1.08); }
.sb-wide { width: 100%; padding: 11px 14px; font-size: 13.5px; }
.sb-empty, .sb-note { margin: 0; font-size: 12px; color: var(--dim, #6b6b74); line-height: 1.4; }
.sb-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); vertical-align: -1px; }

/* parts */
.mxp-app .sb input.sb-search, .mxp-app .sb input.sb-name, .mxp-app .sb .sb-in {
  display: block; width: 100%; max-width: none; min-width: 0; margin: 0; padding: 10px 13px; border-radius: 12px;
  border: 1px solid var(--line, #232329); background: var(--bg, #0b0b0d); color: var(--ink, #f4f4f1); box-shadow: none;
  font: 500 13px/1.3 inherit; font-family: inherit; outline: none; user-select: text; -webkit-user-select: text; height: auto;
}
.mxp-app .sb .sb-in:focus, .mxp-app .sb input.sb-search:focus, .mxp-app .sb input.sb-name:focus { border-color: var(--acc, #ff4d2e); }
.sb-cats { gap: 5px; }
.sb-cats .sb-chip { padding: 6px 10px; font-size: 11.5px; }
.sb-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 7px; align-content: start; }
.sb-part {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 4px 6px; border-radius: 12px;
  border: 1px solid var(--line, #232329); background: radial-gradient(120% 90% at 50% 20%, #23232b, #111115 75%); text-align: center; transition: border-color .15s, transform .08s;
}
.sb-part:hover { border-color: color-mix(in srgb, var(--acc, #ff4d2e) 60%, var(--line, #232329)); }
.sb-part:active { transform: scale(.97); }
.sb-part.on { border-color: var(--acc, #ff4d2e); box-shadow: 0 0 0 1px var(--acc, #ff4d2e), 0 0 18px color-mix(in srgb, var(--acc, #ff4d2e) 30%, transparent); }
.sb-part img, .sb-ph { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; pointer-events: none; }
.sb-ph { display: grid; place-items: center; font-style: normal; font-weight: 800; font-size: 13px; color: var(--dim, #6b6b74); }
.sb-part span { font-size: 9.5px; font-weight: 600; line-height: 1.15; color: var(--mute, #9a9aa3); max-height: 2.3em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sb-part.on span { color: var(--ink, #f4f4f1); }
.sb-quick .sb-chip { font-size: 12px; }

/* stage */
.sb-stage { position: relative; min-width: 0; min-height: 0; border-radius: 18px; overflow: hidden; border: 1px solid var(--line, #232329); background: var(--bg, #0b0b0d); box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); }
.sb-view { position: absolute; inset: 0; touch-action: none; }
.sb-view canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; outline: none; cursor: crosshair; }
.sb-view canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--acc, #ff4d2e); }
.sb-view[data-tool="select"] canvas { cursor: default; }
.sb-view[data-tool="box"] canvas { cursor: cell; }
.sb-view[data-tool="paint"] canvas, .sb-view[data-tool="pick"] canvas { cursor: copy; }
.sb-view[data-tool="delete"] canvas { cursor: not-allowed; }
.sb-boxsel { position: absolute; border: 1.5px dashed var(--acc, #ff4d2e); background: color-mix(in srgb, var(--acc, #ff4d2e) 12%, transparent); pointer-events: none; border-radius: 3px; }
.sb-hud {
  position: absolute; left: 12px; top: 12px; max-width: calc(100% - 24px); padding: 7px 11px; border-radius: 10px; pointer-events: none;
  background: rgba(8,8,10,.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.08);
  font-size: 12px; color: #e9e9ee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-hud b { color: #fff; }
.sb-camov { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.sb-camov button {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid rgba(255,255,255,.1); background: rgba(8,8,10,.62); color: #f4f4f1;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); font-size: 19px; font-weight: 700; padding: 0; display: grid; place-items: center;
}
.sb-camov button:hover { border-color: var(--acc, #ff4d2e); }
.sb-loading { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; color: var(--mute, #9a9aa3); font-weight: 700; }

/* colors */
.sb-cname { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--ink, #f4f4f1); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-cname::before { content: ''; flex: none; width: 12px; height: 12px; border-radius: 4px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(255,255,255,.3); }
.sb-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(25px, 1fr)); gap: 5px; }
.sb-sw {
  position: relative; aspect-ratio: 1; padding: 0; border-radius: 8px; border: 1px solid rgba(0,0,0,.55);
  background: var(--c); box-shadow: inset 0 2px 0 rgba(255,255,255,.22), inset 0 -2px 0 rgba(0,0,0,.25); transition: transform .08s;
}
.sb-sw:hover { transform: scale(1.1); z-index: 1; }
.sb-sw.on { box-shadow: 0 0 0 2px var(--bg2, #121216), 0 0 0 4px var(--ink, #f4f4f1); z-index: 2; }
.sb-sw.k-t, .sb-dot.k-t { background: linear-gradient(135deg, color-mix(in srgb, var(--c) 75%, transparent) 0 50%, color-mix(in srgb, var(--c) 40%, transparent) 50%), repeating-conic-gradient(#3a3a42 0 25%, #1c1c22 0 50%) 0 0 / 8px 8px; }
.sb-sw.k-m, .sb-dot.k-m { background: linear-gradient(135deg, rgba(255,255,255,.75), transparent 45%, rgba(0,0,0,.35) 70%, rgba(255,255,255,.35)), var(--c); }
.sb-custom { display: flex; align-items: center; gap: 9px; font-size: 12.5px; font-weight: 700; color: var(--mute, #9a9aa3); cursor: pointer; }
.mxp-app .sb .sb-custom input[type=color] { width: 34px; height: 26px; padding: 0; margin: 0; border: 1px solid var(--line, #232329); border-radius: 8px; background: none; cursor: pointer; max-width: none; }
.sb-angle output { font: 700 12px 'JetBrains Mono', ui-monospace, monospace; }
.mxp-app .sb input[type=range] {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; max-width: none; min-width: 0; height: 22px; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: transparent; box-shadow: none; outline: none; cursor: pointer;
}
.mxp-app .sb input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: var(--line, #2a2a31); }
.mxp-app .sb input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--line, #2a2a31); }
.mxp-app .sb input[type=range]::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--acc, #ff4d2e); }
.mxp-app .sb input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--acc, #ff4d2e); border: 2px solid var(--ink, #f4f4f1); box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.mxp-app .sb input[type=range]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--acc, #ff4d2e); border: 2px solid var(--ink, #f4f4f1); }

/* builds */
.sb-saverow { display: flex; gap: 6px; }
.sb-saverow .sb-btn { flex: none; }
.sb-saves { display: flex; flex-direction: column; gap: 6px; }
.sb-save { display: flex; align-items: center; gap: 6px; padding: 7px 8px 7px 11px; border-radius: 12px; background: var(--bg, #0b0b0d); border: 1px solid var(--line, #232329); }
.sb-save span { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sb-save b { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-save small { font-size: 10.5px; color: var(--dim, #6b6b74); }
.sb-save .sb-chip { padding: 6px 9px; font-size: 11.5px; }
.sb-del.arm { background: #ff3b30; border-color: #ff3b30; color: #fff; }

/* parts list */
.sb-bom summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; }
.sb-bom summary::-webkit-details-marker { display: none; }
.sb-bom summary::after { content: '▾'; color: var(--mute, #9a9aa3); margin-left: 6px; }
.sb-bom[open] summary::after { content: '▴'; }
.sb-bomn { margin-left: auto; font: 700 12px 'JetBrains Mono', ui-monospace, monospace; color: var(--acc, #ff4d2e); }
.sb-bomlist table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 0; }
.sb-bomlist td { padding: 5px 4px; border: 0; border-bottom: 1px solid var(--line, #232329); vertical-align: middle; background: none; color: var(--ink, #f4f4f1); }
.sb-bomlist td:first-child { width: 18px; }
.sb-bomlist td:last-child { text-align: right; font-weight: 800; font-family: 'JetBrains Mono', ui-monospace, monospace; white-space: nowrap; }
.sb-bomlist small { display: block; color: var(--dim, #6b6b74); font-size: 10.5px; }

/* pop-ups */
.sb-pop { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(5,5,7,.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); border-radius: inherit; }
.sb-card { position: relative; width: min(100%, 440px); max-height: 100%; overflow-y: auto; background: var(--bg2, #121216); border: 1px solid var(--line, #232329); border-radius: 20px; padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.55); }
.sb-wide-pop .sb-card { width: min(100%, 560px); }
.sb-cardin { display: flex; flex-direction: column; gap: 12px; }
.sb-card h3 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: -.01em; color: var(--ink, #f4f4f1); }
.sb-card p { margin: 0; color: var(--mute, #9a9aa3); font-size: 13px; line-height: 1.45; }
.sb-x { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line, #232329); background: var(--bg, #0b0b0d); font-size: 20px; padding: 0; }
.mxp-app .sb textarea.sb-code { resize: vertical; font: 12px/1.35 'JetBrains Mono', ui-monospace, monospace; word-break: break-all; min-height: 96px; }
.sb-err { color: #ff6b5e !important; font-weight: 700; }
.sb-photo { display: block; width: 100%; border-radius: 12px; border: 1px solid var(--line, #232329); background: #000; }
.sb-maker { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 16px; align-items: start; }
.sb-mprev { aspect-ratio: 1; border-radius: 16px; border: 1px solid var(--line, #232329); background: radial-gradient(120% 90% at 50% 20%, #26262e, #101014 75%); display: grid; place-items: center; overflow: hidden; }
.sb-mprev img { width: 100%; height: 100%; object-fit: contain; }
.sb-mprev img:not([src]) { visibility: hidden; }
.sb-mform { display: flex; flex-direction: column; gap: 8px; }
.sb-rng { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; font-weight: 700; color: var(--mute, #9a9aa3); cursor: pointer; }
.sb-rng output { color: var(--ink, #f4f4f1); font-family: 'JetBrains Mono', ui-monospace, monospace; margin-left: 4px; }
.sb-mname { color: var(--ink, #f4f4f1) !important; font-weight: 700; }

/* desktop: break out of the page column a little so the stage gets room */
@media (min-width: 1300px) {
  .mxp-app[data-game="snap-bricks"] { width: min(calc(100vw - 48px), 1560px); margin-left: calc(50% - min(50vw - 24px, 780px)); }
  .sb-body { grid-template-columns: 270px minmax(0, 1fr) 250px; }
}
@media (max-width: 1100px) {
  .sb-top { grid-template-columns: auto minmax(0, 1fr); }
  .sb-lcd { grid-column: 1 / -1; grid-row: 2; }
  .sb-tools { justify-content: flex-end; }
  .sb-body { grid-template-columns: 220px minmax(0, 1fr) 210px; }
}
/* tablet + phone: the stage goes on top, panels stack under it */
@media (max-width: 860px) {
  .sb { padding: 12px; gap: 12px; }
  .sb-top { grid-template-columns: 1fr; gap: 10px; }
  .sb-brand { flex-direction: row; align-items: baseline; gap: 10px; }
  .sb-lcd { grid-row: auto; }
  .sb-tools { justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 3px; margin: 0 -2px; }
  .sb-tools::-webkit-scrollbar { display: none; }
  .sb-tools .sb-run { order: -1; }   /* Run stays in view on the scrolling toolbar */
  .sb-tool { flex: none; min-width: 58px; height: 56px; }
  .sb-body { display: flex; flex-direction: column; height: auto; min-height: 0; }
  .sb-stage { order: -1; height: 62svh; min-height: 330px; max-height: 640px; }
  .sb-left, .sb-right { overflow: visible; }
  .sb-left .sb-parts { max-height: 300px; overflow-y: auto; padding: 2px; }
  .sb-cats { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .sb-cats::-webkit-scrollbar { display: none; }
  .sb-cats .sb-chip { flex: none; }
  .sb-swatches { grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); }
  .sb-maker { grid-template-columns: 1fr; }
  .sb-mprev { width: 150px; justify-self: center; }
}
@media (max-width: 600px) {
  .sb { width: 100%; margin: 0; border-radius: 0; border-left: 0; border-right: 0; padding: 12px 10px; }
  .sb-stage { border-radius: 14px; height: 58svh; }
  .sb-brand b { font-size: 17px; }
  .sb-hud { font-size: 11px; top: 8px; left: 8px; }
  .sb-parts { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}
@media (hover: none) and (pointer: coarse) {
  .sb-chip { padding: 10px 14px; }
  .sb-camov button { width: 46px; height: 46px; }
  .sb-tool { min-width: 60px; height: 58px; }
}
@media (prefers-reduced-motion: reduce) { .sb-tool, .sb-part, .sb-sw { transition: none; } }
