:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --accent: #3457d5;
  --accent-dark: #2740a8;
  --border: #e3e5ea;
  --good: #1a7f4e;
  --good-bg: #e6f6ee;
  --derived-bg: #eef1fb;
  --derived-ink: #3457d5;
  --error-bg: #fdecea;
  --error-ink: #b3261e;
}

.page-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.ad-slot {
  flex: 0 0 160px;
  width: 160px;
  min-height: 600px;
  position: sticky;
  top: 40px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-placeholder-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Hide ad rails on narrower screens so the converter stays usable */
@media (max-width: 1000px) {
  .ad-slot {
    display: none;
  }
}



* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app {
  max-width: 640px;
  flex: 1 1 auto;
  padding: 40px 0 80px;
}

header h1 {
  font-size: 28px;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 0;
  line-height: 1.5;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-top: 20px;
  box-shadow: 0 1px 2px rgba(20, 20, 40, 0.04);
}

.site-footer {
  text-align: center;
  margin-top: 2rem;
  padding: 1.5rem;
  font-size: 0.95rem;
  color: #555;
  border-top: 1px solid #eaeaea;
  grid-column: 1 / -1; /* Ensures it spans full width if your layout uses CSS grid */
}

.site-footer a {
  color: #0066cc;
  text-decoration: none;
  font-weight: 500;
}

.site-footer a:hover {
  text-decoration: underline;
}

.field {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

select, input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: #fff;
  color: var(--ink);
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 87, 213, 0.15);
}

#swapBtn {
  display: block;
  margin: -6px auto 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  color: var(--accent);
}

#swapBtn:hover {
  background: var(--derived-bg);
}

.button-row {
  display: flex;
  gap: 10px;
}

button.primary, button.secondary {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

button.primary {
  border: none;
  background: var(--accent);
  color: white;
}

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

button.secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
}

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

.result {
  margin-top: 20px;
  text-align: center;
  padding: 18px;
  border-radius: 10px;
  background: var(--good-bg);
}

.result-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
}

.badge {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

.badge.stored {
  background: var(--good-bg);
  color: var(--good);
}

.badge.derived {
  background: var(--derived-bg);
  color: var(--derived-ink);
}

.error {
  margin-top: 20px;
  padding: 14px;
  border-radius: 10px;
  background: var(--error-bg);
  color: var(--error-ink);
  font-size: 14px;
}

details {
  margin-top: 18px;
  font-size: 14px;
}

summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.formula {
  margin-top: 10px;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  background: #f7f8fa;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.steps {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
}

.steps li {
  margin-bottom: 6px;
  font-size: 13px;
}

.steps code {
  background: #f7f8fa;
  padding: 1px 5px;
  border-radius: 4px;
}

.formulas-card summary {
  cursor: pointer;
  color: var(--ink);
  list-style: none;
}

.formulas-card summary::-webkit-details-marker {
  display: none;
}

.formulas-card summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.formulas-card details[open] summary::before {
  transform: rotate(90deg);
}

.formulas-card h2 {
  display: inline;
  font-size: 17px;
}

.formulas-card .subtitle {
  margin-top: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
}

.hidden { display: none; }