*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Roboto', sans-serif;
  background: #F5F5F5;
  color: #212121;
  min-height: 100vh;
}

/* ── Toolbar ── */
.toolbar {
  background: #1565C0;
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.toolbar-title {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.back-link {
  color: #fff;
  text-decoration: none;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
}

.back-link:hover {
  opacity: 0.8;
}

/* ── Language toggle (injected by lang.js) ── */
.lang-toggle {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.lang-toggle button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-family: 'Roboto', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  padding: 2px 4px;
  cursor: pointer;
}

.lang-toggle button:hover {
  color: #fff;
}

.lang-toggle button.active {
  color: #fff;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.lang-sep {
  color: rgba(255, 255, 255, 0.35);
}

/* ── Layout ── */
.container {
  max-width: 480px;
  margin: 28px auto;
  padding: 0 16px;
}

/* ── Card ── */
.card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.14), 0 1px 8px rgba(0, 0, 0, 0.08);
  padding: 16px;
  margin-bottom: 16px;
}

.card-label {
  font-size: 12px;
  font-weight: 700;
  color: #1565C0;
  letter-spacing: 1.5px;
  margin-bottom: 14px;
  text-transform: uppercase;
}

/* ── Home nav buttons ── */
.nav-btn {
  display: block;
  width: 100%;
  background: #1565C0;
  color: #fff;
  text-decoration: none;
  text-align: center;
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.3px;
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 10px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.nav-btn:last-child {
  margin-bottom: 0;
}

.nav-btn:hover {
  background: #0D47A1;
}

/* ── Hide number input spinners ── */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
}

/* ── Form inputs ── */
.input-group {
  margin-bottom: 14px;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #555;
  margin-bottom: 5px;
  letter-spacing: 0.2px;
}

.input-group input {
  display: block;
  width: 100%;
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  color: #212121;
  background: #fff;
  border: 2px solid #BDBDBD;
  border-radius: 6px;
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.input-group input:focus {
  border-color: #1565C0;
}

.input-group .hint {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}

/* ── Calculate button ── */
.btn-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-calculate {
  flex: 1;
  background: #1565C0;
  color: #fff;
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.4px;
  padding: 14px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-calculate:hover {
  background: #0D47A1;
}

.btn-clear {
  flex: 1;
  background: #fff;
  color: #1565C0;
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.4px;
  padding: 14px 16px;
  border: 2px solid #1565C0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-clear:hover {
  background: #E3F2FD;
}

/* ── Error message ── */
.error-msg {
  background: #fff3e0;
  color: #bf360c;
  border: 1px solid #ffcc80;
  border-radius: 6px;
  padding: 10px 13px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}

/* ── Formula breakdown ── */
.formula-card {
  display: none;
}

.formula-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  overflow-x: auto;
  padding: 4px 0;
}

.formula-fracs {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.formula-eq {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
}

.formula-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex-shrink: 0;
}

.formula-num {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  padding-bottom: 5px;
  border-bottom: 1.5px solid #424242;
  width: 100%;
  flex-shrink: 0;
}

.formula-den {
  padding-top: 5px;
}

.formula-or-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 2px 0;
}

.formula-or-line {
  flex: 1;
  height: 1px;
  background: #E8E8E8;
}

.formula-or-text {
  font-size: 11px;
  font-weight: 700;
  color: #BDBDBD;
  letter-spacing: 2px;
  flex-shrink: 0;
}

.formula-rhs-large {
  font-size: 15px;
  color: #424242;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Labeled value */
.formula-lv {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex-shrink: 0;
}

.formula-lv-label {
  font-size: 10px;
  color: #9E9E9E;
  font-style: italic;
  white-space: nowrap;
  margin-bottom: 2px;
}

.formula-lv-val {
  font-size: 13px;
  font-weight: 500;
  color: #212121;
  font-family: 'Roboto Mono', 'Courier New', monospace;
  white-space: nowrap;
}

.formula-op {
  font-size: 13px;
  color: #424242;
  padding-bottom: 1px;
  white-space: nowrap;
  flex-shrink: 0;
}

.formula-unit {
  font-size: 0.82em;
  color: #9E9E9E;
}

.formula-rhs {
  font-size: 13px;
  color: #424242;
  white-space: nowrap;
  flex-shrink: 0;
}

.formula-result-value {
  font-size: 22px;
  font-weight: 700;
  color: #FF6D00;
}

/* Compact formula breakdown inside history entries */
.history-formula {
  justify-content: flex-start;
  margin-top: 2px;
}

.history-formula .formula-rhs-large {
  font-size: 13px;
}

.history-formula .formula-result-value {
  font-size: 16px;
}

/* ── Note picker modal ── */
.note-picker-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.note-picker-overlay.open {
  display: flex;
}
.note-picker-card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  width: min(420px, 100%);
  max-height: 75vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}
