:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4338ca;
  --primary-700: #312e81;
  --primary-50: #eef2ff;
  --accent: #6366f1;
  --op: #f59e0b;
  --op-text: #ffffff;
  --eq: #10b981;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

html.dark {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1f2937;
  --primary: #6366f1;
  --primary-700: #4338ca;
  --primary-50: #1e1b4b;
  --accent: #818cf8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Cairo', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(135deg, var(--bg), var(--surface-2));
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background .25s ease, color .25s ease;
}

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  max-width: 1100px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 28px; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; }

.chip {
  appearance: none; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9999px;
  font: inherit; font-weight: 700; font-size: 13px;
  cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.chip:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.chip.ghost { background: transparent; }
.chip.small { padding: 6px 10px; font-size: 12px; }

.layout {
  flex: 1; max-width: 1100px; width: 100%; margin: 0 auto;
  padding: 8px 24px 24px;
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px;
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.calc {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.display {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; min-height: 110px;
  display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 14px;
}
.expr { color: var(--muted); font-size: 16px; min-height: 22px; word-break: break-all; }
.result { color: var(--text); font-size: 36px; font-weight: 700; word-break: break-all; }

.keypad { display: grid; gap: 10px; grid-template-columns: repeat(4, 1fr); }
.keypad.scientific { grid-template-columns: repeat(5, 1fr); }
.keypad.standard .sci { display: none; }

.key {
  appearance: none; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  padding: 14px 0; font: inherit; font-weight: 700; font-size: 18px;
  border-radius: 12px; cursor: pointer;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.key:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.key:active { transform: translateY(0); }
.key.op { background: var(--op); color: var(--op-text); border-color: transparent; }
.key.eq { background: var(--eq); color: #fff; border-color: transparent; }
.key.util { color: var(--danger); }
.key.sci { background: var(--primary-50); color: var(--primary); }

.history {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 320px;
}
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.history-head h2 { margin: 0; font-size: 16px; font-weight: 900; }
.history-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.history-list li {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; border-radius: 10px;
  cursor: pointer; transition: background .15s ease;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  border: 1px solid transparent;
}
.history-list li:hover { background: var(--surface-2); border-color: var(--border); }
.history-list .h-expr { color: var(--muted); font-size: 12px; }
.history-list .h-res { color: var(--text); font-size: 16px; font-weight: 700; }
.empty { color: var(--muted); font-size: 13px; text-align: center; margin-top: auto; margin-bottom: auto; }

.foot { text-align: center; padding: 14px; color: var(--muted); font-size: 12px; }
.foot a { color: var(--primary); text-decoration: none; }
.foot a:hover { text-decoration: underline; }
