* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

.shell {
  width: min(var(--container-max), calc(100% - 2 * var(--container-px)));
  margin: 0 auto;
  padding: var(--space-12) 0;
}

.hero {
  margin-bottom: var(--space-8);
}

.eyebrow {
  margin: 0 0 var(--space-3);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-black);
  text-transform: uppercase;
}

h1 {
  max-width: 11ch;
  margin: 0;
  font-size: clamp(var(--text-5xl), 8vw, var(--text-7xl));
  line-height: var(--leading-tight);
}

.hero > p:not(.eyebrow):not(.processing-badge) {
  max-width: var(--container-prose);
  margin: var(--space-5) 0 0;
  color: var(--text-muted);
  font-size: var(--text-lg);
  line-height: var(--leading-relaxed);
}

.tool {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
  padding: var(--space-5);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  min-width: 0;
  margin-bottom: var(--space-1);
}

button {
  min-height: var(--tap-target);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 var(--space-4);
  background: var(--accent);
  color: var(--text-inverse);
  font-weight: var(--weight-bold);
  cursor: pointer;
}

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

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: var(--stroke) solid var(--accent);
  background: var(--surface);
  color: var(--accent-strong);
}

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

.secondary-button:disabled {
  background: var(--surface);
}

.toolbar button {
  min-height: var(--control-h-md);
}

.regex-options {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(calc(var(--control-h-sm) * 11), 1.1fr) minmax(var(--next-col-min), 0.45fr);
  gap: var(--space-3);
  align-items: end;
  padding: var(--space-3);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  min-width: 0;
}

.option-group {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.regex-options > * {
  min-width: 0;
}

.option-label,
.flag-group legend {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  text-transform: uppercase;
}

.option-group input[type="text"],
.option-group select {
  width: 100%;
  min-width: 0;
  min-height: var(--control-h-md);
  padding: 0 var(--space-3);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.flag-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.flag-group legend {
  flex: 0 0 100%;
  margin-bottom: var(--space-1);
}

.flag-group label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--control-h-sm);
  min-width: var(--control-h-sm);
  padding: 0 var(--space-2);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: var(--weight-bold);
}

.flag-group input {
  width: var(--space-4);
  height: var(--space-4);
  accent-color: var(--accent);
}

.io-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  min-width: 0;
}

.io-grid label {
  display: grid;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
}

textarea {
  width: 100%;
  min-height: var(--card-min-h);
  padding: var(--space-3);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text);
  font-family: var(--font-mono);
  line-height: var(--leading-relaxed);
  resize: vertical;
}

#replacement {
  min-height: var(--ad-slot-min-h);
}

#output {
  background: var(--surface);
}

.match-panel {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-3);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.match-panel-heading {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: baseline;
}

.match-panel-heading h2,
.match-panel-heading p {
  margin: 0;
}

.match-panel-heading p {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.match-list {
  display: grid;
  gap: var(--space-3);
}

.match-card {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.match-card header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: baseline;
}

.match-card h3,
.match-card p {
  margin: 0;
}

.match-card p {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.match-card pre {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.match-card dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-2) var(--space-3);
  margin: 0;
}

.match-card dt {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: var(--weight-bold);
}

.match-card dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
}

.status[data-tone="error"] {
  color: var(--danger);
}

.status[data-tone="warn"] {
  color: var(--warn);
}

.status[data-tone="ok"] {
  color: var(--accent-strong);
}

@media (max-width: 1040px) {
  .regex-options {
    grid-template-columns: minmax(0, 1fr);
  }

  .match-panel-heading,
  .match-card header {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .shell {
    width: calc(100% - var(--space-6));
    max-width: calc(100vw - var(--space-6));
    padding: var(--space-8) 0;
    overflow-x: hidden;
  }

  h1 {
    max-width: none;
    font-size: clamp(var(--text-4xl), 12vw, var(--text-5xl));
  }

  .tool {
    width: 100%;
    max-width: 100%;
    padding: var(--space-4);
    overflow-x: hidden;
  }

  .regex-options,
  .io-grid,
  .match-panel {
    width: 100%;
    max-width: 100%;
  }

  .toolbar button {
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 0 var(--space-2);
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trust-strip li {
    max-width: 100%;
  }

  .flag-group label {
    min-width: 0;
    width: 100%;
  }

  .flag-group {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .flag-group legend {
    grid-column: 1 / -1;
  }

  textarea {
    min-height: var(--ad-slot-min-h);
  }
}
