:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --btn-bg: #e9ecf1;
  --btn-fg: #1a1d23;
  --btn-hover: #dde1e8;
  --operator-bg: #4f6df5;
  --operator-fg: #ffffff;
  --operator-hover: #3d58d8;
  --equals-bg: #22c55e;
  --equals-fg: #ffffff;
  --equals-hover: #16a34a;
  --danger-bg: #ef4444;
  --border: #d8dce3;
  --shadow: 0 10px 30px rgba(20, 24, 34, 0.08);
}

html[data-theme="dark"] {
  --bg: #14161c;
  --surface: #1e2129;
  --text: #f2f4f7;
  --muted: #9aa1af;
  --btn-bg: #2a2e38;
  --btn-fg: #f2f4f7;
  --btn-hover: #363b47;
  --operator-bg: #5a78ff;
  --operator-fg: #ffffff;
  --operator-hover: #6c88ff;
  --equals-bg: #22c55e;
  --equals-fg: #0e1712;
  --equals-hover: #34d874;
  --danger-bg: #ef4444;
  --border: #303541;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background-color 0.2s ease, color 0.2s ease;
  padding: 24px;
}

.calculator {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calculator__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.calculator__title {
  margin: 0;
  font-size: 1.25rem;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.theme-toggle:hover {
  background: var(--btn-hover);
}

.calculator__display {
  background: var(--btn-bg);
  border-radius: 12px;
  padding: 18px 16px;
  font-size: 2rem;
  text-align: right;
  overflow-x: auto;
  white-space: nowrap;
  min-height: 1.5em;
}

.calculator__keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.key {
  border: none;
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 1.1rem;
  padding: 16px 0;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
}

.key:hover {
  background: var(--btn-hover);
}

.key:active {
  transform: scale(0.97);
}

.key--operator {
  background: var(--operator-bg);
  color: var(--operator-fg);
}

.key--operator:hover {
  background: var(--operator-hover);
}

.key--equals {
  background: var(--equals-bg);
  color: var(--equals-fg);
}

.key--equals:hover {
  background: var(--equals-hover);
}

.key--action {
  background: var(--danger-bg);
  color: #ffffff;
}

.key--wide {
  grid-column: span 2;
}

.key--tall {
  grid-row: span 2;
}

.history {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.history__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.history__title {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
}

.history__clear {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 4px;
}

.history__clear:hover {
  color: var(--text);
}

.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history__list:empty::after {
  content: "Aucun calcul pour le moment.";
  color: var(--muted);
  font-size: 0.85rem;
}

.history__item {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  text-align: right;
  overflow-x: auto;
  white-space: nowrap;
}

.history__item:hover {
  background: var(--btn-hover);
}
