:root {
  --calc-bg:     #13131e;
  --calc-btn:    #1c1c2e;
  --calc-fn:     #2a2a3e;
  --calc-op:     #312e81;
  --calc-eq:     #6366f1;
  --calc-accent: #a5b4fc;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: #0a0a0f;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(99,102,241,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(139,92,246,0.06) 0%, transparent 50%);
}

/* ── Shell ── */
.calc {
  width: min(380px, 92vw);
  background: var(--calc-bg);
  border-radius: 28px;
  overflow: hidden;
  position: relative;
  box-shadow:
    0 50px 100px rgba(0,0,0,0.7),
    0 0 0 1px rgba(255,255,255,0.05),
    inset 0 1px 0 rgba(255,255,255,0.08);
}

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem 0;
}

.top-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.65rem;
  transition: all 0.2s;
}
.top-btn:hover   { background: rgba(255,255,255,0.12); color: #fff; }
.top-btn.active  { background: rgba(99,102,241,0.25); border-color: rgba(99,102,241,0.5); color: var(--calc-accent); }

/* Deg / Rad */
.dr-toggle { display: none; gap: 2px; background: rgba(255,255,255,0.05); border-radius: 6px; padding: 2px; }
.dr-toggle.visible { display: flex; }
.dr-btn {
  background: transparent; border: none; border-radius: 4px;
  color: rgba(255,255,255,0.35); cursor: pointer;
  font-family: 'Inter', sans-serif; font-size: 0.65rem; font-weight: 700;
  letter-spacing: 0.08em; padding: 0.25rem 0.5rem; transition: all 0.15s;
}
.dr-btn.active { background: rgba(99,102,241,0.4); color: var(--calc-accent); }

/* ── Display ── */
.display {
  padding: 1.25rem 1.75rem 1.25rem;
  text-align: right;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.2rem;
  background: linear-gradient(180deg, #0d0d18 0%, #13131e 100%);
  cursor: pointer;
  position: relative;
  user-select: none;
}
.display:hover .copy-hint-label { opacity: 1; }

.expr {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.28);
  min-height: 1.2em;
  word-break: break-all;
  transition: opacity 0.2s;
}

.result {
  font-size: 3.5rem;
  font-weight: 300;
  color: #fff;
  line-height: 1;
  letter-spacing: -0.02em;
  word-break: break-all;
  transition: font-size 0.1s;
}
.result.error { color: #f87171; font-size: 1.6rem; font-weight: 400; }

.copy-toast {
  position: absolute;
  top: 0.6rem; right: 1rem;
  background: rgba(99,102,241,0.85);
  backdrop-filter: blur(8px);
  border-radius: 6px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 0.25rem 0.6rem;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.copy-toast.show { opacity: 1; transform: translateY(0); }

/* ── Scientific ── */
.sci-buttons {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: rgba(255,255,255,0.03);
  border-top: 1px solid rgba(255,255,255,0.05);
}
.sci-buttons.visible { display: grid; }

.btn-sci {
  height: 56px;
  font-size: 0.82rem;
  font-weight: 500;
  background: #161624;
  color: var(--calc-accent);
  border: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: filter 0.1s, transform 0.08s;
  letter-spacing: 0.02em;
}
.btn-sci:hover  { filter: brightness(1.4); }
.btn-sci:active { transform: scale(0.91); filter: brightness(0.85); }

/* ── Standard buttons ── */
.buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid rgba(255,255,255,0.06);
}

.btn {
  height: 76px;
  font-family: 'Inter', sans-serif;
  font-size: 1.3rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: filter 0.1s, transform 0.08s;
  user-select: none;
  background: var(--calc-btn);
  color: #fff;
}
.btn:hover  { filter: brightness(1.25); }
.btn:active { transform: scale(0.93); filter: brightness(0.9); }
.btn.key-flash { animation: keyFlash 0.12s ease-out; }

.btn-fn { background: var(--calc-fn); color: rgba(255,255,255,0.85); font-size: 1.05rem; }

.btn-op { background: var(--calc-op); color: var(--calc-accent); font-size: 1.5rem; font-weight: 400; }
.btn-op.active { background: #a5b4fc; color: #1e1b4b; }

.btn-eq {
  background: linear-gradient(135deg, var(--calc-eq), #8b5cf6);
  color: #fff; font-size: 1.6rem; font-weight: 300;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-eq:hover { filter: brightness(1.15); }

.btn-zero { grid-column: span 2; text-align: left; padding-left: 1.75rem; }

/* ── Keyboard hint ── */
.kbd-hint {
  text-align: center;
  font-size: 0.62rem;
  color: rgba(255,255,255,0.18);
  letter-spacing: 0.04em;
  padding: 0.55rem 1rem;
  background: var(--calc-bg);
}

/* ── History panel ── */
.hist-panel {
  position: absolute;
  inset: 0;
  background: var(--calc-bg);
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  z-index: 10;
}
.hist-panel.open { transform: translateY(0); }

.hist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.hist-header span {
  font-size: 0.95rem;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.04em;
}
#histBackBtn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  padding: 0.3rem 0.7rem;
  transition: all 0.2s;
}
#histBackBtn:hover { background: rgba(255,255,255,0.12); color: #fff; }

#clearHistBtn {
  background: rgba(248,113,113,0.12);
  border: 1px solid rgba(248,113,113,0.25);
  border-radius: 8px;
  color: #f87171;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  transition: all 0.2s;
}
#clearHistBtn:hover { background: rgba(248,113,113,0.22); }

.hist-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.hist-item {
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.hist-item:hover { background: rgba(99,102,241,0.1); }

.hist-item .hi-expr   { font-size: 0.78rem; color: rgba(255,255,255,0.3); margin-bottom: 0.2rem; }
.hist-item .hi-result { font-size: 1.4rem; font-weight: 300; color: #fff; }

.hist-empty {
  text-align: center;
  color: rgba(255,255,255,0.2);
  font-size: 0.85rem;
  padding: 3rem 1rem;
  display: none;
}
.hist-empty.visible { display: block; }

/* ── Animations ── */
@keyframes keyFlash {
  0%   { filter: brightness(1.7); }
  100% { filter: brightness(1); }
}

/* ── Programmer display rows ── */
.prog-rows {
  display: none;
  flex-direction: column;
  width: 100%;
  gap: 1px;
}
.prog-rows.visible { display: flex; }

.prog-expr {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.28);
  text-align: right;
  min-height: 1.1em;
  padding: 0 0 0.25rem;
  word-break: break-all;
}

.prog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  opacity: 0.4;
}
.prog-row.active { opacity: 1; }
.prog-row:hover  { background: rgba(255,255,255,0.05); }

.pr-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--calc-accent);
  min-width: 2.4rem;
}
.prog-row.active .pr-label { color: #fff; }

.pr-val {
  font-size: 1.05rem;
  font-weight: 400;
  color: rgba(255,255,255,0.7);
  font-family: 'Inter', monospace;
  word-break: break-all;
  text-align: right;
}
.prog-row.active .pr-val { font-size: 1.25rem; color: #fff; font-weight: 500; }

/* ── Programmer pad (hex digits + bitwise) ── */
.prog-pad {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: rgba(255,255,255,0.03);
  border-top: 1px solid rgba(255,255,255,0.05);
}
.prog-pad.visible { display: grid; }

.btn-hex {
  height: 52px;
  font-size: 1rem;
  font-weight: 600;
  background: #1a1a2e;
  color: #c4b5fd;
  border: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: filter 0.1s, transform 0.08s;
  letter-spacing: 0.04em;
}
.btn-hex:hover  { filter: brightness(1.4); }
.btn-hex:active { transform: scale(0.91); filter: brightness(0.8); }

.btn-bw {
  height: 52px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #1e1a2e;
  color: #f0abfc;
  border: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: filter 0.1s, transform 0.08s;
  letter-spacing: 0.06em;
}
.btn-bw:hover  { filter: brightness(1.4); }
.btn-bw:active { transform: scale(0.91); filter: brightness(0.8); }
.btn-bw.active { background: #f0abfc; color: #1e1a2e; }

/* disabled digit (wrong base) */
.prog-disabled {
  opacity: 0.2 !important;
  cursor: not-allowed !important;
  pointer-events: none;
}
