/* ============================================================
   Shape Builder — the layout for build.html.
   The site colours come from style.css; this file only arranges
   the four panels around the 3D view.
   ============================================================ */

.builder-page { overflow: hidden; }

.builder {
  display: grid;
  grid-template-columns: 190px 1fr 260px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "top top top"
    "palette stage panel";
  height: 100dvh;
  background: var(--bg);
}

/* ---------- top strip ---------- */
.bx-top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--band);
  color: #fff;
}
.bx-top h1 { font-size: 1.15rem; letter-spacing: 0; margin: 0; white-space: nowrap; }
.bx-home {
  color: #fff; text-decoration: none; font-size: 1.3rem; line-height: 1;
  padding: 2px 8px; border-radius: 8px; background: rgba(255,255,255,0.15);
}
.bx-home:hover { background: rgba(255,255,255,0.3); }
.bx-top-buttons { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.bx-sep { width: 1px; height: 22px; background: rgba(255,255,255,0.3); }

.bx-btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.bx-btn:hover { background: #fff7f2; }
.bx-btn:disabled { opacity: 0.4; cursor: default; }
.bx-btn-go { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.bx-btn-go:hover { background: var(--accent-dk); }
.bx-btn-bad { color: #b91c1c; }
.bx-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.bx-wide { width: 100%; margin-top: 6px; }

/* ---------- shape palette on the left ---------- */
.bx-palette {
  grid-area: palette;
  padding: 14px 12px;
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--line);
}
.bx-palette h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
                 color: var(--ink-soft); margin: 0 0 8px; }
.bx-palette h2 + * { margin-bottom: 20px; }

.bx-shapes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bx-shape {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: grab;
  font: inherit; font-size: 0.7rem; color: var(--ink-soft);
  touch-action: none;
  user-select: none;
}
.bx-shape:hover { border-color: var(--accent); color: var(--ink); }
.bx-shape svg { width: 30px; height: 30px; }
.bx-shape.dragging { opacity: 0.4; }

.bx-colours { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.bx-colour {
  aspect-ratio: 1; border-radius: 50%; border: 2px solid rgba(0,0,0,0.12);
  cursor: pointer; padding: 0;
}
.bx-colour[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }

.bx-help { font-size: 0.75rem; color: var(--ink-soft); line-height: 1.5; }
.bx-help p { margin-bottom: 5px; }
.bx-help b { color: var(--ink); }

/* ---------- the 3D stage ---------- */
.bx-stage { grid-area: stage; position: relative; overflow: hidden; }
.bx-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.bx-stage-tools {
  /* The bar itself lets the mouse through, only its buttons catch it. The
     wheel does nothing over anything that isn't the 3D canvas, so a solid
     panel sitting in the corner of the view is a patch where zooming just
     silently stops working. */
  pointer-events: none;
  position: absolute; top: 10px; left: 10px;
  display: flex; gap: 8px; align-items: center;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 0.8rem;
}
.bx-stage-tools > * { pointer-events: auto; }
.bx-snap select { font: inherit; font-size: 0.8rem; margin-left: 4px; }

.bx-empty {
  position: absolute; left: 0; right: 0; top: 45%;
  text-align: center; color: var(--ink-soft); pointer-events: none;
  font-size: 0.95rem;
}

/* the ghost that follows your finger while you drag a new shape in */
.bx-ghost {
  position: fixed; z-index: 50; pointer-events: none;
  width: 46px; height: 46px; margin: -23px 0 0 -23px;
  opacity: 0.85;
}

/* the little "there you go" message after a file is saved */
.bx-toast {
  /* Top right corner: clear of the tools on the left and the running total
     in the bottom corner. */
  position: absolute; right: 14px; top: 14px;
  background: var(--ink); color: #fff;
  padding: 9px 15px; border-radius: 11px; font-size: 0.85rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.22);
  max-width: 90%; text-align: center;
}
.bx-toast a { color: #ffd9c2; }
/* A warning gets more room, because it has something to explain. */
.bx-toast-warn {
  background: #7f1d1d;
  max-width: 420px;
  text-align: left;
  line-height: 1.45;
}

/* ---------- "hang on, I'm working" ---------- */
.bx-busy {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(255, 217, 194, 0.75);
}
.bx-busy-box {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px 22px; min-width: 240px; text-align: center;
}
.bx-bar { height: 8px; border-radius: 4px; background: var(--line); margin-top: 10px; overflow: hidden; }
.bx-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }

/* ---------- the panel on the right ---------- */
.bx-panel {
  grid-area: panel;
  padding: 14px 12px;
  overflow-y: auto;
  background: var(--paper);
  border-left: 1px solid var(--line);
}
.bx-panel h2 { font-size: 1rem; margin-bottom: 10px; }
.bx-nothing { color: var(--ink-soft); font-size: 0.9rem; }
.bx-nothing p + p { margin-top: 6px; }

.bx-panel fieldset { border: none; margin-bottom: 16px; }
.bx-panel legend {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft); margin-bottom: 6px; padding: 0;
}
.bx-panel label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 0.85rem; margin-bottom: 5px;
}
.bx-panel input[type="number"] {
  font: inherit; font-size: 0.85rem; width: 76px; padding: 4px 6px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink);
}
/* style.css sets `input { width: 100% }` for the order form, which turns a
   tick box into a stretched-out blob. Put tick boxes and drop-downs back. */
.bx-panel input[type="checkbox"],
.bx-stage-tools select { width: auto; margin-top: 0; padding: 0; }
.bx-stage-tools select { padding: 2px 4px; }
.bx-check { justify-content: flex-start !important; gap: 7px; font-size: 0.8rem; color: var(--ink-soft); }
.bx-check input { margin: 0; flex: none; }
.bx-hole { font-size: 0.9rem; color: var(--ink); }

.bx-turn { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.bx-turn .bx-btn { width: 100%; }

.bx-panel-buttons { display: flex; gap: 6px; }
.bx-panel-buttons .bx-btn { flex: 1; }

/* The running total, parked in the corner of the 3D view so it is always
   in sight -- it is the bit that tells you whether the thing can be printed. */
.bx-stats {
  position: absolute; left: 10px; bottom: 10px; max-width: 285px;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 11px;
  font-size: 0.78rem; color: var(--ink-soft); line-height: 1.55;
  pointer-events: none;
}
.bx-stats:empty { display: none; }
.bx-stats b { color: var(--ink); font-weight: 600; }
.bx-warn { color: #b91c1c; font-weight: 600; }

/* ---------- small screens: stack it all up ---------- */
@media (max-width: 820px) {
  .builder {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "top" "palette" "stage" "panel";
  }
  .bx-palette {
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 8px 10px; display: flex; gap: 10px; align-items: center; overflow-x: auto;
  }
  .bx-palette h2, .bx-help { display: none; }
  .bx-palette h2 + * { margin-bottom: 0; }
  .bx-shapes { display: flex; gap: 6px; }
  .bx-shape { min-width: 58px; }
  .bx-colours { display: flex; gap: 6px; }
  .bx-colour { width: 26px; height: 26px; }
  .bx-panel {
    border-left: none; border-top: 1px solid var(--line);
    max-height: 42dvh;
  }
  /* One line that scrolls sideways beats three lines of wrapped buttons. */
  .bx-top { flex-wrap: nowrap; overflow-x: auto; gap: 8px; }
  .bx-top h1 { font-size: 1rem; }
  .bx-top-buttons { gap: 4px; flex-wrap: nowrap; }
  .bx-btn { padding: 5px 8px; font-size: 0.78rem; }
}
