:root {
  color-scheme: dark;

  /* Heat — Firecrawl-adjacent orange, restrained */
  --heat: oklch(0.68 0.19 42);
  --heat-soft: oklch(0.68 0.19 42 / 0.14);
  --heat-mid: oklch(0.68 0.19 42 / 0.32);
  --heat-strong: oklch(0.72 0.18 42);

  /* Warm near-black surfaces (never pure #000) */
  --bg: oklch(0.12 0.008 42);
  --bg-elevated: oklch(0.15 0.01 42);
  --bg-input: oklch(0.14 0.01 42);
  --bg-code: oklch(0.13 0.009 42);

  --text: oklch(0.93 0.008 42);
  --text-secondary: oklch(0.72 0.012 42);
  --text-muted: oklch(0.55 0.014 42);
  --text-faint: oklch(0.42 0.012 42);

  --line: oklch(0.28 0.014 42);
  --line-strong: oklch(0.36 0.02 42);
  --line-focus: color-mix(in oklch, var(--heat) 42%, var(--line));

  --danger: oklch(0.72 0.14 25);

  --font-sans: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Emil Kowalski strong ease-out — responsive, under 300ms UI */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --duration-press: 140ms;
  --duration-ui: 200ms;
  --duration-enter: 240ms;
  --radius: 2px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-synthesis: none;
  font-feature-settings: "ss01" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse 80% 50% at 50% 42%, oklch(0.18 0.03 42 / 0.45), transparent 70%),
    var(--bg);
}

body.is-loading {
  cursor: progress;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  transition: transform var(--duration-press) var(--ease-out);
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

/* ── Header ───────────────────────────────────────── */

.site-header {
  position: fixed;
  z-index: 10;
  top: var(--space-5);
  left: 28px;
}

.site-header a {
  display: flex;
  min-height: 28px;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  line-height: 1;
  text-decoration: none;
  transition: color var(--duration-ui) var(--ease-out);
}

.site-header a:focus-visible {
  color: var(--text);
  outline: 0;
}

@media (hover: hover) and (pointer: fine) {
  .site-header a:hover {
    color: var(--text);
  }
}

.site-header a:focus-visible {
  box-shadow: 0 1px 0 var(--heat);
}

.brand-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--heat);
  box-shadow: 0 0 0 3px var(--heat-soft);
}

/* ── Layout ───────────────────────────────────────── */

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

main {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
}

.converter {
  display: grid;
  min-height: 100svh;
  place-items: center;
  padding: var(--space-7) 0;
}

.input-shell {
  position: relative;
  isolation: isolate;
  width: min(520px, 100%);
  margin: 0 auto;
  will-change: transform;
}

body.has-result .input-shell {
  width: min(640px, 100%);
}

/* ── Dot field ────────────────────────────────────── */

.dot-field {
  position: absolute;
  z-index: -1;
  inset: -96px -128px;
  overflow: hidden;
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--duration-enter) var(--ease-out);
  -webkit-mask-image: radial-gradient(
    ellipse at center,
    #000 0%,
    rgba(0, 0, 0, 0.85) 32%,
    transparent 72%
  );
  mask-image: radial-gradient(
    ellipse at center,
    #000 0%,
    rgba(0, 0, 0, 0.85) 32%,
    transparent 72%
  );
}

body.has-result .dot-field {
  opacity: 0.38;
  inset: -56px -96px;
}

.dot-field canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Input ────────────────────────────────────────── */

form {
  width: 100%;
}

.input-row {
  display: grid;
  /* Two tracks when clear is display:none; three when results show.
     A zero-width middle track would park submit in a tiny hit sliver. */
  grid-template-columns: minmax(0, 1fr) 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-input);
  box-shadow:
    0 0 0 1px oklch(0 0 0 / 0.35),
    0 12px 40px oklch(0 0 0 / 0.35);
  transition:
    border-color var(--duration-ui) var(--ease-out),
    box-shadow var(--duration-ui) var(--ease-out);
}

body.has-result .input-row {
  grid-template-columns: minmax(0, 1fr) 44px 48px;
}

.input-row:focus-within {
  border-color: var(--line-focus);
  box-shadow:
    0 0 0 1px oklch(0 0 0 / 0.35),
    0 0 0 3px var(--heat-soft),
    0 12px 40px oklch(0 0 0 / 0.35);
}

body.is-loading .input-row {
  border-color: color-mix(in oklch, var(--heat) 34%, var(--line));
  box-shadow:
    0 0 0 1px oklch(0 0 0 / 0.35),
    0 0 0 3px var(--heat-soft),
    0 12px 40px oklch(0 0 0 / 0.35);
}

