:root {
  color-scheme: dark;
  --page: #101418;
  --panel: rgba(255, 255, 255, 0.075);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.18);
  --text: #f4f7fb;
  --muted: rgba(244, 247, 251, 0.72);
  --accent: #72d2c8;
  --accent-strong: #f4c95d;
  --danger: #ff8a8a;
  --success: #90e7a7;
  --warning: #ffd47a;
  --shadow: rgba(0, 0, 0, 0.26);
  --motion-fast: 160ms;
  --motion-page: 260ms;
  font-family: "Source Sans Pro", Helvetica, sans-serif;
}

@view-transition {
  navigation: auto;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(rgba(16, 20, 24, 0.88), rgba(16, 20, 24, 0.94)),
    url("../../../images/bg.jpg") center / cover fixed;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    linear-gradient(135deg, rgba(114, 210, 200, 0.1), transparent 36%),
    linear-gradient(180deg, rgba(244, 201, 93, 0.08), transparent 42%);
  pointer-events: none;
}

a {
  color: inherit;
}

a,
button {
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

.tool-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 64px;
  animation: tool-page-enter var(--motion-page) cubic-bezier(0.2, 0.8, 0.2, 1) both;
  view-transition-name: tool-page;
}

body.is-tool-leaving .tool-shell {
  animation: tool-page-exit var(--motion-fast) ease-in both;
}

::view-transition-old(tool-page) {
  animation: tool-page-exit var(--motion-fast) ease-in both;
}

::view-transition-new(tool-page) {
  animation: tool-page-enter var(--motion-page) cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes tool-page-enter {
  from {
    opacity: 0;
    transform: translateY(14px);
    filter: blur(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

@keyframes tool-page-exit {
  from {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }

  to {
    opacity: 0;
    transform: translateY(-8px);
    filter: blur(5px);
  }
}

.tool-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 34px;
}

.tool-back {
  color: var(--muted);
  text-decoration: none;
}

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

.tool-back::before {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  margin-right: 0.45em;
  border-left: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-0.05em);
}

.tool-back:focus-visible,
.tool-card:focus-visible,
.tool-button:focus-visible,
.tool-input:focus-visible,
.tool-select:focus-visible,
.tool-textarea:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
}

.tool-title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
  letter-spacing: 0;
}

.tool-shell > header {
  margin-bottom: 34px;
}

.tool-subtitle {
  max-width: 720px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.tool-card,
.tool-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.055)),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px var(--shadow);
  backdrop-filter: blur(10px);
}

.tool-card {
  display: grid;
  gap: 12px;
  min-height: 190px;
  padding: 20px;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: var(--panel-strong);
}

.tool-card h2,
.tool-card h3,
.tool-panel h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0;
}

.tool-card p,
.tool-panel p {
  margin: 0;
  color: var(--muted);
}

.tool-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: end;
}

.tool-tag {
  padding: 3px 8px;
  color: var(--page);
  background: var(--accent);
  border-radius: 999px;
  font-size: 0.78rem;
}

.tool-panel {
  padding: 20px;
}

.tool-stack {
  display: grid;
  gap: 16px;
}

.tool-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.tool-form-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.tool-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.72fr);
  gap: 16px;
}

.tool-split.even {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-field {
  display: grid;
  gap: 6px;
}

.tool-field span {
  color: var(--muted);
  font-size: 0.9rem;
}

.tool-input,
.tool-select,
.tool-textarea {
  width: 100%;
  color: var(--text);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.tool-input[type="range"] {
  min-height: auto;
  padding: 0;
  accent-color: var(--accent);
}

.tool-input[type="checkbox"] {
  width: auto;
  min-height: auto;
  accent-color: var(--accent);
}

.tool-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.tool-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.tool-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px;
  color: var(--muted);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.045)),
    rgba(0, 0, 0, 0.18);
  border: 1px dashed var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color var(--motion-fast) ease, background var(--motion-fast) ease, color var(--motion-fast) ease;
}

.tool-upload:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(114, 210, 200, 0.08);
}

.tool-upload-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  color: #071312;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.tool-upload:hover .tool-upload-button {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.tool-file:focus-visible + .tool-upload-button {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
}

.tool-upload-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-input,
.tool-select {
  min-height: 44px;
  padding: 0 12px;
}

.tool-textarea {
  min-height: 260px;
  padding: 12px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.tool-input:focus,
.tool-select:focus,
.tool-textarea:focus {
  border-color: var(--accent);
}

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

.tool-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.94rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.tool-button.compact {
  min-height: 30px;
  padding: 0 9px;
  font-size: 0.82rem;
}

.tool-button:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.12);
}

.tool-button.primary {
  color: #071312;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.tool-status {
  min-height: 1.5rem;
  color: var(--muted);
}

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

.tool-status.success {
  color: var(--success);
}

.tool-section-title {
  margin: 40px 0 14px;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
}

.tool-panel + .tool-section-title,
.tool-grid + .tool-section-title,
.tool-split + .tool-section-title {
  margin-top: 46px;
}

.tool-results {
  display: grid;
  gap: 8px;
}

.tool-result-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(160px, 2fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tool-result-row strong {
  color: var(--accent-strong);
}

.tool-result-row span {
  overflow-wrap: anywhere;
}

.tool-result-row > :nth-child(2):last-child {
  grid-column: 2 / -1;
}

.tool-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

.tool-table th,
.tool-table td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
  vertical-align: top;
}

.tool-table th {
  color: var(--accent-strong);
  font-weight: 600;
}

.tool-preview {
  min-height: 180px;
  padding: 14px;
  overflow: auto;
  color: var(--text);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tool-preview pre,
.tool-code {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.tool-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.86rem;
}

.tool-swatch {
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.tool-color-pair {
  display: grid;
  place-items: center;
  min-height: 120px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.tool-canvas-wrap,
.tool-image-frame {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 18px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tool-canvas-wrap canvas {
  max-width: 100%;
  height: auto;
  background: #ffffff;
  border-radius: 6px;
}

.tool-image-frame img,
.tool-image-frame canvas {
  max-width: 100%;
  max-height: 420px;
  border-radius: 6px;
}

.tool-match {
  padding: 0 2px;
  color: #071312;
  background: var(--accent-strong);
  border-radius: 3px;
}

.tool-diff-line {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.tool-diff-line.add {
  background: rgba(144, 231, 167, 0.16);
}

.tool-diff-line.remove {
  background: rgba(255, 138, 138, 0.16);
}

.tool-diff-line.same {
  color: var(--muted);
}

.tool-markdown-preview h1,
.tool-markdown-preview h2,
.tool-markdown-preview h3 {
  margin: 0.7em 0 0.35em;
}

.tool-markdown-preview p {
  margin: 0.65em 0;
}

.tool-markdown-preview code {
  padding: 0.1em 0.35em;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

.tool-markdown-preview pre {
  padding: 12px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 8px;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .tool-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 24px;
  }

  .tool-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .tool-split,
  .tool-split.even {
    grid-template-columns: 1fr;
  }

  .tool-result-row {
    grid-template-columns: 1fr;
  }

  .tool-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }

  .tool-shell,
  body.is-tool-leaving .tool-shell,
  ::view-transition-old(tool-page),
  ::view-transition-new(tool-page) {
    animation: none !important;
    filter: none !important;
    transform: none !important;
  }
}
