/* The template pages under /create. Builds on style.css. */

.maker { display: grid; gap: 36px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: start; }
/* The form comes second in the page so a phone shows the preview first; on a
 * wide screen it goes back on the left. */
.maker .fields { order: -1; }
.maker h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 34px); }
.maker .blurb { margin: 0 0 6px; font-size: 17px; }

/* ---------------------------------------------------------------- form --- */

.maker fieldset {
  margin: 20px 0 0; padding: 6px 18px 18px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid var(--line); border-radius: 16px;
}
.maker legend { padding: 0 8px; font: 700 12px var(--mono); letter-spacing: .1em; color: var(--text); }
.maker legend small { font-weight: 400; color: var(--muted); opacity: 1; }

.field-grid { display: grid; gap: 0 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-text, .field-wide, .field-filament-color, .field:has(#f-filament) { grid-column: 1 / -1; }
.field label { margin-top: 16px; }

.maker input, .maker select, .maker .cpick-btn { min-height: 46px; background: var(--bg); }
.maker input[type="number"] { font-family: var(--mono); }

/* A number between its own − and + buttons, the unit sitting inside the box.
 * The browser's stepper arrows are hidden: a phone never drew them, and the
 * buttons do the job everywhere. */
.stepper { display: flex; gap: 6px; }
.stepper > input, .stepper > .with-unit { flex: 1 1 0; min-width: 0; }
.stepper input { width: 100%; text-align: center; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-btn {
  flex: none; display: grid; place-items: center; width: 46px; min-height: 46px; padding: 0;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: border-color .15s, color .15s, background .15s;
}
.stepper-btn svg { width: 20px; height: 20px; }
.stepper-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.stepper-btn:active:not(:disabled) { background: color-mix(in srgb, var(--accent) 16%, var(--bg)); }
.stepper-btn:disabled { opacity: .35; cursor: default; }
.with-unit { position: relative; }
.with-unit input { padding-left: 30px; padding-right: 30px; }
.with-unit .unit { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font: 12px var(--mono); color: var(--muted); pointer-events: none; }

/* "Same as the text": a color that is whatever another one is. */
.swatch.same { background: repeating-linear-gradient(135deg, var(--muted) 0 2px, transparent 2px 6px); }

.maker-from { margin: 10px 0 0; padding: 9px 13px; font-size: 14px; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 12px; }

/* ----------------------------------------------------- tiles and tabs --- */

.tiles { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); }
.tiles-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px 8px;
  font: 12px var(--mono); line-height: 1.25; color: var(--muted); text-align: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.tiles-opt svg { width: 40px; height: 40px; }
.tiles-opt:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.tiles-opt[aria-checked="true"] { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg)); }
.tiles-opt[aria-checked="true"] span { color: var(--text); font-weight: 700; }

.seg { display: flex; min-height: 46px; padding: 3px; gap: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.seg-opt {
  flex: 1 1 0; min-width: 0; padding: 4px 6px;
  font: 13px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: none; border: 0; border-radius: 7px; cursor: pointer; transition: background .15s, color .15s;
}
.seg-opt:hover { color: var(--text); }
.seg-opt[aria-checked="true"] { color: var(--accent-ink); background: var(--accent); font-weight: 700; }

/* --------------------------------------------------------------- stage --- */

.maker-notes { margin: 14px 0 0; padding: 10px 14px 10px 30px; font-size: 14px; color: var(--text); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 12px; }
.maker-notes li + li { margin-top: 4px; }

.maker-get { margin-top: 18px; }
.maker-get .btn.primary { width: 100%; min-height: 52px; font-size: 15px; border-radius: 12px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 28%, transparent); }
.maker-get .btn.primary:disabled { box-shadow: none; }
.maker-send { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; font: 12px var(--mono); color: var(--muted); }
.maker-send .err { color: var(--danger); }
.maker-other { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; font: 12px var(--mono); color: var(--muted); }

