/* InstantPalette - pattern generator (/pattern-generator) only.
   Layer 5: loaded after tokens.css, base.css, site.css and tools.css, and nothing else loads it.

   Only what is specific to this tool: the preview and its tile outline, the pattern options with their live
   thumbnails, the background chips and the export rows. Panels, sliders, segmented controls, buttons and code
   blocks come from the shared layers. */

/* ================= Preview ================= */
.pstage { margin: 0 0 16px; }
.pprev {
  position: relative; overflow: hidden;   /* holds only the tile outline, which takes no focus */
  width: 100%; height: clamp(240px, min(46vw, 48vh), 460px);
  border-radius: var(--r-lg);
  background-repeat: repeat; background-position: 0 0;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink-1) 14%, transparent);
}
/* Black between two white lines reads on every colour */
.poutline {
  position: absolute; pointer-events: none;
  outline: 2px solid #000; outline-offset: -1px;
  box-shadow: 0 0 0 3px #FFF, inset 0 0 0 3px #FFF;
}
.pbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 10px 0 0; }
.pbar .field-hint { font: 500 12px/1.4 var(--f-mono); }
.pbar .btn-o { min-height: 44px; }
.pbar .btn-o[aria-pressed="true"] { border-color: var(--ink-1); background: var(--sunken); box-shadow: inset 0 0 0 1px var(--ink-1); }

/* ================= Pattern options ================= */
.popts { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px 4px; }
.popt { display: flex; flex-direction: column; gap: 5px; min-width: 0; text-align: center; border-radius: var(--r-sm); }
.popt .th {
  display: block; height: 46px; margin: 0 2px; border-radius: var(--r-sm);
  background-size: 48px 48px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink-1) 16%, transparent);
}
.popt .nm { font: 500 12px/1.15 var(--f-sans); letter-spacing: -.02em; color: var(--ink-2); }
.popt[aria-checked="true"] .th { box-shadow: 0 0 0 2px var(--raised), 0 0 0 4px var(--ink-1); }
.popt[aria-checked="true"] .nm { color: var(--ink-1); font-weight: 600; }
.popt:focus-visible { outline-offset: 5px; }
@media (hover: hover) and (pointer: fine) { .popt[aria-checked="false"]:hover .th { box-shadow: 0 0 0 1.5px var(--ink-3); } .popt:hover .nm { color: var(--ink-1); } }

.pset { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 20px; }
.ppanel .tpanel-hd { margin-bottom: 10px; }
.ppanel .tpanel-hd .btn-o { min-height: 44px; }
.ppanel .btn-o[aria-disabled="true"] { color: var(--ink-3); border-style: dashed; cursor: default; }
.pset .wide { grid-column: 1 / -1; }
/* Two angles share a row with the gap; four take a row of their own, beside their label */
.pset .tseg button { flex: 1 1 0; padding: 0 9px; text-align: center; }
#f-rt.wide { flex-direction: row; align-items: center; gap: 16px; }
#f-rt.wide .tseg { flex: 1 1 auto; }

/* ================= Colors ================= */
.pcolors { display: grid; gap: 14px 24px; }
.pchips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: var(--r); background: var(--sw); color: var(--ink);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink-1) 22%, transparent);
}
.pchip .i { opacity: 0; stroke-width: 2.4; }
.pchip[aria-checked="true"] { box-shadow: 0 0 0 2px var(--raised), 0 0 0 4px var(--ink-1); }
.pchip[aria-checked="true"] .i { opacity: 1; }
.pchip:focus-visible { outline-offset: 5px; }
@container tpage (min-width: 1000px) { .pcolors { grid-template-columns: minmax(0, 1fr) minmax(200px, 280px); } .pcolors .wide { grid-column: 1 / -1; } }

/* ================= Export ================= */
.pexp { align-items: flex-end; margin: 0 0 12px; }
.pexp .tprimary { flex: 1 1 auto; }
.codeout pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 190px; }
.codeout-hd .field-hint { text-align: right; }
.pdl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: end; margin: 14px 0 0; }
.pdl .btn-o { height: 44px; padding: 0 10px; min-width: 0; }
.pdl .wide { grid-column: 1 / -1; }

@media (max-width: 600px) {
  .pprev { height: clamp(220px, 60vw, 340px); }
  .popts { gap: 12px 6px; }
}
/* Landscape phones: keep the pattern choices on screen with the preview */
@media (orientation: landscape) and (max-height: 500px) {
  .pprev { height: clamp(120px, 40vh, 190px); }
}
