/* ══════════════════════════════════════════════
   DeCalc — Calculator  |  style.css
   ══════════════════════════════════════════════ */

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

:root {
  --bg:        #0f0f0f;
  --calc-bg:   #1c1c1e;
  --disp-bg:   #141414;
  --surface:   #2c2c2e;
  --border:    rgba(255,255,255,.07);

  --num-bg:    #2a2a2c;
  --num-hover: #38383a;
  --fn-bg:     #3a3a3c;
  --fn-hover:  #4a4a4e;
  --op-bg:     #ff9500;
  --op-hover:  #ffaa22;
  --op-text:   #fff;
  --eq-from:   #ff9500;
  --eq-to:     #ff6b00;
  --sci-bg:    #252530;
  --sci-hover: #32323e;
  --mem-bg:    #1e1e22;
  --mem-hover: #2a2a32;

  --text:      #ffffff;
  --text2:     rgba(255,255,255,.55);
  --accent:    #ff9500;

  --radius-calc: 22px;
  --radius-btn:  16px;
  --gap:         8px;
  --btn-h:       64px;

  --font: 'Inter', system-ui, sans-serif;
}

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

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 16px 40px;
  min-height: 100vh;
}

/* ── Back pill ───────────────────────────────── */
.back-pill {
  position: fixed;
  top: 18px; left: 18px;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .8rem; font-weight: 500;
  color: var(--text2);
  text-decoration: none;
  transition: background .2s, color .2s;
  z-index: 100;
}
.back-pill:hover { background: rgba(255,255,255,.14); color: var(--text); }

/* ── Page wrap ───────────────────────────────── */
.page-wrap {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
  max-width: 740px;
  justify-content: center;
}

/* ── Calc shell ──────────────────────────────── */
.calc-shell {
  background: var(--calc-bg);
  border-radius: var(--radius-calc);
  border: 1px solid var(--border);
  overflow: hidden;
  width: 340px;
  flex-shrink: 0;
  box-shadow: 0 32px 80px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.04);
}

/* ── Toolbar ─────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.calc-brand {
  font-size: .9rem; font-weight: 700; letter-spacing: -.3px;
  color: var(--text2);
}
.calc-brand span { color: var(--accent); }
.toolbar-right { display: flex; gap: 6px; }
.tool-btn {
  background: var(--fn-bg);
  border: none; border-radius: 8px;
  color: var(--text2); font-size: .72rem; font-weight: 600;
  padding: 5px 9px; cursor: pointer;
  transition: background .15s, color .15s;
  font-family: var(--font);
}
.tool-btn:hover { background: var(--fn-hover); color: var(--text); }
.tool-btn.active  { background: var(--accent); color: #fff; }

/* ── Display ─────────────────────────────────── */
.display {
  background: var(--disp-bg);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  min-height: 110px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative;
}
.display-expr {
  font-size: .85rem; font-weight: 400;
  color: var(--text2);
  min-height: 1.3em;
  text-align: right;
  word-break: break-all;
  letter-spacing: .3px;
}
.display-result {
  font-size: 2.8rem; font-weight: 300;
  color: var(--text);
  text-align: right;
  line-height: 1.1;
  word-break: break-all;
  transition: font-size .1s;
}
.display-result.sm  { font-size: 1.8rem; }
.display-result.xsm { font-size: 1.2rem; }
.display-sub {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.mem-badge {
  background: var(--accent); color: #000;
  font-size: .65rem; font-weight: 700;
  padding: 2px 7px; border-radius: 5px;
  letter-spacing: .5px;
}
.copy-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text2); font-size: .8rem;
  padding: 4px 6px; border-radius: 6px;
  transition: color .15s, background .15s;
}
.copy-btn:hover { color: var(--accent); background: rgba(255,149,0,.12); }

/* ── Scientific panel ────────────────────────── */
.sci-panel {
  padding: 10px 12px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--disp-bg);
}
.sci-panel.hidden { display: none; }

/* ── Memory row ──────────────────────────────── */
.mem-row {
  display: flex; gap: 6px;
  padding: 8px 12px 4px;
  background: var(--mem-bg);
  border-bottom: 1px solid var(--border);
}
.mem-row .btn {
  flex: 1;
  height: 32px;
  font-size: .7rem;
  border-radius: 8px;
  background: transparent;
  color: var(--text2);
  border: 1px solid rgba(255,255,255,.08);
}
.mem-row .btn:hover { background: var(--mem-hover); color: var(--text); }

