:root {
  color-scheme: light dark;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-soft: #eef3ec;
  --ink: #1e2420;
  --muted: #637068;
  --line: #d6ded5;
  --accent: #0b6b5c;
  --accent-strong: #094d43;
  --danger: #a93131;
  --code: #17211d;
  --shadow: 0 14px 40px rgba(26, 42, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  min-height: 40px;
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 700;
}

button[type="submit"]:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.search-surface,
.result-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-surface {
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: 0;
  padding: 16px 18px 0;
}

#serviceMeta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.query-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
}

#queryInput {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: #fbfcfa;
  color: var(--ink);
}

#queryInput:focus {
  outline: 2px solid rgba(11, 107, 92, 0.24);
  border-color: var(--accent);
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.7fr);
  gap: 14px;
  margin-top: 16px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--surface-soft);
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(99, 112, 104, 0.25);
  border-radius: 6px;
  background: var(--surface);
  white-space: nowrap;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.mode-controls {
  align-content: flex-start;
}

.status-row {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.result-section {
  margin-top: 16px;
  overflow: hidden;
}

.rendered {
  padding: 14px 18px 18px;
  font-size: 15px;
}

.rendered p {
  margin: 0 0 12px;
}

.rendered h3 {
  margin: 18px 0 8px;
  font-size: 16px;
  letter-spacing: 0;
}

.rendered a {
  color: var(--accent-strong);
  font-weight: 650;
  text-decoration: none;
}

.rendered a:hover {
  text-decoration: underline;
}

.rendered pre,
#errorOutput {
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: var(--code);
  background: #eef1ed;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}

.error {
  border-color: rgba(169, 49, 49, 0.4);
}

.error h2,
.error pre {
  color: var(--danger);
}

.hidden {
  display: none;
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 20px, 1120px);
    margin-top: 14px;
  }

  .search-surface {
    padding: 16px;
  }

  .topbar,
  .status-row {
    align-items: stretch;
  }

  .query-row,
  .controls {
    grid-template-columns: 1fr;
  }

  button[type="submit"] {
    min-height: 46px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141815;
    --surface: #1d231f;
    --surface-soft: #222a25;
    --ink: #edf4ee;
    --muted: #a3afa8;
    --line: #344039;
    --accent: #2fbfa8;
    --accent-strong: #74dfce;
    --danger: #ff8989;
    --code: #e7f0e8;
    --shadow: none;
  }

  #queryInput {
    background: #151b17;
  }

  .rendered pre,
  #errorOutput {
    background: #151b17;
  }
}
