/* =============================================================================
   Tools — generative design tools at /tools/.
   Built on site.css tokens, so both themes work without extra rules.
   ========================================================================== */

.tl-body { background: var(--bg); }

.tl-main {
  padding: 104px 0 64px;
}

/* ---------- tool page ---------- */

.tl-app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
  width: min(1440px, calc(100% - 48px));
  margin-inline: auto;
}

.tl-stage {
  position: sticky;
  top: 96px;
  height: calc(100vh - 120px);
  height: calc(100dvh - 120px);
  min-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tl-canvas-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  border: 1px solid var(--hairline);
  border-radius: 20px;
  /* A quiet checkerboard, so the canvas edge reads against any paper colour. */
  background:
    repeating-conic-gradient(var(--hairline-soft) 0 25%, transparent 0 50%) 0 0 / 22px 22px,
    var(--panel);
}

.tl-canvas {
  display: block;
  border-radius: 4px;
  box-shadow: var(--shadow-lift);
}

.tl-meta {
  margin: 0;
  font-size: 13px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  text-align: center;
  min-height: 1.5em;
}

/* ---------- panel ---------- */

.tl-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  border: 1px solid var(--hairline);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(6px);
}

.tl-head h1 {
  margin: 10px 0 6px;
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.8px;
  color: var(--white);
}
.tl-head p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text-dim); }
.tl-head .back { margin: 0; font-size: 14px; color: var(--text-mute); }
.tl-head .back:hover { color: var(--white); }

.tl-group { display: flex; flex-direction: column; gap: 12px; }
.tl-group h2 {
  margin: 0;
  padding-top: 18px;
  border-top: 1px solid var(--hairline);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* buttons */
.tl-actions, .tl-export { display: flex; flex-wrap: wrap; gap: 8px; }

.tl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--btn-edge);
  background: var(--btn-face);
  color: var(--white);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s cubic-bezier(.22,1,.36,1), opacity 0.2s;
}
.tl-btn:hover:not(:disabled) { border-color: var(--btn-edge-hi); transform: translateY(-1px); }
.tl-btn:disabled { opacity: 0.4; cursor: default; }
.tl-btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.tl-btn-primary:hover:not(:disabled) { border-color: transparent; filter: brightness(1.08); }
.tl-actions .tl-btn-primary { flex: 1 1 100%; min-height: 44px; font-size: 15px; }

.tl-link {
  align-self: flex-start;
  padding: 2px 0;
  min-height: 24px;
  border: 0;
  background: none;
  color: var(--text-mute);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.tl-link:hover { color: var(--white); }

/* fields */
.tl-basics { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }
.tl-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tl-field label, .tl-row label, .tl-row-head label { font-size: 13px; color: var(--text-dim); }

.tl-input {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--field-edge);
  border-radius: 10px;
  background: var(--field);
  color: var(--white);
  font: inherit;
  font-size: 14px;
}
select.tl-input { cursor: pointer; }
select.tl-input option { background: var(--bg); color: var(--text); }
#tl-seed { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.04em; }

.tl-controls { display: flex; flex-direction: column; gap: 14px; }
.tl-row { display: flex; flex-direction: column; gap: 6px; }
.tl-row[hidden] { display: none; }
.tl-row-head { display: flex; justify-content: space-between; align-items: baseline; }
.tl-out { font-size: 13px; color: var(--text-mute); font-variant-numeric: tabular-nums; }
.tl-speed-ends { display: flex; justify-content: space-between; margin-top: -2px; font-size: 12px; color: var(--text-mute); }

.tl-row input[type='range'] {
  width: 100%;
  margin: 0;
  height: 24px;
  accent-color: var(--accent);
  cursor: pointer;
}

.tl-row-toggle { flex-direction: row; justify-content: space-between; align-items: center; }

.tl-switch {
  appearance: none;
  position: relative;
  width: 40px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid var(--field-edge);
  background: var(--field);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.tl-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s cubic-bezier(.22,1,.36,1), background 0.2s;
}
.tl-switch:checked { background: var(--accent); border-color: var(--accent); }
.tl-switch:checked::after { transform: translateX(16px); background: #fff; }

/* palettes */
.tl-palettes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tl-pal {
  display: flex;
  height: 28px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--btn-edge);
  border-radius: 8px;
  background: none;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(.22,1,.36,1), border-color 0.2s;
}
.tl-pal span { flex: 1; }
.tl-pal:hover { transform: translateY(-1px); border-color: var(--btn-edge-hi); }

/* colours */
.tl-colors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tl-color {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
  transition: opacity 0.2s;
}
.tl-color.is-unused { opacity: 0.4; }
.tl-color input[type='color'] {
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--field-edge);
  border-radius: 10px;
  background: none;
  cursor: pointer;
}
.tl-color input[type='color']::-webkit-color-swatch-wrapper { padding: 3px; }
.tl-color input[type='color']::-webkit-color-swatch { border: 0; border-radius: 6px; }
.tl-color input[type='color']::-moz-color-swatch { border: 0; border-radius: 6px; }
.tl-color-text { display: flex; flex-direction: column; min-width: 0; font-size: 13px; color: var(--text-dim); line-height: 1.3; }
.tl-hex { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-mute); }

