.calc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 25rem);
  grid-template-areas: "intro calc" "history calc";
  grid-template-rows: auto 1fr;
  gap: 2rem clamp(2rem, 7vw, 7rem);
  max-width: 68rem; margin: 1.5rem auto 0;
}
.calc-intro { grid-area: intro; }
.calc { grid-area: calc; }
.history { grid-area: history; align-self: start; }

.calc {
  align-self: start; padding: 1.1rem; border-radius: 1.8rem; background: var(--ink); color: var(--mist);
}

.calc-display { padding: 0.9rem 0.7rem 1.1rem; text-align: right; }
.calc-expr {
  min-height: 1.6em; overflow-x: auto; white-space: nowrap; scrollbar-width: none;
  font-family: var(--display); font-variation-settings: "wdth" 100, "wght" 420; font-size: 1.05rem; opacity: 0.7;
}
.calc-expr::-webkit-scrollbar { display: none; }
.calc-result {
  margin-top: 0.3rem; overflow-x: auto; white-space: nowrap; scrollbar-width: none;
  font-family: var(--display); font-variation-settings: "wdth" 104, "wght" 720;
  font-size: clamp(2.8rem, 9vw, 3.8rem); line-height: 1.1; letter-spacing: -0.03em;
}
.calc-result::-webkit-scrollbar { display: none; }
.calc-result[data-size="md"] { font-size: clamp(2.2rem, 7vw, 3rem); }
.calc-result[data-size="sm"] { font-size: clamp(1.7rem, 5.5vw, 2.3rem); }
.calc-result.is-error { color: var(--sun); font-size: 1.5rem; font-variation-settings: "wdth" 100, "wght" 600; letter-spacing: 0; padding-block: 0.6rem; }

.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.key {
  display: grid; place-items: center; height: 4.2rem; border-radius: 999px;
  background: var(--mist); color: var(--ink);
  font-family: var(--display); font-variation-settings: "wdth" 105, "wght" 640; font-size: 1.5rem;
  transition: transform 0.12s, background 0.2s, color 0.2s;
}
.key:hover { background: #fff; }
.key:active, .key.is-pressed { transform: scale(0.93); }
.key-fn { background: #2b2270; color: var(--mist); }
.key-fn:hover { background: #3a2f8f; }
.key-op { background: var(--sun); color: var(--ink); }
.key-op:hover { background: #ffe066; }
.key-eq { background: var(--cobalt); color: #fff; }
.key-eq:hover { background: #4a53ff; }
.key-zero { grid-column: span 2; place-items: center start; padding-left: 1.75rem; }
/* The operator symbols are small glyphs in this font, so they get more size than the digits */
.key-op, .key-eq, .key[data-key="."] { font-size: 2.2rem; font-variation-settings: "wdth" 100, "wght" 500; line-height: 1; }
/* The times sign is drawn, because this font's own is much smaller than its plus and divide */
.key-mul { position: relative; }
.key-mul::before, .key-mul::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 1.25rem; height: 3px; margin: -1.5px 0 0 -0.625rem;
  border-radius: 2px; background: currentColor; transform: rotate(45deg);
}
.key-mul::after { transform: rotate(-45deg); }
.calc :focus-visible { outline-color: var(--sun); }

.history-list { display: grid; gap: 0.5rem; max-width: 26rem; }
.history-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; width: 100%;
  padding: 0.75rem 1rem; text-align: left; border: 2px solid rgb(255 255 255 / 0.35); border-radius: 1rem;
  transition: background 0.2s, border-color 0.2s;
}
.history-item:hover { background: rgb(255 255 255 / 0.14); border-color: #fff; }
.history-expr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-value { flex: none; font-family: var(--display); font-variation-settings: "wdth" 104, "wght" 680; }
.history-empty { max-width: 24rem; opacity: 0.85; }
.history-list:not(:empty) + .history-empty { display: none; }

@media (max-width: 820px) {
  .calc-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "intro" "calc" "history"; grid-template-rows: none; margin-top: 0.5rem; }
  .calc { width: min(100%, 25rem); justify-self: center; }
  .history { width: min(100%, 25rem); justify-self: center; }
  .key { height: 3.9rem; }
}
