/* /math-ruler/: the addition slide rule, on top of the app pages' styles. */

.math-ruler-page {
  --mr-a: #1FC8FF;
  --mr-b: #FF2EA6;
  --mr-c: #A1FB00;
  --mr-line: rgb(29 29 31 / .78);
}

.mr-hero { padding: 64px 0 20px; transition: none; }

/* A sticker slapped over the last r: Math Rulez. */
.mr-rulez { position: relative; display: inline-block; }
.mr-z {
  position: absolute;
  left: 50%;
  top: 54%;
  padding: 0 .1em .04em;
  border-radius: .14em;
  background: #fff;
  color: var(--mr-b);
  font-size: .92em;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 .03em 0 rgb(29 29 31 / .12), 0 .06em .16em rgb(0 0 0 / .22);
  transform: translate(-50%, -50%) rotate(-9deg);
  animation: mr-slap .45s cubic-bezier(.2, 1.6, .4, 1) .5s both;
}
/* The sticker's top corner, peeling up a little. */
.mr-z::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: .16em;
  height: .16em;
  border-radius: 0 .14em 0 .06em;
  background: linear-gradient(225deg, var(--accent) 50%, #e4e4e7 50%);
  box-shadow: -.01em .01em .03em rgb(0 0 0 / .2);
}
@keyframes mr-slap {
  from { opacity: 0; transform: translate(-50%, -50%) rotate(-35deg) scale(1.9); }
  to { opacity: 1; transform: translate(-50%, -50%) rotate(-9deg) scale(1); }
}

