:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface2: #ffffff;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #5b6878;
  --accent: #2563eb;
  --op: #3a4060;
  --op-hover: #4a5080;
  --eq: #2563eb;
  --fn: #e3e8f0;
  --sci: #1e2445;
  --radius: 8px;
  --btn-radius: 8px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; min-height: 100vh; }

nav { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; }
.nav-inner { max-width: 780px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 52px; }
.logo { font-weight: 700; font-size: 1.1rem; }
.nav-badge { font-size: .75rem; color: var(--muted); background: var(--surface2); border: 1px solid var(--border); padding: 3px 10px; border-radius: 20px; }

.container { max-width: 780px; margin: 0 auto; padding: 24px 20px; }
.calc-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }

/* CALC CARD */
.calc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

/* DISPLAY */
.display { background: #0a0d1a; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.display-expr { font-size: .8rem; color: var(--muted); min-height: 20px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: monospace; }
.display-main { font-size: 2rem; font-weight: 700; text-align: right; font-family: 'Consolas', monospace; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 44px; line-height: 1.2; }
.display-mode { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }
.mode-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--muted); padding: 3px 8px; border-radius: 4px; cursor: pointer; font-size: .72rem; font-weight: 700; letter-spacing: .03em; transition: all .15s; }
.mode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* MEMORY ROW */
.mem-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.btn-mem { background: var(--surface2); border: none; color: var(--muted); padding: 8px 4px; cursor: pointer; font-size: .78rem; font-weight: 600; transition: background .1s, color .1s; }
.btn-mem:hover { background: var(--border); color: var(--text); }

/* SCI GRID */
.sci-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.btn-sci { background: var(--sci); border: none; color: var(--muted); padding: 10px 4px; cursor: pointer; font-size: .82rem; font-family: inherit; transition: background .1s, color .1s; }
.btn-sci:hover { background: #2a2e58; color: var(--accent); }

/* MAIN GRID */
.main-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); }
.btn { background: var(--surface2); border: none; color: var(--text); padding: 18px 8px; cursor: pointer; font-size: 1rem; font-weight: 500; transition: background .1s; user-select: none; }
.btn:hover { background: var(--border); }
.btn:active { background: #3a3f60; }
.btn-op { background: var(--op); color: var(--accent); font-weight: 700; }
.btn-op:hover { background: var(--op-hover); }
.btn-fn { background: var(--fn); color: var(--text); font-size: .85rem; }
.btn-eq { background: var(--eq); color: #fff; font-weight: 700; font-size: 1.1rem; }
.btn-eq:hover { background: #8aabff; }
.btn-zero { grid-column: span 2; }

/* HISTORY */
.history-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.history-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.history-title { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.btn-sm { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 4px 10px; border-radius: 5px; cursor: pointer; font-size: .78rem; transition: background .15s; }
.btn-sm:hover { background: var(--border); }
.history-list { max-height: 500px; overflow-y: auto; }
.history-empty { padding: 24px 16px; color: var(--muted); font-size: .875rem; text-align: center; }
.history-item { padding: 10px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .15s; }
.history-item:hover { background: var(--surface2); }
.history-item:last-child { border-bottom: none; }
.hi-expr { font-size: .8rem; color: var(--muted); font-family: monospace; }
.hi-result { font-size: 1rem; font-weight: 600; font-family: monospace; color: var(--text); margin-top: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 700px) {
  .calc-layout { grid-template-columns: 1fr; }
  .history-list { max-height: 200px; }
}
