body {
  background: linear-gradient(to right, #fbc2eb, #a6c1ee);
  font-family: "Segoe UI", sans-serif;
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

body.dark {
  background: #121212;
  color: #eee;
}

.calculator-card {
  background: white;
  color: #333;
  padding: 30px;
  border-radius: 14px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
}

body.dark .calculator-card {
  background: #1e1e1e;
  color: #eee;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.theme-toggle {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: inherit;
}

input[type="number"] {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-sizing: border-box;
}

.mode-toggle {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 15px;
  flex-wrap: wrap;
}

.mode-toggle label {
  font-weight: bold;
}

button {
  margin-top: 15px;
  padding: 12px;
  width: 100%;
  font-size: 16px;
  background: linear-gradient(to right, #4facfe, #00f2fe);
  color: white;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.result {
  margin-top: 20px;
  font-size: 18px;
  font-weight: bold;
  min-height: 24px;
  color: #2a9d8f;
}

ul#historyList {
  list-style: none;
  padding-left: 0;
  margin-top: 10px;
  text-align: left;
}

ul#historyList li {
  background: #eee;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 5px;
  color: #333;
}

body.dark ul#historyList li {
  background: #2b2b2b;
  color: #ccc;
}

.steps {
  margin-top: 10px;
  font-size: 15px;
  color: #444;
  text-align: left;
  white-space: pre-line;
}

body.dark .steps {
  color: #ccc;
}
/* Chart – Default Size */
canvas#factorChart {
  width: 100% !important;
  max-width: 350px;
  height: auto !important;
  display: block;
  margin: 20px auto 0;
}

/* Chart – Smaller on Mobile */
@media (max-width: 600px) {
  canvas#factorChart {
    max-width: 250px;
    height: auto;
  }
}
canvas#factorChart {
  width: 100% !important;
  max-width: 300px;
  height: 180px !important;
  display: block;
  margin: 20px auto 0;
}

/* On small screens, reduce even more */
@media (max-width: 600px) {
  canvas#factorChart {
    max-width: 220px;
    height: 150px !important;
  }
}

/* Responsive Chart */
canvas#factorChart {
  width: 100% !important;
  max-width: 100%;
  height: auto !important;
  display: block;
  margin-top: 20px;
  margin-left: auto;
  margin-right: auto;
}

/* Mobile Optimization */
@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .calculator-card {
    padding: 20px;
    border-radius: 10px;
  }

  .top-bar h2 {
    font-size: 20px;
    text-align: center;
  }

  input[type="number"],
  button {
    font-size: 15px;
  }

  .mode-toggle {
    flex-direction: column;
    gap: 8px;
  }

  .steps,
  .result {
    font-size: 16px;
  }

  canvas#factorChart {
    max-width: 20%;
    height: auto;
  }
}
