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

:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232730;
  --surface-3: #2a2f3d;
  --border: #2d3342;
  --text: #e8eaf0;
  --text-muted: #8b92a8;
  --text-dim: #5c6278;
  --accent: #6c5ce7;
  --accent-hover: #7d6ef0;
  --accent-active: #5a4bd4;
  --accent-glow: rgba(108, 92, 231, 0.35);
  --op-bg: #6c5ce7;
  --op-hover: #7d6ef0;
  --op-active: #5a4bd4;
  --func-bg: #2a2f3d;
  --func-hover: #333a4d;
  --func-active: #252a38;
  --num-bg: #232730;
  --num-hover: #2e3442;
  --num-active: #1e222c;
  --equals-bg: #6c5ce7;
  --equals-hover: #7d6ef0;
  --equals-active: #5a4bd4;
  --radius-lg: 24px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 20px 60px rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.06) inset;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px 24px;
  position: relative;
  overflow-x: hidden;
}

/* Decorative orbs */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}
.orb-1 {
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(108,92,231,0.15) 0%, transparent 70%);
  top: -200px; right: -150px;
}
.orb-2 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(0,184,148,0.08) 0%, transparent 70%);
  bottom: -100px; left: -150px;
}

/* ── Wrapper ── */
.wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Header ── */
.header { text-align: center; }
.header-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.logo-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}
.header-subtitle {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.header-subtitle kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
}

/* ── Calculator Card ── */
.calculator {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

/* ── Display ── */
.display {
  background: #13151a;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px 14px;
  text-align: right;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  margin-bottom: 18px;
  overflow: hidden;
}
.display-history {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-dim);
  min-height: 1.2em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}
.display-current {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2.2rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
  transition: font-size 0.15s;
}
.display-current.small { font-size: 1.5rem; }
.display-current.smaller { font-size: 1.15rem; }

/* ── Keypad ── */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.key {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 1.2rem;
  font-weight: 500;
  height: 58px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, transform 0.08s, box-shadow 0.12s, filter 0.12s;
  position: relative;
  outline: none;
}
.key:active { transform: scale(0.95); }
.key:focus-visible { box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--accent-glow); }

/* Number keys */
.key--num {
  background: var(--num-bg);
  color: var(--text);
  border: 1px solid transparent;
}
.key--num:hover { background: var(--num-hover); }
.key--num:active { background: var(--num-active); }

/* Function keys (AC, ±, %) */
.key--func {
  background: var(--func-bg);
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid var(--border);
}
.key--func:hover { background: var(--func-hover); color: var(--text); }
.key--func:active { background: var(--func-active); }

/* Operator keys */
.key--op {
  background: var(--op-bg);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(108,92,231,0.3);
}
.key--op:hover { background: var(--op-hover); box-shadow: 0 4px 16px rgba(108,92,231,0.4); }
.key--op:active { background: var(--op-active); box-shadow: 0 1px 6px rgba(108,92,231,0.3); }
.key--op.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 4px 16px rgba(108,92,231,0.4);
}

/* Equals */
.key--equals {
  background: var(--equals-bg);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(108,92,231,0.35);
  grid-column: span 2;
}
.key--equals:hover { background: var(--equals-hover); box-shadow: 0 6px 20px rgba(108,92,231,0.45); }
.key--equals:active { background: var(--equals-active); }

/* Zero spans normally but equals spans 2, so zero is single */
.key--zero { /* single width — layout handled by grid */ }

/* Key press animation helper */
.key.pressed {
  transform: scale(0.93);
  filter: brightness(1.15);
}

/* ── Hints ── */
.hints {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}
.hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}
.hint span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 3px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
}

/* ── Footer ── */
.footer {
  position: relative;
  z-index: 1;
  margin-top: 20px;
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay[hidden] { display: none !important; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.modal-close {
  appearance: none;
  border: none;
  background: var(--surface-2);
  color: var(--text-muted);
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.modal-grid div {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.modal-grid kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  white-space: nowrap;
}
.modal-grid span { margin-left: auto; font-size: 0.75rem; color: var(--text-dim); }

/* ── Responsive ── */
@media (max-width: 400px) {
  .wrapper { max-width: 100%; }
  .calculator { padding: 16px; border-radius: 20px; }
  .key { height: 52px; font-size: 1.1rem; }
  .display-current { font-size: 1.9rem; }
  .modal-grid { grid-template-columns: 1fr; }
}

@media (max-height: 700px) {
  body { justify-content: flex-start; padding-top: 20px; }
  .display { min-height: 72px; padding: 14px 18px 10px; }
  .key { height: 50px; }
}