/* The rulers there are, in the hero's colour band. */
.mr-picker {
  width: 100vw;
  margin: -40px 0 32px calc(50% - 50vw);
  padding: 8px 24px 40px;
  box-sizing: border-box;
  background: var(--accent);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 14px;
}
.mr-pick {
  display: inline-block;
  padding: 10px 20px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: rgb(255 255 255 / .55);
  color: var(--ink);
  font: 700 18px/1.2 ui-rounded, -apple-system, BlinkMacSystemFont, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform .2s ease, background-color .2s ease;
}
button.mr-pick:hover { transform: scale(1.04); background: #fff; }
.mr-pick-current, button.mr-pick-current:hover { background: var(--ink); color: #fff; transform: none; cursor: default; }
.mr-pick:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
/* The way into the overview: quieter than the current ruler, with an arrow that hints at more. */
.mr-pick-other { border-color: transparent; background: rgb(255 255 255 / .55); font-weight: 600; }
.mr-pick-other::after { content: " \2192"; }

/* All rulers, grouped */
.mr-dialog.mr-overview { max-width: 560px; }
.mr-group { margin: 18px 0 0; }
.apps main .mr-group h3 { margin: 0; font-size: 17px; font-weight: 700; }
.mr-dialog .mr-group-note { margin: 2px 0 10px; color: var(--muted); font-size: 15px; }
.mr-group-rulers { display: flex; flex-wrap: wrap; gap: 8px; }
.mr-group-rulers .mr-pick { padding: 8px 16px; font-size: 17px; background: var(--surface); border-color: transparent; }
.mr-group-rulers button.mr-pick:hover { background: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.mr-group-rulers .mr-pick-current, .mr-group-rulers button.mr-pick-current:hover { background: var(--ink); color: #fff; }

/* Choosing what to keep when switching rulers */
.mr-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgb(29 29 31 / .45);
  animation: mr-fade .2s ease both;
}
.mr-dialog {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow: auto;
  box-sizing: border-box;
  padding: 28px 24px 20px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 24px 64px rgb(0 0 0 / .3);
  animation: mr-pop .25s cubic-bezier(.2, 1.2, .4, 1) both;
}
.apps main .mr-dialog h2 { font-size: 26px; font-weight: 700; margin: 0 0 6px; }
.mr-dialog p { margin: 0 0 18px; }
.mr-options { display: grid; gap: 8px; }
.mr-option {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  width: 100%;
  padding: 14px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color .15s ease;
}
.mr-option:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.mr-option:disabled { cursor: default; opacity: .55; }
.mr-option-note { flex: none; color: var(--muted); font-size: 14px; font-weight: 600; }
.mr-option:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.mr-option-title { font-weight: 600; }
.mr-option-equation {
  flex: none;
  font: 700 20px/1 ui-rounded, -apple-system, BlinkMacSystemFont, sans-serif;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mr-dialog-cancel {
  display: block;
  margin: 14px auto 0;
  padding: 8px 16px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.mr-dialog-cancel:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 8px; }
@keyframes mr-fade { from { opacity: 0; } }
@keyframes mr-pop { from { opacity: 0; transform: translateY(12px) scale(.97); } }
.apps main .mr-hero h1 { font-size: clamp(40px, 9vw, 72px); font-weight: 700; margin-bottom: 10px; }
.apps main .mr-hero p { margin-bottom: 0; }

.mr-band { padding: 40px 0 72px; }
.mr-mount { min-height: 420px; }
.mr-status { text-align: center; color: var(--muted); padding: 120px 24px; margin: 0; }

/* The ruler runs the full width of the window: its scales have no ends. */
.mr-stage {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.mr-ruler {
  position: relative;
  overflow: hidden;
  background: #fff;
  border-block: 1px solid rgb(0 0 0 / .08);
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

.mr-row { position: relative; }
.mr-readouts { height: 44px; background: var(--surface); }

.mr-scale {
  position: relative;
  height: 76px;
  cursor: grab;
  touch-action: none;
}
.mr-top { background: #fff; box-shadow: inset 0 -2px 0 var(--mr-line); }
.mr-bottom { background: color-mix(in srgb, var(--mr-b) 10%, #fff); }
.mr-dragging .mr-scale, .mr-dragging .mr-frame { cursor: grabbing; }

.mr-frame {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid rgb(0 0 0 / .06);
  cursor: grab;
  touch-action: none;
}
.mr-grip { color: var(--muted); font-size: 14px; font-weight: 600; letter-spacing: .02em; pointer-events: none; }
.mr-grip::before, .mr-grip::after { content: "⟷"; margin: 0 10px; opacity: .6; }

/* Ticks are laid out from each scale's zero; the scale slides by moving this box. */
.mr-ticks { position: absolute; left: 0; top: 0; bottom: 0; width: 0; pointer-events: none; }
.mr-tick { position: absolute; width: 1px; margin-left: -.5px; height: 10px; background: rgb(29 29 31 / .45); }
.mr-tick.mr-half { height: 18px; background: rgb(29 29 31 / .6); }
.mr-tick.mr-major { height: 28px; background: var(--ink); }
.mr-tick.mr-zero { width: 3px; margin-left: -1.5px; height: 40px; }
/* The angles an inverse trig ruler answers with. */
.mr-principal { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--mr-c) 22%, transparent); }
.mr-top .mr-tick { bottom: 0; }
.mr-bottom .mr-tick { top: 0; }
.mr-label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.mr-top .mr-label { bottom: 32px; }
/* The LL0 scale, for numbers below 1, in red like on a real slide rule. */
.mr-below-one .mr-label { color: #C8102E; }
.mr-below-one .mr-tick.mr-major { background: #C8102E; }
.mr-bottom .mr-label { top: 32px; }
.mr-zero .mr-label { font-weight: 800; }
.mr-top .mr-zero .mr-label { bottom: 44px; }
.mr-bottom .mr-zero .mr-label { top: 44px; }
.mr-bottom .mr-tick.mr-zero { background: var(--mr-b); box-shadow: 0 0 0 1px rgb(29 29 31 / .5); }

/* Pins are zero-width columns at a position; their chip centres on it. */
.mr-pin {
  position: absolute;
  left: 0;
  width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.mr-chip {
  /* A fixed box, so every pill is the same height whatever it sits in. */
  flex: none;
  box-sizing: border-box;
  height: 26px;
  padding: 0 10px;
  line-height: 26px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 0 0 1px rgb(29 29 31 / .5);
}
.mr-chip-a { background: var(--mr-a); }
.mr-chip-b { background: var(--mr-b); color: #fff; }
.mr-chip-c { background: var(--mr-c); }

.mr-pin-zero { top: 7px; bottom: -76px; pointer-events: none; z-index: 1; }
.mr-pin-zero::after {
  content: "";
  position: absolute;
  top: 26px;
  bottom: 0;
  border-left: 2px dashed var(--mr-guide);
}
.mr-guide-a { --mr-guide: var(--mr-a); }
/* The lime of C is too light for a thin line on white; darken it. */
.mr-guide-c { --mr-guide: color-mix(in srgb, var(--mr-c) 55%, var(--ink)); }

/* The hairline sits in a cursor of clear plastic that slides over both scales,
   like the glass on a real slide rule. The whole pane is the grab area. */
.mr-hairline {
  --mr-glass-w: 68px;
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--mr-glass-w) / -2);
  width: var(--mr-glass-w);
  z-index: 2;
  cursor: grab;
  touch-action: none;
}
.mr-dragging .mr-hairline { cursor: grabbing; }

/* The pane: a faint tint, a sheen across it, bright edges and a soft shadow underneath. */
.mr-hairline::after {
  content: "";
  position: absolute;
  /* Starts 7px below the C pill and ends 8px above the B pill. */
  inset: 40px 0 44px;
  border-radius: 12px;
  background:
    linear-gradient(100deg, rgb(255 255 255 / .5) 0%, rgb(255 255 255 / .06) 22%, rgb(255 255 255 / 0) 70%, rgb(255 255 255 / .3) 100%),
    rgb(190 225 255 / .14);
  border: 1px solid rgb(255 255 255 / .85);
  box-shadow:
    0 0 0 1px rgb(29 29 31 / .22),
    inset 0 1px 0 rgb(255 255 255 / .95),
    inset 0 -1px 0 rgb(29 29 31 / .08),
    inset 6px 0 10px -8px rgb(255 255 255 / .9),
    0 8px 22px rgb(0 0 0 / .16),
    0 2px 5px rgb(0 0 0 / .1);
  transition: box-shadow .2s ease, transform .2s ease;
}
.mr-hairline:hover::after {
  box-shadow:
    0 0 0 1px rgb(29 29 31 / .3),
    inset 0 1px 0 rgb(255 255 255 / .95),
    inset 0 -1px 0 rgb(29 29 31 / .08),
    inset 6px 0 10px -8px rgb(255 255 255 / .9),
    0 12px 28px rgb(0 0 0 / .2),
    0 3px 7px rgb(0 0 0 / .12);
}
.mr-dragging .mr-hairline::after { transform: translateY(-1px); }

/* The hairline itself, etched into the pane and running out to the chips. */
.mr-hairline::before {
  content: "";
  position: absolute;
  left: calc(50% - 1px);
  top: 0;
  bottom: 0;
  width: 2px;
  background: #d4202a;
  z-index: 1;
}
.mr-hairline .mr-pin { left: 50%; z-index: 2; }
.mr-pin-top { top: 7px; }
.mr-pin-bottom { bottom: 10px; }

.mr-scale:focus-visible, .mr-frame:focus-visible { outline: 3px solid var(--mr-a); outline-offset: -3px; }
.mr-hairline:focus-visible { outline: none; }
.mr-hairline:focus-visible::after { box-shadow: 0 0 0 3px var(--ink), 0 8px 22px rgb(0 0 0 / .16); }

@media (prefers-reduced-motion: reduce) {
  .mr-hairline::after { transition: none; }
  .mr-dragging .mr-hairline::after { transform: none; }
}

/* Zoom */
.mr-tools { display: flex; justify-content: center; gap: 10px; margin: 18px 0 0; }
.mr-tool {
  min-width: 44px;
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: 600 20px/1 ui-rounded, -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  transition: transform .2s ease;
}
.mr-tool-wide { font-size: 15px; }
.mr-tool:hover { transform: scale(1.05); }
.mr-tool:focus-visible { outline: 3px solid var(--mr-a); outline-offset: 2px; }

/* A + B = C */
.mr-equation {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 4px clamp(10px, 2.5vw, 24px);
  margin: 48px auto 0;
  padding: 0 24px;
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: clamp(34px, 7vw, 80px);
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}
.mr-op { color: var(--muted); font-weight: 500; padding-bottom: .12em; }

/* A²: the 2 rides high next to A. */
.mr-power { display: flex; align-items: flex-start; }
.mr-exponent {
  margin: calc(15px + 6px - .05em) 0 0 .04em; /* below the field name, level with the top of the digits */
  color: var(--muted);
  font-size: .5em;
  font-weight: 700;
  line-height: 1;
}
/* √A: the radical sign in front of A. */
.mr-root { display: flex; align-items: flex-end; gap: .04em; }
.mr-radical { color: var(--muted); font-weight: 500; line-height: 1; padding-bottom: .12em; }
/* 10ᴬ: A raised and smaller, as an exponent, but still an input you can type in. */
.mr-exp { display: flex; align-items: flex-start; }
.mr-base { align-self: flex-end; padding-bottom: .06em; }
.mr-exp-field { font-size: .5em; margin: -.5em 0 0 .04em; } /* lifted so its digits start level with the top of 10 */
/* Aᴮ: the exponent rides at the top of A's digits. */
.mr-exp-of-field { margin-top: calc(15px + 6px - .5em); }
/* ᴮ√A: B small and raised before the root sign. */
.mr-root-index { font-size: .5em; align-self: flex-start; margin: calc((15px + 6px) * 2 - .55em) -.3em 0 0; }
/* log_B A: the base sits small and low after "log". */
.mr-sub-field { font-size: .5em; align-self: flex-end; margin: 0 .12em -.35em 0; }
/* C rad: the unit after the value, small. */
.mr-unit { color: var(--muted); font-size: .45em; font-weight: 600; padding: 0 0 .25em .2em; }

/* log A: the function name in front of A, a little smaller than the numbers. */
.mr-function { color: var(--muted); font-size: .6em; font-weight: 600; line-height: 1; padding: 0 .12em .3em 0; }
/* sin A°: the degree sign rides high after the angle, level with the top of its digits. */
.mr-degree { align-self: flex-start; margin: calc(15px + 6px) 0 0 -.12em; color: var(--muted); font-weight: 500; line-height: 1; }
.mr-field { display: flex; flex-direction: column; align-items: center; }
.mr-field-name { font-size: 15px; font-weight: 700; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.mr-field input {
  field-sizing: content;
  min-width: 1ch;
  max-width: 9ch;
  padding: 0 .08em .06em;
  border: 0;
  border-bottom: .07em solid var(--accent-field);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: center;
}
.mr-field input:focus { outline: none; background: color-mix(in srgb, var(--accent-field) 18%, transparent); }
/* A number the scales can't show, like 0 on a log scale. */
.mr-field-rejected input { color: #c4161c; text-decoration: underline wavy #c4161c .04em; text-underline-offset: .12em; }
.mr-hint { min-height: 1.5em; margin: 14px 24px 0; text-align: center; color: #c4161c; font-weight: 600; }
.mr-field-a { --accent-field: var(--mr-a); }
.mr-field-b { --accent-field: var(--mr-b); }
.mr-field-c { --accent-field: var(--mr-c); }

/* How it works */
.mr-help { margin-top: 64px; }
.mr-reading { max-width: 36em; margin: 0 auto 32px; text-align: center; font-size: 18px; }
.mr-tips { margin-top: 8px; }
.mr-how { display: grid; grid-template-columns: repeat(4, 1fr); gap: 28px; }
.mr-how p { margin: 0; }
.mr-tip { margin: 32px 0 0; text-align: center; }

@media (max-width: 800px) {
  .mr-how { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .mr-how { grid-template-columns: 1fr; gap: 20px; }
  .mr-grip { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .mr-tool, .mr-pick, .mr-option { transition: none; }
  .mr-z, .mr-dialog, .mr-dialog-backdrop { animation: none; }
}
