:root {
  color-scheme: dark;
  background: #232224;
  color: #faf7ef;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(7px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
    max(7px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 10%, #403d3b 0%, #232224 69%);
}

.calculator {
  width: min(100%, 474px);
  border: 1px solid #716960;
  border-radius: 27px;
  overflow: hidden;
  background: #45423f;
  box-shadow: 0 19px 44px #0006, 0 3px 6px #0006, inset 0 1px 0 #fff2;
}

.face {
  padding: 13px clamp(11px, 4.6vw, 24px) clamp(12px, 4vw, 21px);
  background: linear-gradient(147deg, #2e2e30, #232325 75%);
  border-bottom: 1px solid #121214;
}

.top, .screen-top, .dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top { margin: 0 0 8px 2px; }
h1 { margin: 0; font-size: clamp(22px, 5.8vw, 29px); letter-spacing: -.045em; font-weight: 760; }
h1 span { color: #efaa75; font-variant-numeric: tabular-nums; }

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 1px solid #242120;
  border-radius: 9px;
  background: linear-gradient(155deg, #55504c, #3c3938);
}

button:focus-visible { outline: 2px solid #ffe6bd; outline-offset: 2px; position: relative; z-index: 1; }
button:active { filter: brightness(1.17); transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }

.help, .dialog-head button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: #f0e6d9;
  font-size: 19px;
  font-weight: 650;
  border-color: #79716a;
  background: #353333;
}

.screen {
  background: linear-gradient(165deg, #b2b8ae, #d2d8ca 82%);
  color: #212c25;
  border: 1px solid #151a17;
  border-radius: 12px;
  padding: 8px 11px 10px;
  min-height: clamp(94px, 15svh, 128px);
  display: grid;
  align-content: space-between;
  box-shadow: inset 0 2px 7px #28332955, 0 1px 0 #ffffff20;
}

.screen-top { height: 17px; font: 750 11px/1 ui-monospace, monospace; }
.indicators { display: flex; gap: 9px; }
.indicators span { padding: 2px 3px; color: #405247; visibility: hidden; }
.indicators span.active { visibility: visible; }
.indicators #error.active { color: #792920; }
#operator { padding-right: 2px; font-size: 14px; }
.reading { text-align: right; min-width: 0; }
.expression {
  height: 19px;
  line-height: 19px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: #34463b;
}

output {
  display: block;
  white-space: nowrap;
  font: 670 clamp(46px, 15.2vw, 73px)/1.04 ui-monospace, 'SF Mono', Consolas, monospace;
  letter-spacing: -.085em;
  padding-right: .09em;
}

.keys { padding: clamp(9px, 2.8vw, 17px) clamp(7px, 3vw, 17px) clamp(10px, 3vw, 17px); }
.functions, .editing, .numbers { display: grid; gap: clamp(5px, 1.55vw, 9px); }
.functions { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.functions, .editing { margin-bottom: clamp(8px, 2vw, 11px); }
.editing { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.functions.extra {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: clamp(8px, 2.1vw, 12px) 0 0;
}
.keys button {
  min-width: 0;
  padding: 0 1px;
  box-shadow: inset 0 1px 0 #ffffff2d, 0 2px 0 #201e1d, 0 3px 4px #0003;
}
.functions button { min-height: 44px; font-size: clamp(11px, 3.25vw, 16px); font-weight: 710; }
.functions.extra button { background: #3c3a39; color: #eee1d4; }
.editing button { min-height: 44px; font-size: clamp(17px, 5.1vw, 23px); font-weight: 700; }
.numbers {
  grid-template-columns: repeat(3, minmax(0, 1.23fr)) repeat(2, minmax(0, .96fr));
  grid-auto-rows: clamp(48px, 8.8svh, 77px);
}
.numbers button { font-size: clamp(26px, 7.4vw, 35px); font-weight: 620; font-variant-numeric: tabular-nums; }
.numbers .digit {
  color: #292521;
  font-size: clamp(29px, 9.5vw, 43px);
  background: linear-gradient(155deg, #dbd2be, #bdb19a);
  border-color: #6c6252;
  box-shadow: inset 0 1px 0 #fff8, 0 2px 0 #25211e, 0 3px 4px #0003;
}
.numbers .compact { font-size: clamp(20px, 6.25vw, 30px); letter-spacing: -.055em; }
.numbers .op { color: #fffbf3; }
.numbers .selected { background: #6c5648; border-color: #f8ba8c; }
.editing .clear {
  color: #2b160c;
  background: linear-gradient(155deg, #ffb570, #ed8945);
  border-color: #774522;
  font-weight: 760;
}
.numbers .tall, .numbers .equals { grid-row: span 2; font-size: clamp(30px, 8.8vw, 41px); }
.numbers .equals { background: #272628; color: #ffd1ae; border-color: #191719; }
.calculator.asleep .screen { background: #a7afa0; }

dialog {
  width: min(calc(100% - 26px), 440px);
  max-height: 83vh;
  max-height: 83svh;
  border: 1px solid #70665d;
  border-radius: 19px;
  background: #302d2c;
  color: #faf7ef;
  padding: 18px;
}

dialog::backdrop { background: #000a; }
.dialog-head h2 { font-size: 20px; margin: 0; }
dt { margin-top: 14px; font-weight: 700; color: #ffd0a9; }
dd { margin: 4px 0 0; font-size: 14px; line-height: 1.45; color: #eee5db; }
dl { margin: 0 0 4px; }

@media (max-width: 510px) and (max-height: 700px) {
  .face { padding-top: 6px; padding-bottom: 10px; }
  .top { margin-bottom: 4px; }
  .screen { min-height: 82px; padding: 5px 9px 7px; }
  .keys { padding-top: 7px; }
  .functions, .editing { margin-bottom: 6px; }
  .functions.extra { margin-top: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  button:active { transform: none; }
}
