:root {
  color-scheme: light;
  --canvas: #f3f5f7;
  --surface: #ffffff;
  --surface-subtle: #f8f9fa;
  --ink: #17212b;
  --muted: #596572;
  --border: #d5dbe1;
  --border-strong: #aeb8c2;
  --accent: #146b5d;
  --accent-hover: #0d564b;
  --accent-soft: #e1f1ed;
  --focus: #266ed8;
  --danger: #a33939;
  --danger-soft: #faeceb;
  --warning: #8a5a11;
  --warning-soft: #fff4d8;
  --editor: #141a20;
  --editor-ink: #eef2f5;
  --editor-muted: #9ca8b4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

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

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

button,
textarea,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  color: #ffffff;
  background: var(--ink);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-header,
.control-bar,
.app-footer {
  display: flex;
  align-items: center;
  width: 100%;
  padding-inline: clamp(14px, 3vw, 32px);
  background: var(--surface);
}

.app-header {
  min-height: 64px;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.brand-block {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 12px;
}

.brand-block h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand-block span {
  color: var(--muted);
  font-size: 13px;
}

.header-actions,
.control-actions,
.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions a {
  font-size: 13px;
  font-weight: 600;
}

.control-bar {
  min-height: 70px;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.dialect-control {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.dialect-control legend {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.segments {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-subtle);
}

.segments label {
  position: relative;
  cursor: pointer;
}

.segments label + label {
  border-left: 1px solid var(--border-strong);
}

.segments input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segments span {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.segments input:checked + span {
  color: #ffffff;
  background: var(--accent);
}

.segments input:focus-visible + span {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.button {
  min-height: 34px;
  padding: 7px 12px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 700;
  transition: background-color 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-primary {
  color: #ffffff;
  background: var(--accent);
}

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

.button-quiet {
  color: var(--ink);
  border-color: var(--border-strong);
  background: var(--surface);
}

.button-quiet:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-soft);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.05fr) minmax(250px, 0.75fr) minmax(320px, 1fr);
  min-height: calc(100vh - 174px);
  border-bottom: 1px solid var(--border);
}

.panel {
  min-width: 0;
  padding: 18px;
  background: var(--surface);
}

.panel + .panel {
  border-left: 1px solid var(--border);
}

.panel-heading {
  display: flex;
  min-height: 42px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.panel h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.panel-count {
  min-width: 42px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  text-align: right;
}

.code-input,
.code-output {
  display: block;
  width: 100%;
  min-height: 420px;
  padding: 15px;
  resize: vertical;
  border: 1px solid var(--editor);
  border-radius: 6px;
  color: var(--editor-ink);
  background: var(--editor);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
}

.code-input::placeholder,
.code-output::placeholder {
  color: var(--editor-muted);
}

.code-output {
  min-height: 224px;
  resize: vertical;
}

.variables-list {
  display: grid;
  gap: 14px;
}

.empty-state {
  margin: 0;
  padding: 22px 12px;
  border-block: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.variable-field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.variable-field-heading {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.variable-field label,
.output-label {
  min-width: 0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.variable-field code {
  min-width: 0;
  color: var(--accent-hover);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.remove-value-button {
  min-height: 28px;
  flex: 0 0 auto;
  padding: 4px 8px;
  font-size: 11px;
}

.variable-field textarea {
  width: 100%;
  min-height: 78px;
  padding: 10px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.preflight-status {
  display: flex;
  min-height: 28px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--danger);
}

.preflight-status.ready .status-dot {
  background: var(--accent);
}

.findings-list {
  display: grid;
  max-height: 218px;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.finding {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px 9px;
  padding: 9px 10px;
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  background: var(--danger-soft);
}

.finding > * {
  min-width: 0;
}

.finding.warning {
  border-left-color: var(--warning);
  background: var(--warning-soft);
}

.finding code {
  color: inherit;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.finding-location {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  text-align: right;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.finding-message {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
}

.output-label {
  display: block;
  margin-bottom: 6px;
}

.result-actions {
  justify-content: flex-end;
  margin-top: 10px;
}

.app-footer {
  min-height: 40px;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 11px;
}

.toast {
  position: fixed;
  z-index: 10;
  right: 18px;
  bottom: 18px;
  max-width: min(340px, calc(100vw - 36px));
  padding: 10px 13px;
  pointer-events: none;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  opacity: 0;
  color: #ffffff;
  background: var(--ink);
  font-size: 12px;
  transform: translateY(8px);
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

@media (max-width: 1099px) {
  .workspace-grid {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr);
  }

  .template-panel {
    grid-column: 1 / -1;
    border-bottom: 1px solid var(--border);
  }

  .variables-panel {
    border-left: 0;
  }

  .code-input {
    min-height: 250px;
  }
}

@media (max-width: 719px) {
  .app-header,
  .control-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header {
    padding-block: 13px;
  }

  .brand-block {
    justify-content: space-between;
  }

  .header-actions {
    justify-content: space-between;
  }

  .control-bar {
    padding-block: 12px;
  }

  .segments {
    display: grid;
    width: 100%;
  }

  .segments span {
    min-height: 42px;
    padding-inline: 8px;
    white-space: normal;
    text-align: center;
  }

  .control-actions .button {
    flex: 1;
  }

  .workspace-grid {
    display: block;
    min-height: 0;
  }

  .panel,
  .panel + .panel {
    padding: 15px 14px 18px;
    border-left: 0;
    border-bottom: 1px solid var(--border);
  }

  .code-input,
  .code-output {
    min-height: 230px;
  }

  .result-actions .button {
    flex: 1;
  }
}

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