.tool-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
}
.tool-modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 29, 38, 0.46);
  backdrop-filter: blur(8px);
}
.calculator-panel {
  position: relative;
  width: min(410px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(35, 36, 50, 0.24);
  animation: modal-in 180ms ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.calculator-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.calculator-header h2 {
  margin: 0;
  font-family: "Manrope", sans-serif;
  font-size: 24px;
  letter-spacing: -1px;
}
.modal-close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.calculator-display {
  min-height: 112px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  text-align: right;
}
.calculation-preview {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
  word-break: break-all;
}
.calculator-output {
  max-width: 100%;
  margin-top: 5px;
  overflow: hidden;
  font-family: "Manrope", sans-serif;
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -1.5px;
  text-overflow: ellipsis;
}
.calculator-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}
.calc-key {
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: var(--surface);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 100ms ease, background 100ms ease;
}
.calc-key:hover { background: var(--bg); }
.calc-key:active { transform: scale(0.96); }
.calc-muted { color: var(--accent); background: #f4f1fd; }
.calc-operation { color: var(--accent); background: #eeeafa; }
.calc-equals { border-color: var(--accent); color: white; background: var(--accent); }
.calc-equals:hover { background: #6850d4; }
body.dark .calc-muted { background: #302e43; }
body.dark .calc-operation { background: #302e43; }
body.dark .calc-equals { background: var(--accent); }
