:root {
  --page: #0f1216;
  --body: #1b1f25;
  --body-hi: #262b33;
  --bezel: #0b0d10;
  --key-fn: #2e343d;
  --key-fn-hi: #3a414c;
  --key-num: #e8eaee;
  --key-num-hi: #ffffff;
  --key-op: #4b535f;
  --key-top: #c9ced6;
  --second: #3b7ddd;
  --alpha: #2e9d58;
  --second-label: #6aa8ff;
  --alpha-label: #63d38f;
  --ink: #f3f4f6;
}

@font-face {
  font-family: "CalcMono";
  src: url("../fonts/calc-mono.woff2") format("woff2");
  font-weight: 100 900;
  font-display: block;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: #c9ced6;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: max(10px, env(safe-area-inset-top)) 10px 24px;
}

.calc {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--body-hi), var(--body) 30%);
  border-radius: 26px 26px 34px 34px;
  padding: 12px 12px 16px;
  box-shadow: 0 1px 0 #3a414c inset, 0 20px 50px rgba(0, 0, 0, .55);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 8px 8px;
  font: 600 10px/1 system-ui, sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #8d96a3;
}
.brand .model { font-size: 15px; letter-spacing: .04em; color: #d6dae0; font-weight: 700; }

.bezel {
  background: var(--bezel);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 0 0 1px #000 inset;
}

#screen {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  background: #fff;
  image-rendering: auto;
}

/* ---------------------------------------------------------------- keys */

.keys {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  column-gap: 7px;
  row-gap: 3px;
  /* Key height: whatever is left of the viewport after the screen. */
  --kh: clamp(24px, calc((100dvh - min(0.75 * (100vw - 64px), 282px) - 262px) / 9.8), 38px);
}

.k {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.k .lbl {
  display: flex;
  justify-content: space-between;
  height: 13px;
  font: 600 9.5px/13px system-ui, sans-serif;
  padding: 0 2px;
  white-space: nowrap;
  overflow: visible;
  gap: 2px;
}
.k .lbl .s { color: var(--second-label); letter-spacing: .02em; }
.k .lbl .a { color: var(--alpha-label); }

.k button {
  appearance: none;
  border: 0;
  height: var(--kh);
  width: 100%;
  border-radius: 9px;
  background: var(--key-fn);
  color: var(--ink);
  font: 600 13px/1 system-ui, sans-serif;
  text-transform: lowercase;
  box-shadow: 0 2px 0 #0b0d10, 0 1px 0 rgba(255, 255, 255, .08) inset;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}
.k button:active, .k button.pressed {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #0b0d10;
  filter: brightness(1.18);
}
.k.num button { background: var(--key-num); color: #16191d; font-size: 17px; text-transform: none; box-shadow: 0 2px 0 #7d838c, 0 1px 0 #fff inset; }
.k.op button { background: var(--key-op); font-size: 17px; text-transform: none; }
.k.top button { background: var(--key-top); color: #16191d; height: calc(var(--kh) * .78); border-radius: 12px; font-size: 11.5px; box-shadow: 0 2px 0 #6c727b; }
.k.second button { background: var(--second); font-size: 13px; }
.k.alpha button { background: var(--alpha); font-size: 13px; }
.k.fn button { font-size: 12.5px; }
.k.fn.nolower button { text-transform: none; }
.k.enter button { font-size: 13px; text-transform: lowercase; }
.k.enter .lbl { font-size: 8.5px; gap: 3px; }

/* The arrow pad sits in the two right columns of the 2nd/alpha rows. */
.dpad {
  grid-column: 4 / span 2;
  grid-row: 2 / span 2;
  position: relative;
  align-self: center;
  justify-self: center;
  width: min(100%, calc(var(--kh) * 3.1));
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #1b1f25 0 26%, #2e343d 27% 100%);
  box-shadow: 0 2px 0 #0b0d10, 0 1px 0 rgba(255, 255, 255, .08) inset;
}
.dpad button {
  position: absolute;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  width: 36%;
  height: 36%;
  border-radius: 50%;
}
.dpad button:active, .dpad button.pressed { background: rgba(255, 255, 255, .14); }
.dpad .pad-up { top: 1%; left: 32%; }
.dpad .pad-down { bottom: 1%; left: 32%; }
.dpad .pad-left { left: 1%; top: 32%; }
.dpad .pad-right { right: 1%; top: 32%; }

.k.r2, .k.r3 { grid-column: auto; }

/* ---------------------------------------------------------------- help */

.help {
  max-width: 420px;
  font-size: 12.5px;
  color: #8d96a3;
}
.help p { margin: 0 0 8px; }
.help h2 { margin: 0 0 4px; font-size: 15px; color: #e6e9ee; }
.help .lede { margin-bottom: 10px; }

.demos {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 2px;
}
.demos li { display: block; }
.demos a {
  display: block;
  padding: 7px 10px 2px;
  border-radius: 8px 8px 0 0;
  color: #8ec0ff;
  font-weight: 600;
  font-size: 13.5px;
  text-decoration: none;
  background: #171b21;
}
.demos a:hover, .demos a:focus-visible { background: #1f252e; color: #b5d5ff; outline: none; }
.demos .keys-used, .demos .note {
  display: block;
  padding: 0 10px;
  background: #171b21;
  font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace;
  color: #c9ced6;
}
.demos .note { padding-bottom: 7px; border-radius: 0 0 8px 8px; font-family: inherit; color: #8d96a3; }
.help b { color: #c9ced6; }
.help code, .help kbd {
  font: 12px/1 ui-monospace, Menlo, Consolas, monospace;
  background: #1d2128;
  border: 1px solid #2c323b;
  border-radius: 4px;
  padding: 1px 4px;
  color: #d6dae0;
}

@media (min-width: 900px) {
  .wrap { flex-direction: row; justify-content: center; align-items: flex-start; padding-top: 16px; gap: 32px; }
  .help { margin-top: 60px; max-width: 300px; }
  .keys { --kh: clamp(24px, calc((100dvh - 282px - 290px) / 9.8), 38px); }
}