@media (hover: hover) and (pointer: fine) {
  .input-row:hover {
    border-color: var(--line-strong);
  }
}

input {
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0 var(--space-4);
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 400;
  letter-spacing: -0.01em;
}

input::placeholder {
  color: var(--text-faint);
  font-weight: 400;
}

.input-row > button {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  background: oklch(0.16 0.012 42);
  color: color-mix(in oklch, var(--heat) 70%, var(--text-muted));
  transition:
    background-color var(--duration-ui) var(--ease-out),
    color var(--duration-ui) var(--ease-out),
    border-color var(--duration-ui) var(--ease-out),
    opacity var(--duration-ui) var(--ease-out),
    transform var(--duration-press) var(--ease-out);
}

.input-row > button[type="submit"] {
  min-width: 48px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.clear-btn {
  min-width: 44px;
  color: var(--text-muted);
  background: transparent;
}

.clear-btn[hidden] {
  display: none;
}

.clear-btn .button-icon {
  width: 14px;
  height: 14px;
}

.button-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: opacity var(--duration-press) var(--ease-out);
}

.input-row > button[type="submit"]::after {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--heat);
  content: "";
  opacity: 0;
  box-shadow: 0 0 0 3px var(--heat-soft);
  animation: none;
}

.input-row > button:focus-visible {
  background: color-mix(in oklch, var(--heat) 12%, oklch(0.16 0.012 42));
  color: var(--heat-strong);
  outline: 0;
}

.clear-btn:focus-visible {
  background: color-mix(in oklch, var(--heat) 8%, transparent);
  color: var(--text);
}

.input-row > button:active:not(:disabled) {
  background: color-mix(in oklch, var(--heat) 18%, oklch(0.16 0.012 42));
  transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
  .input-row > button:hover {
    background: color-mix(in oklch, var(--heat) 12%, oklch(0.16 0.012 42));
    color: var(--heat-strong);
  }

  .clear-btn:hover {
    background: color-mix(in oklch, var(--heat) 8%, transparent);
    color: var(--text);
  }
}

.input-row > button:disabled {
  cursor: wait;
  color: var(--text-faint);
}

form.is-loading .button-icon-submit {
  opacity: 0;
}

form.is-loading .input-row > button[type="submit"]::after {
  opacity: 1;
  animation: pulse-dot 520ms var(--ease-out) infinite;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 0.4;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ── Tagline + examples ───────────────────────────── */

.tagline {
  margin: var(--space-4) 0 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
  line-height: 1.55;
  text-align: center;
  letter-spacing: -0.005em;
  transition:
    opacity var(--duration-ui) var(--ease-out),
    transform var(--duration-ui) var(--ease-out);
}

.tagline a {
  color: var(--text-secondary);
  text-decoration-color: var(--line);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition:
    color var(--duration-ui) var(--ease-out),
    text-decoration-color var(--duration-ui) var(--ease-out);
}

.tagline a:focus-visible {
  color: color-mix(in oklch, var(--heat) 55%, var(--text-secondary));
  outline: 0;
  text-decoration-color: currentColor;
}

@media (hover: hover) and (pointer: fine) {
  .tagline a:hover {
    color: color-mix(in oklch, var(--heat) 55%, var(--text-secondary));
    text-decoration-color: currentColor;
  }
}

.examples {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-5);
  transition:
    opacity var(--duration-ui) var(--ease-out),
    transform var(--duration-ui) var(--ease-out);
}

.example {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  background: oklch(0.14 0.01 42 / 0.72);
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.2;
  transition:
    border-color var(--duration-ui) var(--ease-out),
    color var(--duration-ui) var(--ease-out),
    background-color var(--duration-ui) var(--ease-out),
    transform var(--duration-press) var(--ease-out);
}

.example:focus-visible {
  border-color: var(--line-focus);
  background: var(--heat-soft);
  color: var(--text);
  outline: 0;
}

.example:active {
  border-color: color-mix(in oklch, var(--heat) 50%, var(--line));
  transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
  .example:hover {
    border-color: var(--line-focus);
    background: var(--heat-soft);
    color: var(--text);
  }
}

