/* Geometry comes from app.js (layout()), which sets the custom properties below from the
   live screen size. That's what lets one page fit the iPhone Duo's narrow cover screen, its
   wide unfolded screen and an ordinary iPhone, and re-fit instantly when it folds or unfolds.
   The defaults here only matter for the first frame. */
:root {
  --s: 1;                 /* scale: 1 = an 86pt key on a 393pt-wide iPhone */
  --key-w: 84px;
  --key-h: 84px;
  --gap-x: 8px;
  --gap-y: 8px;
  --kp-left: 16px;
  --kp-top: 340px;
  --kp-width: 361px;
  --label: 34px;
  --disp-font: 62px;
  --disp-top: 260px;
  --expr-font: 26px;
  --expr-top: 220px;
  --text-left: 16px;
  --text-right: 16px;
  --round: 44px;
  --round-top: 12px;
  --round-left: 16px;
  --round-right: 16px;

  --rs: 1;                /* scale for the top round buttons' icons */
  --cols: 4;

  /* Colours sampled from the iPhone Duo Calculator */
  --orange: #f19837;
  --orange-press: #f9c995;
  --fn: #616161;
  --fn-press: #a5a5a8;
  --num: #353535;
  --num-press: #737373;
  --round-bg: #1f1f1f;
  --grey-text: #8e8e93;
  --rim: rgba(255, 255, 255, 0.07);
  --rim-top: rgba(255, 255, 255, 0.13);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: #fff;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.calc {
  position: fixed;
  inset: 0;
  background: #000;
  touch-action: manipulation;
}
/* Optional blackout when held sideways (off by default on the Duo: unfolded is landscape). */
.calc.blackout { visibility: hidden; }

.safe-probe {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
  cursor: default;
}

button svg {
  display: block;
  pointer-events: none;
  width: calc(var(--w) * var(--s) * 1px);
  height: calc(var(--h) * var(--s) * 1px);
}

/* Top corner buttons */
.round {
  position: absolute;
  top: var(--round-top);
  width: var(--round);
  height: var(--round);
  border-radius: 50%;
  background: var(--round-bg);
  box-shadow: inset 0 1px 0 var(--rim-top), inset 0 0 0 1px var(--rim);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.28s ease-out;
}
.round.left { left: var(--round-left); }
.round.right { right: var(--round-right); }
.round.pressed { transition: none; background: #3a3a3c; }
/* The clock's minute hand is the tell; it swings between 3, 9 and 6 o'clock */
#minuteHand {
  transform-box: view-box;
  transform-origin: 12px 12px;
  transition: transform 0.45s cubic-bezier(0.3, 1.35, 0.5, 1);
}
.round svg {
  width: calc(var(--w) * var(--rs) * 1px);
  height: calc(var(--h) * var(--rs) * 1px);
}


/* Keypad: 4 x 5. Keys are circles when width allows, and stretch into capsules on
   short-and-wide screens like the Duo's, the way iPad and foldable layouts do. */
.keypad {
  position: absolute;
  left: var(--kp-left);
  top: var(--kp-top);
  width: var(--kp-width);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--key-w));
  /* iPhone: 4 x 5 */
  grid-template-areas:
    "bs ac pct div"
    "k7 k8 k9 mul"
    "k4 k5 k6 sub"
    "k1 k2 k3 add"
    "neg k0 dot eq";
  grid-auto-rows: var(--key-h);
  column-gap: var(--gap-x);
  row-gap: var(--gap-y);
}
/* iPhone Duo: 5 x 4 */
.calc.duo .keypad {
  grid-template-areas:
    "k7 k8 k9 bs div"
    "k4 k5 k6 ac mul"
    "k1 k2 k3 pct sub"
    "neg k0 dot eq add";
}
.key[data-key="0"] { grid-area: k0; }
.key[data-key="1"] { grid-area: k1; }
.key[data-key="2"] { grid-area: k2; }
.key[data-key="3"] { grid-area: k3; }
.key[data-key="4"] { grid-area: k4; }
.key[data-key="5"] { grid-area: k5; }
.key[data-key="6"] { grid-area: k6; }
.key[data-key="7"] { grid-area: k7; }
.key[data-key="8"] { grid-area: k8; }
.key[data-key="9"] { grid-area: k9; }
.key[data-key="bs"] { grid-area: bs; }
.key[data-key="clear"] { grid-area: ac; }
.key[data-key="percent"] { grid-area: pct; }
.key[data-key="/"] { grid-area: div; }
.key[data-key="*"] { grid-area: mul; }
.key[data-key="-"] { grid-area: sub; }
.key[data-key="+"] { grid-area: add; }
.key[data-key="="] { grid-area: eq; }
.key[data-key="negate"] { grid-area: neg; }
.key[data-key="."] { grid-area: dot; }

.key {
  width: var(--key-w);
  height: var(--key-h);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--label);
  font-weight: 400;
  line-height: 1;
  color: #fff;
  box-shadow: inset 0 1px 0 var(--rim-top), inset 0 0 0 1px var(--rim);
  transition: background-color 0.28s ease-out;
}
.key.num { background: var(--num); }
.key.fn  { background: var(--fn); }
.key.op  { background: var(--orange); }
.key.pressed { transition: none; }
.key.num.pressed { background: var(--num-press); }
.key.fn.pressed  { background: var(--fn-press); }
.key.op.pressed  { background: var(--orange-press); }
/* A forced digit lights its key, as if pressed */
.key.num.flash { background: var(--num-press); transition: none; }
.key.num[data-key="."].flash { background: var(--num-press); }

/* Indicator specks: with a force number set, a speck on + or − shows which one reaches it, and
   one on a digit key shows how many digits that takes. Each sits just below the key's symbol, a
   little right of centre, with its own spot, size and shape (set in app.js), so it looks like
   dust rather than a mark. Sizes are points on an 84.25pt key, scaled by --ks. */
.key { position: relative; }
.key.speck-on::after {
  content: "";
  position: absolute;
  left: calc(50% + var(--speck-dx, 6.7) * var(--ks, 1) * 1px);
  top: calc(50% + var(--speck-dy, 25.3) * var(--ks, 1) * 1px);
  width: calc(var(--speck-size, 1.6) * max(var(--ks, 1), 0.7) * 1px);
  height: calc(var(--speck-size, 1.6) * max(var(--ks, 1), 0.7) * 1px);
  border-radius: var(--speck-shape, 50%);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 calc(0.5px * var(--ks, 1)) rgba(255, 255, 255, 0.35);
  transform: translate(-50%, -50%) rotate(var(--speck-rot, 0deg));
  pointer-events: none;
}
.key.num:not([data-key="negate"]), .key[data-key="clear"] { padding-bottom: calc(1px * var(--s)); }
.key[data-key="bs"] svg { transform: translateX(calc(-1px * var(--s))); }

/* Grey line: the sum that produced the result */
.expr {
  position: absolute;
  left: var(--text-left);
  right: var(--text-right);
  top: var(--expr-top);
  height: var(--expr-font);
  color: var(--grey-text);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
}
.expr span {
  font-size: var(--expr-font);
  line-height: 1;
  white-space: nowrap;
}

/* Big white line */
.display {
  position: absolute;
  left: var(--text-left);
  right: var(--text-right);
  top: var(--disp-top);
  height: var(--disp-font);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
}
.display-text {
  display: block;
  font-size: var(--disp-font);
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
}
/* Text too long even at 75% runs off the left edge and fades, as on iOS */
.clipped {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 calc(24px * var(--s)));
  mask-image: linear-gradient(to right, transparent, #000 calc(24px * var(--s)));
}
