:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --text: #0f172a;
  --text-soft: #475569;
  --border: #dbe4ef;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-soft: #eef2ff;
  --danger: #b91c1c;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --radius-sm: 10px;
  --font: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(circle at 18% -8%, #dbeafe 0, transparent 38%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

.shell {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: -999px;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 1000;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
}

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

.nav-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  color: #fff;
  font-size: 0.9rem;
}

.brand-text {
  font-size: 1.05rem;
}

.brand-sub {
  font-weight: 400;
  color: var(--text-soft);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.header-tagline {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.site-nav a {
  color: var(--text-soft);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.2rem 0;
  white-space: nowrap;
  text-decoration: none;
}

.site-nav a.active,
.site-nav a:hover {
  color: var(--text);
}

.mobile-nav-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
}

.main-wrap {
  padding: 2rem 0 3rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 2vw, 2rem);
}

.panel-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.6rem, 2.4vw, 2rem);
  letter-spacing: -0.02em;
}

.lede {
  margin: 0;
  color: var(--text-soft);
  max-width: 62ch;
}

.lede.full-width {
  max-width: none;
  margin: 0 0 1.25rem;
  font-size: 1.1rem;
  line-height: 1.4;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1.35rem 0 1.25rem;
}

.tab {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  color: var(--text-soft);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.tab:hover {
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  color: var(--text);
}

.tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.tab.active {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.25);
}

.grid-io {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: start;
}

.field-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.45rem;
  color: var(--text);
}

.hint-text {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--text-soft);
}

.char-counter {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--text-soft);
  text-align: right;
}

.io-area {
  width: 100%;
  min-height: 180px;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.5;
  background: var(--surface-muted);
  color: var(--text);
  overflow-x: auto;
}

.io-area:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 1px;
  border-color: var(--primary);
  background: var(--surface);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
}

.btn {
  border: 1px solid transparent;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff;
  box-shadow: 0 10px 24px rgba(79, 70, 229, 0.22);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.message {
  min-height: 1.35rem;
  margin: 0.75rem 0 0;
  font-size: 0.95rem;
}

.message.is-error {
  color: var(--danger);
}

.message.is-success {
  color: var(--primary-dark);
}

.ad-slot {
  border: 1px dashed color-mix(in srgb, var(--border) 75%, transparent);
  background: color-mix(in srgb, var(--surface-muted) 80%, transparent);
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  text-align: center;
  min-height: 76px;
  display: grid;
  place-items: center;
  font-weight: 600;
  margin: 0 0 1rem;
}

.ad-slot-compact {
  min-height: 64px;
  margin: 0.25rem 0 1rem;
}

.ad-slot-after-actions {
  margin-top: 1.75rem;
}

.tool-content {
  display: none;
  margin-top: 1.25rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--border);
}

.tool-content.is-active {
  display: block;
}

.tool-content h2 {
  margin: 1rem 0 0.5rem;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.tool-content p {
  margin: 0 0 0.75rem;
  color: var(--text-soft);
  max-width: 82ch;
}

.tool-content p.max-width {
  width: 100%;
  max-width: none;
}

.tool-links {
  margin: 0.25rem 0 1rem;
  font-size: 0.95rem;
}

.tool-links a {
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 600;
}

.tool-links a:hover {
  text-decoration: underline;
}

.howto-list {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
  color: var(--text-soft);
}

.code-block {
  margin: 0.5rem 0 0;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.example-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.example-box strong {
  display: block;
  color: var(--text);
}

.legal-content {
  display: none;
  margin-top: 1.25rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--border);
}

.legal-content-visible {
  display: block;
}

.legal-content h2 {
  margin: 1rem 0 0.5rem;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.legal-content p {
  margin: 0 0 0.75rem;
  color: var(--text-soft);
  max-width: 82ch;
}

.footer-ad {
  padding: 0 0 1rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-muted) 78%, transparent);
  padding: 3rem 0;
}

.footer-grid {
  display: grid;
  gap: 1.4rem;
  grid-template-columns: 1.1fr 1fr 1fr;
}

.footer-brand {
  margin-bottom: 0.5rem;
}

.footer-copy {
  margin: 0.35rem 0 0;
  color: var(--text-soft);
}

.footer-links {
  display: grid;
  gap: 0.55rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.footer-links a {
  color: var(--text-soft);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--text);
  text-decoration: underline;
}

.copyright {
  color: var(--text-soft);
  margin: 0;
}

.footer-note {
  color: var(--text-soft);
  margin: 0;
  max-width: 30ch;
}

.footer-bottom {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.75rem;
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(2px);
  z-index: 200;
  color: #fff;
  font-weight: 600;
  text-align: center;
  padding: 1rem;
}

.loading-overlay.is-visible {
  display: flex;
}

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.75s linear infinite;
}

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

@media (max-width: 768px) {
  body {
    padding-bottom: 1rem;
  }

  .nav-wrap {
    min-height: 74px;
  }

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

  .io-area {
    min-height: 160px;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .actions .btn {
    width: 100%;
    text-align: center;
  }

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

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

@media (max-width: 720px) {
  .mobile-nav-toggle {
    display: inline-flex;
  }

  .site-nav {
    position: absolute;
    left: 0;
    right: 0;
    top: 74px;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-0.5rem);
    pointer-events: none;
    transition: opacity 0.24s ease, transform 0.24s ease, max-height 0.3s ease;
  }

  .site-nav.open {
    max-height: calc(100vh - 74px);
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: rgba(255, 255, 255, 0.8);
  }

  .btn:active {
    transform: none;
  }
}
