/* Brickyard — styled after an instruction booklet: pale blue pages, navy ink,
   white callout boxes, and buttons that press like plastic keys. */

:root {
  --sky-1: #eaf3fa;
  --sky-2: #c3d9eb;
  --ink: #15233b;
  --ink-2: #4b5e79;
  --ink-3: #8898ad;
  --paper: #ffffff;
  --paper-2: #f2f7fc;
  --edge: #15233b;
  --yellow: #ffd23f;
  --yellow-d: #d6a400;
  --red: #e4352b;
  --red-d: #a6241c;
  --green: #2f9e57;
  --r: 14px;
  --panel-w: 312px;
  --top-h: 60px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --sheet-h: 0px;
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: radial-gradient(120% 90% at 60% 30%, var(--sky-1) 0%, #d8e7f3 45%, var(--sky-2) 100%);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible { outline: 3px solid #1f6fd1; outline-offset: 2px; }
svg { width: 22px; height: 22px; flex: none; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  background: var(--paper); border: 2px solid var(--edge);
  box-shadow: 0 3px 0 var(--edge);
  font-weight: 600; font-size: 15px; letter-spacing: 0.01em;
  transition: transform .06s ease, box-shadow .06s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge); }
.btn.primary { background: var(--yellow); }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; text-decoration: underline; text-underline-offset: 3px; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn svg { width: 20px; height: 20px; }
.btn:disabled { opacity: .45; pointer-events: none; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--paper); border: 2px solid var(--edge); box-shadow: 0 3px 0 var(--edge);
  transition: transform .06s ease, box-shadow .06s ease;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }

/* ------------------------------------------------------------ screens */
.screen { position: fixed; inset: 0; display: none; z-index: 20; }
body[data-screen="menu"] #menu { display: flex; }
body[data-screen="catalog"] #catalog { display: flex; }
.hud { display: none; }
body[data-screen="free"] .hud, body[data-screen="guide"] .hud { display: flex; }
body[data-screen="free"] #guidePanel, body[data-screen="guide"] #freePanel { display: none; }