.note-picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-top: 1px solid #F0F0F0;
  font-size: 15px;
  font-weight: 500;
  color: #1565C0;
  cursor: pointer;
}
.note-picker-row:first-child { border-top: none; }
.note-picker-row:hover { color: #0D47A1; }
.note-picker-row.added {
  opacity: 0.45;
  cursor: default;
}
.note-picker-go {
  padding: 0 4px;
  cursor: pointer;
  flex-shrink: 0;
}
.note-picker-go:hover {
  color: #FF6D00;
}
.note-picker-empty {
  font-size: 13px;
  color: #9E9E9E;
  padding: 8px 0 12px;
}
.note-picker-divider {
  border: none;
  border-top: 1px solid #E0E0E0;
  margin: 12px 0;
}
.picker-feedback {
  font-size: 12px;
  margin-top: 8px;
  min-height: 18px;
}
.picker-feedback.ok  { color: #2E7D32; }
.picker-feedback.err { color: #bf360c; }
.btn-add-to-note {
  background: none;
  border: 1px solid #BDBDBD;
  border-radius: 5px;
  font-family: 'Roboto', sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: #757575;
  padding: 3px 7px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.btn-add-to-note:hover {
  border-color: #1565C0;
  color: #1565C0;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .container {
    margin: 16px auto;
  }

  .toolbar {
    padding: 14px 16px;
  }

  .result-row.shrink-row .result-value {
    font-size: 22px;
  }

  .history-field {
    flex-direction: column;
    gap: 1px;
  }

  .history-field-label {
    font-size: 11px;
  }

  .history-field-value {
    font-size: 13px;
  }
}

/* ── History card ── */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.history-header .card-label {
  margin-bottom: 0;
}

.btn-clear-all {
  background: none;
  border: 1px solid #BDBDBD;
  border-radius: 5px;
  font-family: 'Roboto', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: #757575;
  padding: 4px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-clear-all:hover {
  border-color: #bf360c;
  color: #bf360c;
}

.history-empty {
  font-size: 13px;
  color: #9E9E9E;
  text-align: center;
  padding: 8px 0;
}

.history-item {
  padding: 10px 0;
  border-top: 1px solid #F0F0F0;
}

.history-item:first-child {
  border-top: none;
}

.history-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.history-label-input {
  flex: 1;
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: #212121;
  border: none;
  border-bottom: 1px dashed #BDBDBD;
  background: transparent;
  outline: none;
  padding: 2px 0;
  min-width: 0;
}

.history-label-input:focus {
  border-bottom-color: #1565C0;
}

.btn-delete {
  background: none;
  border: none;
  color: #BDBDBD;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  flex-shrink: 0;
  transition: color 0.15s;
}

.btn-delete:hover {
  color: #bf360c;
}

.history-field {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  padding: 2px 0;
}

.history-field-label {
  color: #757575;
}

.history-field-value {
  font-weight: 500;
  color: #212121;
}

.history-field.shrink-field .history-field-label {
  font-weight: 700;
  color: #212121;
  font-size: 14px;
}

.history-field.shrink-field .history-field-value {
  font-size: 17px;
  font-weight: 700;
  color: #FF6D00;
}

.history-divider {
  border: none;
  border-top: 1px dashed #E8E8E8;
  margin: 5px 0;
}

/* ── Results card ── */
.results-card {
  display: none;
}

.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.result-divider {
  border: none;
  border-top: 1px solid #E0E0E0;
  margin: 4px 0;
}

.result-label {
  font-size: 15px;
  color: #212121;
}

.result-value {
  font-size: 15px;
  font-weight: 700;
  color: #1565C0;
}

.result-row.shrink-row .result-label {
  font-size: 18px;
  font-weight: 700;
  color: #212121;
}

.result-row.shrink-row .result-value {
  font-size: 28px;
  font-weight: 700;
  color: #FF6D00;
}