.example-kind {
  flex-shrink: 0;
  color: color-mix(in oklch, var(--heat) 72%, var(--text-muted));
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.example-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trust {
  margin: var(--space-5) 0 0;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  line-height: 1.5;
  text-align: center;
  text-transform: uppercase;
  transition:
    opacity var(--duration-ui) var(--ease-out),
    transform var(--duration-ui) var(--ease-out);
}

body.is-loading .examples,
body.is-loading .trust {
  opacity: 0.35;
  pointer-events: none;
}

body.has-result .tagline,
body.has-result .examples,
body.has-result .trust {
  display: none;
}

/* ── Error ────────────────────────────────────────── */

.error {
  margin-top: var(--space-3);
  border: 1px solid color-mix(in oklch, var(--danger) 28%, var(--line));
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  background: color-mix(in oklch, var(--danger) 8%, var(--bg-elevated));
  color: var(--danger);
  font-size: 0.8125rem;
  line-height: 1.45;
}

.error[hidden] {
  display: none;
}

.error p {
  margin: 0;
}

/* ── Result ───────────────────────────────────────── */

body.has-result .converter {
  min-height: 0;
  place-items: start center;
  padding: 88px 0 var(--space-5);
}

body.has-result main {
  width: min(760px, calc(100% - 32px));
}

.result {
  padding-bottom: var(--space-8);
}

.result.is-entering {
  animation: result-in var(--duration-enter) var(--ease-out) both;
}

@keyframes result-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#new {
  color: var(--text-muted);
}

#new:focus-visible {
  color: var(--heat-strong);
}

@media (hover: hover) and (pointer: fine) {
  #new:hover {
    color: var(--heat-strong);
  }
}

.result-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-4);
}

.result-heading {
  min-width: 0;
}

#title {
  margin: 0;
  color: var(--text);
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-2) 0 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2px 7px;
  background: var(--bg-elevated);
  color: color-mix(in oklch, var(--heat) 68%, var(--text-muted));
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#meta {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
}

.actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.actions button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 12px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  transition:
    border-color var(--duration-ui) var(--ease-out),
    color var(--duration-ui) var(--ease-out),
    background-color var(--duration-ui) var(--ease-out),
    transform var(--duration-press) var(--ease-out);
}

.actions button:focus-visible {
  border-color: var(--line-focus);
  background: var(--heat-soft);
  color: var(--heat-strong);
  outline: 0;
}

.actions button:active {
  background: color-mix(in oklch, var(--heat) 18%, var(--bg-elevated));
  transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
  .actions button:hover {
    border-color: var(--line-focus);
    background: var(--heat-soft);
    color: var(--heat-strong);
  }
}

.actions button.is-success {
  border-color: color-mix(in oklch, var(--heat) 40%, var(--line));
  color: var(--heat-strong);
}

pre {
  max-height: 70vh;
  min-height: 240px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
  background: var(--bg-code);
  color: var(--text-secondary);
  font: 0.8125rem/1.7 var(--font-mono);
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.03);
}

pre:focus-visible {
  border-color: var(--line-focus);
  outline: 0;
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.03),
    0 0 0 3px var(--heat-soft);
}

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

@media (max-width: 520px) {
  .site-header {
    top: var(--space-4);
    left: var(--space-4);
  }

  main {
    width: min(100% - 24px, 760px);
  }

  .input-row {
    height: 46px;
    grid-template-columns: minmax(0, 1fr) 46px;
  }

  body.has-result .input-row {
    grid-template-columns: minmax(0, 1fr) 42px 46px;
  }

  .input-row > button[type="submit"] {
    min-width: 46px;
  }

  .clear-btn {
    min-width: 42px;
  }

  .result-header {
    align-items: start;
    flex-direction: column;
    gap: var(--space-3);
  }

  .actions {
    width: 100%;
  }

  .actions button {
    flex: 1;
  }

  pre {
    padding: var(--space-4);
    font-size: 0.75rem;
  }

  .dot-field {
    inset-inline: -40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Keep gentle opacity/color; drop movement (Emil a11y: gentler, not zero). */
  .input-shell,
  .result,
  .example,
  .actions button,
  .input-row > button,
  button {
    transition:
      opacity var(--duration-ui) var(--ease-out),
      color var(--duration-ui) var(--ease-out),
      background-color var(--duration-ui) var(--ease-out),
      border-color var(--duration-ui) var(--ease-out) !important;
    animation: none !important;
    transform: none !important;
  }

  .result.is-entering {
    animation: result-fade var(--duration-ui) var(--ease-out) both !important;
  }

  @keyframes result-fade {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  form.is-loading .input-row > button[type="submit"]::after {
    animation: none;
    opacity: 0.72;
  }
}