/* saved palettes and presets */
.tl-palettes-own { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.tl-actions-pal { margin-bottom: 2px; }
.tl-calm { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); cursor: pointer; }
.tl-calm input { accent-color: var(--accent, #2d66eb); margin: 0; }
.tl-pal-groups { display: flex; flex-direction: column; gap: 10px; }
.tl-pal-head { margin: 0 0 6px; font-size: 12px; font-weight: 400; color: var(--text-mute); }
.tl-palettes-own[hidden] { display: none; }
.tl-pal-own { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tl-pal-own .tl-pal { flex: 1; min-width: 0; }

.tl-x {
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-mute);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.tl-x:hover { color: var(--white); background: var(--chip); }

.tl-presets { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.tl-presets[hidden] { display: none; }
.tl-presets li { display: flex; align-items: center; gap: 4px; }
.tl-preset {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  padding: 6px 12px;
  overflow: hidden;
  border: 1px solid var(--btn-edge);
  border-radius: 10px;
  background: var(--btn-face);
  color: var(--white);
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.tl-preset:hover { border-color: var(--btn-edge-hi); }
.tl-preset-form { display: flex; gap: 8px; }
.tl-preset-form .tl-input { flex: 1; min-width: 0; }

.tl-video { display: flex; flex-direction: column; gap: 10px; }
.tl-video[hidden] { display: none; }
.tl-progress { width: 100%; height: 6px; accent-color: var(--accent); }
.tl-progress[hidden] { display: none; }
.tl-field-inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.tl-field-inline .tl-input { width: auto; min-width: 0; flex: 0 1 190px; }
.tl-btn[hidden] { display: none; }

.tl-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* image input */
.tl-img-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tl-img-thumb { flex: none; width: 72px; height: 48px; border-radius: 8px; border: 1px solid var(--hairline); background: var(--card); }
.tl-img-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--text-dim); }
.tl-hint { margin: 0; font-size: 12px; line-height: 1.5; color: var(--text-mute); }
label.tl-btn { cursor: pointer; }
.tl-sr:focus-visible + .tl-btn, label.tl-btn:has(+ .tl-sr:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.tl-canvas-wrap.is-drop { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }

/* gallery sections */
.tl-section { margin-top: 44px; }
.tl-section h2 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.tl-section h2 span { margin-left: 8px; color: var(--text-dim); letter-spacing: 0; }
.tl-jump { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.tl-jump a {
  padding: 6px 12px;
  border: 1px solid var(--btn-edge);
  border-radius: 999px;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.2s;
}
.tl-jump a:hover { border-color: var(--btn-edge-hi); }
.tl-jump a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.tl-status { margin: 0; min-height: 1.4em; font-size: 13px; color: var(--text-dim); }

.tl-keys { margin: 0; font-size: 12px; color: var(--text-mute); }
.tl-keys kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border: 1px solid var(--hairline);
  border-radius: 5px;
  font: inherit;
  text-align: center;
}

.tl-btn:focus-visible, .tl-pal:focus-visible, .tl-link:focus-visible, .tl-x:focus-visible, .tl-preset:focus-visible,
.tl-input:focus-visible, .tl-switch:focus-visible,
.tl-row input[type='range']:focus-visible, .tl-color input[type='color']:focus-visible,
.tl-card:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- gallery ---------- */

.tl-intro { max-width: 640px; margin: 40px 0 36px; }
.tl-intro h1 {
  margin: 0 0 12px;
  font-size: clamp(34px, 5vw, 52px);
  font-weight: 500;
  letter-spacing: -1.6px;
  color: var(--white);
}
.tl-intro p { margin: 0; font-size: 18px; color: var(--text-dim); }
.tl-intro .tl-btn { margin-top: 18px; }

.tl-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tl-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 18px;
  background: var(--panel);
  transition: transform 0.25s cubic-bezier(.22,1,.36,1), border-color 0.25s;
}
.tl-card:hover { transform: translateY(-3px); border-color: var(--btn-edge-hi); }
.tl-thumb { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; background: var(--card); }
.tl-card-body { padding: 16px 18px 20px; }
.tl-card h2, .tl-card h3 { margin: 0 0 6px; font-size: 20px; font-weight: 500; color: var(--white); }
.tl-card p { margin: 0; font-size: 14px; color: var(--text-dim); }

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

@media (max-width: 900px) {
  .tl-main { padding-top: 88px; }
  .tl-app { grid-template-columns: 1fr; width: calc(100% - 32px); gap: 16px; }
  /* The preview stays pinned while the controls scroll underneath it. */
  /* Pinned flush to the top with its own background, so nothing scrolls
     visibly above it. Height follows the image's aspect ratio (set by the
     script as --ar) up to half the screen, so wide images waste no space. */
  .tl-stage {
    top: 0;
    z-index: 2;
    height: min(50vh, calc((100vw - 32px - 24px) / var(--ar, 1.78) + 24px + 16px + 30px));
    height: min(50dvh, calc((100vw - 32px - 24px) / var(--ar, 1.78) + 24px + 16px + 30px));
    min-height: 200px;
    padding: 8px 0;
    background: var(--bg);
  }
  .tl-canvas-wrap { padding: 12px; border-radius: 16px; }
  .tl-panel { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .tl-btn, .tl-pal, .tl-card, .tl-switch::after { transition: none; }
}
.tl-layer { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.tl-layer + .tl-layer { border-top: 1px solid var(--hairline); padding-top: 14px; }
.tl-layer-body[hidden] { display: none; }
.tl-layer .tl-link { align-self: flex-start; }
