:root {
  --bg: #07090f;
  --card: #121624;
  --card-border: #1e263d;
  --accent: #00f0ff;
  --accent-glow: rgba(0, 240, 255, 0.3);
  --secondary: #ff007f;
  --text: #f8fafc;
  --muted: #64748b;
  --font: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow-x: hidden;
}

.matrix-bg {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background-image: radial-gradient(rgba(0, 240, 255, 0.07) 1px, transparent 1px),
                    radial-gradient(rgba(255, 0, 127, 0.05) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
  z-index: 0;
  pointer-events: none;
}

.calculator-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.calc-header {
  background: rgba(18, 22, 36, 0.8);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

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

.pulse-dot {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 240, 255, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(0, 240, 255, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 240, 255, 0); }
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 2px;
}

.accent { color: var(--accent); }

.status-pill {
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid rgba(0, 240, 255, 0.3);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.calc-main {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
}

@media (max-width: 680px) {
  .calc-main { grid-template-columns: 1fr; }
}

.calc-card, .history-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}

.display-section {
  background: #04060a;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
  text-align: right;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.8);
}

.history-screen {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 20px;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-screen {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text);
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

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

.btn {
  background: #181f33;
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 14px 0;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.btn:hover {
  background: #242e4a;
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

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

.btn.fn {
  background: #1e1b2e;
  color: var(--secondary);
  border-color: rgba(255, 0, 127, 0.3);
}

.btn.fn:hover {
  background: #2d2442;
  border-color: var(--secondary);
  box-shadow: 0 0 12px rgba(255, 0, 127, 0.3);
}

.btn.sci {
  background: #152238;
  color: #38bdf8;
  font-size: 0.95rem;
}

.btn.op {
  background: #16263b;
  color: var(--accent);
  font-weight: 700;
}

.btn.equals {
  background: linear-gradient(135deg, var(--accent), #0088ff);
  color: #07090f;
  font-weight: 800;
  grid-column: span 2;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 16px;
}

.clear-log-btn {
  background: none;
  border: none;
  color: var(--secondary);
  font-size: 0.75rem;
  cursor: pointer;
  font-weight: 600;
}

.clear-log-btn:hover { text-decoration: underline; }

.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 290px;
  overflow-y: auto;
}

.log-item {
  background: #090c14;
  border: 1px solid var(--card-border);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: monospace;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.log-item.placeholder {
  color: var(--muted);
  justify-content: center;
  font-style: italic;
}

.log-expr { color: var(--muted); }
.log-res { color: var(--accent); font-weight: 700; }
