/* =========================================================
   Tool workbench - the exhibition's vocabulary applied to the utilities.
   Loaded after redesign.css. Open layout, hairline dividers, one framed
   canvas. Controls, canvases, and export behaviour are unchanged.
   ========================================================= */

.detail-page {
  --wb-frame: #0d0e11;
  --wb-field: #16181d;
  --wb-accent: #4f61cd;
  --wb-accent-soft: #a9b6ff;
  --wb-focus: #7186ff;
  --wb-error: #f0a898;
  --wb-grid: rgba(255, 255, 255, 0.035);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

/* ── Hero ───────────────────────────────────────────── */

.detail-page .tools-hero {
  padding-bottom: 36px;
  border-bottom: 0;
}

.detail-page .tools-hero__desc {
  max-width: 62ch;
}

.tool-page-hero__back {
  min-height: 44px;
  margin-bottom: 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

.tool-page-hero__back svg {
  transition: transform 220ms var(--ease-out);
}

.detail-page .tool-section {
  padding-block: 0 96px;
}

/* ── Workbench shell: open, no outer card ───────────── */

.texture-tool {
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
}

/* The page hero already names the tool; the card header keeps only its
   status badge and any actions, and its heading stays for assistive tech. */
.texture-tool__header {
  align-items: center;
  justify-content: flex-end;
  min-height: 62px;
  padding: 10px 0;
  border-top: 1px solid var(--border-medium);
}

.texture-tool__header > div:first-child {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.texture-tool__intro {
  display: none;
}

.texture-tool__workspace {
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: clamp(28px, 3.4vw, 56px);
  padding: 8px 0 0;
}

.texture-tool__controls {
  gap: 20px;
  min-width: 0;
}

/* ── Drop zones ─────────────────────────────────────── */

.upload-tile {
  position: relative;
  min-height: 104px;
  padding: 20px;
  gap: 4px 18px;
  grid-template-columns: 48px minmax(0, 1fr);
  border: 1.5px dashed var(--border-medium);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.upload-tile__icon {
  grid-row: span 2;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(169, 182, 255, 0.07);
  border-color: rgba(169, 182, 255, 0.2);
  color: var(--wb-accent-soft);
  transition: background-color 160ms ease, transform 220ms var(--ease-out);
}

.upload-tile__title {
  align-self: end;
  font-size: 15px;
}

.upload-tile__meta {
  grid-column: 2;
  align-self: start;
  margin-top: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.upload-tile:has(input:focus-visible) {
  outline: 3px solid var(--wb-focus);
  outline-offset: 5px;
}

.upload-tile.is-dragover {
  border-style: solid;
  border-color: var(--wb-focus);
  background: rgba(113, 134, 255, 0.09);
}

.upload-tile.is-dragover .upload-tile__icon {
  transform: translateY(-2px) scale(1.05);
}

.upload-tile.is-disabled {
  cursor: not-allowed;
}

/* ── Options: an open group, not a nested panel ─────── */

.tool-options {
  gap: 20px;
  padding: 24px 0 0;
  border: 0;
  border-top: 1px solid var(--border-subtle);
  border-radius: 0;
  background: transparent;
}

.upload-tile__title,
.tool-field span,
.tool-check span,
.tool-range span {
  font-size: 14px;
}

.tool-field select,
.tool-field input:not([type="checkbox"]),
.sprite-tool .tool-field input {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  background-color: var(--wb-field);
  color: var(--text-primary);
  transition: border-color 160ms ease, background-color 160ms ease;
}

.tool-field select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23a9b6ff' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  cursor: pointer;
}

.tool-field select option {
  background: #1b1d22;
  color: var(--text-primary);
}

@media (hover: hover) and (pointer: fine) {
  .tool-field select:hover,
  .tool-field input:not([type="checkbox"]):hover {
    border-color: #5a6070;
  }

  .upload-tile:hover:not(.is-disabled) {
    border-color: var(--wb-focus);
    background: rgba(113, 134, 255, 0.06);
  }

  .upload-tile:hover:not(.is-disabled) .upload-tile__icon {
    background: rgba(169, 182, 255, 0.14);
  }

  .tool-page-hero__back:hover {
    color: var(--wb-accent-soft);
  }

  .tool-page-hero__back:hover svg {
    transform: translateX(-3px);
  }

  .preview-tool-button:hover {
    border-color: var(--wb-focus);
    background: rgba(113, 134, 255, 0.18);
    color: #fff;
  }
}

.tool-field select:focus-visible,
.tool-field input:focus-visible {
  border-color: var(--wb-focus);
  outline-offset: 3px;
}

/* Range slider */

.tool-range input[type="range"] {
  appearance: none;
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.tool-range input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: #3a3e49;
}

.tool-range input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: #3a3e49;
}

.tool-range input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 0;
  border-radius: 50%;
  background: var(--wb-accent-soft);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transition: transform 160ms var(--ease-out);
}

.tool-range input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: var(--wb-accent-soft);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.tool-range input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

.tool-range output {
  color: var(--wb-accent-soft);
  font-weight: 500;
}

/* Checkbox */

.tool-check {
  min-height: 32px;
  cursor: pointer;
}

.tool-check input[type="checkbox"] {
  appearance: none;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  border: 1.5px solid #5a6070;
  border-radius: 5px;
  background-color: var(--wb-field);
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.tool-check input[type="checkbox"]:checked {
  border-color: var(--wb-accent);
  background-color: var(--wb-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='10' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1.5 5.2 3 3 6-6.4'/%3E%3C/svg%3E");
}

.tool-check input[type="checkbox"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Help tooltip */

.tool-help .tool-help__icon {
  border-color: var(--border-medium);
  background: transparent;
  transition: border-color 160ms ease, color 160ms ease;
}

.tool-help:hover .tool-help__icon,
.tool-help:focus-within .tool-help__icon {
  border-color: var(--wb-accent-soft);
  color: var(--wb-accent-soft);
}

.tool-help__bubble {
  border-color: var(--border-medium);
  border-radius: 10px;
  background: #20232b;
  line-height: 1.55;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  transition: opacity 160ms ease, transform 200ms var(--ease-out);
}

/* ── Actions and status ─────────────────────────────── */

.tool-actions {
  gap: 12px;
  padding-top: 4px;
}

.tool-actions .btn {
  min-height: 48px;
}

.tool-status {
  min-height: 1.65em;
  font-size: 13px;
  line-height: 1.5;
}

.tool-status.is-error {
  color: var(--wb-error);
}

/* ── Preview canvas: the one framed object ──────────── */

.preview-frame {
  min-height: clamp(420px, 62vh, 640px);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  background-color: var(--wb-frame);
  background-image:
    linear-gradient(45deg, var(--wb-grid) 25%, transparent 25%),
    linear-gradient(-45deg, var(--wb-grid) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--wb-grid) 75%),
    linear-gradient(-45deg, transparent 75%, var(--wb-grid) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.preview-canvas,
.preview-frame.has-image .image-compressor-preview__img {
  max-height: clamp(380px, 56vh, 600px);
}

.preview-frame.has-image .preview-canvas,
.preview-frame.has-image .image-compressor-preview__img,
.preview-frame.has-image .preview-pan-target {
  animation: wb-settle 420ms var(--ease-out) both;
}

@keyframes wb-settle {
  from {
    opacity: 0;
    filter: blur(6px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

.preview-empty {
  color: var(--text-muted);
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
}

.preview-updating {
  background: rgba(13, 14, 17, 0.7);
  letter-spacing: 0;
  text-transform: none;
}

.preview-updating__spinner {
  width: 28px;
  height: 28px;
  border-width: 2px;
  border-color: rgba(169, 182, 255, 0.22);
  border-top-color: var(--wb-accent-soft);
}

.preview-stats {
  margin-top: 14px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.preview-tool-overlay {
  top: 14px;
  right: 14px;
}

.preview-tool-button {
  min-width: 36px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(17, 18, 20, 0.82);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.preview-compare-label {
  border-radius: 999px;
  padding: 4px 10px;
}

.preview-compare-slider {
  accent-color: var(--wb-accent-soft);
}

/* ── File queue: open rows ──────────────────────────── */

.file-queue {
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: #596173 transparent;
}

.file-queue__item {
  padding: 14px 0;
  border: 0;
  border-top: 1px solid var(--border-subtle);
  border-radius: 0;
  background: transparent;
}

.file-queue__item:last-child {
  border-bottom: 1px solid var(--border-subtle);
}

.file-queue__meta {
  font-variant-numeric: tabular-nums;
}

.file-queue__status {
  letter-spacing: 0;
  text-transform: none;
  font-size: 13px;
}

.file-queue__remove {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
}

.file-queue__item.is-error .file-queue__status,
.file-queue__item.is-error .file-queue__meta {
  color: var(--wb-error);
}

.image-compressor-queue__empty {
  border: 1.5px dashed var(--border-medium);
  border-radius: 12px;
}

/* ── Toast, modal ───────────────────────────────────── */

.tool-toast {
  border-color: var(--border-medium);
  border-radius: 10px;
  background: #20232b;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  transition: opacity 160ms ease, transform 260ms var(--ease-out);
}

.tool-modal__backdrop {
  background: rgba(8, 9, 11, 0.78);
}

.tool-modal__panel {
  border-color: var(--border-medium);
  border-radius: 14px;
  background: #1b1d22;
  scrollbar-width: thin;
  scrollbar-color: #596173 transparent;
}

.license-list a,
.tool-modal__body a {
  color: var(--wb-accent-soft);
  text-underline-offset: 0.25em;
}

/* ── Markdown to PDF ────────────────────────────────── */

.doc-preview-wrap {
  border-radius: 14px;
  background: var(--wb-frame);
  scrollbar-width: thin;
  scrollbar-color: #596173 transparent;
}

/* ── Sprite sheet viewer ────────────────────────────── */

.sprite-tool :focus-visible,
.sprite-tool .upload-tile:focus-within {
  outline-color: var(--wb-focus);
}

.sprite-scrubber input,
.sprite-tool input[type="range"] {
  accent-color: var(--wb-accent-soft);
}

.sprite-tool .upload-tile__meta,
.sprite-hint {
  color: var(--text-muted);
}

.sprite-tool .tool-status.is-error {
  color: var(--wb-error);
}

.sprite-tool .tool-status,
.sprite-tool .tool-range output {
  color: var(--text-muted);
}

.sprite-tool .tool-range output {
  color: var(--wb-accent-soft);
}

.sprite-options {
  padding: 24px 0 0;
  border: 0;
  border-top: 1px solid var(--border-subtle);
}

.sprite-options legend {
  float: left;
  width: 100%;
  padding: 0;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
}

.sprite-options legend + * {
  clear: both;
}

.sprite-panel-heading {
  padding-top: 4px;
  border-top: 1px solid var(--border-medium);
}

.sprite-panel-heading h2 {
  padding-top: 16px;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.sprite-panel-heading span {
  color: var(--text-muted);
}

.sprite-stage,
.sprite-sheet-stage {
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  background-color: var(--wb-frame);
  background-image: conic-gradient(#14161a 25%, var(--wb-frame) 0 50%, #14161a 0 75%, var(--wb-frame) 0);
  background-size: 20px 20px;
  scrollbar-width: thin;
  scrollbar-color: #596173 transparent;
}

.sprite-stage[data-background="dark"] {
  background: #08090b;
}

.sprite-stage[data-background="light"] {
  background: #e9eaee;
}

.sprite-stage p,
.sprite-sheet-stage > p {
  color: var(--text-muted);
  font-size: 14px;
}

.sprite-transport {
  gap: 10px;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 980px) {
  .texture-tool__workspace {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .preview-frame {
    min-height: 380px;
  }
}

@media (max-width: 760px) {
  .detail-page .tools-hero {
    padding-bottom: 24px;
  }

  .detail-page .tool-section {
    padding-bottom: 60px;
  }

  .texture-tool__header {
    flex-direction: row;
    min-height: 56px;
    padding: 8px 0;
  }

  .texture-tool__workspace {
    padding: 4px 0 0;
  }

  .tool-options {
    padding-top: 20px;
  }

  .preview-frame {
    min-height: 320px;
    border-radius: 12px;
  }

  .sprite-workspace {
    padding: 4px 0 0;
  }
}

@media (max-width: 480px) {
  .upload-tile {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 4px 14px;
    padding: 16px;
  }

  .upload-tile__icon {
    width: 40px;
    height: 40px;
  }

  .preview-tool-overlay {
    top: 10px;
    right: 10px;
    gap: 6px;
  }
}

/* ── Preview proportions ────────────────────────────────
   Textures are mostly square, so the canvas is a 5:4 field sized from the
   viewport height instead of a stretched wide strip, and it keeps that shape
   before and after a file loads. */

.texture-tool__preview {
  --wb-h: clamp(380px, 70vh, 680px);
}

.texture-tool__preview .preview-frame {
  width: min(100%, calc(var(--wb-h) * 1.25));
  height: var(--wb-h);
  min-height: 0;
  margin-inline: auto;
}

.texture-tool__preview .preview-canvas,
.texture-tool__preview .preview-compare-before,
.texture-tool__preview .preview-frame.has-image .image-compressor-preview__img {
  max-width: calc(100% - 32px);
  max-height: calc(var(--wb-h) - 32px);
}

.texture-tool__preview .image-compressor-preview {
  min-height: 0;
}

.texture-tool__preview .preview-stats {
  width: min(100%, calc(var(--wb-h) * 1.25));
  margin-inline: auto;
}

@media (max-width: 980px) {
  .texture-tool__preview {
    --wb-h: clamp(300px, 72vw, 560px);
  }

  .texture-tool__preview .preview-frame {
    width: 100%;
  }
}

/* Sprite viewer: both stages get real proportions. */

.sprite-stage {
  height: auto;
  aspect-ratio: 4 / 3;
  min-height: 300px;
  max-height: min(70vh, 600px);
  padding: 24px;
}

.sprite-sheet-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  aspect-ratio: 16 / 10;
  max-height: min(70vh, 640px);
  padding: 24px;
  overflow: auto;
}

.sprite-sheet-stage:has(#sheet-display:not([hidden])) {
  aspect-ratio: auto;
  min-height: 240px;
  padding: 16px;
}

#sheet-image {
  max-height: min(60vh, 560px);
}

.sprite-stage > p,
.sprite-sheet-stage > p {
  display: grid;
  justify-items: center;
  gap: 12px;
  max-width: 32ch;
  padding: 24px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.sprite-stage > p svg,
.sprite-sheet-stage > p svg {
  color: var(--wb-accent-soft);
  opacity: 0.7;
}

.sprite-stage > p[hidden],
.sprite-sheet-stage > p[hidden] {
  display: none;
}

@media (max-width: 760px) {
  .sprite-stage {
    aspect-ratio: 1 / 1;
    min-height: 0;
    padding: 16px;
  }

  .sprite-sheet-stage {
    aspect-ratio: 4 / 3;
  }
}

/* Sprite viewer: each viewer has its own controls beside it. ───────────── */

.sprite-intake,
.sprite-tool .sprite-workspace {
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: clamp(28px, 3.4vw, 56px);
}

.sprite-intake {
  display: grid;
  align-items: center;
  padding: 8px 0 32px;
}

.sprite-intake__side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
}

.sprite-intake__side .tool-status {
  flex: 1 1 24ch;
  min-height: 0;
}

.sprite-tool .sprite-workspace {
  padding: 32px 0;
  border-top: 1px solid var(--border-subtle);
}

.sprite-tool .sprite-workspace:last-child {
  padding-bottom: 0;
}

.sprite-controls {
  align-self: start;
}

.sprite-controls .sprite-options {
  padding-top: 0;
  border-top: 0;
}

.sprite-panel-heading {
  padding-top: 0;
  border-top: 0;
}

.sprite-panel-heading h2 {
  padding-top: 0;
}

@media (max-width: 980px) {
  .sprite-intake,
  .sprite-tool .sprite-workspace {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  /* On narrow screens the viewer comes first, its controls right below. */
  .sprite-tool .sprite-previews {
    order: -1;
  }
}
