:root {
  /* Dark Theme (Default) */
  --bg-gradient: radial-gradient(circle at 50% 20%, #1e2433 0%, #0d111a 100%);
  --calc-bg: rgba(22, 28, 41, 0.95);
  --calc-border: rgba(255, 255, 255, 0.08);
  --calc-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.6), 0 0 30px rgba(56, 189, 248, 0.05);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --btn-num-bg: rgba(255, 255, 255, 0.05);
  --btn-num-hover: rgba(255, 255, 255, 0.1);
  --btn-num-active: rgba(255, 255, 255, 0.16);
  --btn-num-text: #f8fafc;

  --btn-action-bg: rgba(244, 63, 94, 0.15);
  --btn-action-hover: rgba(244, 63, 94, 0.25);
  --btn-action-active: rgba(244, 63, 94, 0.35);
  --btn-action-text: #fb7185;

  --btn-op-bg: rgba(56, 189, 248, 0.12);
  --btn-op-hover: rgba(56, 189, 248, 0.22);
  --btn-op-active: rgba(56, 189, 248, 0.32);
  --btn-op-text: #38bdf8;

  --btn-equals-bg: linear-gradient(135deg, #0ea5e9, #6366f1);
  --btn-equals-hover: linear-gradient(135deg, #0284c7, #4f46e5);
  --btn-equals-active: linear-gradient(135deg, #0369a1, #4338ca);
  --btn-equals-text: #ffffff;
  --btn-equals-shadow: 0 8px 20px -4px rgba(14, 165, 233, 0.45);

  --display-bg: rgba(13, 17, 26, 0.6);
  --display-border: rgba(255, 255, 255, 0.04);

  --history-bg: rgba(18, 24, 38, 0.98);
  --history-item-bg: rgba(255, 255, 255, 0.03);
  --history-item-hover: rgba(255, 255, 255, 0.08);

  --radius-lg: 28px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

[data-theme="light"] {
  --bg-gradient: radial-gradient(circle at 50% 20%, #f1f5f9 0%, #cbd5e1 100%);
  --calc-bg: rgba(255, 255, 255, 0.95);
  --calc-border: rgba(0, 0, 0, 0.06);
  --calc-shadow: 0 25px 60px -15px rgba(15, 23, 42, 0.15), 0 0 25px rgba(14, 165, 233, 0.06);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --btn-num-bg: #f8fafc;
  --btn-num-hover: #f1f5f9;
  --btn-num-active: #e2e8f0;
  --btn-num-text: #1e293b;

  --btn-action-bg: #ffe4e6;
  --btn-action-hover: #fecdd3;
  --btn-action-active: #fda4af;
  --btn-action-text: #e11d48;

  --btn-op-bg: #e0f2fe;
  --btn-op-hover: #bae6fd;
  --btn-op-active: #7dd3fc;
  --btn-op-text: #0284c7;

  --btn-equals-bg: linear-gradient(135deg, #0284c7, #4f46e5);
  --btn-equals-hover: linear-gradient(135deg, #0369a1, #4338ca);
  --btn-equals-active: linear-gradient(135deg, #075985, #3730a3);
  --btn-equals-text: #ffffff;
  --btn-equals-shadow: 0 8px 20px -4px rgba(2, 132, 199, 0.35);

  --display-bg: #f8fafc;
  --display-border: rgba(0, 0, 0, 0.05);

  --history-bg: rgba(255, 255, 255, 0.98);
  --history-item-bg: #f8fafc;
  --history-item-hover: #f1f5f9;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-gradient);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  color: var(--text-primary);
  padding: 20px;
  transition: background 0.3s ease;
}

.calculator-wrapper {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--calc-bg);
  border: 1px solid var(--calc-border);
  box-shadow: var(--calc-shadow);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(16px);
  overflow: hidden;
  transition: all 0.3s ease;
}

/* Header */
.calculator-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  font-size: 1.25rem;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--btn-num-bg);
  border: 1px solid var(--calc-border);
  color: var(--text-primary);
  font-size: 1.05rem;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--btn-num-hover);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

/* Display */
.display-container {
  background: var(--display-bg);
  border: 1px solid var(--display-border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  min-height: 105px;
  overflow: hidden;
  word-break: break-all;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.previous-operand {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  color: var(--text-secondary);
  min-height: 1.4em;
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: color 0.2s ease;
}

.current-operand {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.02em;
  transition: font-size 0.15s ease, color 0.2s ease;
}

/* Keypad Grid */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.btn {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  height: 62px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  user-select: none;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active {
  transform: scale(0.95);
}

.btn-num {
  background: var(--btn-num-bg);
  color: var(--btn-num-text);
  border-color: var(--calc-border);
}

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

.btn-num:active {
  background: var(--btn-num-active);
}

.btn-action {
  background: var(--btn-action-bg);
  color: var(--btn-action-text);
}

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

.btn-action:active {
  background: var(--btn-action-active);
}

.btn-operator {
  background: var(--btn-op-bg);
  color: var(--btn-op-text);
  font-size: 1.35rem;
}

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

.btn-operator:active {
  background: var(--btn-op-active);
}

.btn-equals {
  background: var(--btn-equals-bg);
  color: var(--btn-equals-text);
  box-shadow: var(--btn-equals-shadow);
  font-size: 1.4rem;
}

.btn-equals:hover {
  background: var(--btn-equals-hover);
  box-shadow: 0 10px 24px -4px rgba(14, 165, 233, 0.6);
  transform: translateY(-1px);
}

.btn-equals:active {
  background: var(--btn-equals-active);
  transform: translateY(1px) scale(0.97);
}

/* Keyboard Hints */
.keyboard-hints {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.keyboard-hints kbd {
  background: var(--btn-num-bg);
  border: 1px solid var(--calc-border);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: inherit;
  font-weight: 600;
  color: var(--text-secondary);
}

/* History Panel */
.history-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--history-bg);
  backdrop-filter: blur(20px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 24px;
  box-sizing: border-box;
  transform: translateY(0);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  opacity: 1;
}

.history-panel.hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--calc-border);
}

.history-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.text-btn {
  background: transparent;
  border: none;
  color: var(--btn-action-text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
}

.text-btn:hover {
  background: var(--btn-action-bg);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.history-list::-webkit-scrollbar {
  width: 5px;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--calc-border);
  border-radius: 4px;
}

.history-empty {
  margin: auto;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.history-item {
  background: var(--history-item-bg);
  border: 1px solid var(--calc-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: right;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: var(--history-item-hover);
  border-color: rgba(56, 189, 248, 0.3);
  transform: translateX(-2px);
}

.history-equation {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 4px;
}

.history-result {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
}

/* Animations & Responsive */
@media (max-width: 420px) {
  body {
    padding: 10px;
  }
  .calculator-wrapper {
    max-width: 100%;
    border-radius: 20px;
    padding: 18px;
  }
  .btn {
    height: 56px;
    font-size: 1.15rem;
  }
  .current-operand {
    font-size: 1.85rem;
  }
}