.setup { margin-top: 16px; padding: 4px 14px; font-size: 14px; background: color-mix(in srgb, var(--surface) 72%, transparent); border: 1px solid var(--line); border-radius: 12px; }
.setup:empty { display: none; }
.setup-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; min-width: 0; }
.setup-row + .setup-row { border-top: 1px solid var(--line); }
.setup-key { flex: none; width: 84px; font: 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.setup-for { margin-left: auto; padding-left: 8px; font: 12px var(--mono); color: var(--muted); text-align: right; }

.maker-tips { margin-top: 14px; font-size: 14px; color: var(--muted); }
.maker-tips summary { display: inline-flex; align-items: center; gap: 6px; padding: 4px 0; font: 13px var(--mono); color: var(--text); cursor: pointer; }
.maker-tips ul { margin: 8px 0 0; padding-left: 18px; }
.maker-tips li + li { margin-top: 6px; }

/* --------------------------------------------------------------- small --- */

/* ----------------------------------------------- the preview on a phone --- */

/* A finger moving up or down on the preview scrolls the page; see viewer.js. */
.maker .viewer { touch-action: pan-y; }
.hint-touch, .stage-toggle { display: none; }

/* The preview goes above the form, and scrolls away with the page until only
 * a strip of it is left; that strip stays, as a small live preview. stage.js
 * has the whole account. The stage's box never changes height: small, it is
 * the same box pinned with all but --strip of it above the top of the screen,
 * its contents rearranged along its bottom edge. */
@media (max-width: 860px) {
  .maker { display: block; --strip: 128px; }
  .maker .fields { margin-top: 18px; }
  .maker.is-typing { padding-bottom: 60vh; }

  .maker .stage {
    position: sticky; z-index: 5;
    /* Until the script has measured it: far enough up never to pin. */
    top: calc(var(--strip) - var(--stage-h, 300vh));
    margin: 0 -16px; padding: 8px 16px 10px;
    background: var(--bg); border-bottom: 1px solid var(--line);
    transition: top .24s ease;
  }
  .maker .viewer { aspect-ratio: 16 / 9; max-height: 32vh; margin: 0 auto; }
  .maker .maker-tips, .maker .hint, .maker .setup, .maker-other span { display: none; }
  .maker .hint-touch { display: inline; font: 11px var(--mono); color: var(--muted); }
  .maker .viewer-bar { margin-top: 6px; }
  .maker .viewer-bar .btn { min-height: 30px; padding: 4px 10px; }
  .maker .stats { margin-top: 6px; }
  .maker .stats dd { font-size: 13px; }
  .maker-get { display: flex; gap: 8px; margin-top: 8px; }
  .maker-get .btn.primary { flex: 1 1 0; width: auto; min-width: 0; min-height: 40px; padding: 6px 10px; font-size: 13px; box-shadow: none; }
  .maker-other { margin-top: 0; }
  .maker-other .btn { min-height: 40px; }
  .maker-notes { margin-top: 6px; padding: 6px 10px 6px 26px; font-size: 13px; }
  .maker fieldset { padding: 4px 14px 14px; }

  /* Small: the picture on the left, the size and the download beside it. */
  .maker .stage.is-small {
    height: var(--stage-h);
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto;
    align-content: end; align-items: center; gap: 6px 12px;
  }
  .maker .stage.is-small > * { display: none; }
  .maker .stage.is-small > .viewer {
    display: block; grid-area: 1 / 1 / 3 / 2; height: calc(var(--strip) - 19px);
    aspect-ratio: auto; max-height: none; border-radius: 12px; pointer-events: none;
  }
  .maker .stage.is-small > .stats { display: block; grid-area: 1 / 2; margin: 0; align-self: end; }
  .maker .stage.is-small > .stats > div:not(:first-child) { display: none; }
  .maker .stage.is-small > .stats dd { font-size: 12px; white-space: nowrap; }
  .maker .stage.is-small > .maker-get { display: block; grid-area: 2 / 2; margin: 0; align-self: start; }
  .maker .stage.is-small .maker-other { display: none; }
  .maker .stage.is-small .get-long { display: none; }
  /* The whole small preview is the button that opens the full one. */
  .maker .stage.is-small > .stage-toggle {
    display: block; grid-area: 1 / 1 / 3 / 2; align-self: stretch; z-index: 1; position: relative;
    background: none; border: 0; border-radius: 12px; cursor: pointer;
  }
  .maker .stage.is-small > .stage-toggle svg {
    position: absolute; right: 6px; bottom: 6px; width: 26px; height: 26px; padding: 4px;
    color: var(--text); background: color-mix(in srgb, var(--bg) 78%, transparent); border: 1px solid var(--line); border-radius: 8px;
  }
  .stage-toggle svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

  /* Opened over the form from the small preview: the whole stage, pinned. */
  .maker .stage.is-open { top: 0; box-shadow: 0 16px 32px rgb(0 0 0 / .4); }
  /* Its handle hangs under the bottom edge, out of the box, so that opening
   * adds nothing to the stage's height — the height the layout is built on. */
  .maker .stage.is-open > .stage-toggle {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    position: absolute; left: 50%; top: 100%; transform: translate(-50%, -1px); min-height: 34px; padding: 4px 16px;
    font: 12px var(--mono); color: var(--text); background: var(--bg); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 12px 12px; cursor: pointer;
    box-shadow: 0 10px 18px rgb(0 0 0 / .3);
  }
  .maker .stage.is-open > .stage-toggle svg { width: 16px; height: 16px; transform: rotate(180deg); }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .maker .stage { transition: none; }
}

/* Two numbers side by side leave no room for their buttons on a phone. */
@media (max-width: 560px) {
  .field-number { grid-column: 1 / -1; }
  .maker .stats { grid-template-columns: repeat(2, auto); gap: 4px 18px; }
}

@media (max-width: 420px) {
  .get-long { display: none; }
}

/* The site header is sticky too, and on a phone the two together (plus a
 * keyboard) would leave no room for the form. Here the preview wins. */
@media (max-width: 860px) {
  .top { position: static; }
}