/* ------------------------------------------------------------ menu */
#menu { align-items: center; padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b)); pointer-events: none; }
.menu-inner { width: min(520px, 100%); margin-left: max(0px, calc((100vw - 1180px) / 2)); pointer-events: auto; }
.logo {
  margin: 0; font-weight: 900; font-size: clamp(52px, 8.4vw, 104px); line-height: .9; letter-spacing: -0.035em;
  color: var(--ink);
}
.logo .studs { display: flex; gap: 10px; margin: 0 0 14px 4px; }
.logo .studs i {
  width: clamp(20px, 2.4vw, 30px); aspect-ratio: 1; border-radius: 50%;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), 0 3px 0 rgba(21,35,59,.25);
}
.logo .studs i:nth-child(1) { background: var(--red); }
.logo .studs i:nth-child(2) { background: var(--yellow); }
.logo .studs i:nth-child(3) { background: #1f6fd1; }
.logo .studs i:nth-child(4) { background: var(--green); }
.tag { font-size: clamp(16px, 1.6vw, 19px); line-height: 1.45; color: var(--ink-2); max-width: 30em; margin: 18px 0 28px; }
.choices { display: grid; gap: 14px; }
.choice {
  display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto; column-gap: 16px; align-items: center;
  text-align: left; padding: 16px 20px; border-radius: 18px;
  background: var(--paper); border: 2.5px solid var(--edge); box-shadow: 0 5px 0 var(--edge);
  transition: transform .07s ease, box-shadow .07s ease;
}
.choice:active { transform: translateY(5px); box-shadow: 0 0 0 var(--edge); }
.choice svg { grid-row: span 2; width: 52px; height: 52px; padding: 11px; border-radius: 14px; background: var(--paper-2); border: 2px solid var(--edge); }
.choice b { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.choice span { font-size: 15px; color: var(--ink-2); line-height: 1.35; }
.choice.free { background: var(--yellow); }
.choice.free svg { background: #fff3c4; color: var(--red); }
.choice.guide svg { color: #1f6fd1; }
.menu-foot { margin: 18px 2px 0; font-size: 14px; color: var(--ink-2); min-height: 1.4em; }
.menu-foot button { text-decoration: underline; text-underline-offset: 3px; font-weight: 600; color: var(--ink); }

@media (max-width: 760px) {
  #menu { align-items: flex-end; }
  .menu-inner { margin: 0 auto; }
  .logo { font-size: clamp(48px, 15vw, 72px); }
  .tag { margin: 12px 0 18px; font-size: 16px; }
  .choice { padding: 13px 16px; grid-template-columns: 44px 1fr; }
  .choice svg { width: 44px; height: 44px; padding: 9px; }
  .choice b { font-size: 19px; }
  .choice span { font-size: 14px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  #menu { align-items: center; }
  .menu-inner { margin: 0 0 0 max(12px, var(--safe-l)); width: min(440px, 55vw); }
  .logo { font-size: 46px; }
  .logo .studs { margin-bottom: 8px; }
  .tag { margin: 8px 0 12px; font-size: 14px; }
  .choices { gap: 10px; }
  .choice { padding: 10px 14px; grid-template-columns: 40px 1fr; }
  .choice svg { width: 40px; height: 40px; padding: 8px; }
  .choice b { font-size: 17px; }
  .choice span { font-size: 13px; }
}

/* ------------------------------------------------------------ catalog */
#catalog { flex-direction: column; background: rgba(214, 231, 244, .9); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.cat-head { display: flex; align-items: center; gap: 14px; padding: calc(14px + var(--safe-t)) max(18px, var(--safe-r)) 10px max(18px, var(--safe-l)); }
.cat-head h2 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.cat-grid {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); grid-auto-rows: max-content; gap: 18px;
  padding: 8px max(18px, var(--safe-r)) calc(28px + var(--safe-b)) max(18px, var(--safe-l));
  align-content: start;
  max-width: 1240px; width: 100%; margin: 0 auto;
}
.mcard {
  text-align: left; background: var(--paper); border: 2.5px solid var(--edge); border-radius: 18px; overflow: hidden;
  box-shadow: 0 5px 0 var(--edge); display: flex; flex-direction: column;
  transition: transform .07s ease, box-shadow .07s ease;
}
.mcard:active { transform: translateY(5px); box-shadow: 0 0 0 var(--edge); }
.mcard .pic { aspect-ratio: 4 / 3; background: linear-gradient(180deg, #e9f2f9, #cfe0ee); position: relative; border-bottom: 2px solid var(--edge); }
.mcard .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mcard .body { padding: 12px 14px 14px; display: grid; gap: 4px; }
.mcard .name { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.mcard .blurb { font-size: 14px; color: var(--ink-2); line-height: 1.35; }
.mcard .meta { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.level { display: inline-flex; gap: 3px; }
.level i { width: 14px; height: 9px; border-radius: 2px; background: #d3dde8; position: relative; }
.level i.on { background: var(--ink); }
.badge { position: absolute; top: 10px; left: 10px; padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; border: 2px solid var(--edge); background: var(--paper); }
.badge.built { background: #bfe8cc; }
.badge.going { background: var(--yellow); }
@media (max-width: 560px) {
  .cat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .mcard .blurb { display: none; }
  .mcard .name { font-size: 16px; }
  .mcard .body { padding: 9px 10px 11px; }
  .mcard .meta { font-size: 12px; gap: 6px; flex-wrap: wrap; }
  .cat-head h2 { font-size: 22px; }
}

/* ------------------------------------------------------------ top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) max(12px, var(--safe-r)) 8px max(12px, var(--safe-l));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.tb-title { flex: 1; min-width: 0; display: grid; gap: 6px; pointer-events: none !important; }
.tb-title b { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 0 rgba(255,255,255,.7); }
.tb-actions { display: flex; gap: 8px; }
.progress { display: flex; gap: 3px; max-width: 360px; height: 8px; }
.progress:empty { display: none; }
.progress i { flex: 1; border-radius: 3px; background: rgba(21,35,59,.14); overflow: hidden; position: relative; }
.progress i.done { background: var(--green); }
.progress i.cur { background: rgba(21,35,59,.14); }
.progress i.cur::after { content: ''; position: absolute; inset: 0; width: var(--p, 0%); background: var(--yellow-d); border-radius: 3px; transition: width .25s ease; }

/* ------------------------------------------------------------ panels (phone portrait: bottom sheet) */
.panel {
  position: fixed; z-index: 9; left: 0; right: 0; bottom: 0;
  flex-direction: column;
  background: var(--paper); border-top: 2.5px solid var(--edge);
  border-radius: 20px 20px 0 0;
  padding: 10px 0 calc(8px + var(--safe-b));
  box-shadow: 0 -6px 24px rgba(21,35,59,.12);
}
.tools { display: flex; gap: 6px; padding: 0 12px 8px; align-items: center; }
.tool {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 40px;
  border-radius: 11px; border: 2px solid var(--edge); background: var(--paper); font-weight: 600; font-size: 14px;
  box-shadow: 0 2px 0 var(--edge);
}
.tool svg { width: 18px; height: 18px; }
.tool.on { background: var(--ink); color: #fff; }
@media (max-width: 440px) {
  .tools { gap: 5px; padding: 0 10px 8px; }
  .tool { flex-direction: column; gap: 2px; height: 48px; font-size: 11.5px; }
  .tools .fold { height: 48px; width: 36px; }
}
.tool[data-tool="paint"] svg { color: var(--c, #1f6fd1); }
.tool.on[data-tool="paint"] svg { color: var(--c, #fff); filter: drop-shadow(0 0 1px #fff); }
.tools .fold { width: 40px; height: 40px; flex: none; box-shadow: 0 2px 0 var(--edge); }
.tools .fold svg { transition: transform .2s ease; }
.panel.folded .foldable { display: none; }
.panel.folded .fold svg { transform: rotate(180deg); }

.cats { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; touch-action: pan-x; }
.cats::-webkit-scrollbar { display: none; }
.cat { flex: none; height: 32px; padding: 0 13px; border-radius: 999px; font-size: 14px; font-weight: 600; background: var(--paper-2); color: var(--ink-2); border: 2px solid transparent; }
.cat.on { background: var(--paper); border-color: var(--edge); color: var(--ink); }

.parts { display: flex; gap: 6px; overflow-x: auto; padding: 2px 12px 8px; scrollbar-width: none; touch-action: pan-x; }
.parts::-webkit-scrollbar { display: none; }
.pt {
  flex: none; width: 72px; height: 76px; border-radius: 12px; display: grid; justify-items: center; align-content: center; gap: 2px;
  background: #e6eff7; border: 2px solid transparent; position: relative;
}
.pt.on { background: #fff8d6; border-color: var(--edge); }
.pt small { font-size: 11px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }

.thumb { position: relative; width: 52px; height: 52px; isolation: isolate; }
.thumb .tint, .thumb .shade { position: absolute; inset: 0; }
.thumb .tint { background: var(--c, #ccc); -webkit-mask: var(--img) center / contain no-repeat; mask: var(--img) center / contain no-repeat; }
.thumb .shade { background: var(--img) center / contain no-repeat; mix-blend-mode: multiply; }
.thumb.trans { opacity: .72; }
.thumb.ready { filter: drop-shadow(0 0 0.7px rgba(21,35,59,.6)) drop-shadow(0 1.5px 1px rgba(21,35,59,.18)); }
.thumb:not(.ready) .tint { -webkit-mask: none; mask: none; border-radius: 8px; opacity: .25; inset: 12px; }

.colors { display: flex; gap: 7px; overflow-x: auto; padding: 4px 12px 2px; scrollbar-width: none; touch-action: pan-x; align-items: center; }
.colors::-webkit-scrollbar { display: none; }
.sw {
  flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--c); position: relative;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18), 0 0 0 1.5px rgba(21,35,59,.18);
}
.sw.trans { background: linear-gradient(135deg, var(--c) 0 50%, color-mix(in srgb, var(--c) 55%, #fff) 50% 100%); opacity: .85; }
.sw.metal { background: linear-gradient(135deg, color-mix(in srgb, var(--c) 60%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 70%, #000)); }
.sw.on { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5.5px var(--edge); }
.sw.add { background: conic-gradient(#e4352b, #ffd23f, #2f9e57, #1f6fd1, #ac78ba, #e4352b); display: grid; place-items: center; }
.sw.add svg { width: 16px; height: 16px; color: #fff; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.sw input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.swatches.small { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.swatches.small .sw { width: 28px; height: 28px; }

/* guide panel: a page of the booklet */
.page { padding: 0 14px; display: grid; gap: 10px; }
.step-head { display: flex; align-items: baseline; gap: 12px; }
.stepno { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
.stepno b { font-size: 40px; font-weight: 900; line-height: .9; letter-spacing: -0.04em; }
.stepno small { font-size: 16px; font-weight: 600; color: var(--ink-3); }
.step-title { font-size: 16px; font-weight: 600; color: var(--ink-2); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.callout {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; touch-action: pan-x;
  padding: 8px; border: 2px solid var(--edge); border-radius: 12px; background: #dbe8f4;
}
.callout::-webkit-scrollbar { display: none; }
.gp {
  flex: none; width: 70px; border-radius: 10px; padding: 4px 2px 5px; display: grid; justify-items: center; gap: 1px; position: relative;
  border: 2px solid transparent;
}
.gp .thumb { width: 50px; height: 50px; }
.gp .n { font-size: 15px; font-weight: 800; justify-self: start; padding-left: 6px; line-height: 1; }
.gp.on { background: #fff8d6; border-color: var(--edge); }
.gp.left0 { opacity: .35; }
.gp.left0::after { content: ''; position: absolute; top: 4px; right: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/12px no-repeat; }
.gp.wiggle { animation: wiggle .5s ease; }
@keyframes wiggle { 0%,100% { transform: none; } 20% { transform: rotate(-7deg) scale(1.08); } 45% { transform: rotate(6deg) scale(1.08); } 70% { transform: rotate(-3deg); } }
.g-actions { display: flex; gap: 8px; }
.g-actions .btn { flex: 1; min-height: 42px; font-size: 14px; padding: 0 10px; }

/* ------------------------------------------------------------ floating buttons */
#fab {
  position: fixed; z-index: 8; right: max(12px, var(--safe-r)); bottom: calc(var(--sheet-h) + 12px);
  flex-direction: row; align-items: flex-end; gap: 10px;
  transition: bottom .2s ease;
}
.fab-col { display: flex; flex-direction: column; gap: 10px; }
.fab-btn {
  width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center;
  background: var(--paper); border: 2px solid var(--edge); box-shadow: 0 3px 0 var(--edge);
}
.fab-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge); }

/* move pad: four nudge arrows around a knob that places (tap) or steers (drag) */
.pad {
  --pad: 132px;
  position: relative; flex: none; width: var(--pad); height: var(--pad); border-radius: 50%;
  background: var(--paper); border: 2.5px solid var(--edge); box-shadow: 0 4px 0 var(--edge);
  touch-action: none;
}
.pad::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background:
    linear-gradient(45deg, transparent calc(50% - 1px), #d9e3ee calc(50% - 1px), #d9e3ee calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(-45deg, transparent calc(50% - 1px), #d9e3ee calc(50% - 1px), #d9e3ee calc(50% + 1px), transparent calc(50% + 1px));
}
.pad-arrow { position: absolute; width: 44px; height: 44px; display: grid; place-items: center; color: var(--ink-2); touch-action: none; }
.pad-arrow svg { width: 17px; height: 17px; transition: transform .08s ease; }
.pad-arrow[data-dir="up"] { top: 1px; left: calc(50% - 22px); }
.pad-arrow[data-dir="down"] { bottom: 1px; left: calc(50% - 22px); }
.pad-arrow[data-dir="left"] { left: 1px; top: calc(50% - 22px); }
.pad-arrow[data-dir="right"] { right: 1px; top: calc(50% - 22px); }
.pad-arrow[data-dir="down"] svg { transform: rotate(180deg); }
.pad-arrow[data-dir="left"] svg { transform: rotate(-90deg); }
.pad-arrow[data-dir="right"] svg { transform: rotate(90deg); }
.pad-arrow.on { color: #1f6fd1; }
.pad-arrow.on svg { scale: 1.25; }
.pad-knob {
  position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%;
  display: grid; place-items: center; touch-action: none;
  background: var(--yellow); border: 2.5px solid var(--edge); box-shadow: 0 3px 0 var(--edge);
  transform: translate(var(--kx, 0px), var(--ky, 0px)); transition: transform .16s cubic-bezier(.3, 1.5, .5, 1), background .15s ease;
}
.pad-knob svg { width: 26px; height: 26px; }
.pad-knob.drag { transition: background .15s ease; box-shadow: 0 1px 0 var(--edge); }
.pad-knob.bad { background: #f3d2cf; color: var(--red-d); }
.pad-knob.idle { background: var(--paper-2); color: var(--ink-3); }
body:not(.touch) #pad { display: none; }
body[data-tool="paint"] #pad, body[data-tool="erase"] #pad, body[data-tool="copy"] #pad { display: none; }
body[data-tool="paint"] #btnRotate, body[data-tool="erase"] #btnRotate, body[data-tool="copy"] #btnRotate { display: none; }

#hint {
  position: fixed; z-index: 11; left: 50%; transform: translateX(-50%);
  top: calc(var(--top-h) + var(--safe-t) + 8px);
  padding: 8px 14px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 500;
  pointer-events: none; opacity: 0; transition: opacity .2s ease; white-space: nowrap; max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis;
}
#hint.show { opacity: 1; }
#toast {
  position: fixed; z-index: 40; left: 50%; top: calc(var(--top-h) + var(--safe-t) + 44px); transform: translate(-50%, -8px);
  padding: 10px 18px; border-radius: 12px; background: var(--paper); border: 2px solid var(--edge); box-shadow: 0 3px 0 var(--edge);
  font-weight: 700; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.good { background: #bfe8cc; }

/* ------------------------------------------------------------ sheets */
#scrim { position: fixed; inset: 0; z-index: 50; background: rgba(21,35,59,.35); }
.sheet { position: fixed; inset: 0; z-index: 51; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; }
.sheet-card {
  pointer-events: auto; width: min(460px, 100%); max-height: 88vh; overflow-y: auto; touch-action: pan-y;
  background: var(--paper); border: 2.5px solid var(--edge); border-bottom: 0; border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + var(--safe-b));
  animation: up .2s ease;
}
.sheet-card.tall { min-height: 60vh; display: flex; flex-direction: column; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) and (min-height: 560px) {
  .sheet { align-items: center; }
  .sheet-card { border-bottom: 2.5px solid var(--edge); border-radius: 20px; box-shadow: 0 6px 0 var(--edge); }
}
.sheet h3 { margin: 0 0 14px; font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.sheet p { margin: 0 0 16px; color: var(--ink-2); line-height: 1.45; }
.menu-list { display: grid; gap: 2px; margin-bottom: 10px; }
.menu-list button { display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: 10px; font-weight: 600; font-size: 16px; text-align: left; }
.menu-list button:hover { background: var(--paper-2); }
.menu-list svg { color: var(--ink-2); }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 10px; border-top: 1.5px solid #e2e9f1; font-weight: 500; }
body:not(.touch) .touch-only { display: none; }
.seg { display: flex; border: 2px solid var(--edge); border-radius: 10px; overflow: hidden; }
.seg button { padding: 7px 12px; font-weight: 600; font-size: 14px; }
.seg button + button { border-left: 2px solid var(--edge); }
.seg button.on { background: var(--ink); color: #fff; }
.switch { width: 52px; height: 30px; border-radius: 999px; background: #cfd9e4; position: relative; border: 2px solid var(--edge); flex: none; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--edge); transition: left .15s ease; box-sizing: border-box; }
.switch.on { background: var(--green); }
.switch.on::after { left: 24px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; font-weight: 600; font-size: 14px; }
.field input { font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--edge); background: var(--paper-2); user-select: text; -webkit-user-select: text; }
.row-btns { display: flex; gap: 10px; justify-content: flex-end; }
.row-btns .btn { flex: 1; }
.builds { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); grid-auto-rows: max-content; gap: 12px; align-content: start; }
.bcard { border: 2px solid var(--edge); border-radius: 12px; overflow: hidden; background: var(--paper-2); text-align: left; position: relative; }
.bcard img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #dfeaf4; }
.bcard .bn { padding: 7px 9px 8px; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard .bd { padding: 0 9px 8px; font-size: 12px; color: var(--ink-2); margin-top: -4px; }
.bcard .del { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; background: var(--paper); border: 2px solid var(--edge); display: grid; place-items: center; }
.bcard .del svg { width: 16px; height: 16px; }
.empty { grid-column: 1 / -1; color: var(--ink-2); padding: 20px 4px; line-height: 1.5; }

/* ------------------------------------------------------------ done */
#done { align-items: center; justify-content: center; padding: 20px; background: rgba(21,35,59,.3); z-index: 45; }
#done.show { display: flex; }
.done-card {
  width: min(440px, 100%); background: var(--paper); border: 2.5px solid var(--edge); border-radius: 22px; box-shadow: 0 6px 0 var(--edge);
  overflow: hidden; text-align: center; animation: pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.done-pic { background: linear-gradient(180deg, #e9f2f9, #cfe0ee); border-bottom: 2px solid var(--edge); }
.done-pic img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.done-card h2 { margin: 16px 20px 4px; font-size: 26px; font-weight: 900; letter-spacing: -0.02em; }
.done-card p { margin: 0 20px 16px; color: var(--ink-2); }
.done-btns { display: grid; gap: 10px; padding: 0 20px 20px; }
@media (max-height: 560px) and (orientation: landscape) {
  .done-card { display: grid; grid-template-columns: 44% 1fr; width: min(640px, 100%); text-align: left; }
  .done-pic { border-bottom: 0; border-right: 2px solid var(--edge); }
  .done-pic img { height: 100%; }
  .done-card h2 { font-size: 22px; margin-top: 14px; }
  .done-btns { padding-bottom: 14px; gap: 8px; }
  .done-btns .btn { min-height: 40px; }
}
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ------------------------------------------------------------ side-panel layouts (desktop, phone landscape) */
@media (min-width: 860px) and (min-height: 560px), (max-height: 560px) and (orientation: landscape) and (min-width: 560px) {
  .panel {
    top: calc(var(--top-h) + var(--safe-t) + 8px); bottom: 14px; left: max(14px, var(--safe-l)); right: auto; width: var(--panel-w);
    border: 2.5px solid var(--edge); border-radius: 18px; padding: 12px 0 10px; box-shadow: 0 5px 0 var(--edge);
  }
  #fab { bottom: calc(16px + var(--safe-b)); }
  .tools .fold { display: none; }
  .tool { flex-direction: column; height: 54px; gap: 3px; font-size: 12.5px; }
  .tool svg { width: 20px; height: 20px; }
  .foldable { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .panel.folded .foldable { display: flex; }
  .cats { flex-wrap: wrap; overflow: visible; }
  .parts {
    flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; touch-action: pan-y;
    display: grid; grid-template-columns: repeat(3, 1fr); align-content: start; scrollbar-width: thin;
  }
  .pt { width: auto; height: 84px; }
  .thumb { width: 58px; height: 58px; }
  .colors { flex-wrap: wrap; overflow: visible; padding-top: 10px; border-top: 1.5px solid #e2e9f1; margin-top: 2px; }
  .sw { width: 30px; height: 30px; }
  #guidePanel { bottom: auto; max-height: calc(100% - var(--top-h) - 30px); }
  .page { gap: 12px; }
  .stepno b { font-size: 64px; }
  .stepno small { font-size: 20px; }
  .step-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .step-title { font-size: 18px; white-space: normal; }
  .callout { flex-wrap: wrap; overflow: visible; }
  .gp { width: calc((100% - 12px) / 3); }
  .gp .thumb { width: 58px; height: 58px; }
  #hint { left: calc(50% + var(--panel-w) / 2); }
}
@media (max-height: 560px) and (orientation: landscape) and (min-width: 560px) {
  :root { --panel-w: 262px; --top-h: 52px; }
  #topbar { padding-top: calc(6px + var(--safe-t)); }
  .icon-btn { width: 40px; height: 40px; }
  .panel { top: calc(var(--top-h) + var(--safe-t) + 4px); bottom: 8px; padding: 8px 0 6px; }
  .tools { padding: 0 8px 6px; gap: 4px; }
  .tool { height: 36px; font-size: 0; gap: 0; }
  .tool svg { width: 20px; height: 20px; }
  .cats { padding: 0 8px 6px; gap: 4px; flex-wrap: nowrap; overflow-x: auto; }
  .colors { flex-wrap: nowrap; overflow-x: auto; }
  .cat { height: 28px; padding: 0 9px; font-size: 13px; }
  .parts { padding: 2px 8px 6px; gap: 4px; }
  .pt { height: 70px; }
  .thumb { width: 46px; height: 46px; }
  .colors { padding: 6px 8px 0; gap: 5px; }
  .sw { width: 26px; height: 26px; }
  .page { padding: 0 10px; gap: 8px; }
  .stepno b { font-size: 44px; }
  .step-head { flex-direction: row; align-items: baseline; gap: 10px; }
  .step-title { font-size: 15px; }
  #guidePanel { overflow-y: auto; bottom: 8px; max-height: none; }
  .callout { flex-wrap: nowrap; overflow-x: auto; padding: 6px; }
  .gp { width: 62px; flex: none; }
  .gp .thumb { width: 44px; height: 44px; }
  .g-actions { gap: 6px; }
  .g-actions .btn { min-height: 38px; font-size: 13px; padding: 0 8px; gap: 5px; }
  .g-actions .btn svg { width: 17px; height: 17px; }
  .fab-btn { width: 44px; height: 44px; }
  .pad { --pad: 118px; }
  .pad-knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
  #fab { gap: 8px; bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
