:root {
  --bg-color: #030303;
  --border-color: #222222;
  --key-bg: #0a0a0a;
  --key-hover: #1a1a1a;
  --key-active: #ffffff;
  --text-main: #ffffff;
  --text-inverse: #000000;
  --text-muted: #555555;
  --accent-pass: #00e385;
  --accent-fail: #ff2a4d;
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: "Space Grotesk", monospace, sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  overflow: hidden;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 0px;
  background: transparent;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-height: 0;
}

.display {
  flex: 0 0 40%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border-color);
  background: #0a0a0a;
}

.display-section {
  flex: 1;
  min-height: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
}

.display-section:nth-child(2) {
  padding-right: 20px;
}

.top-display {
  flex: 2;
  border-bottom: 1px solid var(--border-color);
  padding-top: 46px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

#notes-display {
  flex: 1;
  padding: 10px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  align-content: flex-start;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  border: 1px solid var(--border-color);
}

.label {
  font-size: 14px;
  font-weight: bold;
  color: var(--text-muted);
  letter-spacing: 2px;
  position: absolute;
  top: 16px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.values {
  font-size: 36px;
  font-weight: normal;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
  min-height: 40px;
}

.grade-badge {
  background: transparent;
  border: 1px solid #444;
  color: #fff;
  padding: 4px 8px;
  font-size: 28px;
}

.top-display .grade-badge {
  padding: 4px 8px;
  font-size: 24px;
}

.values.average {
  font-size: 48px;
  font-weight: bold;
  line-height: 0.9;
  letter-spacing: -2px;
  margin-right: 16px;
}

.keypad {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(5, 1fr);
  background: var(--border-color);
  gap: 1px; /* Creates borders between keys */
}

.key {
  background: var(--key-bg);
  border: none;
  color: var(--text-main);
  font-size: 32px;
  font-weight: normal;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
    background 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
    color 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

@media (hover: hover) {
  .key:hover {
    background: var(--key-hover);
    z-index: 1;
  }
}

.key:active {
  background: var(--key-active);
  color: var(--text-inverse);
}

.action-key {
  font-size: 28px;
  font-weight: bold;
  color: var(--text-muted);
}

.comma-key {
  font-size: 40px;
}

.bmac-key {
  color: var(--text-main);
}
.bmac-key svg {
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.icon-btn {
  transition:
    transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
    color 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (hover: hover) {
  .icon-btn:hover {
    color: var(--text-main) !important;
    transform: scale(1.1);
  }
  .delete-history-btn:hover {
    color: var(--accent-fail) !important;
  }
}

.icon-btn:active {
  transform: scale(0.9);
  opacity: 0.7;
}

.history-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #0a0a0a;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 100;
}

.history-panel.visible {
  transform: translateY(0);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 24px 12px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: bold;
  letter-spacing: 2px;
  background: transparent;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: #111111;
  padding: 10px;
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.history-item:last-child {
  border-bottom: 1px solid var(--border-color);
}

.history-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: normal;
  letter-spacing: 1px;
}

.history-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-notes .grade-badge {
  background: #1a1a1a;
  border: 1px solid #333333;
  color: var(--text-main);
  padding: 2px 8px;
  font-size: 16px;
}

.history-average-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.history-average {
  font-size: 36px;
  font-weight: bold;
  line-height: 1;
}

.history-average-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: bold;
  letter-spacing: 1px;
  margin-top: 4px;
}

.history-footer {
  padding: 24px;
  border-top: 1px solid var(--border-color);
  background: #0a0a0a;
  position: sticky;
  bottom: 0;
  width: 100%;
}

.clear-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--accent-fail);
  color: var(--accent-fail);
  padding: 16px;
  font-family: inherit;
  font-weight: bold;
  letter-spacing: 2px;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    color 0.2s ease;
}

@media (hover: hover) {
  .clear-btn:hover {
    background: var(--accent-fail);
    color: var(--text-main);
  }
}

.clear-btn:active {
  transform: scale(0.98);
  background: var(--accent-fail);
  color: var(--text-main);
}

.footer {
  background: var(--key-bg);
  padding: 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  font-weight: bold;
  letter-spacing: 2px;
  border-top: 1px solid var(--border-color);
}

@media (min-width: 1024px) {
  body {
    align-items: center;
    justify-content: center;
    padding: 60px;
    background: #030303;
  }
  main {
    width: 100%;
    max-width: 1500px;
    height: 100vh;
    max-height: 850px;
    flex-direction: row;
    border: 1px solid var(--border-color);
    overflow: hidden;
  }
  .history-panel {
    position: relative;
    width: 280px;
    height: 100%;
    background: #0a0a0a;
    transform: none;
    display: flex;
    flex-direction: column;
    flex: 0 0 280px;
    border-right: 1px solid var(--border-color);
  }
  .history-panel.visible {
    transform: none;
  }
  #open-history,
  #close-history {
    display: none;
  }
  .history-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .history-meta {
    font-size: 10px;
  }
  .history-notes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .history-notes .grade-badge {
    font-size: 14px;
    padding: 2px 6px;
    background: #1a1a1a;
    border: 1px solid #333333;
  }
  .history-average-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }
  .history-average {
    font-size: 24px;
    font-weight: bold;
  }
  .history-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
  }
  .clear-btn {
    padding: 10px 12px;
    font-size: 10px;
    width: 100%;
  }
  .display {
    flex: 0 0 35%;
    border-bottom: none;
    border-right: 1px solid var(--border-color);
  }
  .display-section {
    padding: 24px;
  }
  .top-display {
    padding-top: 60px;
  }
  .label {
    top: 20px;
    left: 24px;
    font-size: 14px;
  }
  .values {
    font-size: 36px;
    gap: 10px;
  }
  .values.average {
    font-size: 64px;
    margin-right: 20px;
  }
  .top-display .grade-badge {
    font-size: 28px;
    padding: 6px 12px;
  }
  .keypad {
    flex: 1;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr) auto;
    gap: 4px;
    padding: 20px;
    background: #050505;
  }
  .key {
    font-size: 32px;
  }
  .key svg {
    width: 36px;
    height: 36px;
  }
  .num-key {
    font-size: 36px;
  }
  .action-key {
    font-size: 32px;
  }
  .comma-key {
    font-size: 40px;
  }
  .bmac-key {
    grid-column: span 2;
  }
  .footer {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    transform: none;
    border-top: 1px solid var(--border-color);
    padding: 10px;
  }
}
