:root {
  --bg: #f3efe5;
  --surface: #fffaf0;
  --surface-strong: #efe5d4;
  --surface-soft: #f9f2e4;
  --text: #1f1e1a;
  --muted: #5f5a4f;
  --line: #dbcfb8;
  --accent: #0f766e;
  --accent-strong: #0b5e58;
  --danger: #9f1239;
  --shadow: 0 10px 30px rgba(49, 35, 7, 0.08);
  --radius: 14px;
  --chip-bg: var(--surface-soft);
  --chip-border: var(--line);
  --chip-text: var(--text);
  --chip-hover-bg: var(--surface-strong);
}

:root[data-theme='dark'] {
  --bg: #111926;
  --surface: #1a2435;
  --surface-strong: #27344a;
  --surface-soft: #202d42;
  --text: #ecf2ff;
  --muted: #acc1de;
  --line: #344766;
  --accent: #2dd4bf;
  --accent-strong: #79f7e4;
  --danger: #fb7185;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.36);
  --chip-bg: #1c2a41;
  --chip-border: #2f3b55;
  --chip-text: #f8fafc;
  --chip-hover-bg: #27344a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Space Grotesk', 'Avenir Next', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--surface) 60%, transparent) 0%, transparent 45%),
    radial-gradient(circle at 80% 0%, color-mix(in srgb, var(--accent) 22%, transparent) 0%, transparent 35%),
    var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 42px;
}

.site-header {
  position: sticky;
  top: 16px;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr minmax(300px, 420px);
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(7px);
  box-shadow: var(--shadow);
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 1.18rem;
}

.brand-sub {
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.header-controls {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
}

.theme-toggle {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  background: var(--surface-soft);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
}

.header-search-wrap {
  position: relative;
}

.header-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  background: color-mix(in srgb, var(--surface) 78%, #fff 22%);
  color: var(--text);
}

.header-search:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 32%, transparent);
}

.search-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  max-height: 300px;
  overflow: auto;
  display: none;
}

.search-results.show {
  display: block;
}

.search-item {
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.search-item:hover,
.search-item.is-active {
  background: var(--surface-strong);
}

.search-item.is-disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.search-item-name {
  font-weight: 600;
  color: var(--text);
}

.search-item-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.hero {
  margin-bottom: 26px;
  animation: reveal 600ms ease-out;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.hero p {
  color: var(--muted);
  max-width: 70ch;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px;
}

.tool-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 220ms ease, border-color 220ms ease;
}

.tool-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--line) 55%, var(--accent));
}

.tool-card h3 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.tool-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.badge {
  display: inline-block;
  margin-bottom: 10px;
  font-size: 0.72rem;
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 999px;
  padding: 2px 8px;
}

.category-block {
  margin-bottom: 24px;
}

.category-title {
  margin: 0 0 10px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(260px, 0.92fr);
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-body {
  padding: 14px 16px;
}

textarea,
input,
select,
pre,
button {
  font-family: 'IBM Plex Mono', monospace;
}

textarea,
input,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 78%, #fff 22%);
  color: var(--text);
  font-size: 0.9rem;
  padding: 10px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 32%, transparent);
}

textarea {
  min-height: 300px;
  resize: vertical;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

button {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.83rem;
  transition: transform 180ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.btn-primary {
  color: #fff;
  background: var(--accent);
}

.btn-muted {
  color: var(--text);
  background: var(--surface-strong);
  border-color: var(--line);
}

.btn-danger {
  color: #fff;
  background: var(--danger);
}

.status {
  font-size: 0.82rem;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 8px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.help-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.error-text {
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
  min-height: 1.1em;
}

.warning-text {
  margin: 0;
  color: color-mix(in srgb, #b45309 70%, var(--muted));
  font-size: 0.82rem;
  min-height: 1.1em;
}

.regex-output-box {
  min-height: 220px;
}

.regex-line {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  background: var(--surface-soft);
  word-break: break-word;
}

.issues-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.issue-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.83rem;
  color: var(--chip-text);
  background: var(--chip-bg);
  border-color: var(--chip-border);
}

.issue-chip-button {
  cursor: pointer;
}

.issue-chip-button:hover {
  background: var(--chip-hover-bg);
  border-color: var(--accent);
  transform: none;
}

.project-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-soft);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.project-block .actions {
  margin-top: 10px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

label {
  font-size: 0.82rem;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.image-viewer-wrapper {
  position: relative;
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.image-viewer-wrapper.fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  margin: 0;
  z-index: 30;
  background: var(--bg);
  box-shadow: none;
}

body.no-scroll {
  overflow: hidden;
}

.image-viewer {
  width: 100%;
  height: 420px;
  position: relative;
  cursor: grab;
}

.image-viewer-wrapper.fullscreen .image-viewer {
  height: 100vh;
}

.image-viewer.panning {
  cursor: grabbing;
}

#viewer-img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center center;
  max-width: none;
  transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.image-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.image-prompt-card {
  background: color-mix(in srgb, var(--surface) 80%, rgba(15, 23, 42, 0.7));
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
}

.fullscreen-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 1.2rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 31;
}

.image-viewer-wrapper.fullscreen .fullscreen-close {
  display: flex;
}

.panel-body .actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.panel-body .actions .btn-muted {
  min-width: 150px;
}

.image-prompt-icon {
  width: 48px;
  height: 48px;
  color: var(--muted);
}

.image-prompt h3 {
  margin: 12px 0 4px;
  font-size: 1.2rem;
  color: var(--text);
}

.image-prompt .muted {
  font-size: 0.9rem;
}

.path-list {
  margin-top: 10px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 6px;
}

.path-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  margin-bottom: 4px;
}

.path-item:hover,
.path-item.is-active {
  border-color: var(--line);
  background: var(--surface-strong);
}

.path-item-title {
  display: block;
  color: var(--text);
  font-weight: 600;
}

.path-item-sub {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 2px;
}

.path-list-empty {
  margin: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

pre {
  margin: 0;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-strong) 65%, var(--surface));
  border: 1px solid var(--line);
  padding: 12px;
  min-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.collapsible {
  border-top: 1px solid var(--line);
}

.collapsible summary {
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 500;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #1f2937;
  color: #fff;
  border-radius: 9px;
  padding: 8px 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}

.toast.show {
  opacity: 1;
}

.highlight-key {
  color: #0f5f85;
}

.highlight-string {
  color: #0f766e;
}

.highlight-number {
  color: #bb3e03;
}

.highlight-boolean {
  color: #5f3dc4;
}

.highlight-null {
  color: #9333ea;
}

:root[data-theme='dark'] .highlight-key {
  color: #93c5fd;
}

:root[data-theme='dark'] .highlight-string {
  color: #5eead4;
}

:root[data-theme='dark'] .highlight-number {
  color: #fdba74;
}

:root[data-theme='dark'] .highlight-boolean {
  color: #c4b5fd;
}

:root[data-theme='dark'] .highlight-null {
  color: #f0abfc;
}

@keyframes reveal {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #111926;
    --surface: #1a2435;
    --surface-strong: #27344a;
    --surface-soft: #202d42;
    --text: #ecf2ff;
    --muted: #acc1de;
    --line: #344766;
    --accent: #2dd4bf;
    --accent-strong: #79f7e4;
    --danger: #fb7185;
    --shadow: 0 16px 36px rgba(0, 0, 0, 0.36);
  }
}

@media (max-width: 930px) {
  .site-header {
    position: static;
    grid-template-columns: 1fr;
  }

  .header-controls {
    grid-template-columns: 1fr;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }
}
