/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0D0D0D;
  --surface:   #1A1A1A;
  --surface2:  #242424;
  --border:    #2E2E2E;
  --num-bg:    #2A2A2A;
  --num-hover: #363636;
  --util-bg:   #3A3A3A;
  --util-hover:#4A4A4A;
  --op-bg:     #CCFF00;
  --op-hover:  #DEFF44;
  --op-text:   #0D0D0D;
  --eq-bg:     #CCFF00;
  --eq-hover:  #DEFF44;
  --text:      #F0F0F0;
  --muted:     #888;
  --display-glow: rgba(204, 255, 0, 0.15);
  --font-display: 'Syne', sans-serif;
  --font-mono:    'Space Mono', monospace;
  --radius:    16px;
  --radius-btn:12px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  overflow: hidden;
}

/* ── Background Grid ──────────────────────────────────────── */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(204,255,0,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(204,255,0,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ───────────────────────────────────────────────── */
.wrapper {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  gap: 20px;
}

/* ── Brand ────────────────────────────────────────────────── */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.3em;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
}
.brand-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--op-bg);
  box-shadow: 0 0 10px var(--op-bg);
  animation: pulse 2.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

/* ── Calculator Shell ─────────────────────────────────────── */
.calculator {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.04) inset,
    0 32px 80px rgba(0,0,0,0.6),
    0 0 60px rgba(204,255,0,0.04);
}

/* ── Display ──────────────────────────────────────────────── */
.display {
  position: relative;
  background: #111;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  overflow: hidden;
  box-shadow: 0 0 30px var(--display-glow) inset;
}

.display-expression {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
  word-break: break-all;
  text-align: right;
  transition: opacity 0.2s;
}

.display-result {
  font-family: var(--font-display);
  font-size: 52px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  word-break: break-all;
  text-align: right;
  transition: transform 0.1s ease, color 0.2s;
  text-shadow: 0 0 30px rgba(204,255,0,0.2);
}

.display-result.pop {
  transform: scale(1.04);
  color: var(--op-bg);
}

/* Scanlines overlay */
.scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
  border-radius: var(--radius);
}

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

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  position: relative;
  height: 68px;
  border: none;
  border-radius: var(--radius-btn);
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background 0.12s ease,
    transform 0.08s ease,
    box-shadow 0.12s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

/* Number buttons */
.btn-num {
  background: var(--num-bg);
  color: var(--text);
  box-shadow: 0 4px 0 rgba(0,0,0,0.4);
}
.btn-num:hover {
  background: var(--num-hover);
  box-shadow: 0 4px 0 rgba(0,0,0,0.4), 0 0 12px rgba(255,255,255,0.04);
}
.btn-num:active {
  box-shadow: 0 1px 0 rgba(0,0,0,0.4);
}

/* Utility buttons (AC, +/−, %) */
.btn-util {
  background: var(--util-bg);
  color: var(--text);
  box-shadow: 0 4px 0 rgba(0,0,0,0.4);
}
.btn-util:hover {
  background: var(--util-hover);
}
.btn-util:active {
  box-shadow: 0 1px 0 rgba(0,0,0,0.4);
}

/* Operator buttons */
.btn-op {
  background: var(--op-bg);
  color: var(--op-text);
  font-size: 22px;
  box-shadow: 0 4px 0 rgba(100,130,0,0.5);
}
.btn-op:hover {
  background: var(--op-hover);
  box-shadow: 0 4px 0 rgba(100,130,0,0.5), 0 0 20px rgba(204,255,0,0.3);
}
.btn-op:active {
  box-shadow: 0 1px 0 rgba(100,130,0,0.5);
}
.btn-op.active-op {
  background: #fff;
  color: #0D0D0D;
  box-shadow: 0 4px 0 rgba(100,130,0,0.5), 0 0 24px rgba(204,255,0,0.5);
}

/* Equals button */
.btn-equals {
  background: var(--eq-bg);
  color: var(--op-text);
  font-size: 24px;
  grid-column: span 2;
  box-shadow: 0 4px 0 rgba(100,130,0,0.5);
}
.btn-equals:hover {
  background: var(--eq-hover);
  box-shadow: 0 4px 0 rgba(100,130,0,0.5), 0 0 28px rgba(204,255,0,0.4);
}
.btn-equals:active {
  box-shadow: 0 1px 0 rgba(100,130,0,0.5);
}

/* Zero button spans 2 columns */
.btn-zero {
  grid-column: span 2;
  text-align: left;
  padding-left: 24px;
}

/* ── Footer ───────────────────────────────────────────────── */
.footer {
  font-size: 11px;
  color: #444;
  letter-spacing: 0.05em;
  text-align: center;
}

/* ── Keyboard focus ring ──────────────────────────────────── */
.btn:focus-visible {
  outline: 2px solid var(--op-bg);
  outline-offset: 2px;
}

/* ── Error state ──────────────────────────────────────────── */
.display-result.error {
  font-size: 28px;
  color: #ff4444;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-height: 680px) {
  .btn { height: 56px; font-size: 16px; }
  .display-result { font-size: 40px; }
  .calculator { gap: 12px; padding: 16px; }
}

@media (max-width: 380px) {
  .calculator { padding: 14px; }
  .keypad { gap: 8px; }
  .btn { height: 62px; }
}