:root {
  color-scheme: light dark;
  --surface-primary: #ffffff;
  --surface-secondary: #fafafa;
  --surface-elevated: #ffffff;
  --text-primary: #171717;
  --text-secondary: #4d4d4d;
  --text-tertiary: #737373;
  --border-default: rgba(0, 0, 0, 0.08);
  --border-strong: #171717;
  --accent-primary: #0072f5;
  --accent-hover: #005fd1;
  --status-success: #087f5b;
  --status-error: #d92d20;
  --status-warning: #b26a00;
  --focus-ring: rgba(0, 114, 245, 0.24);
  --shadow-ring: 0 0 0 1px var(--border-default);
  --shadow-card: 0 0 0 1px var(--border-default), 0 2px 2px rgba(0, 0, 0, 0.04), 0 8px 8px -8px rgba(0, 0, 0, 0.04);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --radius-control: 6px;
  --radius-panel: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-primary: #0b0b0b;
    --surface-secondary: #141414;
    --surface-elevated: #1c1c1c;
    --text-primary: #f5f5f5;
    --text-secondary: #b8b8b8;
    --text-tertiary: #858585;
    --border-default: rgba(255, 255, 255, 0.14);
    --border-strong: #f5f5f5;
    --accent-primary: #4da3ff;
    --accent-hover: #7bbcff;
    --status-success: #2dd4a3;
    --status-error: #ff8a80;
    --status-warning: #ffbf47;
    --focus-ring: rgba(77, 163, 255, 0.28);
    --shadow-card: 0 0 0 1px var(--border-default), 0 2px 2px rgba(0, 0, 0, 0.2), 0 8px 8px -8px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--surface-primary);
  color: var(--text-primary);
  font-family: Geist, Arial, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "liga" 1;
  letter-spacing: 0;
  word-break: keep-all;
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--surface-primary);
}

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

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: var(--space-4) 0 var(--space-10);
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
}

.brand,
.topnav,
.hero-status,
.actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: var(--space-2);
  font-size: 14px;
  font-weight: 600;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-control);
  background: var(--text-primary);
  color: var(--surface-primary);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1;
}

.topnav {
  gap: var(--space-2);
  font-size: 14px;
  color: var(--text-secondary);
}

.topnav a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-3);
  border-radius: var(--radius-control);
}

.topnav a:hover {
  color: var(--text-primary);
  box-shadow: var(--shadow-ring);
}

.hero {
  min-height: 168px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-6);
  padding: var(--space-8) 0 var(--space-10);
}

.eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--text-tertiary);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

h1,
h2 {
  margin: 0;
  color: var(--text-primary);
  font-weight: 600;
}

h1 {
  max-width: 780px;
  font-size: clamp(32px, 5vw, 48px);
  line-height: 1.08;
}

h2 {
  font-size: 24px;
  line-height: 1.28;
}

.hero-status {
  min-height: 36px;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 13px;
  box-shadow: var(--shadow-ring);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-warning);
}

.hero-status.is-ready .status-dot {
  background: var(--status-success);
}

.hero-status.is-error .status-dot {
  background: var(--status-error);
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  gap: var(--space-4);
  align-items: start;
}

.panel {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-6);
  border-radius: var(--radius-panel);
  background: var(--surface-secondary);
  box-shadow: var(--shadow-card);
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-4);
}

.status-text {
  min-height: 28px;
  margin: 0;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-control);
  color: var(--text-secondary);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: var(--shadow-ring);
}

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

.status-text.is-error {
  color: var(--status-error);
}

.form-stack,
.field {
  display: grid;
  gap: var(--space-3);
}

.field > span,
.range-field output {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

input,
textarea {
  width: 100%;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-ring);
  outline: none;
}

input {
  min-height: 42px;
  padding: 0 var(--space-3);
}

textarea {
  min-height: 124px;
  padding: var(--space-3);
  resize: vertical;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

input:hover,
textarea:hover {
  box-shadow: 0 0 0 1px var(--text-tertiary);
}

input:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  box-shadow: var(--shadow-ring), 0 0 0 3px var(--focus-ring);
  outline: none;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.toggle {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border-radius: var(--radius-control);
  color: var(--text-secondary);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-ring);
  cursor: pointer;
}

.toggle input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent-primary);
  box-shadow: none;
}

.toggle:has(input:checked) {
  color: var(--text-primary);
  box-shadow: 0 0 0 1px var(--accent-primary);
}

.range-field span {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
}

input[type="range"] {
  min-height: 32px;
  padding: 0;
  box-shadow: none;
  accent-color: var(--accent-primary);
}

.actions {
  flex-wrap: wrap;
  gap: var(--space-2);
}

.button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-control);
  padding: 0 var(--space-4);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms ease-out, color 120ms ease-out, transform 120ms ease-out, box-shadow 120ms ease-out;
}

.button.primary {
  background: var(--text-primary);
  color: var(--surface-primary);
}

.button.secondary {
  background: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-ring);
}

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

.button.primary:hover {
  background: var(--accent-hover);
}

.button:active {
  transform: translateY(0);
}

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

.result-field textarea {
  min-height: 148px;
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius-control);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-ring);
}

.stats div {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: var(--space-1);
  padding: var(--space-3);
  box-shadow: 1px 0 0 0 var(--border-default);
}

.stats div:last-child {
  box-shadow: none;
}

.stats dt,
.stats dd {
  margin: 0;
}

.stats dt {
  color: var(--text-tertiary);
  font-size: 12px;
}

.stats dd {
  color: var(--text-primary);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

@media (max-width: 899px) {
  .hero,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    align-items: start;
    padding-top: var(--space-6);
  }

  .hero-status {
    justify-self: start;
  }
}

@media (max-width: 639px) {
  .app-shell {
    width: min(100% - 24px, 1180px);
  }

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

  .topnav {
    width: 100%;
    justify-content: space-between;
  }

  .topnav a {
    flex: 1;
    justify-content: center;
  }

  .panel {
    padding: var(--space-4);
  }

  .toggle-grid,
  .stats {
    grid-template-columns: 1fr;
  }

  .panel-header {
    align-items: start;
    flex-direction: row;
  }

  .stats div {
    box-shadow: 0 1px 0 0 var(--border-default);
  }

  .stats div:last-child {
    box-shadow: none;
  }
}

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