/* ── Button grid ─────────────────────────────── */
.btn-grid {
  display: grid;
  gap: var(--gap);
  padding: 12px;
}
.main-grid  { grid-template-columns: repeat(4, 1fr); }
.sci-grid   { grid-template-columns: repeat(4, 1fr); }

/* ── Base button ─────────────────────────────── */
.btn {
  height: var(--btn-h);
  border: none; border-radius: var(--radius-btn);
  font-family: var(--font);
  font-size: 1.1rem; font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .08s ease, filter .08s ease, background .12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255,255,255,.12);
  opacity: 0;
  transition: opacity .12s;
}
.btn:active::after { opacity: 1; }
.btn:active { transform: scale(.93); }

/* ── Button variants ─────────────────────────── */
.btn-num { background: var(--num-bg); color: var(--text); }
.btn-num:hover { background: var(--num-hover); }

.btn-fn  { background: var(--fn-bg);  color: var(--text); }
.btn-fn:hover  { background: var(--fn-hover);  }

.btn-op  { background: var(--op-bg);  color: var(--op-text); font-size: 1.3rem; }
.btn-op:hover  { background: var(--op-hover); }
.btn-op.active-op { background: #fff; color: var(--op-bg); }

.btn-eq  {
  background: linear-gradient(145deg, var(--eq-from), var(--eq-to));
  color: #fff; font-size: 1.4rem;
  box-shadow: 0 4px 16px rgba(255,149,0,.35);
}
.btn-eq:hover { filter: brightness(1.1); }

.btn-sci { background: var(--sci-bg); color: var(--text2); font-size: .78rem; height: 48px; border-radius: 10px; }
.btn-sci:hover { background: var(--sci-hover); color: var(--text); }

.btn-mem { font-size: .72rem; }

/* ── Wide zero button ────────────────────────── */
.btn-zero { grid-column: span 2; justify-content: flex-start; padding-left: 24px; }

/* ── History panel ───────────────────────────── */
.hist-panel {
  background: var(--calc-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-calc);
  width: 280px;
  flex-shrink: 0;
  max-height: 620px;
  display: flex; flex-direction: column;
  box-shadow: 0 32px 80px rgba(0,0,0,.4);
  animation: fadeSlideIn .2s ease;
}
.hist-panel.hidden { display: none; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.hist-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: .85rem; font-weight: 600; color: var(--text2);
}
.hist-header i { color: var(--accent); margin-right: 6px; }
.hist-clear-btn {
  background: none; border: 1px solid rgba(255,255,255,.1);
  color: var(--text2); border-radius: 6px;
  font-size: .72rem; padding: 3px 9px; cursor: pointer;
  font-family: var(--font);
  transition: background .15s, color .15s;
}
.hist-clear-btn:hover { background: rgba(231,76,60,.15); color: #e74c3c; border-color: #e74c3c; }

.hist-list {
  flex: 1; overflow-y: auto; padding: 8px;
}
.hist-list::-webkit-scrollbar { width: 4px; }
.hist-list::-webkit-scrollbar-track { background: transparent; }
.hist-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.hist-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px;
  padding: 40px 20px;
  color: var(--text2);
  font-size: .85rem;
}
.hist-empty i { font-size: 2rem; opacity: .25; }

.hist-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
  border: 1px solid transparent;
}
.hist-item:hover {
  background: rgba(255,149,0,.08);
  border-color: rgba(255,149,0,.15);
}
.hist-expr {
  font-size: .75rem; color: var(--text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-res {
  font-size: 1.1rem; font-weight: 500; color: var(--text);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-time {
  font-size: .68rem; color: rgba(255,255,255,.25); margin-top: 3px;
}

/* ── Toast ───────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(16px);
  background: rgba(30,30,32,.96);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text); font-size: .82rem;
  padding: 9px 18px; border-radius: 999px;
  pointer-events: none; opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 999; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Utility ─────────────────────────────────── */
.hidden { display: none !important; }

.active-key {
  filter: brightness(1.3) !important;
  transform: scale(.93) !important;
}

/* ── Ripple ──────────────────────────────────── */
@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}
.ripple-el {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  transform: scale(0);
  animation: ripple .4s linear;
  pointer-events: none;
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 680px) {
  .page-wrap { flex-direction: column; align-items: center; }
  .hist-panel { width: 340px; max-height: 360px; }
  body { padding: 70px 12px 40px; }
}
@media (max-width: 380px) {
  .calc-shell, .hist-panel { width: 100%; }
  :root { --btn-h: 58px; }
}
