:root {
  --bg: #ffffff;
  --surface: #f7f7f7;
  --text: #111111;
  --muted: #555555;
  --border: #d0d0d0;
  --accent: #4caf50;
  --accent-text: #ffffff;
  --error: #c0392b;
  --header-bg: #f2f2f2;
}
.dark-theme {
  --bg: #1a1a1a;
  --surface: #242424;
  --text: #f0f0f0;
  --muted: #aaaaaa;
  --border: #444444;
  --accent: #4caf50;
  --accent-text: #0d0d0d;
  --error: #ff7675;
  --header-bg: #333333;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 12px; font-size: 1rem; cursor: pointer;
}
#install-btn { background: var(--accent); color: var(--accent-text); border: none; }
main { max-width: 680px; margin: 0 auto; padding: 16px; }
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 84px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.card:active { transform: scale(0.98); }
.back { display: inline-block; margin-bottom: 8px; color: var(--accent); text-decoration: none; }
h2 { margin: 4px 0; }
.formula { color: var(--muted); font-size: 0.9rem; margin-top: 0; }
.field { margin: 12px 0; }
.field label { display: block; margin-bottom: 4px; font-size: 0.9rem; color: var(--muted); }
.field input {
  width: 100%; padding: 12px; font-size: 1rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
}
button.primary {
  width: 100%; padding: 14px; margin-top: 8px; font-size: 1rem; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
  border: none; border-radius: 8px; cursor: pointer;
}
.result { margin-top: 16px; font-weight: 600; }
.result.error { color: var(--error); }
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { border: 1px solid var(--border); padding: 8px; text-align: center; }
th { background: var(--header-bg); }
.summary { font-weight: 700; margin-top: 12px; }
@media (min-width: 520px) {
  .field { display: grid; grid-template-columns: 200px 1fr; align-items: center; gap: 12px; }
  .field label { margin: 0; }
}
