:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --text: #e6edf3;
  --muted: #8b949e;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-contrast: #07111f;
  --danger: #ff7b72;
  --success: #56d364;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f8;
  --text: #1f2937;
  --muted: #64748b;
  --border: #d8dee9;
  --accent: #275efe;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --success: #027a48;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, color-mix(in srgb, var(--accent), transparent 88%), transparent 30rem), var(--bg);
  color: var(--text);
}

button, input, select {
  font: inherit;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 28px;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.github-link, .theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.github-link {
  padding: 8px 13px;
  text-decoration: none;
  font-weight: 650;
}

.github-link:hover, .theme-toggle:hover {
  border-color: var(--accent);
}

.github-mark {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.theme-toggle {
  padding: 8px 14px;
  cursor: pointer;
}

.theme-toggle-icon {
  width: 18px;
  text-align: center;
  font-size: 16px;
  line-height: 1;
}

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.logo {
  width: min(560px, 88vw);
  max-height: 140px;
  object-fit: contain;
}

/*html[data-theme="dark"] .logo {*/
/*  background: rgba(255, 255, 255, 0.92);*/
/*  border-radius: 18px;*/
/*  padding: 14px 18px;*/
/*}*/

.tagline {
  color: var(--muted);
  margin: 12px auto 0;
  max-width: 760px;
  line-height: 1.5;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 18px 0;
}

.card h2, .card h3 {
  margin-top: 0;
}

.status, .message {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 14px 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.status[hidden], .message:empty { display: none; }

.message.error { color: var(--danger); }
.message.success { color: var(--success); }

.input-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

label span {
  display: block;
  font-weight: 650;
  margin-bottom: 6px;
}

small {
  color: var(--muted);
  display: block;
  margin-top: 5px;
}

input, select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 42px;
}

input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent), transparent 70%);
  border-color: var(--accent);
}

.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 5px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  max-width: 520px;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(2, 6, 23, 0.45); }

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.section-header p {
  color: var(--muted);
  margin-top: -6px;
}

.icon-button, .primary, #downloadCsv {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  min-height: 42px;
  padding: 10px 16px;
}

.icon-button {
  width: 44px;
  font-size: 24px;
  line-height: 1;
  background: var(--accent);
  color: var(--accent-contrast);
}

.add-row-wrap {
  display: flex;
  justify-content: flex-start;
  margin-top: 10px;
}

.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 750;
}

#downloadCsv {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.formula-table-wrap, .results-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px;
}

td {
  padding: 8px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.formula-table th:nth-child(1), .formula-table td:nth-child(1) { min-width: 130px; }
.formula-table th:nth-child(2), .formula-table td:nth-child(2) { min-width: 180px; }
.formula-table th:nth-child(3), .formula-table td:nth-child(3),
.formula-table th:nth-child(4), .formula-table td:nth-child(4) { min-width: 140px; }
.formula-table th:nth-child(5), .formula-table td:nth-child(5) { width: 58px; text-align: right; }

.remove-row {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--danger);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 22px;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.results-table {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.results-table tbody tr:nth-child(odd) {
  background: color-mix(in srgb, var(--surface-2), transparent 35%);
}

.examples summary {
  cursor: pointer;
  font-weight: 700;
}

code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
}

.site-footer {
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
  padding: 22px 0 0;
}

@media (max-width: 760px) {
  .input-grid { grid-template-columns: 1fr; }
  .page-shell { width: min(100% - 20px, 1180px); padding-top: 14px; }
  .card { padding: 16px; }
  .topbar { justify-content: center; flex-wrap: wrap; }
}
