/* Build Us: the builder */
html, body.app { height: 100%; overflow: hidden; overscroll-behavior: none; }
body.app { background: linear-gradient(180deg, var(--bg1, #fff3e4) 0%, var(--bg2, #fde2ea) 55%, var(--bg3, #dcebff) 100%); }
body[data-theme=sunday] { --bg1: #fff3e4; --bg2: #fde2ea; --bg3: #dcebff; }
body[data-theme=toybox] { --bg1: #e6f5ff; --bg2: #fff6d6; --bg3: #ffe3d6; }
body[data-theme=golden] { --bg1: #ffe2bf; --bg2: #ffcaa8; --bg3: #e9b8c8; }
body[data-theme=night] { --bg1: #10163a; --bg2: #241f4d; --bg3: #3d2a55; }
body[data-theme=night]::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; opacity: 0.8;
  background-image: radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 34% 8%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 58% 22%, #ffe9b0 50%, transparent 51%), radial-gradient(1px 1px at 76% 12%, #fff 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 88% 30%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 22% 36%, #fff 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 46% 40%, #cfe0ff 50%, transparent 51%), radial-gradient(1px 1px at 66% 4%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 44%, #fff 50%, transparent 51%), radial-gradient(1.3px 1.3px at 94% 6%, #fff 50%, transparent 51%);
}
#app { position: fixed; inset: 0; }
.stage { position: absolute; inset: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; -webkit-tap-highlight-color: transparent; }
.stage canvas:focus-visible { box-shadow: inset 0 0 0 3px var(--focus); }
body[data-erase] .stage canvas { cursor: crosshair; }

/* floating labels over the 3D */
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.dist {
  position: absolute; left: 0; top: 0; margin: 0; transform: translate(-50%, -100%); white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; padding: 6px 14px 7px; border-radius: 14px;
  background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: var(--shadow);
  transition: opacity 0.3s ease;
}
.dist::after { content: ''; position: absolute; bottom: -6px; left: 50%; width: 12px; height: 12px; background: inherit; transform: translateX(-50%) rotate(45deg); border-radius: 2px; }
.dist-num { font-family: var(--display); font-size: 17px; line-height: 1.1; }
.dist-sub { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.dist.met .dist-num { color: var(--a); }
.dist.flat { flex-direction: row; gap: 8px; align-items: baseline; padding: 6px 14px; }
.dist.flat::after { display: none; }
.dist.flat .dist-num { font-size: 15px; }

/* top bar */
.top {
  position: fixed; z-index: 20; top: calc(var(--sat) + 8px); left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px);
  display: flex; align-items: flex-start; gap: 8px; pointer-events: none;
}
.top > * { pointer-events: auto; }
.top-left { min-width: 0; flex: 1 1 auto; padding: 7px 14px 8px; border-radius: 18px; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); max-width: max-content; }
.names { margin: 0; font-family: var(--display); font-size: 16px; line-height: 1.15; display: flex; gap: 0.35em; align-items: baseline; min-width: 0; }
.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9.5em; }
.nm-a { color: var(--a-dark); }
.nm-b { color: var(--b-dark); }
.amp { color: var(--ink-3); font-size: 0.85em; }
.status { margin: 2px 0 0; font-size: 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-btns { display: flex; gap: 6px; flex: none; margin-left: auto; }
.ibtn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; display: grid; place-items: center;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); color: var(--ink);
}
.ibtn svg, .tbtn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ibtn .ic-on { display: none; }
.ibtn[aria-pressed=true] .ic-on { display: block; }
.ibtn[aria-pressed=true] .ic-off { display: none; }
body[data-mode=finale] .top-left, body[data-mode=intro] .top-left { visibility: hidden; }

.demo-ribbon {
  position: fixed; z-index: 19; left: 50%; transform: translateX(-50%); top: calc(var(--sat) + 66px);
  font-size: 14px; font-weight: 700; padding: 0 16px; min-height: 44px; display: inline-flex; align-items: center; border-radius: 999px; text-decoration: none;
  background: var(--ink); color: #fff; white-space: nowrap; box-shadow: var(--shadow);
}
body[data-mode=build] .demo-ribbon, body[data-mode=finale] .demo-ribbon { display: none; }

/* the dock */
.dock {
  position: fixed; z-index: 20; left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); bottom: calc(var(--sab) + 8px);
  max-width: 780px; margin: 0 auto; padding: 8px 8px 6px; border-radius: 22px;
  background: rgba(255, 250, 243, 0.94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: var(--shadow);
  transform: translateY(0); transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1), opacity 0.3s ease;
}
body:not([data-mode=build]) .dock { transform: translateY(130%); opacity: 0; pointer-events: none; visibility: hidden; }
.tools { display: flex; align-items: center; gap: 4px; }
.tbtn {
  min-width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 8px; font-weight: 700; font-size: 14px;
}
.tbtn:hover { background: rgba(45, 38, 64, 0.06); }
.tbtn span { display: none; }
.tbtn[aria-pressed=true] { background: var(--ink); color: #fff; }
#btn-erase[aria-pressed=true] { background: #ff3b5c; }
.tbtn[disabled] { opacity: 0.35; }
.count { flex: 1 1 auto; min-width: 0; display: none; font-size: 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.btn-send { margin: 6px 0 0 auto; min-height: 44px; padding: 0 14px; font-size: 15.5px; max-width: 48vw; flex: 0 1 auto; min-width: 96px; }
.btn-send #send-label { min-width: 0; white-space: nowrap; }
.btn-send #send-label { overflow: hidden; text-overflow: ellipsis; }
.btn-send.btn-brick::before { left: 18%; }
.btn-send.btn-brick::after { right: 18%; }
@media (min-width: 560px) { .tbtn span { display: inline; } .count { display: block; } }

.colors, .tabs, .tray { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.colors::-webkit-scrollbar, .tabs::-webkit-scrollbar, .tray::-webkit-scrollbar { display: none; }
.colors { margin-top: 2px; }
.swatch { flex: none; width: 44px; height: 44px; border: 0; background: transparent; display: grid; place-items: center; border-radius: 50%; padding: 0; }
.swatch i { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.14), 0 0 0 1px rgba(45, 38, 64, 0.12); transition: transform 0.15s ease; }
.swatch[aria-checked=true] i { transform: scale(1.12); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.14), 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.tabs { margin: 2px 0; gap: 4px; }
.tab { flex: none; min-height: 44px; padding: 0 11px; border: 0; border-radius: 999px; background: transparent; font-weight: 700; font-size: 14.5px; color: var(--ink-2); }
.tab[aria-selected=true] { background: var(--ink); color: #fff; }
.tray { gap: 6px; padding: 2px 2px 4px; }
.piece {
  flex: none; width: 66px; height: 66px; border-radius: 16px; border: 2px solid transparent; background: #ebe5f0; padding: 0;
  display: grid; place-items: center; position: relative; box-shadow: 0 2px 0 rgba(45, 38, 64, 0.08);
}
.piece canvas { width: 58px; height: 58px; display: block; pointer-events: none; }
.piece[aria-checked=true] { border-color: var(--ink); background: #ddd4e8; }
.piece .rot { position: absolute; right: 3px; top: 3px; font-size: 12px; line-height: 1; padding: 2px 4px; border-radius: 6px; background: var(--ink); color: #fff; font-weight: 700; }
.piece.add { font-size: 30px; color: var(--ink-2); border: 2px dashed var(--line); background: transparent; }
.piece .tag { position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%); max-width: 62px; font-size: 12px; font-weight: 800; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 1px 5px; border-radius: 6px; color: #fff; }
@media (max-height: 700px) {
  .piece { width: 58px; height: 58px; }
  .piece canvas { width: 52px; height: 52px; }
}

/* coach marks */
.coach {
  position: fixed; z-index: 18; left: 50%; transform: translateX(-50%); top: calc(var(--sat) + 70px);
  margin: 0; width: max-content; max-width: min(92vw, 420px); padding: 10px 16px; border-radius: 16px; background: var(--ink); color: #fff;
  font-weight: 600; font-size: 15px; text-align: center; box-shadow: var(--shadow); pointer-events: none;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -5px); } }

/* replay */
.replaybar {
  position: fixed; z-index: 20; left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); bottom: calc(var(--sab) + 8px);
  max-width: 620px; margin: 0 auto; padding: 10px 10px 8px 14px; border-radius: 20px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
.rb-track { display: flex; gap: 3px; height: 14px; margin: 0 0 6px; }
.rb-seg { position: relative; flex: 1 1 0; min-width: 14px; border: 0; padding: 0; border-radius: 6px; background: color-mix(in srgb, var(--c) 25%, white); overflow: hidden; }
.rb-seg::before { content: ''; position: absolute; inset: -16px 0; }
.rb-seg i { position: absolute; left: 0; top: 0; bottom: 0; width: var(--p, 0%); background: var(--c); border-radius: 6px; }
.rb-row { display: flex; align-items: center; gap: 6px; }
.rb-label { flex: 1 1 auto; min-width: 0; margin: 0; font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#rb-pause .ic-play { display: none; }
#rb-pause[aria-pressed=true] .ic-play { display: block; fill: currentColor; }
#rb-pause[aria-pressed=true] .ic-pause { display: none; }

/* the chapter note */
.note { position: fixed; z-index: 30; left: calc(var(--sal) + 10px); right: calc(var(--sar) + 10px); bottom: calc(var(--sab) + 96px); display: flex; justify-content: center; pointer-events: none; }
body[data-mode=note] .note, body[data-mode=finale] .note { bottom: calc(var(--sab) + 14px); }
.note-card {
  pointer-events: auto; width: 100%; max-width: 440px; padding: 16px 18px 16px; border-radius: 22px; background: var(--paper);
  box-shadow: var(--shadow); border-top: 6px solid var(--c, var(--a)); position: relative;
  animation: note-in 0.5s cubic-bezier(0.2, 1.3, 0.4, 1);
  max-height: 46vh; max-height: 46dvh; overflow: auto;
}
@keyframes note-in { from { transform: translateY(26px) scale(0.92) rotate(-2deg); opacity: 0; } to { transform: none; opacity: 1; } }
.note-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.avatar { width: 36px; height: 36px; border-radius: 12px; flex: none; display: grid; place-items: center; background: var(--c, var(--a)); color: #fff; font-family: var(--display); font-size: 17px; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15); }
.note-meta { margin: 0; font-size: 14.5px; color: var(--ink-2); line-height: 1.25; }
.note-meta b { color: var(--ink); font-size: 16px; }
.note-text { margin: 0 0 4px; font-size: 18px; line-height: 1.4; font-weight: 500; white-space: pre-line; overflow-wrap: anywhere; }
.note-text:empty { display: none; }
.note-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.note-actions:empty { display: none; }
.note-actions .btn { flex: 1 1 auto; }

/* intro */
.intro {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  padding: 0 calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px);
  background: linear-gradient(180deg, transparent 30%, color-mix(in srgb, var(--bg3, #fff) 60%, transparent) 100%);
}
.intro-card {
  width: 100%; max-width: 460px; padding: 22px 20px 16px; border-radius: 26px; background: var(--paper); box-shadow: var(--shadow); text-align: center;
  animation: note-in 0.6s cubic-bezier(0.2, 1.2, 0.4, 1);
  max-height: calc(100dvh - var(--sat) - 24px); overflow: auto;
}
.intro-card .wordmark { font-size: 20px; margin-bottom: 12px; }
.intro-kicker { margin: 0; font-weight: 700; color: var(--ink-2); font-size: 15px; }
.intro-title { font-family: var(--display); font-weight: 400; font-size: clamp(30px, min(10vw, 7vh), 46px); line-height: 1.04; margin: 4px 0 8px; overflow-wrap: anywhere; }
.intro-title .who-a { color: var(--a); }
.intro-title .who-b { color: var(--b); }
.intro-text { margin: 0 auto 14px; max-width: 34ch; color: var(--ink-2); font-size: 16.5px; }
.intro-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.intro-foot { margin: 6px 0 0; font-size: 14px; color: var(--ink-3); }
@media (min-height: 760px) and (min-width: 700px) { .intro { align-items: center; } }

/* sheets bits */
.chapters { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 8px; }
.chapter { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 16px; background: #fff; border-left: 6px solid var(--c); }
.chapter .avatar { width: 34px; height: 34px; font-size: 15px; }
.ch-body { flex: 1 1 auto; min-width: 0; }
.ch-meta { margin: 0; font-weight: 700; font-size: 15px; }
.ch-meta span { font-weight: 500; color: var(--ink-2); }
.ch-note { margin: 3px 0 0; font-size: 15px; color: var(--ink-2); overflow-wrap: anywhere; white-space: pre-line; }
.ch-play { flex: none; }
.w-p { margin: 0 0 12px; }
.w-h { font-family: var(--display); font-weight: 400; font-size: 16px; margin: 18px 0 6px; }
.w-list { padding-left: 20px; margin: 0; }
.w-list li { margin: 0 0 12px; }
.w-list b { font-weight: 800; }
.w-list q { display: block; margin-top: 2px; color: var(--ink-2); quotes: '“' '”'; }

/* figure designer */
.fig-wrap { display: grid; grid-template-columns: 1fr; gap: 10px; }
.fig-preview { width: 150px; height: 150px; margin: 0 auto; display: block; border-radius: 22px; background: radial-gradient(circle at 50% 60%, #fff 0%, var(--paper-2) 70%); }
@media (min-width: 460px) { .fig-wrap { grid-template-columns: 170px 1fr; align-items: start; } .fig-preview { width: 170px; height: 170px; position: sticky; top: 0; } }
.fig-row { margin: 0 0 10px; }
.fig-row .lbl { font-size: 14.5px; margin-bottom: 4px; }
.opts { display: flex; flex-wrap: wrap; gap: 4px; }
.opt { min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-weight: 600; font-size: 14.5px; }
.opt[aria-checked=true] { border-color: var(--ink); background: var(--paper-2); }
.opt.sw { padding: 0; display: grid; place-items: center; }
.opt.sw i { width: 26px; height: 26px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15); }

/* finale */
.finale { position: fixed; inset: 0; z-index: 25; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; padding: calc(var(--sat) + 64px) calc(var(--sar) + 14px) calc(var(--sab) + 14px) calc(var(--sal) + 14px); }
.fin-top { text-align: center; pointer-events: none; }
.fin-kicker { margin: 0; font-weight: 800; font-size: 15px; color: var(--ink-2); letter-spacing: 0.04em; }
.fin-title { font-family: var(--display); font-weight: 400; font-size: clamp(28px, min(9vw, 7vh), 60px); line-height: 1.02; margin: 4px auto 6px; max-width: 16ch; overflow-wrap: anywhere; text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6); }
.fin-names { margin: 0; font-weight: 800; font-size: 18px; }
.fin-meta { margin: 2px 0 0; font-size: 15px; font-weight: 600; color: var(--ink-2); }
body[data-theme=night] .fin-kicker, body[data-theme=night] .fin-names, body[data-theme=night] .fin-meta, body[data-theme=night] .fin-title { color: #fff; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); }
.fin-actions { pointer-events: auto; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 520px; margin: 0 auto; width: 100%; }
.fin-actions .btn-brick { flex: 1 1 100%; }
.fin-actions .btn { flex: 1 1 auto; }
.fin-actions .btn:not(.btn-brick) { background: var(--glass); backdrop-filter: blur(8px); }

/* poster */
.poster-frame { position: relative; border-radius: 16px; overflow: hidden; background: var(--paper-2); aspect-ratio: 4 / 5; max-height: 56vh; max-height: 56dvh; margin: 0 auto 6px; }
.poster-frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.poster-wait { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font-weight: 700; color: var(--ink-2); }

body[data-theme=night] { --glass: rgba(255, 250, 243, 0.9); }

/* short landscape phones: the dock becomes a side panel so the build stays visible */
@media (orientation: landscape) and (max-height: 540px) {
  .dock {
    left: auto; right: calc(var(--sar) + 8px); top: calc(var(--sat) + 8px); bottom: calc(var(--sab) + 8px);
    width: 328px; max-width: none; margin: 0; overflow-y: auto; overscroll-behavior: contain;
  }
  body:not([data-mode=build]) .dock { transform: translateX(110%); }
  .tools { flex-wrap: wrap; }
  .btn-send { flex: 1 1 100%; max-width: none; margin: 8px 0 2px; }
  .colors, .tabs { flex-wrap: wrap; overflow: visible; }
  .tray { flex-wrap: wrap; overflow: visible; }
  body[data-mode=build] .top { right: calc(var(--sar) + 344px); }
  .note { left: calc(var(--sal) + 10px); right: auto; width: min(420px, 50vw); bottom: calc(var(--sab) + 10px); justify-content: flex-start; }
  body[data-mode=note] .note { bottom: calc(var(--sab) + 10px); }
  .note-card { max-height: calc(100vh - 90px); max-height: calc(100dvh - 90px); }
  .demo-ribbon { top: calc(var(--sat) + 8px); }
  .finale { padding-top: calc(var(--sat) + 10px); }
  .fin-top { padding: 0 150px; }
  .fin-title { font-size: clamp(22px, 7vh, 40px); }
  .fin-actions { flex-wrap: nowrap; max-width: 680px; }
  .fin-actions .btn-brick { flex: 1 1 auto; }
  .coach { top: auto; bottom: calc(var(--sab) + 12px); left: calc(50% - 170px); }
  .intro-card { max-width: 560px; }
}

/* ================================================================ v2: bin, hand, booklet, views */
body[data-night] { --bg1: #10163a; --bg2: #241f4d; --bg3: #3d2a55; }
body[data-night]::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; opacity: 0.8;
  background-image: radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 34% 8%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 58% 22%, #ffe9b0 50%, transparent 51%), radial-gradient(1px 1px at 76% 12%, #fff 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 88% 30%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 22% 36%, #fff 50%, transparent 51%);
}
body.app { transition: background 0.6s ease; }

.dock { padding: 6px 8px 8px; }
.tools { gap: 2px; }
.hand {
  position: relative; flex: none; width: 52px; height: 48px; border-radius: 14px; border: 2px dashed var(--line); background: #f3eef6;
  display: grid; place-items: center; padding: 0;
}
.hand canvas { width: 44px; height: 44px; pointer-events: none; }
.hand.full { border: 2px solid var(--ink); background: #fff; }
.hand-x { position: absolute; right: -5px; top: -5px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 14px; line-height: 19px; font-weight: 800; display: none; }
.hand.full .hand-x { display: block; }
.hand.pop { animation: hand-pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes hand-pop { from { transform: scale(0.7); } to { transform: none; } }
.hand-num { width: 64px; min-height: 44px; border-radius: 12px; border: 2px solid var(--line); padding: 0 6px; font-weight: 800; font-size: 16px; text-align: center; background: #fff; }
.tabs { margin: 4px 0 0; gap: 2px; }
.tab { padding: 0 10px; }
.colors { margin: 0; }
.colors[hidden] { display: none !important; }
.bin-wrap {
  position: relative; height: 128px; margin-top: 4px; border-radius: 18px; overflow: hidden;
  background: linear-gradient(180deg, #efe7f3 0%, #e6dcec 100%);
  box-shadow: inset 0 6px 14px -6px rgba(45, 38, 64, 0.35), inset 0 -2px 0 rgba(255, 255, 255, 0.6);
}
.bin { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: grab; }
.bin:active { cursor: grabbing; }
.bin-btns { position: absolute; top: 4px; right: 4px; display: flex; gap: 4px; z-index: 2; }
.bbtn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255, 255, 255, 0.82); box-shadow: 0 2px 6px rgba(45, 38, 64, 0.15); display: grid; place-items: center; color: var(--ink); }
.bbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bbtn[data-mode=shape], .bbtn[data-mode=colour] { background: var(--ink); color: #fff; }
.bin-add { position: absolute; left: 6px; top: 6px; z-index: 2; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 2px dashed var(--ink-3); background: rgba(255, 255, 255, 0.86); font-weight: 800; font-size: 14px; }
.bin-list { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 4px; overflow-x: auto; padding: 4px; opacity: 0; pointer-events: none; z-index: 3; }
.bin-list:focus-within { opacity: 1; pointer-events: auto; background: rgba(255, 250, 243, 0.96); }
.bin-list button { flex: none; min-height: 44px; padding: 0 10px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-weight: 700; font-size: 14px; }
.float { position: fixed; left: 0; top: 0; width: 96px; height: 96px; pointer-events: none; z-index: 75; display: none; filter: drop-shadow(0 14px 10px rgba(45, 38, 64, 0.35)); }
.float.on { display: block; }
body.carrying, body.carrying * { cursor: grabbing !important; }
body.carrying.over-bin .bin-wrap { box-shadow: inset 0 0 0 3px var(--a), inset 0 6px 14px -6px rgba(45, 38, 64, 0.35); }

/* view buttons: a row above the dock, right side */
.views { position: fixed; z-index: 19; right: calc(var(--sar) + 10px); bottom: calc(var(--sab) + var(--dock-h, 260px) + 16px); display: flex; gap: 6px; }
body:not([data-mode=build]) .views { display: none; }
.vbtn { width: 44px; height: 44px; border-radius: 14px; border: 0; display: grid; place-items: center; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); color: var(--ink); }
.vbtn svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.vbtn[aria-pressed=true] { background: var(--ink); color: #fff; }
.vbtn .ic-moon { display: none; }
.vbtn[aria-pressed=true] .ic-moon { display: block; }
.vbtn[aria-pressed=true] .ic-sun { display: none; }
.vbtn[hidden] { display: none; }

/* the booklet card */
.book { position: fixed; z-index: 21; top: calc(var(--sat) + 66px); left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); max-width: 460px; perspective: 900px; }
body:not([data-mode=build]) .book, body:not([data-mode=build]) .book-pill { display: none !important; }
.book-page {
  background: #fff; border-radius: 18px; padding: 6px 6px 6px 12px; box-shadow: var(--shadow), inset 5px 0 0 var(--c, var(--a));
  transform-origin: left center;
}
.book-page.flip { animation: page-flip 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.05); }
@keyframes page-flip { 0% { transform: rotateY(-80deg); opacity: 0.2; } 100% { transform: none; opacity: 1; } }
.book-head { display: flex; align-items: center; gap: 6px; min-height: 30px; }
.book-no { font-family: var(--display); font-size: 15px; letter-spacing: 0.02em; white-space: nowrap; }
.book-who { font-size: 13.5px; font-weight: 800; color: #fff; background: var(--c, var(--a)); padding: 2px 9px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.book-x { margin-left: auto; width: 44px; height: 30px; border: 0; background: transparent; display: grid; place-items: center; color: var(--ink-2); }
.book-x svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.book-title { margin: 0 0 4px; font-weight: 800; font-size: 15px; line-height: 1.25; }
.book-parts { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 6px; border-radius: 12px; background: #e9f3ff; border: 2px solid #c9e0ff; min-height: 60px; align-items: center; }
.book-parts::-webkit-scrollbar { display: none; }
.part { position: relative; flex: none; width: 48px; height: 48px; border-radius: 12px; border: 0; background: #ece6f2; padding: 0; touch-action: none; box-shadow: 0 2px 0 rgba(45, 38, 64, 0.12); }
.part canvas { width: 46px; height: 46px; pointer-events: none; }
.part b { position: absolute; right: -4px; bottom: -4px; min-width: 22px; height: 20px; padding: 0 4px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 13px; line-height: 20px; font-weight: 800; }
.part-ok { font-weight: 800; color: #2a8a55; font-size: 15px; padding: 0 6px; white-space: nowrap; }
.book-nav { display: flex; gap: 4px; margin-top: 6px; align-items: center; }
.book-btn { min-height: 44px; min-width: 44px; border: 0; border-radius: 12px; background: #f3eef6; font-weight: 800; font-size: 14px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); white-space: nowrap; }
.book-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.book-btn[disabled] { opacity: 0.35; }
.book-magic { flex: 1 1 auto; }
.book-done { margin: 6px 0 0; padding: 8px 10px; border-radius: 12px; background: #fff3d6; font-weight: 700; font-size: 14.5px; }
.book-pill { position: fixed; z-index: 21; top: calc(var(--sat) + 66px); left: calc(var(--sal) + 8px); min-height: 44px; padding: 0 14px; border-radius: 999px; border: 0; background: #fff; box-shadow: var(--shadow); font-weight: 800; font-size: 14.5px; }
@media (max-height: 760px) {
  .book-title { display: none; }
  .book-parts { min-height: 54px; padding: 3px 4px; }
  .book-nav { margin-top: 4px; }
  .bin-wrap { height: 100px; }
}
@media (max-height: 640px) {
  .book-nav .book-all { display: none; }
}

/* the whole-booklet sheet */
.bk-cover { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.bk-cover img { width: 128px; height: 96px; object-fit: cover; border-radius: 14px; background: var(--paper-2); flex: none; }
.bk-kicker { margin: 0; font-weight: 800; font-size: 13.5px; color: var(--ink-3); letter-spacing: 0.04em; text-transform: uppercase; }
.bk-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.bk-list li button { width: 100%; text-align: left; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 12px; border-radius: 14px; border: 0; background: #fff; border-left: 6px solid var(--c); }
.bk-list .bk-pages { font-family: var(--display); font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.bk-list .bk-name { flex: 1 1 auto; font-weight: 800; }
.bk-list .bk-name small { display: block; font-weight: 600; color: var(--ink-2); font-size: 14px; }
.bk-list .bk-tick { font-weight: 800; color: #2a8a55; white-space: nowrap; }

@media (orientation: landscape) and (max-height: 540px) {
  .bin-wrap { height: 150px; }
  .views { top: auto; bottom: calc(var(--sab) + 10px); left: calc(var(--sal) + 10px); right: auto; }
  body[data-mode=build] .top { right: calc(var(--sar) + 344px); }
  .book { right: auto; width: min(380px, calc(100vw - 360px)); top: calc(var(--sat) + 62px); }
  .book-title { display: none; }
}
@media (min-width: 900px) and (min-height: 600px) {
  .bin-wrap { height: 150px; }
  .book { top: calc(var(--sat) + 72px); }
}

.coach { top: auto; bottom: calc(var(--sab) + var(--dock-h, 260px) + 70px); z-index: 22; }
@media (orientation: landscape) and (max-height: 540px) { .coach { bottom: calc(var(--sab) + 12px); } }

/* booklet v2 layout: one head row, then  ◀ parts ▶ */
.book-head { min-height: 44px; }
.book-x { width: 44px; height: 44px; flex: none; border-radius: 12px; }
.book-x:hover { background: #f3eef6; }
.book-who { flex: 0 1 auto; }
.book-head #book-all { margin-left: auto; }
.book-magic { font-size: 20px; }
.book-magic[disabled] { opacity: 0.3; }
.book-row { display: flex; align-items: center; gap: 4px; }
.book-row .book-parts { flex: 1 1 auto; min-width: 0; }
.book-row .book-btn { padding: 0; width: 44px; min-width: 44px; background: transparent; }
.swatch-btn { display: none; }
.swatch-btn i { display: block; width: 28px; height: 28px; border-radius: 50%; background: var(--c, #ccc); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.14), 0 0 0 2px #fff, 0 0 0 4px var(--ink); }
@media (max-height: 760px) {
  .swatch-btn { display: inline-flex; }
  .colors { position: absolute; z-index: 5; left: 8px; right: 8px; bottom: 8px; height: 0; overflow: hidden; background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); padding: 0 4px; transition: height 0.2s ease, visibility 0.2s; visibility: hidden; }
  .dock.colors-open .colors { height: 52px; overflow-x: auto; padding: 4px; visibility: visible; }
  .dock { position: fixed; }
}
@media (max-height: 900px) and (min-height: 761px) { .bin-wrap { height: 112px; } }
.book-head .book-magic { flex: none; }

body[data-mode=build] .toast { top: auto; bottom: calc(var(--sab) + var(--dock-h, 260px) + 66px); }
@media (orientation: landscape) and (max-height: 540px) { body[data-mode=build] .toast { bottom: calc(var(--sab) + 12px); left: 30%; } }
@media (orientation: landscape) and (max-height: 540px) { .coach { bottom: calc(var(--sab) + 64px); } body[data-mode=build] .toast { bottom: calc(var(--sab) + 64px); } }

/* ================================================================ simple mode: one step card at the bottom
   (body.simple: every set with an instruction booklet. Tap a piece, it drops into place, the next step comes up.) */
body.simple .dock, body.simple .book-pill { display: none !important; }
body.simple .book {
  top: auto; bottom: calc(var(--sab) + 8px); left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px);
  max-width: 560px; margin: 0 auto;
}
body.simple .book-page { padding: 8px 10px 10px 14px; border-radius: 22px; transform-origin: center bottom; }
body.simple #book-all, body.simple #book-min, body.simple #book-prev, body.simple #book-next { display: none; }
body.simple .book-head #book-magic { margin-left: auto; }
body.simple .book-magic[hidden] { display: none; }
body.simple .book-no { font-size: 14px; }
body.simple .book-title { display: block; font-size: 18px; margin: 2px 0 8px; }
body.simple .book-row[hidden] { display: none; }
body.simple .book-parts { min-height: 88px; padding: 8px; gap: 12px; background: #f4f8ff; border: 2px dashed #c9dcf8; justify-content: center; flex-wrap: wrap; }
body.simple .part {
  width: 70px; height: 70px; border-radius: 18px; background: #fff; cursor: pointer;
  box-shadow: 0 4px 0 rgba(45, 38, 64, 0.16), 0 0 0 2px #d8e6fb; transition: transform 0.12s ease, box-shadow 0.12s ease;
}
body.simple .part canvas { width: 66px; height: 66px; }
body.simple .part:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(45, 38, 64, 0.16), 0 0 0 2px var(--c, var(--a)); }
body.simple .part:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(45, 38, 64, 0.16), 0 0 0 2px var(--c, var(--a)); }
body.simple .part:first-child { animation: part-nudge 2.6s ease-in-out 1s infinite; }
@keyframes part-nudge { 0%, 70%, 100% { transform: none; } 78% { transform: translateY(-5px) rotate(-3deg); } 86% { transform: translateY(0); } 92% { transform: translateY(-2px) rotate(2deg); } }
body.simple .part b { right: -6px; bottom: -6px; min-width: 28px; height: 26px; line-height: 26px; font-size: 15px; border-radius: 13px; }
body.simple .part-ok { font-size: 16px; }
.book-hint { margin: 8px 2px 0; text-align: center; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.book-foot { display: none; }
body.simple .book-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
body.simple .book-foot .tbtn { padding: 0 10px; background: #f3eef6; }
body.simple .book-foot .tbtn span { display: inline; }
.book-progress { flex: 1 1 auto; min-width: 40px; height: 10px; border-radius: 99px; background: #eee8f3; overflow: hidden; }
.book-progress i { display: block; height: 100%; width: var(--p, 0%); background: var(--c, var(--a)); border-radius: inherit; transition: width 0.4s ease; }
.sb-count { font-weight: 800; font-size: 13.5px; color: var(--ink-2); white-space: nowrap; }
.sb-send { min-height: 44px; white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
body.simple .book-done { margin-top: 2px; padding: 12px; font-size: 16px; line-height: 1.35; background: #fff6dc; text-align: center; }
.book-cta { display: flex; width: 100%; justify-content: center; margin-top: 10px; min-height: 52px; font-size: 17px; }
.book-more { display: block; margin: 8px auto 0; }
body.simple .views #btn-peek, body.simple .views #btn-night, body.simple .views #btn-tint { display: none; }
body.simple .views { bottom: auto; top: calc(var(--sat) + 68px); }
body.simple[data-mode=build] .toast { bottom: calc(var(--sab) + var(--book-h, 260px) + 18px); }
@media (max-height: 760px) {
  body.simple .book-title { display: block; font-size: 16px; margin-bottom: 6px; }
  body.simple .book-parts { min-height: 76px; padding: 6px; }
  body.simple .part { width: 60px; height: 60px; }
  body.simple .part canvas { width: 56px; height: 56px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  body.simple .book {
    left: calc(var(--sal) + 8px); right: auto; top: calc(var(--sat) + 8px); bottom: calc(var(--sab) + 8px);
    width: min(400px, 46vw); margin: 0; overflow-y: auto; display: flex; flex-direction: column; justify-content: flex-end;
  }
  body.simple .book-title { display: block; }
  body.simple[data-mode=build] .top { right: calc(var(--sar) + 8px); left: calc(var(--sal) + min(400px, 46vw) + 20px); }
  body.simple .views { top: auto; bottom: calc(var(--sab) + 10px); left: auto; right: calc(var(--sar) + 10px); }
  body.simple[data-mode=build] .toast { bottom: calc(var(--sab) + 12px); left: auto; right: 12px; }
}
