@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;700;800&family=JetBrains+Mono:wght@300;400;600&display=swap');

/* ─── Variables ─────────────────────────────────────────── */
:root {
  --bg:        #0a0a0f;
  --surface:   #13131c;
  --panel:     #1a1a27;
  --border:    #2a2a3d;
  --digit:     #1e1e2e;
  --digit-h:   #272738;
  --op:        #1b2a3b;
  --op-h:      #223448;
  --op-txt:    #4da6ff;
  --utility:   #1f1f2e;
  --utility-h: #2a2a3e;
  --util-txt:  #a0a0c0;
  --equals:    #2563eb;
  --equals-h:  #1d4ed8;
  --text:      #e8e8f0;
  --muted:     #5a5a7a;
  --accent:    #4da6ff;
  --error:     #ff5f6d;
  --radius:    16px;
  --btn-r:     12px;
}

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

body {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden;
}

/* Subtle radial glow background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 30% 40%, rgba(37,99,235,.08) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 75% 65%, rgba(77,166,255,.05) 0%, transparent 60%);
  pointer-events: none;
}

/* ─── Wrapper ────────────────────────────────────────────── */
.wrapper {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 20px;
  animation: fadeUp .5s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Calculator Shell ───────────────────────────────────── */
.calculator {
  width: 320px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px 20px 20px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.03),
    0 24px 64px rgba(0,0,0,.6),
    0 4px 16px rgba(0,0,0,.4);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ─── Brand ──────────────────────────────────────────────── */
.brand {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .25em;
  color: var(--muted);
  text-transform: uppercase;
}
.brand span {
  color: var(--accent);
}

/* ─── Display ────────────────────────────────────────────── */
.display {
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 16px 18px 14px;
  text-align: right;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.expression {
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
  letter-spacing: .02em;
}

.result {
  font-size: 40px;
  font-weight: 300;
  color: var(--text);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .15s ease, transform .1s ease;
}

.result.pop {
  transform: scale(1.04);
  color: #fff;
}

.result.error {
  font-size: 22px;
  color: var(--error);
}

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

/* ─── Base Button ────────────────────────────────────────── */
.btn {
  height: 64px;
  border: none;
  border-radius: var(--btn-r);
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 400;
  cursor: pointer;
  outline: none;
  transition: background .12s ease, transform .08s ease, box-shadow .12s ease;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Ripple pseudo */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.06);
  opacity: 0;
  border-radius: inherit;
  transition: opacity .15s ease;
}
.btn:active::after { opacity: 1; }
.btn:active { transform: scale(.94); }

/* ─── Button Types ───────────────────────────────────────── */
.btn.digit {
  background: var(--digit);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.04);
}
.btn.digit:hover { background: var(--digit-h); }

.btn.operator {
  background: var(--op);
  color: var(--op-txt);
  font-size: 20px;
  font-weight: 600;
  border: 1px solid rgba(77,166,255,.1);
}
.btn.operator:hover { background: var(--op-h); }
.btn.operator.active-op {
  background: rgba(77,166,255,.18);
  box-shadow: 0 0 0 1px var(--accent);
  color: #fff;
}

.btn.utility {
  background: var(--utility);
  color: var(--util-txt);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .05em;
  border: 1px solid rgba(255,255,255,.04);
}
.btn.utility:hover { background: var(--utility-h); color: var(--text); }

.btn.equals {
  grid-column: span 4;
  height: 52px;
  background: var(--equals);
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  border: none;
  letter-spacing: .05em;
  box-shadow: 0 4px 20px rgba(37,99,235,.35);
}
.btn.equals:hover {
  background: var(--equals-h);
  box-shadow: 0 6px 24px rgba(37,99,235,.45);
}

/* Zero button spans 2 cols */
.btn.zero { grid-column: span 2; }

/* ─── History Panel ──────────────────────────────────────── */
.history-panel {
  width: 200px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-header span {
  font-family: 'Syne', sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .2em;
  color: var(--muted);
}
.history-header button {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  transition: all .15s;
}
.history-header button:hover {
  color: var(--error);
  border-color: var(--error);
}

#historyList {
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#historyList::-webkit-scrollbar { width: 4px; }
#historyList::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#historyList li {
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .15s;
}
#historyList li:hover { border-color: var(--accent); }

#historyList li .h-expr {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#historyList li .h-result {
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
  margin-top: 2px;
}

/* Empty state */
#historyList:empty::after {
  content: 'No history yet';
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  display: block;
  margin-top: 20px;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 580px) {
  .wrapper { flex-direction: column; align-items: center; padding: 12px; }
  .history-panel { width: 320px; max-height: 220px; }
}
