@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --background: hsl(220, 15%, 10%);
  --foreground: hsl(0, 0%, 95%);
  --card: hsl(220, 15%, 13%);
  --card-foreground: hsl(0, 0%, 95%);
  --primary: hsl(25, 95%, 55%);
  --primary-foreground: hsl(0, 0%, 100%);
  --secondary: hsl(220, 15%, 20%);
  --secondary-foreground: hsl(0, 0%, 85%);
  --muted-foreground: hsl(220, 10%, 55%);
  --accent: hsl(220, 15%, 25%);
  --border: hsl(220, 15%, 20%);
  --calc-number: hsl(220, 15%, 22%);
  --calc-number-hover: hsl(220, 15%, 28%);
  --calc-operator: hsl(25, 95%, 55%);
  --calc-operator-hover: hsl(25, 95%, 62%);
  --calc-function: hsl(220, 15%, 30%);
  --calc-function-hover: hsl(220, 15%, 38%);
  --calc-display: hsl(220, 15%, 8%);
  --calc-scientific: hsl(220, 15%, 18%);
  --calc-scientific-hover: hsl(220, 15%, 25%);
}

.light-theme {
  --background: hsl(220, 20%, 96%);
  --foreground: hsl(220, 15%, 15%);
  --card: hsl(0, 0%, 100%);
  --card-foreground: hsl(220, 15%, 15%);
  --secondary: hsl(220, 15%, 90%);
  --secondary-foreground: hsl(220, 15%, 25%);
  --muted-foreground: hsl(220, 10%, 45%);
  --accent: hsl(220, 15%, 88%);
  --border: hsl(220, 15%, 85%);
  --calc-number: hsl(220, 10%, 92%);
  --calc-number-hover: hsl(220, 10%, 85%);
  --calc-operator: hsl(25, 95%, 55%);
  --calc-operator-hover: hsl(25, 95%, 48%);
  --calc-function: hsl(220, 15%, 82%);
  --calc-function-hover: hsl(220, 15%, 75%);
  --calc-display: hsl(0, 0%, 100%);
  --calc-scientific: hsl(220, 15%, 86%);
  --calc-scientific-hover: hsl(220, 15%, 78%);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--background);
  color: var(--foreground);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  transition: background 0.3s, color 0.3s;
}

.calculator-wrapper {
  width: 100%;
  max-width: 380px;
  transition: max-width 0.3s;
}
.calculator-wrapper.scientific { max-width: 440px; }

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.toolbar button {
  background: var(--secondary);
  color: var(--foreground);
  border: none;
  border-radius: 50%;
  width: 36px; height: 36px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.1s;
  font-size: 1rem;
}
.toolbar button:hover { background: var(--accent); }
.toolbar button:active { transform: scale(0.95); }
.toolbar button.active { background: var(--primary); color: var(--primary-foreground); }

/* Calculator body */
.calc-body {
  background: var(--card);
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.3);
}

/* Display */
.calc-display {
  background: var(--calc-display);
  padding: 2rem 1.5rem 1rem;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
}
.calc-display .history-line {
  font-size: 0.875rem;
  color: var(--muted-foreground);
  height: 1.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  text-align: right;
}
.calc-display .display-value {
  font-weight: 300;
  color: var(--foreground);
  width: 100%;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: font-size 0.15s;
}

/* Buttons grid */
.buttons-container { padding: 0.75rem; }
.btn-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
.sci-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-bottom: 0.5rem; }

/* Button base */
.calc-btn {
  border: none;
  border-radius: 0.75rem;
  font-family: 'Inter', sans-serif;
  font-size: 1.125rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.875rem 0;
  transition: background 0.15s, transform 0.1s, box-shadow 0.1s;
  border-bottom: 3px solid rgba(0,0,0,0.2);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
  position: relative;
}
.calc-btn:active, .calc-btn.pressed {
  transform: translateY(3px);
  border-bottom-width: 0;
  box-shadow: none;
}
.calc-btn.wide { grid-column: span 2; }

/* Number */
.calc-btn.number { background: var(--calc-number); color: var(--foreground); }
.calc-btn.number:hover { background: var(--calc-number-hover); }

/* Operator */
.calc-btn.operator { background: var(--calc-operator); color: var(--primary-foreground); }
.calc-btn.operator:hover { background: var(--calc-operator-hover); }

/* Function */
.calc-btn.function { background: var(--calc-function); color: var(--foreground); }
.calc-btn.function:hover { background: var(--calc-function-hover); }

/* Scientific */
.calc-btn.scientific {
  background: var(--calc-scientific);
  color: var(--foreground);
  font-size: 0.8rem;
  padding: 0.625rem 0;
}
.calc-btn.scientific:hover { background: var(--calc-scientific-hover); }

/* History panel */
.history-panel {
  border-top: 1px solid var(--border);
  padding: 0.5rem 0;
  max-height: 320px;
  display: flex; flex-direction: column;
}
.history-panel .header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 1rem;
}
.history-panel .header span { font-size: 0.875rem; font-weight: 600; }
.history-panel .clear-btn {
  background: none; border: none; color: var(--primary);
  cursor: pointer; font-size: 0.75rem; font-family: 'Inter', sans-serif;
}
.history-panel .clear-btn:hover { text-decoration: underline; }
.history-list {
  overflow-y: auto; flex: 1; padding: 0 0.5rem;
  max-height: 260px;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.history-entry {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.15s;
  text-align: right;
}
.history-entry:hover { background: var(--accent); }
.history-entry .expr { font-size: 0.75rem; color: var(--muted-foreground); }
.history-entry .result { font-size: 1rem; font-weight: 500; }
.history-empty {
  text-align: center; padding: 2rem;
  color: var(--muted-foreground); font-size: 0.875rem;
}

.footer {
  text-align: center; margin-top: 1rem;
  font-size: 0.75rem; color: var(--muted-foreground);
}
