/* Tools section — matches site tokens from site.css */

.site-main:has(.tools-layout) {
  width: 100%;
  margin: 0;
  padding: 0;
}

.tools-layout {
  --tools-max: 1120px;
  min-height: calc(100vh - 140px);
}

.tools-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}

.tools-header-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  width: min(100%, var(--tools-max));
  margin: 0 auto;
  padding: 16px;
  box-sizing: border-box;
}

.tools-back {
  color: var(--muted);
  font-size: 0.95rem;
  justify-self: start;
}

.tools-back:hover {
  color: var(--text);
  text-decoration: none;
}

.tools-header-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  justify-self: center;
}

.tools-header-switch {
  color: var(--muted);
  font-size: 0.95rem;
  justify-self: end;
}

.tools-header-switch:hover {
  color: var(--text);
  text-decoration: none;
}

.tools-shell {
  width: min(100% - 32px, var(--tools-max));
  margin: 0 auto;
  padding: 32px 0 64px;
}

.tools-index-list {
  display: grid;
  gap: 16px;
  margin-top: 32px;
}

.tools-index-card {
  display: block;
  padding: 20px 22px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

.tools-index-card:hover {
  text-decoration: none;
  border-color: var(--link);
}

.tools-index-card strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.tools-index-card span {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* —— Sprite auto-split extractor —— */

.tool-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

@media (min-width: 768px) {
  .tool-panel {
    padding: 32px;
  }
}

.tool-panel-head {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

@media (min-width: 640px) {
  .tool-panel-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }
}

.tool-panel-titles h1 {
  margin: 0 0 8px;
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  line-height: 1.25;
  font-weight: 700;
}

.tool-panel-titles p {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.7;
  max-width: 40rem;
}

.tool-settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 55%, var(--card));
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  flex-shrink: 0;
}

.tool-settings-btn:hover {
  border-color: var(--link);
}

.tool-settings-btn svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  flex-shrink: 0;
}

.tool-settings-summary {
  color: var(--link);
  font-weight: 600;
}

.tool-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  margin-bottom: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.tool-dropzone:hover,
.tool-dropzone.drag-over {
  border-color: var(--link);
  background: color-mix(in srgb, var(--link) 8%, transparent);
}

.tool-dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.tool-upload-icon {
  width: 40px;
  height: 40px;
  color: var(--muted);
}

.tool-dropzone-title {
  margin: 14px 0 0;
  color: var(--text);
  font-size: 1.05rem;
}

.tool-dropzone-title .accent {
  color: var(--link);
  font-weight: 600;
}

.tool-dropzone-hint,
.tool-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.tool-status .status-warning {
  display: block;
  margin-top: 0.5rem;
  color: #d4a574;
  font-size: 0.82rem;
}

.preview-thumb {
  max-width: 6rem;
  max-height: 6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}

.preview-thumb.is-single {
  max-width: min(100%, 36rem);
  max-height: 28rem;
}

#preview-images {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 12px;
}

.tool-loader {
  border: 3px solid var(--border);
  border-top-color: var(--link);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  margin: 2rem auto;
  animation: tool-spin 0.8s linear infinite;
}

@keyframes tool-spin {
  to {
    transform: rotate(360deg);
  }
}

.tool-output-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  padding-bottom: 12px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

@media (min-width: 640px) {
  .tool-output-head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.tool-output-head h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
}

.tool-btn:hover {
  text-decoration: none;
  filter: brightness(1.06);
}

.tool-btn svg {
  width: 18px;
  height: 18px;
}

.tool-btn-primary {
  background: color-mix(in srgb, var(--link) 35%, #3949ab);
  border-color: color-mix(in srgb, var(--link) 50%, transparent);
}

.tool-btn-muted {
  background: color-mix(in srgb, var(--bg) 40%, var(--card));
  border-color: var(--border);
}

.tool-btn-muted:hover {
  border-color: var(--link);
}

.tool-sprite-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 480px) {
  .tool-sprite-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 720px) {
  .tool-sprite-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 960px) {
  .tool-sprite-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.sprite-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: color-mix(in srgb, var(--bg) 70%, var(--card));
  background-image:
    linear-gradient(45deg, #2a3040 25%, transparent 25%),
    linear-gradient(-45deg, #2a3040 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a3040 75%),
    linear-gradient(-45deg, transparent 75%, #2a3040 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  transition: border-color 0.15s ease;
}

.sprite-wrapper:hover {
  border-color: var(--link);
}

.sprite-canvas {
  max-width: 100%;
  max-height: 100%;
}

.download-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  padding: 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 2;
}

.sprite-wrapper:hover .download-btn {
  opacity: 0.9;
}

.download-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.75);
}

.download-btn svg {
  width: 16px;
  height: 16px;
  color: #fff;
  display: block;
}

.tool-sample {
  margin-top: 28px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.tool-sample-copy h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 600;
}

.tool-sample-copy p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

.tool-sample-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 55%, var(--card));
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease;
}

.tool-sample-btn:hover {
  border-color: var(--link);
}

.tool-sample-btn:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.tool-sample-btn img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 18rem;
  object-fit: contain;
  background:
    linear-gradient(45deg, #2a3040 25%, transparent 25%),
    linear-gradient(-45deg, #2a3040 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a3040 75%),
    linear-gradient(-45deg, transparent 75%, #2a3040 75%);
  background-color: #151821;
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.tool-sample-cta {
  display: block;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  color: var(--link);
  font-size: 0.92rem;
  font-weight: 600;
}

.tool-cta {
  margin-top: 28px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 45%, var(--card));
}

.tool-cta p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

.tool-cta a {
  font-weight: 600;
}

/* Modals */
.tool-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.72);
}

.tool-modal-card {
  width: min(100%, 500px);
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tool-modal-card.is-wide {
  width: min(100%, 720px);
}

.tool-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.tool-modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.tool-modal-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.tool-modal-close:hover {
  color: var(--text);
}

.tool-field {
  margin-bottom: 22px;
}

.tool-field label,
.tool-field .tool-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text);
}

.tool-field .hint {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.tool-field .range-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.tool-field input[type="range"] {
  width: 100%;
  accent-color: var(--link);
}

.tool-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text);
}

.tool-radio input {
  accent-color: var(--link);
}

.tool-color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.tool-color-row input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.tool-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.color-picker-image {
  max-width: 100%;
  max-height: 60vh;
  cursor: crosshair;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.color-preview {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-block;
}

.tool-color-pick-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.tool-color-pick-bar .selected {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}
