@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #090909;
  --panel: #111111;
  --panel2: #181818;
  --border: #262626;
  --text: #f5f5f5;
  --muted: #777777;
  --accent: #c8102e;
  --accent-light: #ed2445;
  --key: #202020;
  --key-hover: #303030;
  --display: #0d0d0d;
}

body.light {
  --bg: #f0f0f0;
  --panel: #ffffff;
  --panel2: #f2f2f2;
  --border: #dddddd;
  --text: #171717;
  --muted: #777777;
  --key: #eeeeee;
  --key-hover: #dddddd;
  --display: #f8f8f8;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', sans-serif;
  transition: background .25s, color .25s;
}

button {
  font: inherit;
  border: none;
  cursor: pointer;
}

.app {
  width: min(1200px, 92%);
  margin: auto;
}

.topbar {
  height: 85px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 14px;
}

.brand-icon {
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  height: 35px;
  width: 35px;
  border-radius: 8px;
  font-size: 20px;
}

.brand-light {
  color: var(--muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.version {
  color: var(--muted);
  font: 11px 'DM Mono', monospace;
}

.icon-btn {
  width: 39px;
  height: 39px;
  border-radius: 50%;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 20px;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, .8fr);
  gap: 30px;
  padding: 55px 0;
}

.section-heading,
.history-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 25px;
}

.eyebrow {
  color: var(--accent-light);
  font: 10px 'DM Mono', monospace;
  letter-spacing: 2px;
}

h1 {
  font-size: clamp(30px, 5vw, 45px);
  margin-top: 7px;
  letter-spacing: -2px;
}

h1 span,
h2 span {
  color: var(--accent);
}

.mode-btn {
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: 10px 'DM Mono', monospace;
  letter-spacing: 1px;
  border-radius: 5px;
}

.calculator,
.history-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
}

.display {
  min-height: 155px;
  background: var(--display);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: end;
  justify-content: space-between;
  overflow: hidden;
}

.display-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font: 10px 'DM Mono', monospace;
  letter-spacing: 1px;
}

.copy-btn,
.clear-history {
  color: var(--accent-light);
  background: transparent;
  font: 10px 'DM Mono', monospace;
  letter-spacing: 1px;
}

.expression {
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  font: 17px 'DM Mono', monospace;
  color: var(--muted);
  margin-top: 12px;
}

.result {
  font-size: clamp(30px, 6vw, 43px);
  font-weight: 700;
  letter-spacing: -2px;
  overflow-x: auto;
  max-width: 100%;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.key {
  height: 65px;
  border-radius: 7px;
  background: var(--key);
  color: var(--text);
  font-size: 19px;
  transition: .15s;
}

.key:hover,
.scientific-grid button:hover {
  background: var(--key-hover);
  transform: translateY(-2px);
}

.utility {
  color: var(--accent-light);
  background: rgba(200,16,46,.10);
}

.operator {
  color: var(--accent-light);
  background: rgba(200,16,46,.12);
}

.equals {
  background: var(--accent);
  color: white;
}

.equals:hover {
  background: var(--accent-light);
}

.scientific-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 15px;
}

.scientific-grid button {
  min-height: 42px;
  border-radius: 5px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  transition: .15s;
}

.hidden {
  display: none;
}

.keyboard-hint {
  color: var(--muted);
  font: 9px 'DM Mono', monospace;
  letter-spacing: 1px;
  text-align: center;
  margin-top: 20px;
}

.history-panel {
  min-height: 480px;
  display: flex;
  flex-direction: column;
}

.history-heading h2 {
  font-size: 30px;
  margin-top: 7px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  max-height: 440px;
}

.empty-history {
  text-align: center;
  padding: 90px 10px;
  color: var(--muted);
}

.empty-history span {
  font-size: 35px;
}

.empty-history p {
  margin-top: 12px;
  color: var(--text);
  font-weight: 600;
}

.empty-history small {
  display: block;
  margin-top: 5px;
}

.history-item {
  padding: 15px 5px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.history-item:hover {
  background: var(--panel2);
}

.history-expression {
  color: var(--muted);
  font: 12px 'DM Mono', monospace;
  overflow-wrap: anywhere;
}

.history-result {
  font-size: 20px;
  font-weight: 700;
  margin-top: 5px;
}

.history-footer {
  display: flex;
  justify-content: space-between;
  padding-top: 15px;
  margin-top: 15px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font: 9px 'DM Mono', monospace;
  letter-spacing: 1px;
}

.footer {
  border-top: 1px solid var(--border);
  padding: 23px 0;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font: 10px 'DM Mono', monospace;
  letter-spacing: 1px;
}

.toast {
  position: fixed;
  bottom: 25px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--accent);
  color: white;
  padding: 12px 20px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: .25s;
  font-size: 12px;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media(max-width: 800px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: 35px 0;
  }

  .history-panel {
    min-height: 300px;
  }

  .history-list {
    max-height: 300px;
  }
}

@media(max-width: 450px) {
  .app {
    width: 94%;
  }

  .calculator,
  .history-panel {
    padding: 13px;
  }

  .keypad {
    gap: 7px;
  }

  .key {
    height: 57px;
  }

  .scientific-grid {
    gap: 5px;
  }

  .scientific-grid button {
    font-size: 11px;
  }

  .mode-btn {
    font-size: 8px;
    padding: 9px 7px;
  }

  .brand {
    font-size: 11px;
  }
}