Kentucky public school teachers earn a TRS pension instead of Social Security for their classroom years. Full Credit shows what that pension is worth, compares staying with leaving for other work at the same stop age, prices the three choices for a TRS account, and finds the monthly saving that covers the rest. It works offline with no account or key and sends nothing anywhere. Rules are listed with sources and review dates. For education only, not advice.
<!-- Copyright (c) 2026 Noah Emery and Noah Crider. Released under the MIT License. -->
<!--
Full Credit KY: a retirement planning page for Kentucky public school teachers.
One self-contained file. It makes no network requests and keeps your numbers on your device.
Third-party libraries in this file: none.
Fonts: the device's own system fonts. Icons and charts: inline SVG drawn for this page.
The calculation engine (calc.js) is the authors' own work and is included below unchanged.
The full MIT License text is in the About dialog.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'">
<title>Full Credit: Kentucky Teacher Pension Planner</title>
<meta name="description" content="See what a Kentucky Teachers' Retirement System pension pays at each retirement age, what changes if you leave teaching, and how to cover the rest. For education only.">
<meta name="theme-color" content="#ffffff">
<meta name="color-scheme" content="light">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%2314171a'/%3E%3Cpath d='M9 16.5l4.5 4.5L23 11' fill='none' stroke='%23fff' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E">
<style>
/* ===== Tokens ===== */
:root {
/* A composition notebook on a desk: ink, paper, desk gray and one yellow ruler. */
--bg: #e9ece8; /* the desk */
--surface: #e9ece8; /* quiet fills on paper: hover, readouts */
--card: #ffffff; /* paper */
--ink: #14171a;
--ink-soft: #2b3137; /* an ink button under the pointer */
--muted: #56605a;
--focus: #2f6db5;
--line: #d3d8d2;
--edge: #6b746e;
--ruler: #f2c649;
--ruler-edge: #cf9f26;
--ruler-ink: #3b2f12;
/* One color each, everywhere: pension, Social Security, savings. */
--pension: #1f7a4d;
--pension-soft: #9ac3af;
--ss: #2f6db5;
--ss-soft: #d3e1f1;
--savings: #b98300;
--grid: #e4e8e3;
--axis: #b9c0b9;
/* The fill of a heads-up, reserved for things that cannot be undone. Gray and ink: yellow belongs to the ruler, gold to savings. */
--caution-soft: #f4f6f3;
--gut: 12px;
--r-sm: 6px;
--r-md: 8px;
--r-lg: 10px;
/* Serif for the name, big numbers, headings and summary values. System sans for everything else. Nothing is downloaded. */
--display: "Century Schoolbook", "New Century Schoolbook", "Century Schoolbook L", C059, "Iowan Old Style", Charter, "Palatino Linotype", Palatino, Georgia, serif;
--font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
/* Headings step down by about 1.3 on a laptop and 1.2 on a phone: h1, h2, then the 20px card titles. */
--t-h1: clamp(28px, 1.3vw + 22px, 40px);
--t-h2: clamp(24px, 0.6vw + 21.5px, 30px);
--ease: cubic-bezier(.2, .8, .2, 1);
--t-result: clamp(17.5px, 0.45vw + 15.8px, 21px);
}
@media (min-width: 861px) { :root { --gut: 20px; } }
/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: auto; }
html, body { margin: 0; }
body {
font-family: var(--font);
font-size: 16px;
line-height: 1.6;
color: var(--ink);
background: var(--bg);
-webkit-font-smoothing: antialiased;
overflow-wrap: break-word;
}
h1, h2, h3, h4, p, ul, ol, dl, dd, figure, table, fieldset, legend { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
strong, b { font-weight: 600; }
svg { display: block; }
[hidden] { display: none !important; }
.wrap { width: min(100% - 2 * var(--gut), 1220px); margin-inline: auto; }
.sr {
position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
clip-path: inset(50%); white-space: nowrap; border: 0;
}
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
:focus:not(:focus-visible) { outline: none; }
h2[tabindex="-1"]:focus-visible, main:focus-visible { outline: none; }
h1, h2, h3, h4, .result, .chart__title { text-wrap: balance; }
h1, h2, h3, h4, .chart__title { font-family: var(--display); font-variant-numeric: lining-nums; }
p, li, dd { text-wrap: pretty; }
.skip {
position: absolute; left: 16px; top: -64px; z-index: 30; padding: 10px 16px; border-radius: var(--r-sm);
background: var(--ink); color: #fff; font-weight: 600; text-decoration: none;
}
.skip:focus { top: 12px; outline-color: #fff; outline-offset: -4px; }
/* ===== Buttons ===== */
.btn {
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
min-height: 44px; padding: 0 24px; border: 1px solid transparent; border-radius: var(--r-sm);
background: transparent; color: var(--ink); font-size: 16px; font-weight: 600; line-height: 1.2;
text-decoration: none; white-space: nowrap;
transition: background-color .12s var(--ease), border-color .12s var(--ease), color .12s var(--ease), transform .09s var(--ease);
}
@media (hover: hover) and (pointer: fine) { .btn:hover:not([disabled]) { transform: translateY(-1px); } }
.btn:active:not([disabled]) { transform: translateY(1px) scale(.985); }
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover { background: var(--ink-soft); }
.btn--secondary { background: var(--card); border-color: var(--ink); }
.btn--secondary:hover { background: var(--surface); }
.btn--quiet { padding: 0 12px; }
.btn--quiet:hover { background: var(--surface); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn svg { width: 18px; height: 18px; flex: none; }
.linkbtn {
display: inline; padding: 0; border: 0; background: none; color: var(--ink); font-weight: 600;
text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.linkbtn:hover { text-decoration-thickness: 2px; }
/* ===== Scripts off: shown only when the page cannot run, such as in a phone's file preview ===== */
.noscript { padding-block: 20px 4px; }
.noscript__box {
max-width: 640px; padding: 18px 20px; background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-lg);
font-size: 17px; line-height: 1.5; color: var(--ink);
}
.noscript__box strong { display: block; margin-bottom: 4px; font: 700 21px/1.25 var(--display); }
/* ===== Top line: the for-education notice and the file buttons ===== */
.bar { background: var(--card); border-bottom: 1px solid var(--line); }
.bar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.bar__note { font-size: 13px; line-height: 1.35; color: var(--muted); }
.bar__note strong { color: var(--ink); }
.bar__full { display: none; }
.bar__nav { display: flex; align-items: center; gap: 2px; flex: none; }
.barbtn {
display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border: 0; border-radius: var(--r-sm);
background: none; font-size: 14px; font-weight: 600; line-height: 1.2; white-space: nowrap; transition: background-color .12s var(--ease);
}
.barbtn:hover, .barbtn[aria-expanded="true"] { background: var(--surface); }
.bar__more { position: relative; display: none; }
.bar__menu {
position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; display: grid; gap: 2px; min-width: 200px; padding: 6px;
background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: 0 12px 24px -14px rgba(20, 23, 26, .55);
}
.bar__menu .barbtn { justify-content: flex-start; min-height: 44px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.tag {
display: inline-block; padding: 1px 9px; border: 1px solid var(--ink); border-radius: 999px;
font-size: 12.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; background: var(--card);
}
/* ===== The book: a composition cover on the left, the first page on the right ===== */
.book {
display: grid; grid-template-columns: minmax(0, 9fr) minmax(0, 11fr); margin-top: 14px; background: var(--card); border-radius: var(--r-lg);
overflow: hidden; box-shadow: 0 1px 0 rgba(20, 23, 26, .1), 0 14px 26px -20px rgba(20, 23, 26, .55);
}
.cover { position: relative; display: grid; align-items: center; padding: 34px 34px 34px 56px; background: #17191b; min-height: 344px; }
.cover .marble { position: absolute; inset: 0; width: 100%; height: 100%; }
.cover::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 22px; background: #0d0e10; z-index: 1; box-shadow: 1px 0 0 rgba(255, 255, 255, .14); }
.plate {
position: relative; background: #fdfdfb; border: 2px solid var(--ink); border-radius: 14px; padding: 22px 26px 18px;
box-shadow: 0 0 0 5px #fdfdfb, 0 0 0 6.5px var(--ink);
}
.plate h1 { margin-bottom: 10px; font: 700 clamp(38px, 4vw, 58px)/1 var(--display); letter-spacing: -.01em; }
.plate__lede { font-size: 17.5px; line-height: 1.4; }
.plate__for { margin-top: 14px; padding-top: 11px; border-top: 1.5px solid var(--ink); font: italic 16px/1.35 var(--display); }
.page { display: flex; flex-direction: column; padding: 16px 32px 24px; min-width: 0; }
.example { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 8px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.example button {
min-height: 28px; padding: 3px 9px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--card);
font-size: 13px; font-weight: 600; color: var(--ink); transition: border-color .12s var(--ease);
}
.example button:hover { border-color: var(--ink); }
.filestatus { margin-bottom: 8px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.filestatus:empty { display: none; }
.answer__line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.answer__num { font: 700 clamp(46px, 5.6vw, 78px)/1 var(--display); font-variant-numeric: lining-nums tabular-nums; letter-spacing: -.01em; }
.answer__unit { font-size: 18px; color: var(--muted); }
.answer__prompt { font: 700 clamp(26px, 2.7vw, 36px)/1.15 var(--display); letter-spacing: -.005em; max-width: 18em; text-wrap: balance; }
.say { margin-top: 8px; font-size: 17.5px; line-height: 1.4; max-width: 56ch; }
.say strong { font-weight: 600; }
.next { margin-top: 6px; font-size: 15px; }
/* Stay beside leave: two small cards under the ruler. The amount is set like the big number, smaller.
The marker's age tab hangs 6px below the ruler's block, so the cards start 16px down to stand 10px clear of it. */
.paths { margin-top: 16px; }
.paths__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.path { min-width: 0; padding: 9px 14px 11px; border: 1px solid var(--line); border-radius: var(--r-md); }
.path__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 8px; }
.path__head h2 { font: 600 14px/1.4 var(--font); }
.path__big { margin-top: 1px; font-size: 14px; line-height: 1.3; color: var(--muted); }
.path__big b { font: 700 24px/1.15 var(--display); font-variant-numeric: lining-nums tabular-nums; color: var(--ink); }
.path__line { margin-top: 3px; font-size: 13.5px; line-height: 1.4; }
.path__big + .path__line { margin-top: 2px; }
.paths__go { margin-top: 6px; font-size: 14.5px; }
/* Side by side on a phone the cards are narrow, so the amount takes a line of its own and "a month from 67" stays whole under it. */
@media (max-width: 639px) {
.path { padding: 8px 12px 10px; }
.path__big b { display: block; }
}
@media (max-width: 359px) { .paths__grid { grid-template-columns: minmax(0, 1fr); } }
/* The ruler is the control: slide the marker to the age you stop teaching. */
.pick { --thumb: 30px; margin-top: auto; padding: 14px 0 20px; }
@media (pointer: coarse) { .pick { --thumb: 44px; } }
.pick label { display: block; font-size: 13px; line-height: 1.45; color: var(--muted); margin-bottom: 33px; }
.ruler {
position: relative; height: 56px; border-radius: 3px; border: 1px solid var(--ruler-edge);
background: linear-gradient(#f7d368, var(--ruler) 55%, #e8b838); box-shadow: 0 2px 0 rgba(20, 23, 26, .1);
}
.ruler__ticks, .ruler__flags, .ruler__tabs { position: absolute; left: calc(var(--thumb) / 2); right: calc(var(--thumb) / 2); }
.ruler__ticks { top: 0; bottom: 0; display: flex; justify-content: space-between; }
.ruler__ticks i { position: relative; width: 0; }
.ruler__ticks i::before { content: ""; position: absolute; left: -.5px; top: 0; width: 1px; height: 9px; background: var(--ruler-ink); opacity: .8; }
.ruler__ticks i.five::before { left: -.75px; width: 1.5px; height: 17px; opacity: 1; }
.ruler__ticks i span { position: absolute; top: 22px; left: 0; transform: translateX(-50%); font: 700 13px/1 var(--font); color: var(--ruler-ink); font-variant-numeric: lining-nums tabular-nums; }
.ruler__flags { bottom: 100%; height: 28px; }
/* A flag stands at the age a service milestone is reached. Its words may slide sideways to stay on the ruler; its mark does not.
The words sit 15px above the ruler: the marker stands 8px proud of it and its focus ring 5px more, and neither may touch them. */
.flag { position: absolute; bottom: 0; width: 0; height: 100%; }
.flag::after { content: ""; position: absolute; left: -.5px; bottom: 0; width: 1px; height: 12px; background: var(--ink); }
.flag b { position: absolute; left: 0; bottom: 15px; transform: translateX(calc(-50% + var(--shift, 0px))); font: 600 12px/1 var(--font); white-space: nowrap; }
/* The marker's foot: an ink tab with the chosen age, hanging under the ruler where no tick number or flag can be covered. */
.ruler__tabs { top: 100%; height: 0; pointer-events: none; z-index: 1; } /* above the marker's focus ring, which would clip the age */
.ruler__tab {
position: absolute; top: 7px; left: 50%; transform: translateX(-50%); display: grid; place-items: center; width: var(--thumb); height: 19px;
border-radius: 0 0 6px 6px; background: var(--ink); color: #fff; font: 700 13px/1 var(--font); font-variant-numeric: lining-nums tabular-nums;
}
.ruler input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: ew-resize; touch-action: pan-y; }
.ruler input::-webkit-slider-runnable-track { height: 100%; background: transparent; }
.ruler input::-webkit-slider-thumb {
-webkit-appearance: none; appearance: none; width: var(--thumb); height: 72px; margin-top: -9px; border: 2px solid var(--ink); border-radius: 6px;
background: linear-gradient(90deg, transparent calc(50% - 1px), var(--ink) calc(50% - 1px), var(--ink) calc(50% + 1px), transparent calc(50% + 1px)), rgba(255, 255, 255, .26);
box-shadow: 0 2px 5px rgba(20, 23, 26, .3);
}
.ruler input::-moz-range-track { height: 100%; background: transparent; }
.ruler input::-moz-range-thumb {
width: calc(var(--thumb) - 4px); height: 68px; border: 2px solid var(--ink); border-radius: 6px;
background: linear-gradient(90deg, transparent calc(50% - 1px), var(--ink) calc(50% - 1px), var(--ink) calc(50% + 1px), transparent calc(50% + 1px)), rgba(255, 255, 255, .26);
box-shadow: 0 2px 5px rgba(20, 23, 26, .3);
}
/* The focus ring goes round the marker: a white gap, then 3px of blue. */
.ruler input:focus-visible { outline: none; }
.ruler input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px #fff, 0 0 0 5px var(--focus); }
.ruler input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px #fff, 0 0 0 5px var(--focus); }
/* ===== Summary strip (stays visible) ===== */
/* The bar is 6px taller than it looks when stuck: it rests 6px above the window's top edge, so the strip keeps a thin margin. */
.stripbar { position: sticky; top: -6px; z-index: 5; padding: 12px 0 6px; background: var(--bg); }
.strip { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.strip__cap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 34px; padding: 3px 6px 3px 16px; border-bottom: 1px solid var(--line); }
.strip__capr { display: flex; align-items: center; gap: 8px; flex: none; }
.strip__unit { font-size: 13px; color: var(--muted); line-height: 1.35; min-width: 0; }
.strip__tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tile { display: flex; flex-direction: column; min-width: 0; padding: 8px 16px 10px; border-left: 1px solid var(--line); }
.tile:first-child { border-left: 0; }
.tile__label { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.tile__value { margin-top: 2px; font: 700 26px/1.15 var(--display); font-variant-numeric: lining-nums tabular-nums; white-space: nowrap; }
.tile__note { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.sw { width: 11px; height: 11px; flex: none; border-radius: 2px; overflow: hidden; }
.seg { display: inline-flex; border: 1px solid var(--edge); border-radius: var(--r-sm); overflow: hidden; background: var(--card); width: max-content; }
.seg label { position: relative; display: inline-flex; align-items: center; justify-content: center; min-height: 32px; padding: 0 12px; font-size: 14px; font-weight: 600; cursor: pointer; }
.seg label + label { border-left: 1px solid var(--edge); }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--ink); color: #fff; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: -4px; }
.seg label:has(input:checked:focus-visible) { outline-color: #fff; box-shadow: inset 0 0 0 1px var(--focus); }
.seg label:has(input:disabled) { color: var(--muted); cursor: not-allowed; }
.strip .seg label { min-height: 26px; padding: 0 10px; font-size: 13px; }
/* ===== Steps ===== */
.steps { margin-top: 6px; }
.steps ol { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stepbtn {
display: flex; align-items: center; gap: 10px; width: 100%; min-height: 46px; padding: 9px 14px; text-align: left;
border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); font-size: 15px; font-weight: 600; line-height: 1.25;
transition: border-color .12s var(--ease);
}
.stepbtn:hover { border-color: var(--ink); }
.stepbtn__n { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border: 1.5px solid currentColor; border-radius: 50%; font-size: 13.5px; }
.stepbtn[aria-current="step"] { background: var(--ink); border-color: var(--ink); color: #fff; }
@media (max-width: 860px) {
.bar .wrap { flex-wrap: wrap; padding-top: 5px; padding-bottom: 2px; gap: 0 8px; }
.bar__note { font-size: 12px; line-height: 1.3; flex: 1 1 100%; }
.bar__nav { margin-left: -8px; }
.barbtn { padding: 0 8px; min-height: 34px; font-size: 13.5px; }
.bar__wide { display: none; }
.bar__more { display: block; }
.book { grid-template-columns: minmax(0, 1fr); margin-top: 8px; }
.cover { padding: 12px 16px 12px 36px; min-height: 0; }
.cover::before { width: 16px; }
.plate { padding: 12px 15px 11px; border-radius: 11px; box-shadow: 0 0 0 4px #fdfdfb, 0 0 0 5.5px var(--ink); }
.plate h1 { font-size: 33px; margin-bottom: 6px; }
.plate__lede { font-size: 15px; line-height: 1.35; }
.plate__for { font-size: 14px; margin-top: 8px; padding-top: 7px; }
.page { padding: 10px 14px 14px; }
.example { margin-bottom: 6px; font-size: 12.5px; }
.example span { flex: 1 1 100%; }
.filestatus { margin-bottom: 6px; font-size: 12.5px; }
.answer__num { font-size: 44px; }
.answer__unit { font-size: 16px; }
.say { font-size: 16px; margin-top: 4px; }
.next { font-size: 14.5px; }
.pick { padding-top: 6px; }
.pick label { margin-bottom: 32px; line-height: 1.4; }
.stripbar { padding-top: 8px; }
.strip__cap { padding-left: 12px; }
.strip__unit { font-size: 12.5px; }
.strip__tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.tile { grid-column: span 2; padding: 6px 12px 7px; }
.tile--wide { grid-column: span 3; border-top: 1px solid var(--line); }
.tile--wide:not(.tile--left) { border-left: 0; }
.tile__label { font-size: 12.5px; gap: 5px; }
.tile__value { font-size: 21px; }
.tile__note { font-size: 12px; line-height: 1.3; }
.tile--left .tile__value { white-space: normal; }
.steps ol { grid-template-columns: minmax(0, 1fr); gap: 6px; }
}
/* On a phone the strip stays small enough to keep at the top of the screen: the lines under each amount are left out,
all but the one under Left To Plan For. That amount is for one age, and its line gives the amount at the other ages
checked, so the summary does not read as Target minus the rest. */
@media (max-width: 639px) {
.strip__capr .tag, .tile__note, .strip__in { display: none; }
.tile--left .tile__note { display: block; }
.strip .seg label { min-height: 28px; }
.tile { padding: 5px 10px 6px; }
.tile:first-child, .tile--wide:not(.tile--left) { padding-left: 12px; }
/* On a phone narrower than about 375 "Social Security" does not fit one line of its third. It takes two, and the amounts stay level. */
.tile__label { white-space: normal; align-items: flex-start; gap: 4px; }
.tile__label .sw { margin-top: 3px; }
.tile__value { margin-top: auto; padding-top: 2px; }
/* Target and Left To Plan For share a row. Their amounts sit right under their labels, so the two stay level with a line under only one. */
.tile--wide .tile__value { margin-top: 0; }
}
/* A phone first screen: the Stay and Leave amounts sit above the fold, under the whole ruler. Below 480 wide the
spacing from the top line to the cards is trimmed (no text gets smaller), and each card opens on its title alone,
with the amount under it and the detail lines below. The example banner just above already says these are
example numbers, so the cards' own Example tags are left out here. The laptop layout does not change. */
@media (max-width: 479px) {
.bar .wrap { padding-top: 3px; padding-bottom: 0; }
.book { margin-top: 4px; }
.cover { padding-top: 8px; padding-bottom: 8px; }
.plate { padding: 9px 15px 8px; }
.plate h1 { margin-bottom: 4px; }
.plate__lede { line-height: 1.3; }
.plate__for { margin-top: 6px; padding-top: 5px; line-height: 1.3; }
.page { padding-top: 6px; }
.example { gap: 4px 10px; margin-bottom: 4px; }
.say { margin-top: 2px; line-height: 1.35; }
.pick { padding-top: 4px; padding-bottom: 0; }
.pick label { margin-bottom: 30px; line-height: 1.3; }
.ruler { height: 48px; }
.ruler input::-webkit-slider-thumb { height: 64px; }
.ruler input::-moz-range-thumb { height: 60px; }
.ruler__ticks i span { top: 19px; }
.paths { margin-top: 30px; }
.path { padding: 6px 10px 8px; }
.path__head .tag { display: none; }
.path__big { margin-top: 0; }
}
/* ===== Step panels ===== */
.step { padding-block: 16px; }
.step__head { margin-bottom: 8px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; }
.step__head h2 { font-size: var(--t-h2); line-height: 1.12; font-weight: 700; letter-spacing: -.01em; }
.eyebrow { font-size: 14px; font-weight: 600; color: var(--muted); width: 100%; }
.step__grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.lead { grid-area: lead; min-width: 0; }
.lead > div:empty { display: none; }
.side { grid-area: form; min-width: 0; display: grid; gap: 16px; align-content: start; align-self: start; }
.numbers { min-width: 0; }
.body { grid-area: body; min-width: 0; display: grid; gap: 24px; align-content: start; }
.aside { grid-area: aside; min-width: 0; display: grid; gap: 24px; align-content: start; }
.stack { min-width: 0; display: grid; gap: 24px; align-content: start; }
.stack > * { min-width: 0; }
.step__grid { grid-template-areas: "lead" "form" "body" "aside"; }
@media (min-width: 1080px) {
.step__grid { grid-template-columns: minmax(0, 1fr) 372px; grid-template-areas: "lead form" "body form" "body aside"; grid-template-rows: auto auto 1fr; gap: 24px 40px; }
}
.result { font-size: var(--t-result); line-height: 1.4; max-width: 36em; }
.result strong { font-weight: 600; }
.result + .result { margin-top: 12px; }
.result-note { margin-top: 12px; font-size: 15px; color: var(--muted); max-width: 44em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; min-width: 0; }
.card > h3, .numbers h3, .card__title { font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -.005em; }
.card > h3 + *, .card__title + * { margin-top: 12px; }
.card h4 { font-size: 17px; font-weight: 700; line-height: 1.3; }
.card p + p, .card p + ul, .card ul + p, .card dl + p, .card p + dl { margin-top: 12px; }
.prose { max-width: 44em; }
.prose p + p { margin-top: 12px; }
.small { font-size: 14px; line-height: 1.5; }
@media (max-width: 639px) { .card { padding: 16px; } }
/* Heads-up: only for things that cannot be undone. A thick ink edge, a pale gray fill, a small warning sign and a bold first line. */
.caution {
display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 4px 10px; padding: 14px 18px 15px 15px;
background: var(--caution-soft); border: 1px solid var(--line); border-left: 3px solid var(--ink); border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.caution svg { width: 20px; height: 20px; margin-top: 1px; grid-row: span 2; }
.caution__title { font-weight: 700; line-height: 1.4; }
.caution p { grid-column: 2; }
.caution p + p { margin-top: 8px; }
/* Facts lists */
.facts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.facts > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: baseline; padding-block: 10px; border-top: 1px solid var(--line); }
.facts > div:first-child { border-top: 0; padding-top: 0; }
.facts dt { font-weight: 400; }
.facts dd { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.facts .facts__sub { grid-column: 1 / -1; font-size: 14px; color: var(--muted); font-weight: 400; text-align: left; }
.facts--stack > div { grid-template-columns: minmax(0, 1fr); }
.facts--stack dd { text-align: left; }
/* Milestones */
.miles li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 2px 12px; padding-block: 10px; border-top: 1px solid var(--line); }
.miles li:first-child { border-top: 0; padding-top: 0; }
.miles svg { width: 24px; height: 24px; grid-row: span 2; }
.miles__when { font-weight: 600; line-height: 1.4; }
.miles__when span { font-weight: 400; color: var(--muted); }
.miles__what { grid-column: 2; font-size: 15px; line-height: 1.5; }
/* ===== Forms ===== */
.numbers { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; align-self: start; }
.numbers > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin: -8px 0; font-family: var(--display); font-size: 20px; font-weight: 700; letter-spacing: -.005em; cursor: pointer; list-style: none; border-radius: var(--r-sm); }
.numbers > summary::-webkit-details-marker { display: none; }
.numbers > summary .chev { width: 20px; height: 20px; flex: none; transition: transform .12s ease; }
.numbers[open] > summary .chev { transform: rotate(180deg); }
.numbers__in { margin-top: 20px; display: grid; gap: 24px; }
@media (min-width: 1080px) {
.numbers > summary { cursor: default; pointer-events: none; }
.numbers > summary .chev { display: none; }
}
.fieldset legend { font-size: 16px; font-weight: 600; line-height: 1.3; margin-bottom: 12px; }
.fieldset__note { font-size: 14px; color: var(--muted); line-height: 1.45; margin: -6px 0 12px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; align-items: start; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--full { grid-column: 1 / -1; }
.field label, .field .label { font-size: 14px; font-weight: 600; line-height: 1.35; }
.hint { font-size: 14px; color: var(--muted); line-height: 1.45; }
.inputbox { display: flex; align-items: center; height: 48px; border: 1px solid var(--edge); border-radius: var(--r-sm); background: #fff; }
.inputbox:hover { border-color: var(--ink); }
.inputbox:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; border-color: var(--ink); }
.inputbox input { flex: 1; min-width: 0; width: 100%; height: 100%; padding: 0 12px; border: 0; background: transparent; outline: 0; font-size: 16px; font-variant-numeric: tabular-nums; border-radius: var(--r-sm); }
.inputbox__pre { padding-left: 12px; margin-right: -6px; color: var(--muted); }
.inputbox__post { padding-right: 12px; margin-left: -6px; color: var(--muted); white-space: nowrap; }
.inputbox.is-invalid { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.select {
height: 48px; width: 100%; padding: 0 36px 0 12px; border: 1px solid var(--edge); border-radius: var(--r-sm);
background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 7.5l5 5 5-5' fill='none' stroke='%2314171a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 10px center / 18px;
font-size: 16px; appearance: none; -webkit-appearance: none;
}
.select:hover { border-color: var(--ink); }
.field__error { font-size: 14px; font-weight: 600; line-height: 1.4; }
.field__error:empty { display: none; }
.field__note { grid-column: 1 / -1; margin-top: -8px; font-size: 14px; line-height: 1.45; }
.field__note:empty { display: none; }
/* A line the page works out to check a typed number against. It never changes the number. */
.field__check { grid-column: 1 / -1; margin-top: -8px; font-size: 14px; color: var(--muted); line-height: 1.45; }
.field__check:empty { display: none; }
.pair { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 8px; }
.more > summary { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 600; cursor: pointer; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; list-style: none; border-radius: 4px; }
.more > summary::-webkit-details-marker { display: none; }
.more > summary::before { content: "+"; display: inline-block; width: 14px; font-weight: 600; text-align: center; }
.more[open] > summary::before { content: "\2212"; }
.more > summary + * { margin-top: 12px; }
/* Choice cards (radio) */
.choices { display: grid; gap: 12px; }
@media (min-width: 720px) { .choices--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.choice { position: relative; display: block; padding: 16px; border: 1px solid var(--edge); border-radius: var(--r-md); background: var(--card); cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice__title { display: flex; align-items: center; gap: 10px; font-weight: 600; line-height: 1.3; }
.choice__title::before { content: ""; width: 18px; height: 18px; flex: none; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.choice:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.choice:has(input:checked) .choice__title::before { background: radial-gradient(circle, var(--ink) 0 4.5px, #fff 5.5px); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice:has(input:disabled) { cursor: not-allowed; background: var(--surface); }
.choice:has(input:disabled) .choice__title { color: var(--muted); }
.choice:has(input:disabled) .choice__title::before { border-color: var(--edge); background: var(--surface); }
.choice__big, .choice__when, .choice__text { display: block; }
.choice__when { margin-top: 2px; font-size: 15px; font-weight: 600; line-height: 1.4; }
.choice__when:empty { display: none; }
.choice__big { margin-top: 10px; font-family: var(--display); font-variant-numeric: lining-nums; font-size: 21px; font-weight: 700; line-height: 1.3; }
.choice__text { margin-top: 4px; font-size: 15px; line-height: 1.5; }
/* What happens if you come back to teaching: a second paragraph in the card it belongs to. */
.choice__back { margin-top: 8px; }
.choice__flag { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; line-height: 1.45; font-weight: 600; }
.choice__flag svg { width: 20px; height: 20px; flex: none; }
/* Inline number stepper (age) */
.agepick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.agepick label { font-weight: 600; }
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--edge); border-radius: var(--r-sm); background: #fff; overflow: hidden; }
.stepper button { width: 44px; min-height: 44px; border: 0; background: #fff; font-size: 20px; font-weight: 600; line-height: 1; transition: background-color .12s ease; }
.stepper button:hover { background: var(--surface); }
.stepper button:focus-visible { outline-offset: -3px; }
.stepper input { width: 60px; border: 0; border-inline: 1px solid var(--edge); text-align: center; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; background: #fff; -moz-appearance: textfield; appearance: textfield; border-radius: 0; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus-visible { outline-offset: -3px; }
/* ===== Charts ===== */
.chart { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; min-width: 0; }
@media (max-width: 639px) { .chart { padding: 16px; } }
.chart__head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 16px; }
.chart__title { font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -.005em; }
.chart__sub { margin-top: 4px; font-size: 14px; color: var(--muted); line-height: 1.45; max-width: 40em; }
.chart__plot { position: relative; min-width: 0; }
.chart__plot svg { width: 100%; height: auto; overflow: visible; }
.chart__plot:focus-visible { outline-offset: 4px; }
.readout { margin-top: 12px; padding: 12px 16px; border-radius: var(--r-sm); background: var(--bg); font-size: 15px; line-height: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 12px; font-size: 14px; line-height: 1.4; }
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.legend svg { width: 14px; height: 14px; flex: none; }
.legend .key-line { width: 18px; }
.tip {
position: absolute; z-index: 4; pointer-events: none; max-width: 250px; padding: 8px 12px; border-radius: var(--r-sm);
background: var(--ink); color: #fff; font-size: 14px; line-height: 1.4; transform: translate(-50%, -100%);
}
.tip strong { display: block; font-size: 16px; font-weight: 600; }
.tview { margin-top: 12px; }
.tview > div { overflow-x: auto; } /* a table wider than a small phone scrolls inside its own box, not the page */
.tview > summary { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 600; cursor: pointer; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; list-style: none; border-radius: 4px; }
.tview > summary::-webkit-details-marker { display: none; }
.tview > summary::before { content: "+"; display: inline-block; width: 14px; text-align: center; }
.tview[open] > summary::before { content: "\2212"; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.4; font-variant-numeric: tabular-nums; }
.table caption { text-align: left; font-size: 14px; color: var(--muted); padding-bottom: 8px; }
.table th, .table td { padding: 8px 8px; border-top: 1px solid var(--line); text-align: right; vertical-align: baseline; }
.table thead th { border-top: 0; font-size: 13px; font-weight: 600; color: var(--muted); vertical-align: bottom; }
.table th:first-child, .table td:first-child { text-align: left; padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table tbody th { font-weight: 400; }
.table tr.is-on > * { font-weight: 700; }
.table tr.is-total > * { font-weight: 600; border-top-color: var(--ink); }
.table--words th, .table--words td { text-align: left; }
.table .agebtn { min-width: 44px; min-height: 32px; padding: 0 8px; border: 1px solid var(--edge); border-radius: 6px; background: #fff; font-weight: 600; }
.table .agebtn[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
@media (max-width: 480px) { .table { font-size: 14px; } .table th, .table td { padding-inline: 4px; } }
/* SVG paint */
.f-pension { fill: var(--pension); }
.f-pension-soft { fill: var(--pension-soft); }
.f-pension-wait { fill: #fff; stroke: var(--pension); stroke-width: 2; }
.f-ss { fill: var(--ss); }
.f-ss-soft { fill: var(--ss-soft); }
.f-savings { fill: var(--savings); }
.f-left { fill: url(#pat-left); stroke: var(--edge); stroke-width: 1; }
.s-pension { stroke: var(--pension); }
.gridline { stroke: var(--grid); stroke-width: 1; }
.axisline { stroke: var(--axis); stroke-width: 1; }
.t-axis { font-size: 13px; fill: var(--muted); }
.t-label { font-size: 13px; font-weight: 600; fill: var(--ink); }
.t-note { font-size: 13px; fill: var(--ink); }
.t-halo { paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }
.part:hover { opacity: .85; }
.wantline { stroke: var(--ink); stroke-width: 2; }
.hit { fill: transparent; cursor: pointer; }
.hit:hover + .col, .col.is-hover { opacity: .82; }
.band line { stroke: var(--edge); stroke-width: 1.5; }
.f-ink { fill: var(--ink); }
.s-ink { stroke: var(--ink); }
.s-paper { stroke: #fff; }
/* Coverage rows */
.cov { display: grid; gap: 20px; }
.cov__row { min-width: 0; }
.cov__title { font-weight: 600; line-height: 1.35; }
.cov__title span { font-weight: 400; color: var(--muted); }
.cov__bar { margin-top: 8px; }
.cov__nums { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 8px; font-size: 14px; line-height: 1.45; }
.cov__nums li { display: inline-flex; align-items: center; gap: 6px; }
.cov__nums svg { width: 12px; height: 12px; flex: none; }
.cov__sum { margin-top: 6px; font-size: 15px; line-height: 1.5; }
/* Plan cards */
.plans { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .plans { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.plan { display: flex; flex-direction: column; gap: 16px; }
.plan__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.plan__name { font-size: 13px; font-weight: 600; color: var(--muted); width: 100%; }
.plan.is-on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.plan > .btn { margin-top: auto; }
/* Staying beside leaving, with work stopping at the same age: a what-if at the top of Step 2. Three columns on a
laptop. On a phone each row's label takes a line of its own and the two amounts sit side by side under it. */
.evenneed { padding: 14px 24px; font-size: 15px; line-height: 1.5; }
.evenpick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 24px; align-items: start; margin-top: 14px; }
.evenpick__one { display: grid; gap: 6px; min-width: 0; }
.evenpick .agepick .label { font-weight: 600; }
.evenpick .seg label { min-height: 44px; padding: 0 16px; font-size: 16px; font-variant-numeric: tabular-nums; }
.even__say { margin-top: 16px; font: 700 20px/1.3 var(--display); font-variant-numeric: lining-nums; max-width: 34em; }
.even__line { display: block; }
.even__line + .even__line { margin-top: 2px; }
.even__where { margin-top: 6px; font-size: 14.5px; line-height: 1.45; color: var(--muted); max-width: 46em; }
/* What each path gives: two boxes of the same size and style, side by side, and stacked on a phone. */
.even__gives { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.even__give { min-width: 0; padding: 16px 18px; border: 1px solid var(--edge); border-radius: var(--r-md); }
.even__give h4 { font: 700 17px/1.3 var(--display); font-variant-numeric: lining-nums; }
.even__give ul { margin-top: 6px; }
.even__give li { padding-block: 8px; border-top: 1px solid var(--line); font-size: 15.5px; line-height: 1.4; font-variant-numeric: tabular-nums; }
.even__give li:first-child { border-top: 0; }
.even__none { margin-top: 14px; font-size: 15px; line-height: 1.4; color: var(--muted); }
/* Play The Years: two tracks in the style of the first screen's ruler, one for each path, from the stop age to 85.
Under each ruler strip, a band for each check starts at the age that check starts, with its name written above
it. A marker stands across both tracks at one age, and each track's heading gives that path's total at that age.
The marker is moved with transform only. The slider that moves it lies unseen over the whole plot. */
.years { --thumb: 30px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
@media (pointer: coarse) { .years { --thumb: 44px; } }
.years__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.years__head h4 { font: 700 17px/1.3 var(--display); font-variant-numeric: lining-nums; }
/* The button keeps the width of its longer label, so it does not shrink or move when it reads Replay. */
#years-play { flex-direction: column; gap: 0; }
#years-play::after { content: "Play The Years"; height: 0; overflow: hidden; visibility: hidden; }
.years__plot { position: relative; margin-top: 10px; padding-bottom: 30px; }
/* One line under the tracks on what the marker's amounts are, set like the comparison's other small lines. */
.years__cap { font-size: 14.5px; line-height: 1.45; color: var(--muted); max-width: 46em; }
.ytrack + .ytrack { margin-top: 14px; }
.ytrack__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 14px; line-height: 1.4; }
.ytrack__name { font-weight: 600; }
.ytrack__sum { color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }
/* The total changes as the marker moves. Its box is wide enough for $99,999 and does not change with the digits. */
.ytrack__sum b { display: inline-block; min-width: 7ch; text-align: right; font: 700 17px/1.2 var(--display); font-variant-numeric: lining-nums tabular-nums; color: var(--ink); }
.ytrack__plot { position: relative; margin-top: 8px; }
.ytrack__plot svg { width: 100%; height: auto; overflow: visible; }
.years__range { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: ew-resize; touch-action: pan-y; }
.years__range::-webkit-slider-runnable-track { height: 100%; background: transparent; }
.years__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: var(--thumb); height: 100%; border: 0; background: transparent; }
.years__range::-moz-range-track { height: 100%; background: transparent; }
.years__range::-moz-range-thumb { width: var(--thumb); height: 100%; border: 0; border-radius: 0; background: transparent; }
.years__range:focus-visible { outline: none; }
.years__mark {
position: absolute; z-index: 1; top: -5px; bottom: -5px; left: 0; width: var(--thumb); border: 2px solid var(--ink); border-radius: 6px; pointer-events: none;
background: linear-gradient(90deg, transparent calc(50% - 1px), var(--ink) calc(50% - 1px), var(--ink) calc(50% + 1px), transparent calc(50% + 1px)), rgba(255, 255, 255, .26);
box-shadow: 0 2px 5px rgba(20, 23, 26, .3);
}
.years__range:focus-visible ~ .ytrack .years__mark { box-shadow: 0 0 0 2px #fff, 0 0 0 5px var(--focus); }
.years__tab {
position: absolute; top: calc(100% + 2px); left: -2px; display: grid; place-items: center; width: var(--thumb); height: 19px; border-radius: 0 0 6px 6px;
background: var(--ink); color: #fff; font: 700 13px/1 var(--font); font-variant-numeric: lining-nums tabular-nums;
}
.yruler { fill: url(#grad-ruler); stroke: var(--ruler-edge); stroke-width: 1; }
.ytick { stroke: var(--ruler-ink); stroke-width: 1; opacity: .8; }
.ytick--five { stroke-width: 1.5; opacity: 1; }
.ynum { font: 700 12px/1 var(--font); fill: var(--ruler-ink); font-variant-numeric: lining-nums tabular-nums; }
/* The band names lie in a drawing of their own laid over each track, above the marker, and each is edged in paper,
so the marker passes behind a name and never over it: every name stays whole wherever the marker stands. The edge
is wide enough to cover a letter's softened rim, and each name's edge is clipped to its own row, so it never cuts
into the band below or the ruler above. The layer has the track's own size and place, takes no room and lets the
pointer through to the slider. */
.ytrack__plot .ytrack__names { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; }
.yname { font-size: 12.5px; font-weight: 600; fill: var(--ink); paint-order: stroke; stroke: var(--card); stroke-width: 6px; stroke-linejoin: round; }
/* See Every Number: the whole table, closed until the reader asks for it. On paper it is open. */
.evenall { margin-top: 16px; border-top: 1px solid var(--line); }
.evenall > summary { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; font-size: 16px; font-weight: 600; cursor: pointer; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; list-style: none; border-radius: 4px; }
.evenall > summary::-webkit-details-marker { display: none; }
.evenall > summary::before { content: "+"; display: inline-block; width: 14px; text-align: center; }
.evenall[open] > summary::before { content: "\2212"; }
.evenall > summary:hover { text-decoration-thickness: 2px; }
.even__grid { margin-top: 8px; }
.even__row { display: grid; grid-template-columns: minmax(0, 1.1fr) repeat(2, minmax(0, 1fr)); gap: 4px 20px; padding-block: 12px; border-top: 1px solid var(--line); }
.even__row--head { padding-top: 0; border-top: 0; }
.even__col b { display: block; font: 700 17px/1.3 var(--display); font-variant-numeric: lining-nums; }
.even__col span { display: block; margin-top: 2px; font-size: 13.5px; line-height: 1.4; color: var(--muted); }
.even__label { font-size: 15px; line-height: 1.4; }
.even__cell { min-width: 0; }
.even__text { font-weight: 600; line-height: 1.4; font-variant-numeric: tabular-nums; }
.even__amt { font-size: 14px; line-height: 1.3; color: var(--muted); }
.even__amt b { font: 700 19px/1.2 var(--display); font-variant-numeric: lining-nums tabular-nums; color: var(--ink); }
.even__parts { display: grid; gap: 1px; margin-top: 5px; font-size: 13.5px; line-height: 1.4; }
.even__parts li { display: flex; align-items: flex-start; gap: 6px; }
.even__parts svg { width: 11px; height: 11px; flex: none; margin-top: 4px; }
.even__note { margin-top: 4px; font-size: 13.5px; line-height: 1.4; color: var(--muted); }
/* Under a row's label: a line that is true of both columns. */
.even__both { display: block; margin-top: 4px; font-size: 13.5px; font-weight: 400; line-height: 1.4; color: var(--muted); }
/* The row the sentence above is about: each path's total from the stop age through 85. */
.even__row.is-key { border-top-color: var(--ink); }
.even__row.is-key .even__label { font-weight: 600; }
.even__row.is-key .even__amt b { font-size: 26px; line-height: 1.1; }
.even__row.is-key + .even__row { border-top-color: var(--ink); }
.even__cap { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 14px; line-height: 1.45; color: var(--muted); }
.even__why { margin-top: 6px; font-size: 14px; line-height: 1.45; color: var(--muted); }
@media (max-width: 639px) {
.evenneed { padding: 12px 16px; }
.evenpick { grid-template-columns: minmax(0, 1fr); }
.even__say { font-size: 18px; }
.even__gives { grid-template-columns: minmax(0, 1fr); gap: 12px; }
.even__give { padding: 14px 16px; }
.even__row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
/* The corner cell has words for screen readers only. It leaves the row here and stays in the table they hear. */
.even__row { position: relative; }
.even__corner { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.even__label { grid-column: 1 / -1; font-size: 14px; font-weight: 600; }
.even__col b { font-size: 16px; }
}
/* Three ways */
.ways { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) { .ways { grid-template-columns: repeat(3, minmax(0, 1fr)); } .way { padding: 20px; } }
/* From 1080 the Your Numbers column sits beside the cards. Until the page is 1240 wide that leaves each of three
cards under 200px, too narrow for the Save More table, so they stack there as they do on a phone. */
@media (min-width: 1080px) and (max-width: 1239px) { .ways { grid-template-columns: minmax(0, 1fr); } .way { padding: 24px; } }
.way { display: flex; flex-direction: column; gap: 12px; }
.way__n { font-size: 13px; font-weight: 600; color: var(--muted); }
.way__big { font-family: var(--display); font-variant-numeric: lining-nums; font-size: 23px; font-weight: 700; line-height: 1.2; text-wrap: balance; }
.way__big small { display: block; margin-top: 4px; font-family: var(--font); font-size: 15px; font-weight: 400; letter-spacing: 0; color: var(--ink); line-height: 1.45; }
.way .fields { margin-top: 4px; grid-template-columns: minmax(0, 1fr); }
.way .table { margin-top: 12px; }
.way .table th:last-child, .way .table td:last-child { white-space: nowrap; }
.way .table + p { margin-top: 8px; }
/* Meter */
.meter { display: grid; gap: 6px; }
.ssblock { margin-top: 20px; display: grid; gap: 8px; }
.ssblock > * { margin-top: 0 !important; }
.meter__label { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.meter__label b { font-variant-numeric: tabular-nums; }
/* To-do */
.todo li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 12px; padding-block: 10px; border-top: 1px solid var(--line); }
.todo li:first-child { border-top: 0; }
.todo__box { width: 20px; height: 20px; margin-top: 3px; border: 2px solid var(--ink); border-radius: 4px; background: #fff; }
.todo__actions { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
/* Empty state */
.empty { padding: 32px 24px; border: 1px dashed var(--edge); border-radius: var(--r-md); background: var(--card); }
.empty p { max-width: 36em; }
.empty__actions { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
/* Pager, footer */
.pager { display: flex; justify-content: space-between; gap: 12px; padding-block: 24px 48px; }
.pager .btn svg { width: 18px; height: 18px; }
#pager-next { margin-left: auto; }
.foot { border-top: 1px solid var(--line); background: var(--card); padding-block: 32px 40px; font-size: 14px; line-height: 1.55; }
.foot__grid { display: grid; gap: 20px; }
.foot__links { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.foot p { max-width: 60em; }
/* ===== Dialogs ===== */
dialog {
width: min(760px, calc(100% - 32px)); max-height: calc(100% - 48px); padding: 0; border: 0; border-radius: var(--r-lg);
background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 23, 26, .5); }
dialog[open] { display: flex; flex-direction: column; }
.dlg__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px 16px; border-bottom: 1px solid var(--line); }
.dlg__head h2 { font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.dlg__body { padding: 20px 24px 24px; overflow-y: auto; overscroll-behavior: contain; }
.dlg__body h3 { font-size: 18px; font-weight: 700; line-height: 1.3; margin-top: 24px; }
.dlg__body h3:first-child { margin-top: 0; }
.dlg__body p, .dlg__body ul, .dlg__body pre { margin-top: 10px; }
.dlg__body ul { list-style: disc; padding-left: 22px; display: grid; gap: 6px; }
.dlg__body pre { white-space: pre-wrap; font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; font-size: 13px; line-height: 1.55; padding: 16px; background: var(--bg); border-radius: var(--r-sm); }
.dlg__foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 16px 24px 20px; border-top: 1px solid var(--line); }
.dlg--small { width: min(520px, calc(100% - 32px)); }
.checked { display: inline-block; margin-top: 0; padding: 4px 12px; border-radius: 999px; background: var(--surface); font-size: 14px; font-weight: 600; }
.srclist a { overflow-wrap: anywhere; }
@media (max-width: 639px) {
.dlg__head { padding: 16px 16px 12px; } .dlg__body { padding: 16px; } .dlg__foot { padding: 12px 16px 16px; }
.dlg__foot .btn { flex: 1 1 100%; }
}
/* Print-only blocks */
.print-only { display: none; }
/* ===== Phone ===== */
@media (max-width: 639px) {
.step { padding-top: 12px; }
.numbers { padding: 16px; }
.pager .btn { flex: 1 1 0; padding: 0 12px; white-space: normal; text-align: center; min-height: 52px; }
.todo__actions .btn { flex: 1 1 0; padding: 0 12px; white-space: normal; text-align: center; }
}
@media (max-width: 359px) {
.fields { grid-template-columns: minmax(0, 1fr); }
/* "Stay" beside "Leave" keeps the picker narrow on the narrowest phones. */
.numbers .seg label { padding: 0 8px; }
}
/* ===== Motion: small feedback and an optional layer of movement, with one switch that turns all of it off =====
The switch is html[data-motion="off"]. The script in the head sets it when the device asks for less motion or the
address ends in ?motion=off, and Pause Motion sets it while the page is open. Nothing is remembered between visits.
Every effect moves or fades only (transform and opacity), plays once, and ends in the state the page shows with
motion off. An effect that needs a starting state gets it from the script, never from a style here, so nothing is
hidden when scripts are off. */
:root { --m-fast: 120ms; --m-mid: 220ms; --m-slow: 420ms; --m-ease: var(--ease); }
html[data-motion="off"] *, html[data-motion="off"] *::before, html[data-motion="off"] *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
html[data-motion="off"] .btn:hover, html[data-motion="off"] .btn:active { transform: none !important; }
/* With scripts off there is no switch, so the device's own setting is followed here. */
@media (prefers-reduced-motion: reduce) {
html:not([data-motion="on"]) *, html:not([data-motion="on"]) *::before, html:not([data-motion="on"]) *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
html:not([data-motion="on"]) .btn:hover, html:not([data-motion="on"]) .btn:active { transform: none !important; }
}
/* Pause Motion keeps the width of its longer label in the top line and the footer, so nothing beside it moves or
wraps when it reads Play Motion. */
.bar__nav > [data-motion-toggle], .foot [data-motion-toggle] { flex-direction: column; justify-content: center; gap: 0; }
.foot [data-motion-toggle] { display: inline-flex; align-items: flex-start; }
.bar__nav > [data-motion-toggle]::after, .foot [data-motion-toggle]::after { content: "Pause Motion"; height: 0; overflow: hidden; visibility: hidden; }
/* A number that rolls. The amount keeps its finished text, unseen, so its box is as wide as it will end up and a
screen reader hears only that. The count is laid over it from a box of no width, so nothing beside it moves. */
.rollbox { white-space: nowrap; }
.rollbox__final { opacity: 0; }
.roll { display: inline-flex; width: 0; white-space: nowrap; pointer-events: none; } /* the count takes the amount's own figures, so its last frame is the amount */
.roll--end { justify-content: flex-end; }
/* The Saved stamp: pressed onto the page just under the Save button after a save, held about a second, then gone.
It is fixed to the window, so it takes no room and nothing moves for it. With motion off it is never shown: the
line under the example banner already says the plan was saved, and that line is what a screen reader hears. */
.stamp {
position: fixed; z-index: 40; left: 0; top: 0; padding: 3px 11px 4px; border: 2px solid var(--ink); border-radius: 5px; background: var(--card); color: var(--ink);
font: 700 15px/1.2 var(--display); letter-spacing: .03em; transform: rotate(-4deg); opacity: 0; pointer-events: none; /* unseen at rest: only the effect shows it */
}
@media print { .stamp { display: none !important; } }
/* The opening: as the page opens with motion on, the page's composition notebook fills the window under the top line.
The cover's label is written and the cover opens onto a contents page, whose three steps are written in one after
another. Then a run of pages flips past as light comes up through the paper, and the light fades into the page.
About 6 seconds, once a load. A script lays it over the finished page, so it takes no room and only moves and
fades. Skip Intro, Escape, Skip To Content or a top-line button ends it at once. */
.intro {
position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; top: 0; overflow: hidden; background: #17191b;
--rule: 34px; --margin: 76px; --spine: 22px; --edge-t: 6px; --edge-r: 11px; --edge-b: 11px; --fold: 30%;
}
.intro__stage { position: absolute; inset: 0; perspective: 2200px; perspective-origin: 50% 42%; forced-color-adjust: none; }
.intro__leaf { position: absolute; inset: 0; transform-origin: left center; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.intro__marble { position: absolute; inset: 0; width: 100%; height: 100%; }
/* The back cover, under the pages: a dark board with its spine. Its edge shows round the page block once the cover is open. */
.intro__back { position: absolute; inset: 0; background: #17191b; }
.intro__back::before, .intro__cover::before { content: ""; position: absolute; inset: 0 auto 0 0; z-index: 1; width: var(--spine); background: #0d0e10; box-shadow: 1px 0 0 rgba(255, 255, 255, .14); }
/* The page block sits on the back cover, a little inside it, as a notebook's pages do. Its edge shows the sheets under
the top one, so the notebook reads as thick. */
.intro__book { position: absolute; top: var(--edge-t); right: var(--edge-r); bottom: var(--edge-b); left: var(--spine); perspective: 2000px; perspective-origin: 50% 42%; }
.intro__base { position: absolute; inset: 0; }
.intro__book > .intro__base { box-shadow: inset -1px -1px 0 #e1e5e0, 1px 1px 0 #e6e9e5, 2px 2px 0 #fbfcfa, 3px 3px 0 #d7dcd6, 4px 4px 0 #f6f7f5, 5px 5px 0 #cdd3cc, 6px 6px 0 #eef0ed, 7px 7px 0 #c3c9c2; }
/* A ruled sheet: rule lines on paper, a margin line, and the soft shade the binding casts near the spine. */
.intro__paper {
background-color: var(--card);
background-image:
linear-gradient(90deg, rgba(20, 23, 26, .13), rgba(20, 23, 26, 0) 56px),
linear-gradient(90deg, transparent calc(var(--margin) - 1px), #c3cac2 calc(var(--margin) - 1px), #c3cac2 var(--margin), transparent var(--margin)),
repeating-linear-gradient(180deg, transparent 0 calc(var(--rule) - 1px), var(--line) calc(var(--rule) - 1px) var(--rule));
box-shadow: inset -1px -1px 0 #e1e5e0;
}
.intro__rules { background-color: var(--card); background-image: repeating-linear-gradient(180deg, transparent 0 calc(var(--rule) - 1px), var(--line) calc(var(--rule) - 1px) var(--rule)); }
/* A turning sheet is a small 3D object: its face, and along its free edge six narrow strips, each hinged to the one
before, that bend a little more each as the sheet is lifted. Together they curl the edge over in a curve, the outer
ones showing the back of the paper: ruled as well, a shade darker. */
.intro__sheet { transform-style: preserve-3d; }
.intro__face { position: absolute; top: 0; bottom: 0; left: 0; width: 100%; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.intro__sheet > .intro__face { width: calc(100% - var(--fold)); box-shadow: none; }
.intro__seg { position: absolute; top: 0; bottom: 0; left: 100%; width: 100%; transform-origin: left center; transform-style: preserve-3d; }
.intro__sheet > .intro__seg { left: calc(100% - var(--fold)); width: calc(var(--fold) / 6); }
.intro__seg > .intro__rules, .intro__seg > .intro__verso { position: absolute; inset: 0 -0.5px 0 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.intro__seg > .intro__rules { box-shadow: inset 0 -1px 0 #e1e5e0; }
.intro__verso { transform: rotateY(180deg); background-color: #f1f3f0; background-image: linear-gradient(90deg, rgba(20, 23, 26, .02), rgba(20, 23, 26, .1)), repeating-linear-gradient(180deg, transparent 0 calc(var(--rule) - 1px), #cdd3cc calc(var(--rule) - 1px) var(--rule)); }
/* The shaded curve that runs across a sheet as it turns, and the darkening as it turns away from the light. */
.intro__curve { position: absolute; top: 0; bottom: 0; left: 0; width: 42%; opacity: 0; pointer-events: none;
background: linear-gradient(90deg, rgba(20, 23, 26, 0), rgba(20, 23, 26, .07) 30%, rgba(20, 23, 26, .2) 54%, rgba(255, 255, 255, .55) 68%, rgba(20, 23, 26, .08) 84%, rgba(20, 23, 26, 0)); }
.intro__shade { position: absolute; inset: 0; z-index: 2; background: #000; opacity: 0; pointer-events: none; }
.intro__cast { position: absolute; inset: 0 auto 0 0; width: 150px; background: linear-gradient(90deg, rgba(20, 23, 26, .36), rgba(20, 23, 26, .13) 38%, rgba(20, 23, 26, 0)); opacity: 0; transform-origin: left center; pointer-events: none; }
/* The contents page: a circled number and the step's name on each of three rules, written in one after another, each
underlined in ink along its rule. The script sets each on its rule after measuring, and makes the type smaller only
if a name would not fit the width. */
.intro__toc { position: absolute; left: calc(var(--margin) + 28px); right: 18px; top: 0; color: var(--ink); font: 700 clamp(19px, calc(9.2vw - 10px), 54px)/calc(var(--rule) * 2) var(--display); letter-spacing: -.01em; }
.intro__line { position: relative; white-space: nowrap; }
.intro__n { display: inline-grid; place-items: center; width: 1.46em; height: 1.46em; margin-right: .5em; border: 1.75px solid var(--ink); border-radius: 50%; font-size: .7em; line-height: 1; font-variant-numeric: lining-nums; }
.intro__ul { position: absolute; left: 0; top: 0; width: 0; height: 2px; border-radius: 1px; background: var(--ink); transform-origin: left center; }
.intro__probe { display: inline-block; width: 0; height: 0; vertical-align: baseline; }
/* The cover: marbled board, a dark spine, and a large label in the style of the small one on the page. */
.intro__cover { display: grid; place-items: center; padding: 24px 28px 24px calc(var(--spine) + 28px); background: #17191b; }
.intro__plate {
position: relative; max-width: 100%; padding: clamp(18px, 3.4vw, 40px) clamp(20px, 4.4vw, 52px) clamp(18px, 3vw, 36px);
background: #fdfdfb; border: 2px solid var(--ink); border-radius: 16px; box-shadow: 0 0 0 6px #fdfdfb, 0 0 0 8px var(--ink); color: var(--ink);
}
.intro__name { font: 700 clamp(36px, 10.6vw, 100px)/1.02 var(--display); letter-spacing: -.012em; white-space: nowrap; }
.intro__name span { display: inline-block; }
.intro__rule { display: block; margin: clamp(12px, 1.8vw, 20px) 0 clamp(10px, 1.5vw, 16px); border-top: 2px solid var(--ink); transform-origin: left center; }
.intro__lede { font: italic clamp(18px, 2.4vw, 28px)/1.3 var(--display); }
/* Light coming up through the paper at the end, before the notebook gives way to the page. */
.intro__light { position: absolute; inset: 0; opacity: 0; pointer-events: none; background: radial-gradient(130% 100% at 50% 52%, #fff 0%, #fff 58%, #f6f8f5 100%); }
.intro__skip {
position: absolute; z-index: 3; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); min-height: 32px; padding: 4px 12px;
border: 0; border-radius: 999px; background: rgba(253, 253, 251, .94); color: var(--muted); font: 600 13px/1.2 var(--font); letter-spacing: .01em;
}
.intro__skip:hover { color: var(--ink); }
@media (pointer: coarse) { .intro__skip { min-height: 38px; padding: 6px 14px; } }
@media (max-width: 639px) {
.intro { --rule: 30px; --margin: 40px; --spine: 16px; --edge-t: 4px; --edge-r: 7px; --edge-b: 7px; --fold: 36%; }
.intro__toc { left: calc(var(--margin) + 14px); right: 10px; }
.intro__book > .intro__base { box-shadow: inset -1px -1px 0 #e1e5e0, 1px 1px 0 #e6e9e5, 2px 2px 0 #fbfcfa, 3px 3px 0 #d3d8d2, 4px 4px 0 #f4f6f3, 5px 5px 0 #c3c9c2; }
.intro__cover { padding: 16px 18px 16px calc(var(--spine) + 18px); }
}
@media print { .intro { display: none !important; } }
/* Hover and press, for a mouse or trackpad only: a small lift under the pointer and a short press-down, on what can
be pressed. That is the top-line buttons, the step tabs, the example's two buttons, the ages in a table, the
account choices and the ruler's marker. (Wide buttons already did this.) The heads-up boxes never move, and
neither does Take It As Cash, which cannot be undone. */
@media (hover: hover) and (pointer: fine) {
/* Each keeps the one color change it had before the layer (a top-line button's fill, a tab's edge) and gains the move. */
html[data-motion="on"] .barbtn { transition: background-color var(--m-fast) var(--m-ease), transform var(--m-fast) var(--m-ease); }
html[data-motion="on"] .stepbtn, html[data-motion="on"] .example button { transition: border-color var(--m-fast) var(--m-ease), transform var(--m-fast) var(--m-ease); }
html[data-motion="on"] .table .agebtn { transition: transform var(--m-fast) var(--m-ease); }
html[data-motion="on"] .barbtn:hover, html[data-motion="on"] .stepbtn:hover, html[data-motion="on"] .example button:hover, html[data-motion="on"] .table .agebtn:hover { transform: translateY(-1px); }
html[data-motion="on"] .barbtn:active, html[data-motion="on"] .stepbtn:active, html[data-motion="on"] .example button:active, html[data-motion="on"] .table .agebtn:active { transform: translateY(1px) scale(.985); }
html[data-motion="on"] .choice:not(:has(input[value="cash"])):not(:has(input:disabled)) { transition: transform var(--m-fast) var(--m-ease); }
html[data-motion="on"] .choice:not(:has(input[value="cash"])):not(:has(input:disabled)):hover { transform: translateY(-2px); }
html[data-motion="on"] .choice:not(:has(input[value="cash"])):not(:has(input:disabled)):active { transform: translateY(0) scale(.995); }
html[data-motion="on"] .ruler input::-webkit-slider-thumb { transition: transform var(--m-fast) var(--m-ease); }
html[data-motion="on"] .ruler input:hover::-webkit-slider-thumb { transform: translateY(-1px); }
html[data-motion="on"] .ruler input:active::-webkit-slider-thumb { transform: translateY(1px); }
html[data-motion="on"] .ruler input::-moz-range-thumb { transition: transform var(--m-fast) var(--m-ease); }
html[data-motion="on"] .ruler input:hover::-moz-range-thumb { transform: translateY(-1px); }
html[data-motion="on"] .ruler input:active::-moz-range-thumb { transform: translateY(1px); }
}
/* Bars that fill grow from their own foot (the chart) or their own left edge (income bars and the credits bar). */
.chart__plot .col { transform-box: fill-box; transform-origin: center bottom; }
.cov__bar .part, .meter .f-ss { transform-box: fill-box; transform-origin: left center; }
/* Pencil underline: a line under the bold amount in the first screen's sentence, drawn once as the page opens and
then gone. It is unseen at rest (opacity 0) and hangs under the amount without taking room. */
#hero-say strong.penciled { position: relative; }
#hero-say strong.penciled::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; border-radius: 1px; background: var(--ink); opacity: 0; transform-origin: left center; pointer-events: none; }
@media print { #hero-say strong.penciled::after { display: none; } }
/* Marker glide: when a point on the ruler is clicked, a copy of the marker slides there from where the marker stood,
and the real marker, already at the new age, is unseen until the copy arrives. The copy takes no room. */
.ruler__ghost {
position: absolute; z-index: 1; top: -8px; bottom: -8px; left: 0; width: var(--thumb); border: 2px solid var(--ink); border-radius: 6px; pointer-events: none;
background: linear-gradient(90deg, transparent calc(50% - 1px), var(--ink) calc(50% - 1px), var(--ink) calc(50% + 1px), transparent calc(50% + 1px)), rgba(255, 255, 255, .26);
box-shadow: 0 2px 5px rgba(20, 23, 26, .3);
}
.ruler input.is-gliding::-webkit-slider-thumb { opacity: 0; }
.ruler input.is-gliding::-moz-range-thumb { opacity: 0; }
@media print { .ruler__ghost { display: none; } }
/* The step tabs' marker: when another step is picked, an ink box the size of a tab slides from the old tab to the
new one and fades as it arrives. The new tab is already filled underneath, so this only shows the way there. */
.steps { position: relative; }
.steps__mark { position: absolute; z-index: 1; border-radius: var(--r-md); background: var(--ink); pointer-events: none; transform-origin: left top; }
@media print { .steps__mark { display: none; } }
@media (forced-colors: active) { .steps__mark { display: none; } }
/* A heads-up that is going away fades out from a copy laid where it stood. The copy is placed against the page's
main block and takes no room. A heads-up never changes color and never pulses. */
main { position: relative; }
.caution--leaving { position: absolute; z-index: 1; margin: 0; pointer-events: none; }
@media print { .caution--leaving { display: none; } }
/* Service credit tally: pencil marks under the years of service in How This Pension Is Figured, one for each year,
in fives. The mark for a year at which the multiplier steps up is drawn heavier. Each mark grows from where a
pencil would start it: the top of a stroke, the left end of the stroke that crosses a group. */
.tally { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 2px; }
.tally:empty { display: none; }
.tally svg { flex: none; overflow: visible; }
.tally__mark { stroke-width: 1.5; stroke-linecap: round; transform-box: fill-box; transform-origin: center top; }
.tally__mark--cross { transform-origin: left bottom; }
.tally__mark--heavy { stroke-width: 3.2; }
/* Show Your Work: a pencil stroke along the rule above each row of How This Pension Is Figured. It is unseen at
rest (opacity 0) and takes no room. The script draws it across once as the row appears. */
#s1-formula .facts > div { position: relative; }
#s1-formula .facts > div::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 1px; background: var(--ink); opacity: 0; transform-origin: left center; pointer-events: none; }
@media print { #s1-formula .facts > div::before { display: none; } }
/* The old headline of the comparison, fading out over the new one. It lies over the headline's own corner and takes no room. */
.even__say { position: relative; }
.ghost { position: absolute; left: 0; top: 0; width: 100%; pointer-events: none; }
@media print { .roll, .ghost { display: none; } .rollbox__final { opacity: 1; } }
/* ===== High contrast mode ===== */
@media (forced-colors: active) {
.f-ss { fill: url(#pat-ss); }
.f-savings { fill: url(#pat-savings); }
.meter .f-ss { fill: CanvasText; }
.meter .f-ss-soft { fill: Canvas; stroke: CanvasText; }
.stepbtn[aria-current="step"], .choice:has(input:checked), .plan.is-on { outline: 2px solid CanvasText; }
.card, .chart, .numbers, .strip, .caution, .book, .path { border: 1px solid CanvasText; }
.caution { border-left-width: 3px; }
.cover .marble { display: none; }
/* The ruler keeps its own yellow and ink, which already contrast strongly. The marker gets a thin edge in the
system's text color, so the ends that stand past the ruler show on a black page too, and its tab and its focus
ring use the system's colors. */
.ruler { forced-color-adjust: none; }
.ruler input::-webkit-slider-thumb { box-shadow: 0 0 0 1px CanvasText; }
.ruler input::-moz-range-thumb { box-shadow: 0 0 0 1px CanvasText; }
.ruler input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px Canvas, 0 0 0 5px Highlight; }
.ruler input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px Canvas, 0 0 0 5px Highlight; }
.ruler__tab { background: CanvasText; color: Canvas; }
/* The flags stand above the ruler, on the page's own background, which is black in most high contrast themes.
They take the system's text color, so ink words are not left on a black page. */
.ruler__flags { forced-color-adjust: auto; }
.flag::after { forced-color-adjust: none; background: CanvasText; }
/* What is picked was shown by an ink fill, which this mode removes. The system's highlight colors say it instead. */
.seg label:has(input:checked), .btn[aria-pressed="true"], .table .agebtn[aria-pressed="true"], .stepbtn[aria-current="step"] {
forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight;
}
.tip { border: 1px solid CanvasText; }
/* Play The Years: the ruler strips keep their yellow, as the first ruler does. The band names, the marker and its tab follow the system. */
.yname { fill: CanvasText; stroke: Canvas; }
.years__mark { forced-color-adjust: none; border-color: CanvasText; background: linear-gradient(90deg, transparent calc(50% - 1px), CanvasText calc(50% - 1px), CanvasText calc(50% + 1px), transparent calc(50% + 1px)); box-shadow: none; }
.years__range:focus-visible ~ .ytrack .years__mark { box-shadow: 0 0 0 2px Canvas, 0 0 0 5px Highlight; }
.years__tab { background: CanvasText; color: Canvas; }
/* Chart words and lines are drawn in ink, which this mode does not change inside a drawing. On a black page they
would vanish, so they take the system's text color, and the white halos take the page color. */
.t-axis, .t-label, .t-note, .f-ink { fill: CanvasText; }
.s-ink, .wantline, .axisline, .band line { stroke: CanvasText; }
.gridline { stroke: GrayText; stroke-opacity: .45; }
.t-halo, .s-paper { stroke: Canvas; }
/* The dot that says there are unsaved changes, and the arrow on a pick list, were ink pictures. */
.dot { forced-color-adjust: none; background: CanvasText; }
.select { appearance: auto; -webkit-appearance: auto; background-image: none; padding-right: 12px; }
}
/* ===== Print ===== */
@media print {
@page { margin: 14mm; }
:root { --bg: #fff; --surface: #fff; --caution-soft: #fff; }
/* 1px of room on the right: a box that ends exactly at the paper's margin loses its right border in the PDF. */
body { font-size: 11pt; line-height: 1.45; background: #fff; padding-right: 1px; }
.skip, .bar__nav, .bar__short, .steps, .pager, .side, .tip, .todo__actions, .empty__actions, dialog, .filestatus, .seg, .agepick, .evenpick, .no-print, .foot__links, .pick, .next, .paths__go, #example-banner { display: none !important; }
.bar__full { display: inline; }
.print-only { display: block; }
.strip__plan { font-weight: 600; }
.wrap { width: 100%; }
.bar { border: 1px solid #000; }
.bar .wrap { min-height: 0; padding: 6px 10px; }
.bar__note { font-size: 10pt; color: #000; }
.readout { padding: 0; }
/* The marbled cover is for the screen. On paper the label stands alone and the first page follows it. */
.book { display: block; margin-top: 10px; border-radius: 0; box-shadow: none; overflow: visible; }
.cover { display: block; padding: 0; min-height: 0; background: none; }
.cover .marble, .cover::before { display: none; }
.plate { padding: 10px 14px; border-width: 1px; border-radius: 8px; box-shadow: none; background: #fff; }
.plate h1 { font-size: 22pt; margin-bottom: 4px; }
.plate__lede { font-size: 11pt; }
.plate__for { font-size: 11pt; margin-top: 6px; padding-top: 5px; border-top-width: 1px; }
.page { display: block; padding: 0; }
#print-example { border: 1px solid #000; padding: 8px 12px; margin-top: 10px; }
.answer { margin-top: 10px; }
.answer__num { font-size: 26pt; }
.answer__unit, .say { font-size: 11pt; }
.say { max-width: none; margin-top: 4px; }
.paths { margin-top: 8px; }
.path { padding: 6px 10px 8px; border-color: #999; break-inside: avoid; }
.path__head h2, .path__big, .path__line { font-size: 10pt; }
.path__big { color: #000; }
.path__big b { font-size: 14pt; }
.stripbar { position: static; padding: 0; background: none; margin-top: 10px; }
.strip { border: 1px solid #000; border-radius: 0; }
.strip__cap { min-height: 0; padding: 4px 10px; }
.strip__unit { color: #000; }
.strip__tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.strip .tile, .strip .tile--wide { grid-column: auto; padding: 4px 10px 6px; border-top: 0; border-left: 1px solid #999; }
.strip .tile:first-child { border-left: 0; }
.tile__note { display: block; }
.tile__value { font-size: 13pt; white-space: normal; }
.step { display: block !important; padding-block: 14px 0; }
.step[hidden] { display: block !important; }
.step__grid { display: block; }
.step__grid > * + * { margin-top: 12px; }
.body, .aside { display: block; }
.body > * + *, .aside > * + * { margin-top: 12px; }
.step__head { margin-bottom: 8px; }
.step__head h2 { font-size: 17pt; }
.result { font-size: 13pt; max-width: none; }
/* Pages: a heading stays with what it heads and small pieces stay whole. A long card or chart may run on to the
next page between its rows, so no page is left mostly blank. */
.step__head, .chart__head, .chart__title, .chart__sub, .chart__plot, .legend, .card > h3, .card > h3 + p,
#s3-ways-title, #s3-ways-sub, #print-numbers h2 { break-after: avoid; }
.card, .lead, .chart__plot, .readout, .caution, .cov__row, .even__row, .even__give, .choice, .way, .ssblock, .miles li, .todo li, .table tr, .facts > div, .foot { break-inside: avoid; }
.plan, #s2-ss, #s3-todo-host, .card[aria-labelledby="s1-miles-title"] { break-inside: auto; }
/* An unfinished Leave Teaching is short. It keeps its own height and stays whole, so its one line is not left alone at
the top of the next page in a box as tall as Stay Teaching. The two plans then start a page together. */
.plan.plan--open { align-self: start; break-inside: avoid; }
.table caption { break-after: avoid; }
p, li, h2, h3, h4 { break-inside: avoid; }
.way .fields { display: none !important; }
.card, .chart { padding: 12px 14px; border-color: #999; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.chart__plot svg { max-width: 170mm; }
.plans { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ways, .choices--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tview > summary { display: none; }
.tview > *:not(summary) { display: block; overflow: visible; }
/* See Every Number prints open. The page opens it before printing. This rule does the same where the browser lets a
style sheet show a closed box's contents, so the table is on paper either way. */
/* Play The Years prints still: no slider, and the marker on the age it stands at, placed by its share of the track's width. */
.years { break-inside: avoid; }
.years__range { display: none; }
.years__mark { left: calc(100% * var(--at, 0) - var(--thumb) / 2); transform: none !important; box-shadow: none; }
.ytick { opacity: 1; }
.evenall { border-top: 0; }
.evenall > summary { display: none; }
.evenall::details-content { content-visibility: visible; display: block; }
/* On paper the ages in the table are plain numbers, not buttons. */
.table .agebtn, .table .agebtn[aria-pressed="true"] { min-width: 0; min-height: 0; padding: 0; border: 0; background: none; color: #000; font-weight: inherit; }
.f-ss { fill: url(#pat-ss); }
.f-savings { fill: url(#pat-savings); }
.f-left { fill: #fff; stroke: #000; stroke-dasharray: 4 3; }
/* The credits bar is stretched to its box, which would smear the stripe pattern. Plain grays there. */
.meter .f-ss { fill: #555; }
.meter .f-ss-soft { fill: #ddd; }
.foot { background: #fff; padding-block: 12px 0; margin-top: 16px; }
a { color: #000; }
/* Print only the to-do list when asked */
html.print-todo .step:not(#step-3), html.print-todo #step-3 .lead, html.print-todo #step-3 .aside, html.print-todo #s3-main > *:not(#s3-todo-host),
html.print-todo .page, html.print-todo .plate__lede, html.print-todo .plate__for, html.print-todo #print-numbers, html.print-todo #step-3 .step__head { display: none !important; }
}
</style>
<script id="motion-switch">
/* Motion is on unless the device asks for less or the address ends in ?motion=off. Set before the page is drawn. */
(function () {
var off = false;
try { off = /[?&]motion=off(&|$)/.test(window.location.search) || !!(window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches); } catch (e) { off = false; }
document.documentElement.setAttribute('data-motion', off ? 'off' : 'on');
})();
</script>
</head>
<body>
<a class="skip" href="#main">Skip To Content</a>
<svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false">
<defs>
<pattern id="pat-left" width="4" height="4" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
<rect width="4" height="4" fill="#ffffff"/><line x1="0" y1="0" x2="0" y2="4" stroke="#7b847e" stroke-width="1.5"/>
</pattern>
<pattern id="pat-ss" width="5" height="5" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
<rect width="5" height="5" fill="#cfdff1"/><line x1="0" y1="0" x2="0" y2="5" stroke="#1d4a80" stroke-width="2.2"/>
</pattern>
<pattern id="pat-savings" width="5" height="5" patternUnits="userSpaceOnUse" patternTransform="rotate(135)">
<rect width="5" height="5" fill="#f3e2b3"/><line x1="0" y1="0" x2="0" y2="5" stroke="#6e4e00" stroke-width="2.2"/>
</pattern>
<linearGradient id="grad-ruler" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#f7d368"/><stop offset=".55" stop-color="#f2c649"/><stop offset="1" stop-color="#e8b838"/></linearGradient>
<symbol id="i-caution" viewBox="0 0 20 20"><path d="M10 2.6 18.4 17.2H1.6z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/><path d="M10 8v4.4" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/><circle cx="10" cy="14.7" r="1.1" fill="currentColor"/></symbol>
<symbol id="i-done" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#14171a"/><path d="M7.5 12.3l3 3 6-6.3" fill="none" stroke="#fff" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
<symbol id="i-ahead" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="#fff" stroke="#14171a" stroke-width="2"/></symbol>
<symbol id="i-next" viewBox="0 0 20 20"><path d="M4 10h12M11 5l5 5-5 5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
<symbol id="i-back" viewBox="0 0 20 20"><path d="M16 10H4M9 5l-5 5 5 5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
<symbol id="i-close" viewBox="0 0 20 20"><path d="M5 5l10 10M15 5L5 15" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-chev" viewBox="0 0 20 20"><path d="M5 7.5l5 5 5-5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
</defs>
</svg>
<!-- Top line: the for-education notice and the file buttons. The full notice is in the footer, in About and on a printed page. -->
<header class="bar" id="notice-top">
<div class="wrap">
<p class="bar__note"><strong>For education only.</strong> <span class="bar__short">Not advice, and not connected to TRS or the Social Security Administration.</span><span class="bar__full">This page is not financial, tax or legal advice, and it is not connected to TRS or the Social Security Administration.</span></p>
<nav class="bar__nav" aria-label="File And Help">
<button type="button" class="barbtn" id="btn-open">Open</button>
<button type="button" class="barbtn" id="btn-save">Save</button>
<button type="button" class="barbtn" id="btn-new">New</button>
<button type="button" class="barbtn bar__wide" data-open="dlg-rules">Rules And Sources</button>
<button type="button" class="barbtn bar__wide" data-open="dlg-about">About</button>
<button type="button" class="barbtn bar__wide" data-motion-toggle>Pause Motion</button>
<div class="bar__more">
<button type="button" class="barbtn" id="btn-more" aria-expanded="false" aria-controls="more-menu">More</button>
<div class="bar__menu" id="more-menu" hidden>
<button type="button" class="barbtn" data-open="dlg-rules" data-opener="btn-more">Rules And Sources</button>
<button type="button" class="barbtn" data-open="dlg-about" data-opener="btn-more">About</button>
<button type="button" class="barbtn" data-motion-toggle>Pause Motion</button>
</div>
</div>
</nav>
</div>
</header>
<!-- The opening. It is built here, right after the top line, so it covers the window before the rest of the page is
first drawn. It plays once, with motion on, over a page that is drawn finished underneath. -->
<script id="intro-script">
(function () {
/* The opening: the page's composition notebook fills the window under the top line, once, as the page opens with
motion on. About 6 seconds in five beats.
1. About 1.6s: the closed cover with a large label, its title rising in a letter at a time, the rule drawn under
it and "You earned a pension." fading in.
2. 0.9s: the cover opens, unhurried, onto a single ruled page.
3. 2.4s: a contents page. Its three lines are written in one after another, top to bottom, each with its
circled number, the step button's own name and an ink underline drawn along its rule; then all three hold.
4. 0.7s: a run of pages flips past, faster and faster, as light comes up through the paper.
5. 0.5s: the light fades down and the page is there.
The paper is made to read as paper: each turning sheet has a shaded curve that runs across it, a free edge that
curls over to show the ruled back of the sheet, and a soft shadow on the sheet under it that follows its edge; the
page block sits inside the back cover with the edges of the sheets under it showing.
Only transform and opacity move. Skip Intro, Escape, the Skip To Content link or a button in the top line ends it
at once. While it plays the page is held at the top: wheel, touch and key scrolling are ignored, and nothing is
hidden, so the scrollbar and the page's width never change. */
var ROOT = document.documentElement, bar = document.getElementById('notice-top'), me = document.currentScript;
if (ROOT.getAttribute('data-motion') !== 'on' || !bar || !me || !me.parentNode || !window.Element || !Element.prototype.animate) return;
try { if (window.matchMedia && window.matchMedia('print').matches) return; } catch (e) { /* draw it */ }
var EASE = 'cubic-bezier(.2, .8, .2, 1)', OPEN = 'cubic-bezier(.42, 0, .22, 1)', RIFFLE = 'cubic-bezier(.5, .02, .74, .3)';
/* When each thing starts and how long it takes, in milliseconds. The last ends at 6100. */
var T = { letters: 160, letterGap: 58, letter: 440, rule: 720, ruleLen: 380, lede: 960, ledeLen: 380,
swing: 1600, swingLen: 900,
toc: 2500, line: 500, linePause: 150,
burst: 4900, flips: [[0, 320], [150, 270], [270, 225], [365, 190], [440, 160]],
light: 4900, lightLen: 700, fade: 5600, fadeLen: 500 };
var NS = 'http://www.w3.org/2000/svg', anims = [], casts = [], lines = [], over = false, watch = null, timer = null, overlay = null, anchor = null;
var STILL = { passive: false, capture: true };
var KEYS = { ' ': 1, Spacebar: 1, PageUp: 1, PageDown: 1, Home: 1, End: 1, ArrowUp: 1, ArrowDown: 1, ArrowLeft: 1, ArrowRight: 1 };
function mk(tag, cls, kids) {
var n = document.createElement(tag);
if (cls) n.className = cls;
(kids || []).forEach(function (c) { n.appendChild(typeof c === 'string' ? document.createTextNode(c) : c); });
return n;
}
function vec(tag, attrs, kids) {
var n = document.createElementNS(NS, tag);
Object.keys(attrs).forEach(function (k) { n.setAttribute(k, attrs[k]); });
(kids || []).forEach(function (c) { n.appendChild(c); });
return n;
}
function go(node, frames, delay, dur, easing) {
var a = node.animate(frames, { delay: delay, duration: dur, easing: easing || EASE, fill: 'both' });
anims.push(a);
return a;
}
/* An animation made later (the contents' letters, once the step names have been read) keeps the same clock as the
rest: its start is set to the first animation's, as soon as that one has started. */
function sync(a) {
if (!anchor || a === anchor) return a;
var set = function () { if (anchor.startTime !== null && !over) { try { a.startTime = anchor.startTime; } catch (e) { /* gone */ } } };
if (anchor.startTime !== null) set(); else anchor.ready.then(set, function () { /* cancelled */ });
return a;
}
/* The page stays at the top while the opening plays. */
function hold() { if (window.pageYOffset || window.pageXOffset) window.scrollTo(0, 0); }
function still(e) { e.preventDefault(); }
function onKey(e) {
if (e.key === 'Escape' || e.key === 'Esc') { finish(); return; }
var t = e.target;
if (!KEYS[e.key] || (t && t.closest && t.closest('input, select, textarea, button, a[href], summary, [contenteditable]'))) return;
e.preventDefault();
}
function onBar(e) { if (e.target && e.target.closest && e.target.closest('button')) finish(); }
var skipLink = document.querySelector('a.skip');
function finish() {
if (over) return;
over = true;
clearTimeout(timer);
if (watch) watch.disconnect();
window.removeEventListener('wheel', still, STILL);
window.removeEventListener('touchmove', still, STILL);
window.removeEventListener('keydown', onKey, true);
window.removeEventListener('scroll', hold, true);
window.removeEventListener('resize', place);
bar.removeEventListener('click', onBar, true);
if (skipLink) skipLink.removeEventListener('click', finish);
if (!overlay) return;
var hadFocus = overlay.contains(document.activeElement);
anims.forEach(function (a) { try { a.cancel(); } catch (e) { /* gone */ } });
if (overlay.parentNode) overlay.parentNode.removeChild(overlay);
hold();
/* Skip Intro had the keyboard: the next Tab goes on into the page. */
if (hadFocus) { var m = document.getElementById('main'); if (m) { try { m.focus({ preventScroll: true }); } catch (e) { m.focus(); } } }
try { overlay.dispatchEvent(new Event('introend')); } catch (e) { /* nobody listening */ }
}
/* Where the far edge of a leaf W wide, turned a degrees on its spine toward the eye, falls across its parent, for a
perspective P seen from the parent's middle. The soft shadow a leaf casts on the sheet under it follows that edge:
it shows as the leaf lifts, then widens and fades as the leaf rises and passes. */
function edgeAt(a, W, P) { var r = a * Math.PI / 180; return W / 2 + (W * Math.cos(r) - W / 2) * P / Math.max(1, P - W * Math.sin(r)); }
function castFrames(W, P, peak, to) {
var out = [];
for (var k = 0; k <= 12; k++) {
var p = k / 12, o = peak * Math.min(1, p / 0.06) * Math.max(0, 1 - Math.max(0, p - 0.1) / 0.65);
out.push({ offset: p, opacity: o, transform: 'translateX(' + Math.round(edgeAt(to * p, W, P)) + 'px) scaleX(' + (1 + 1.6 * p).toFixed(3) + ')' });
}
return out;
}
var size = { W: 0, P: 0, w: 0, p: 0 };
/* Under the top line, whatever its height. The perspectives follow the widths so nothing turns past the eye. The
contents are set on their rules, and made smaller only if a line would not fit the page. */
function place() {
if (over || !overlay) return;
overlay.style.top = (bar.getBoundingClientRect().bottom + (window.pageYOffset || 0)) + 'px';
size.W = overlay.clientWidth || window.innerWidth;
size.P = Math.max(1200, Math.round(size.W * 1.6));
size.w = book.clientWidth || size.W;
size.p = Math.max(1400, Math.round(size.w * 2.2));
stage.style.perspective = size.P + 'px';
book.style.perspective = size.p + 'px';
casts.forEach(function (c) { try { c.anim.effect.setKeyframes(castFrames(c.cover ? size.W : size.w, c.cover ? size.P : size.p, c.peak, c.to)); } catch (e) { /* keep the old path */ } });
var R = parseFloat(window.getComputedStyle(overlay).getPropertyValue('--rule')) || 34, H = book.clientHeight;
toc.style.fontSize = '';
var room = toc.clientWidth, wide = 0;
lines.forEach(function (l) { wide = Math.max(wide, l.n.offsetWidth + l.name.offsetWidth + (l.name.offsetLeft - l.n.offsetLeft - l.n.offsetWidth)); });
if (wide > room && room > 0) toc.style.fontSize = (parseFloat(window.getComputedStyle(toc).fontSize) * room / wide * 0.98).toFixed(2) + 'px';
/* The middle line near the middle of the page; every line box is two rules tall, so all three baselines sit on rules. */
var k = Math.max(3, Math.round(0.45 * H / R) - 2);
toc.style.top = '0px';
toc.style.top = Math.round(k * R - 1 - lines[0].probe.offsetTop - lines[0].row.offsetTop) + 'px';
lines.forEach(function (l) {
l.ul.style.top = (l.probe.offsetTop - 0.5) + 'px';
l.ul.style.left = l.name.offsetLeft + 'px';
l.ul.style.width = l.name.offsetWidth + 'px';
});
}
try {
/* The front cover is marbled like the small one on the page. The back one is a dark board that shows round the page block. */
var marble = vec('svg', { class: 'intro__marble', preserveAspectRatio: 'none', focusable: 'false' }, [
vec('filter', { id: 'intro-marble', x: '0', y: '0', width: '100%', height: '100%', 'color-interpolation-filters': 'sRGB' }, [
vec('feTurbulence', { type: 'fractalNoise', baseFrequency: '0.062 0.074', numOctaves: '4', seed: '23' }),
vec('feColorMatrix', { type: 'matrix', values: '26 0 0 0 -12.2 26 0 0 0 -12.2 26 0 0 0 -12.2 0 0 0 0 1' }),
vec('feGaussianBlur', { stdDeviation: '0.5' })
]),
vec('rect', { width: '100%', height: '100%', filter: 'url(#intro-marble)' })
]);
var back = mk('div', 'intro__back');
/* Beat 1: the front cover and its label. */
var letters = [], name = mk('p', 'intro__name');
'Full Credit'.split(' ').forEach(function (word, i) {
if (i) name.appendChild(document.createTextNode(' '));
var group = mk('span');
word.split('').forEach(function (ch) { var s = mk('span', null, [ch]); letters.push(s); group.appendChild(s); });
name.appendChild(group);
});
var rule = mk('span', 'intro__rule'), lede = mk('p', 'intro__lede', ['You earned a pension.']);
var coverShade = mk('div', 'intro__shade'), cover = mk('div', 'intro__leaf intro__cover', [marble, mk('div', 'intro__plate', [name, rule, lede]), coverShade]);
/* The page block: the sheets under the contents page, each a turning sheet with a curling edge, on a base sheet. */
var book = mk('div', 'intro__book', [mk('div', 'intro__base intro__paper')]), sheets = [];
for (var s = 0; s < T.flips.length - 1; s++) {
var curve = mk('div', 'intro__curve'), shade = mk('div', 'intro__shade');
var sheet = mk('div', 'intro__leaf intro__sheet', [mk('div', 'intro__face intro__paper', [curve, shade])]), cast = mk('div', 'intro__cast'), segs = [], holder = sheet;
for (var g = 0; g < 6; g++) {
/* The shade darkens evenly across the six strips, each carrying on from the one before. */
var segShade = mk('div', 'intro__shade'), seg = mk('div', 'intro__seg', [mk('div', 'intro__rules', [segShade]), mk('div', 'intro__verso')]);
segShade.style.background = 'linear-gradient(90deg, rgba(0, 0, 0, ' + (g / 6).toFixed(3) + '), rgba(0, 0, 0, ' + ((g + 1) / 6).toFixed(3) + '))';
holder.appendChild(seg);
segs.push({ seg: seg, shade: segShade });
holder = seg;
}
book.appendChild(cast);
book.appendChild(sheet);
sheets.unshift({ leaf: sheet, curve: curve, shade: shade, segs: segs, cast: cast });
}
/* The contents page on top: three lines, each a probe for its baseline, a circled number, the name and its underline. */
var toc = mk('div', 'intro__toc');
for (var n = 1; n <= 3; n++) {
var probe = mk('i', 'intro__probe'), num = mk('span', 'intro__n', [String(n)]), nm = mk('span', 'intro__nm'), ul = mk('span', 'intro__ul');
var row = mk('div', 'intro__line', [probe, num, nm, ul]);
toc.appendChild(row);
lines.push({ row: row, probe: probe, n: num, name: nm, ul: ul, letters: [] });
}
var cCurve = mk('div', 'intro__curve'), cShade = mk('div', 'intro__shade'), cCast = mk('div', 'intro__cast');
var contents = mk('div', 'intro__leaf intro__contents', [mk('div', 'intro__face intro__paper', [toc, cCurve, cShade])]);
book.appendChild(cCast);
book.appendChild(contents);
sheets.unshift({ leaf: contents, curve: cCurve, shade: cShade, segs: [], cast: cCast });
var coverCast = mk('div', 'intro__cast'), light = mk('div', 'intro__light');
var stage = mk('div', 'intro__stage', [back, book, coverCast, cover, light]);
stage.setAttribute('aria-hidden', 'true');
/* The one thing a screen reader meets: a small, quiet button in the corner. */
var skip = mk('button', 'intro__skip', ['Skip Intro']);
skip.type = 'button';
skip.addEventListener('click', finish);
overlay = mk('div', 'intro', [stage, skip]);
overlay.id = 'intro';
overlay.finish = finish;
me.parentNode.insertBefore(overlay, me.nextSibling);
place();
window.addEventListener('wheel', still, STILL);
window.addEventListener('touchmove', still, STILL);
window.addEventListener('keydown', onKey, true);
window.addEventListener('scroll', hold, true);
window.addEventListener('resize', place);
bar.addEventListener('click', onBar, true);
if (skipLink) skipLink.addEventListener('click', finish);
if (window.ResizeObserver) { watch = new ResizeObserver(place); watch.observe(bar); watch.observe(overlay); }
hold();
/* Beat 1. */
letters.forEach(function (el, i) { var a = go(el, [{ opacity: 0, transform: 'translateY(.34em)' }, { opacity: 1, transform: 'translateY(0)' }], T.letters + i * T.letterGap, T.letter); if (!i) anchor = a; });
go(rule, [{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], T.rule, T.ruleLen);
go(lede, [{ opacity: 0, transform: 'translateY(6px)' }, { opacity: 1, transform: 'translateY(0)' }], T.lede, T.ledeLen);
/* Beat 2: the cover opens toward the eye on its spine, darkening as it turns, its shadow drawing back across the page. */
go(cover, [{ transform: 'rotateY(0deg)' }, { transform: 'rotateY(-100deg)' }], T.swing, T.swingLen, OPEN);
go(coverShade, [{ opacity: 0 }, { opacity: 0, offset: 0.15 }, { opacity: 0.5 }], T.swing, T.swingLen, OPEN);
casts.push({ anim: go(coverCast, castFrames(size.W, size.P, 1, 100), T.swing, T.swingLen, OPEN), peak: 1, to: 100, cover: true });
/* Beat 3: each line's number, then its letters a few at a time, and its underline along the rule. The names are the
step buttons' own, read once the page has been read, on the same clock as everything else. */
lines.forEach(function (l, i) {
var at = T.toc + i * (T.line + T.linePause);
go(l.n, [{ opacity: 0, transform: 'scale(.6)' }, { opacity: 1, transform: 'scale(1)' }], at, 160);
go(l.ul, [{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], at + 140, T.line - 140, 'linear'); // a step behind the letters, finishing with the last
});
document.addEventListener('DOMContentLoaded', function () {
if (over) return;
var names = document.querySelectorAll('.stepbtn__t');
lines.forEach(function (l, i) {
var text = names[i] ? names[i].textContent : '', at = T.toc + i * (T.line + T.linePause), chars = text.split(''), gap = (T.line - 180) / Math.max(1, chars.length - 1);
chars.forEach(function (ch, j) {
var c = mk('span', null, [ch]);
l.name.appendChild(c);
l.letters.push(c);
sync(go(c, [{ opacity: 0 }, { opacity: 1 }], at + 60 + j * gap, 120, 'linear'));
});
});
place();
});
/* Beat 4: the contents page, then the sheets under it, turn faster and faster. Each darkens as it turns, a curve
runs across it, its shadow follows its edge across the sheet below, and a blank sheet's free edge curls over
first, showing its ruled back. Light comes up through the paper meanwhile. */
sheets.forEach(function (sh, i) {
var at = T.burst + T.flips[i][0], len = T.flips[i][1];
go(sh.leaf, [{ transform: 'rotateY(0deg)' }, { transform: 'rotateY(-100deg)' }], at, len, RIFFLE);
go(sh.shade, [{ opacity: 0 }, { opacity: 0, offset: 0.3 }, { opacity: 0.24 }], at, len, RIFFLE);
go(sh.curve, [{ opacity: 0, transform: 'translateX(240%)' }, { opacity: 1, offset: 0.2 }, { opacity: 0.9, offset: 0.7 }, { opacity: 0, transform: 'translateX(-60%)' }], at, len, RIFFLE);
/* Each strip bends a sixth of the curl, so the edge rolls over in a curve, darker the further it has turned. */
sh.segs.forEach(function (g, j) {
go(g.seg, [{ transform: 'rotateY(0deg)' }, { transform: 'rotateY(-25deg)', offset: 0.24 }, { transform: 'rotateY(-13deg)', offset: 0.6 }, { transform: 'rotateY(-3deg)' }], at, len, RIFFLE);
go(g.shade, [{ opacity: 0 }, { opacity: 0.3, offset: 0.24 }, { opacity: 0.16, offset: 0.6 }, { opacity: 0 }], at, len, RIFFLE);
});
casts.push({ anim: go(sh.cast, castFrames(size.w, size.p, 0.7, 100), at, len, RIFFLE), peak: 0.7, to: 100 });
});
go(light, [{ opacity: 0 }, { opacity: 0.12, offset: 0.35 }, { opacity: 0.55, offset: 0.75 }, { opacity: 0.94 }], T.light, T.lightLen, 'cubic-bezier(.4, 0, .9, .6)');
/* Beat 5: the light fades down, and with it the notebook, into the page. */
go(overlay, [{ opacity: 1 }, { opacity: 0 }], T.fade, T.fadeLen, 'cubic-bezier(.3, 0, .2, 1)').onfinish = finish;
/* In case the browser never reports the end (a tab in the background), it is gone soon after anyway. */
timer = window.setTimeout(finish, T.fade + T.fadeLen + 900);
} catch (err) {
finish();
}
})();
</script>
<!-- Scripts off: a phone's file preview shows the page without running it. The for-education line above stays visible. -->
<noscript>
<div class="wrap noscript" id="noscript-notice">
<p class="noscript__box" role="alert"><strong>This page needs a web browser to work.</strong> On a phone, a file preview will not run it. Open the file in Safari, Chrome or Edge, or on a computer by double-clicking it.</p>
</div>
</noscript>
<main id="main" tabindex="-1">
<div class="wrap">
<!-- The book: a composition notebook cover with the name on its label, and the first page with Step 1's result. -->
<section class="book" aria-labelledby="book-name">
<div class="cover">
<svg class="marble" aria-hidden="true" focusable="false" preserveAspectRatio="none">
<filter id="marble" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB">
<feTurbulence type="fractalNoise" baseFrequency="0.062 0.074" numOctaves="4" seed="23"/>
<feColorMatrix type="matrix" values="26 0 0 0 -12.2 26 0 0 0 -12.2 26 0 0 0 -12.2 0 0 0 0 1"/>
<feGaussianBlur stdDeviation="0.5"/>
</filter>
<rect width="100%" height="100%" filter="url(#marble)"/>
</svg>
<div class="plate">
<h1 id="book-name">Full Credit</h1>
<p class="plate__lede">Kentucky teachers earn a pension instead of Social Security. See what yours is worth, what changes if you leave, and how to cover the rest.</p>
<p class="plate__for" id="built-for"></p>
</div>
</div>
<div class="page">
<p class="example" id="example-banner" hidden>
<span id="example-text">Example numbers, not yours.</span>
<button type="button" id="btn-clear-example">Clear Example</button>
<button type="button" id="btn-mine" title="Keeps these numbers as your own starting point." aria-describedby="btn-mine-hint">These Are Mine</button>
<span class="sr" id="btn-mine-hint">Keeps these numbers as your own starting point.</span>
</p>
<p class="print-only" id="print-example" hidden></p>
<p class="filestatus" id="file-status" role="status"></p>
<div class="answer" id="hero">
<p class="answer__line" id="hero-line"><span class="answer__num" id="hero-num"></span> <span class="answer__unit" id="hero-unit"></span></p>
<p class="answer__prompt" id="hero-prompt" hidden></p>
<p class="say" id="hero-say"></p>
<p class="next" id="hero-next" hidden>Leaving for other work? <button type="button" class="linkbtn" data-go-step="2">Step 2 adds your new job and its Social Security.</button></p>
</div>
<div class="pick" id="pick" hidden>
<label for="ruler-age">Slide the marker to the age you stop teaching. The flags mark your years of service.</label>
<div class="ruler">
<div class="ruler__flags" id="ruler-flags" aria-hidden="true"></div>
<div class="ruler__ticks" id="ruler-ticks" aria-hidden="true"></div>
<div class="ruler__tabs" aria-hidden="true"><b class="ruler__tab" id="ruler-tab"></b></div>
<input type="range" id="ruler-age" min="18" max="80" step="1" value="55" aria-describedby="ruler-miles">
</div>
<p class="sr" id="ruler-miles"></p>
</div>
<!-- Staying beside leaving, each as monthly income once every check has started. They sit under the ruler that
sets the staying age. Step 2 has the whole comparison. -->
<div class="paths" id="paths" hidden>
<div class="paths__grid">
<section class="path" id="path-stay" aria-labelledby="path-stay-title">
<div class="path__head"><h2 id="path-stay-title"></h2><span class="tag" data-example-tag hidden>Example</span></div>
<div id="path-stay-body"></div>
</section>
<section class="path" id="path-leave" aria-labelledby="path-leave-title">
<div class="path__head"><h2 id="path-leave-title"></h2><span class="tag" data-example-tag hidden>Example</span></div>
<div id="path-leave-body"></div>
</section>
</div>
<p class="paths__go"><button type="button" class="linkbtn" data-go-step="2">Compare in Step 2</button></p>
</div>
</div>
</section>
</div>
<!-- The summary stays at the top of the window while the steps scroll under it. -->
<div class="stripbar" id="stripbar">
<div class="wrap">
<section class="strip" id="strip" aria-label="Summary">
<div class="strip__cap">
<span class="strip__unit" id="strip-unit">Monthly income, <span class="nowrap"><span class="strip__in">in </span>today's dollars</span></span>
<div class="strip__capr">
<span class="tag" data-example-tag hidden>Example</span>
<div class="seg" role="radiogroup" aria-label="Plan Shown In The Summary">
<label><input type="radio" name="plan-strip" value="A" checked><span>Stay</span></label>
<label><input type="radio" name="plan-strip" value="B"><span>Leave</span></label>
</div>
<span class="print-only strip__plan" id="strip-plan"></span>
</div>
</div>
<dl class="strip__tiles">
<div class="tile">
<dt class="tile__label"><svg class="sw" viewBox="0 0 12 12" aria-hidden="true"><rect class="f-pension" width="12" height="12"/></svg>Pension</dt>
<dd class="tile__value" id="strip-pension">–</dd>
<dd class="tile__note" id="strip-pension-note"></dd>
</div>
<div class="tile">
<dt class="tile__label"><svg class="sw" viewBox="0 0 12 12" aria-hidden="true"><rect class="f-ss" width="12" height="12"/></svg>Social Security</dt>
<dd class="tile__value" id="strip-ss">–</dd>
<dd class="tile__note" id="strip-ss-note"></dd>
</div>
<div class="tile">
<dt class="tile__label"><svg class="sw" viewBox="0 0 12 12" aria-hidden="true"><rect class="f-savings" width="12" height="12"/></svg>Savings</dt>
<dd class="tile__value" id="strip-savings">–</dd>
<dd class="tile__note" id="strip-savings-note"></dd>
</div>
<div class="tile tile--wide">
<dt class="tile__label">Target</dt>
<dd class="tile__value" id="strip-want">–</dd>
<dd class="tile__note" id="strip-want-note"></dd>
</div>
<div class="tile tile--wide tile--left">
<dt class="tile__label"><svg class="sw" viewBox="0 0 12 12" aria-hidden="true"><rect class="f-left" x=".5" y=".5" width="11" height="11"/></svg>Left To Plan For</dt>
<dd class="tile__value" id="strip-left">–</dd>
<dd class="tile__note" id="strip-left-note"></dd>
</div>
</dl>
</section>
</div>
</div>
<div class="wrap">
<nav class="steps" aria-label="Steps">
<ol>
<li><button type="button" class="stepbtn" data-step="1" aria-current="step"><b class="stepbtn__n" aria-hidden="true">1</b><span class="sr">Step 1: </span><span class="stepbtn__t">What You Have Earned</span></button></li>
<li><button type="button" class="stepbtn" data-step="2"><b class="stepbtn__n" aria-hidden="true">2</b><span class="sr">Step 2: </span><span class="stepbtn__t">If Your Plans Change</span></button></li>
<li><button type="button" class="stepbtn" data-step="3"><b class="stepbtn__n" aria-hidden="true">3</b><span class="sr">Step 3: </span><span class="stepbtn__t">Cover The Rest</span></button></li>
</ol>
</nav>
<!-- ===== Step 1 ===== -->
<section class="step" id="step-1" aria-labelledby="step-1-title">
<div class="step__grid">
<div class="lead">
<div class="step__head">
<p class="eyebrow">Step 1 Of 3 <span class="tag" data-example-tag hidden>Example</span></p>
<h2 id="step-1-title" tabindex="-1">What You Have Earned</h2>
</div>
<div id="s1-lead"></div>
</div>
<div class="side">
<details class="numbers" id="s1-numbers" open>
<summary><span>Your Numbers</span><svg class="chev" aria-hidden="true"><use href="#i-chev"/></svg></summary>
<form class="numbers__in" id="s1-form" novalidate autocomplete="off">
<fieldset class="fieldset">
<legend>About You</legend>
<div class="fields" data-fields="birthYear service entryMonth entryYear salary"></div>
</fieldset>
<fieldset class="fieldset">
<legend>Assumptions You Can Change</legend>
<div class="fields" data-fields="raisePct inflPct"></div>
</fieldset>
</form>
</details>
</div>
<div class="body" id="s1-body">
<div class="empty" id="s1-empty" hidden></div>
<figure class="chart" id="c1" aria-labelledby="c1-title" hidden>
<div class="chart__head">
<div>
<h3 class="chart__title" id="c1-title">Your Pension At Each Retirement Age</h3>
<p class="chart__sub">A month, in today's dollars, at the first check. Pick an age on the chart or with the buttons.</p>
</div>
<div class="agepick">
<label for="f-retireAge">Age You Stop Teaching</label>
<div class="stepper">
<button type="button" id="age-down" aria-label="One Year Earlier">−</button>
<input type="number" id="f-retireAge" inputmode="numeric" step="1" aria-describedby="c1-readout">
<button type="button" id="age-up" aria-label="One Year Later">+</button>
</div>
</div>
</div>
<div class="chart__plot" id="c1-plot"></div>
<p class="readout" id="c1-readout"></p>
<ul class="legend" id="c1-legend"></ul>
<details class="tview">
<summary>Table View</summary>
<div id="c1-table"></div>
</details>
</figure>
<div id="s1-early" hidden></div>
<section class="card" id="s1-formula" aria-labelledby="s1-formula-title" hidden></section>
<figure class="chart" id="c2" aria-labelledby="c2-title" hidden>
<h3 class="chart__title" id="c2-title">After You Retire: 1.5% A Year And Inflation</h3>
<p class="chart__sub" id="c2-sub"></p>
<div class="chart__plot" id="c2-plot" style="margin-top:16px"></div>
<details class="tview">
<summary>Table View</summary>
<div id="c2-table"></div>
</details>
</figure>
</div>
<div class="aside" id="s1-aside"></div>
</div>
</section>
<!-- ===== Step 2 ===== -->
<section class="step" id="step-2" aria-labelledby="step-2-title" hidden>
<div class="step__grid">
<div class="lead">
<div class="step__head">
<p class="eyebrow">Step 2 Of 3 <span class="tag" data-example-tag hidden>Example</span></p>
<h2 id="step-2-title" tabindex="-1">If Your Plans Change</h2>
</div>
<div id="s2-lead"></div>
</div>
<div class="side">
<details class="numbers" id="s2-numbers" open>
<summary><span>Your Numbers</span><svg class="chev" aria-hidden="true"><use href="#i-chev"/></svg></summary>
<form class="numbers__in" id="s2-form" novalidate autocomplete="off">
<fieldset class="fieldset">
<legend>Leave Teaching</legend>
<div class="fields" data-fields="leaveIn nextPayB workUntilB"></div>
</fieldset>
<fieldset class="fieldset">
<legend>Stay Teaching: Work After You Retire From Teaching</legend>
<p class="fieldset__note" id="s2-plana-note"></p>
<div class="fields" data-fields="nextPayA workUntilA"></div>
</fieldset>
<fieldset class="fieldset">
<legend>Social Security From Other Work</legend>
<div class="fields" data-fields="pastYears pastPay sidePay claimAge spousePIA"></div>
</fieldset>
<details class="more">
<summary>TRS Account Details (Optional)</summary>
<div class="fields" data-fields="acctBal suppBal fedBracket"></div>
</details>
</form>
</details>
</div>
<div class="body" id="s2-body">
<!-- Staying beside leaving, with work stopping at the same age. A what-if: the age in the box is not one of
Your Numbers, so it changes nothing else on the page and it is not saved. -->
<p class="card evenneed" id="s2-even-need" hidden></p>
<figure class="chart" id="s2-even" aria-labelledby="even-title" hidden>
<h3 class="chart__title" id="even-title">Stay Or Leave, Stopping Work At The Same Age</h3>
<p class="chart__sub">What each path brings in when work stops at the same age. Taxes and health costs are not subtracted. This is a what-if. It does not change your plans or the file you save.</p>
<div class="evenpick">
<div class="evenpick__one">
<div class="agepick">
<label for="f-stopAt">Stop Working At</label>
<div class="stepper">
<button type="button" id="stop-down" aria-label="One Year Earlier">−</button>
<input type="number" id="f-stopAt" inputmode="numeric" step="1" aria-describedby="h-stopAt e-stopAt">
<button type="button" id="stop-up" aria-label="One Year Later">+</button>
</div>
</div>
<p class="hint"><span id="h-stopAt"></span> <button type="button" class="linkbtn" id="even-back" hidden></button></p>
<p class="field__error" id="e-stopAt" aria-live="polite"></p>
</div>
<!-- A second what-if: the age Social Security starts in this table. It starts on the age in Your Numbers. -->
<div class="evenpick__one">
<div class="agepick">
<span class="label" id="l-claimAt">Social Security Starts At</span>
<div class="seg" role="radiogroup" aria-labelledby="l-claimAt" aria-describedby="h-claimAt" id="claim-seg"></div>
</div>
<p class="hint" id="h-claimAt"></p>
</div>
</div>
<p class="even__say" id="even-say"></p>
<p class="even__where" id="even-where"></p>
<p class="even__where" id="even-same" hidden>About the same means within 5%.</p>
<p class="even__where" id="even-only">Through 85 only. A longer life adds more to the path that pays more later.</p>
<!-- What each path gives at this stop age that the other does not. Two boxes of the same size and style. -->
<div class="even__gives">
<section class="even__give" aria-labelledby="give-stay-title">
<h4 id="give-stay-title">What Staying Gives You</h4>
<div id="give-stay"></div>
</section>
<section class="even__give" aria-labelledby="give-leave-title">
<h4 id="give-leave-title">What Leaving Gives You</h4>
<div id="give-leave"></div>
</section>
</div>
<!-- Play The Years: the same two paths as the boxes above, laid along the years from the stop age to 85.
Each band starts at the age its check starts. The marker shows each path's monthly total at one age. -->
<section class="years" id="years" aria-labelledby="years-title">
<div class="years__head">
<h4 id="years-title">Play The Years</h4>
<button type="button" class="btn btn--secondary no-print" id="years-play">Play The Years</button>
</div>
<div class="years__plot" id="years-plot">
<input type="range" class="years__range" id="years-age" step="1" min="18" max="85" value="18" aria-labelledby="years-title">
<div class="ytrack">
<p class="ytrack__head"><span class="ytrack__name">Stay Teaching</span><span class="ytrack__sum"><b id="years-sum-stay" aria-hidden="true"></b><span class="sr" id="years-say-stay"></span> a month</span></p>
<div class="ytrack__plot"><div id="years-svg-stay"></div><div class="years__mark" aria-hidden="true"></div></div>
</div>
<div class="ytrack">
<p class="ytrack__head"><span class="ytrack__name">Leave Teaching</span><span class="ytrack__sum"><b id="years-sum-leave" aria-hidden="true"></b><span class="sr" id="years-say-leave"></span> a month</span></p>
<div class="ytrack__plot"><div id="years-svg-leave"></div><div class="years__mark" aria-hidden="true"><b class="years__tab" id="years-tab"></b></div></div>
</div>
</div>
<p class="years__cap" id="years-cap">The marker shows one month at that age. The sentence above adds up every month through 85.</p>
</section>
<!-- The whole table, closed until asked for. It prints open. -->
<details class="evenall" id="even-all">
<summary>See Every Number</summary>
<div class="even__grid" id="even-grid" role="table" aria-labelledby="even-title" aria-describedby="even-cap"></div>
<p class="even__cap" id="even-cap"></p>
<p class="even__why" id="even-why"></p>
<details class="tview no-print">
<summary>Table View</summary>
<div id="even-table"></div>
</details>
</details>
<p class="sr" id="even-live" aria-live="polite"></p>
</figure>
<div class="empty" id="s2-empty" hidden></div>
<div class="stack" id="s2-main" hidden>
<figure id="c3" aria-labelledby="c3-title">
<h3 class="chart__title" id="c3-title">Stay Teaching Beside Leave Teaching</h3>
<p class="chart__sub">Monthly income in today's dollars, set against your income target. Staying, leaving and changing careers are all workable plans; this shows what each one pays. Taxes and health costs are not subtracted.</p>
<ul class="legend" style="margin-bottom:16px">
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-pension" width="14" height="14" rx="2"/></svg>Pension</li>
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-ss" width="14" height="14" rx="2"/></svg>Social Security</li>
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-savings" width="14" height="14" rx="2"/></svg>Savings</li>
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-left" x=".5" y=".5" width="13" height="13" rx="2"/></svg>Left To Plan For</li>
<li><svg class="key-line" viewBox="0 0 18 14" aria-hidden="true"><line class="wantline" x1="9" y1="0" x2="9" y2="14"/></svg>Target</li>
</ul>
<div class="plans" id="s2-plans"></div>
<details class="tview">
<summary>Table View</summary>
<div id="c3-table"></div>
</details>
</figure>
<section class="card" id="s2-account" aria-labelledby="s2-account-title" hidden>
<h3 id="s2-account-title">Your TRS Account If You Leave</h3>
<p id="s2-account-intro"></p>
<div class="choices choices--3" role="radiogroup" aria-labelledby="s2-account-title" style="margin-top:16px">
<label class="choice"><input type="radio" name="acctChoice" value="leave"><span class="choice__title">Leave It In TRS</span><span class="choice__big" id="acct-leave-big"></span><span class="choice__when" id="acct-leave-when"></span><span class="choice__text" id="acct-leave-text"></span><span class="choice__text choice__back" id="acct-leave-back" hidden></span></label>
<label class="choice"><input type="radio" name="acctChoice" value="rollover"><span class="choice__title">Roll It Over</span><span class="choice__big" id="acct-rollover-big"></span><span class="choice__when" id="acct-rollover-when"></span><span class="choice__text" id="acct-rollover-text"></span><span class="choice__text choice__back" id="acct-rollover-back"></span></label>
<label class="choice"><input type="radio" name="acctChoice" value="cash"><span class="choice__title">Take It As Cash</span><span class="choice__big" id="acct-cash-big"></span><span class="choice__text" id="acct-cash-text"></span><span class="choice__text choice__back" id="acct-cash-back"></span></label>
</div>
<div id="s2-account-notes" style="margin-top:16px"></div>
</section>
<div id="s2-rules"></div>
</div>
</div>
<div class="aside" id="s2-aside"></div>
</div>
</section>
<!-- ===== Step 3 ===== -->
<section class="step" id="step-3" aria-labelledby="step-3-title" hidden>
<div class="step__grid">
<div class="lead">
<div class="step__head">
<p class="eyebrow">Step 3 Of 3 <span class="tag" data-example-tag hidden>Example</span></p>
<h2 id="step-3-title" tabindex="-1">Cover The Rest</h2>
</div>
<div id="s3-lead"></div>
</div>
<div class="side">
<details class="numbers" id="s3-numbers" open>
<summary><span>Your Numbers</span><svg class="chev" aria-hidden="true"><use href="#i-chev"/></svg></summary>
<form class="numbers__in" id="s3-form" novalidate autocomplete="off">
<fieldset class="fieldset">
<legend>Plan To Cover</legend>
<div class="seg" role="radiogroup" aria-label="Plan To Cover">
<label><input type="radio" name="plan-step3" value="A" checked><span>Stay</span></label>
<label><input type="radio" name="plan-step3" value="B"><span>Leave</span></label>
</div>
<p class="hint" id="s3-plan-note" style="margin-top:8px"></p>
</fieldset>
<fieldset class="fieldset">
<legend>Target</legend>
<div class="fields" data-fields="targetPct"></div>
</fieldset>
<fieldset class="fieldset">
<legend>Savings</legend>
<div class="fields" data-fields="balance monthly"></div>
</fieldset>
<fieldset class="fieldset">
<legend>Assumptions You Can Change</legend>
<div class="fields" data-fields="returnPct drawPct"></div>
</fieldset>
</form>
</details>
</div>
<div class="body" id="s3-body">
<div class="empty" id="s3-empty" hidden></div>
<div class="stack" id="s3-main" hidden>
<figure class="chart" id="c4" aria-labelledby="c4-title">
<h3 class="chart__title" id="c4-title">Income Against Your Target</h3>
<p class="chart__sub" id="c4-sub">A month, in today's dollars, at each age the page checks. Taxes and health costs are not subtracted.</p>
<ul class="legend" style="margin-bottom:20px">
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-pension" width="14" height="14" rx="2"/></svg>Pension</li>
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-ss" width="14" height="14" rx="2"/></svg>Social Security</li>
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-savings" width="14" height="14" rx="2"/></svg>Savings</li>
<li><svg viewBox="0 0 14 14" aria-hidden="true"><rect class="f-left" x=".5" y=".5" width="13" height="13" rx="2"/></svg>Left To Plan For</li>
<li><svg class="key-line" viewBox="0 0 18 14" aria-hidden="true"><line class="wantline" x1="9" y1="0" x2="9" y2="14"/></svg>Target</li>
</ul>
<div class="cov" id="c4-rows"></div>
<details class="tview">
<summary>Table View</summary>
<div id="c4-table"></div>
</details>
</figure>
<section id="s3-ways" aria-labelledby="s3-ways-title">
<h3 class="chart__title" id="s3-ways-title">Three Ways To Cover It</h3>
<p class="chart__sub" id="s3-ways-sub"></p>
<div class="ways" style="margin-top:16px">
<section class="card way" aria-labelledby="way-save-title">
<h4 id="way-save-title">Save More</h4>
<div id="way-save-body"></div>
</section>
<section class="card way" aria-labelledby="way-teach-title">
<h4 id="way-teach-title">Teach Longer</h4>
<div id="way-teach-body"></div>
</section>
<section class="card way" aria-labelledby="way-work-title">
<h4 id="way-work-title">Work After Teaching</h4>
<div id="way-work-body"></div>
<div class="fields" id="way-work-a" data-fields="nextPayA workUntilA" data-dup="way"></div>
<div class="fields" id="way-work-b" data-fields="nextPayB workUntilB" data-dup="way" hidden></div>
</section>
</div>
</section>
<section class="card" id="s3-todo-host" aria-labelledby="s3-todo-title">
<h3 id="s3-todo-title">A Short To-Do List</h3>
<p class="print-only small" id="s3-todo-printhead"></p>
<ul class="todo" id="s3-todo" style="margin-top:12px"></ul>
<div class="todo__actions">
<button type="button" class="btn btn--secondary" id="btn-print-todo">Print To-Do List</button>
<button type="button" class="btn btn--secondary" id="btn-print-all">Print Whole Plan</button>
</div>
</section>
</div>
</div>
<div class="aside" id="s3-aside"></div>
</div>
</section>
<section class="print-only" id="print-numbers" aria-hidden="true"></section>
<div class="pager">
<button type="button" class="btn btn--secondary" id="pager-back"><svg aria-hidden="true"><use href="#i-back"/></svg><span></span></button>
<button type="button" class="btn btn--secondary" id="pager-next"><span></span><svg aria-hidden="true"><use href="#i-next"/></svg></button>
</div>
</div>
</main>
<footer class="foot">
<div class="wrap foot__grid">
<p id="notice-bottom"><strong>For education only.</strong> This page is not financial, tax or legal advice, and it is not connected to TRS or the Social Security Administration. Its numbers are estimates built on the simplified rules it lists. Before you decide anything, check your own figures with TRS at <span class="nowrap">800-618-1687</span>.</p>
<div class="foot__links">
<button type="button" class="linkbtn" data-open="dlg-rules">Rules And Sources</button>
<button type="button" class="linkbtn" data-open="dlg-about">About And License</button>
<button type="button" class="linkbtn" data-motion-toggle>Pause Motion</button>
</div>
<p>Rules last reviewed November 12, 2026, and KRS 161.470 rules on November 18, 2026. Some come from Kentucky statute rather than a TRS fact sheet. Your numbers stay on this device: the page has no accounts and sends nothing anywhere.</p>
<p>Copyright © 2026 Noah Emery and Noah Crider. Released under the MIT License.</p>
</div>
</footer>
<!-- The Saved stamp, shown for a moment after a save when motion is on. Screen readers hear the status line instead. -->
<div class="stamp" id="saved-stamp" aria-hidden="true" hidden>Saved</div>
<!-- ===== Rules And Sources ===== -->
<dialog id="dlg-rules" aria-labelledby="dlg-rules-title">
<div class="dlg__head">
<h2 id="dlg-rules-title" tabindex="-1">Rules And Sources</h2>
<button type="button" class="btn btn--quiet" data-close aria-label="Close Rules And Sources"><svg aria-hidden="true"><use href="#i-close"/></svg></button>
</div>
<div class="dlg__body">
<p class="checked">Last reviewed November 12, 2026. KRS 161.470 rules reviewed November 18, 2026.</p>
<p>These are the rules this page uses. They match its calculation engine. TRS and the Social Security Administration have the final word on your own account. TRS phone: <span class="nowrap">800-618-1687</span>.</p>
<h3>Account Types By First Day In TRS</h3>
<ul>
<li>TRS 1: before July 1, 2002.</li>
<li>TRS 2: July 1, 2002 through June 30, 2008.</li>
<li>TRS 3: July 1, 2008 through December 31, 2021.</li>
<li>TRS 4: from January 1, 2022.</li>
</ul>
<h3>Contributions</h3>
<ul>
<li>TRS 1 to 3 pay 12.855% of pay: 9.105% toward the pension and 3.75% toward retiree health.</li>
<li>TRS 4 pays 14.75%: 9% foundational, 2% supplemental and 3.75% health. The employer adds 2% to the supplemental account.</li>
<li>No Social Security tax comes out of TRS pay. Medicare tax applies if you were hired after March 31, 1986.</li>
</ul>
<h3>Pension Formula</h3>
<ul>
<li>Years of service × multiplier × final average salary. The multiplier is the share of your final average salary that each year of service earns.</li>
<li>TRS 1: 2.5%.</li>
<li>TRS 2: 2.0% with under 10 years, 2.5% on every year with 10 or more.</li>
<li>TRS 3: 1.7% up to 10 years, 2.0% past 10, 2.3% past 20, 2.5% past 26, each on every year.</li>
<li>TRS 1 to 3: 3.0% for years past 30.</li>
<li>TRS 4: 1.70% at ages 57 to 60, rising 0.04 a year to 1.90% at 65, plus 0.25% with 20 years or 0.5% with 30.</li>
</ul>
<h3>Final Average Salary</h3>
<ul>
<li>The average of your 5 highest salaries, or the 3 highest for TRS 1 to 3 members who are 55 with 27 years.</li>
</ul>
<h3>Full Pension</h3>
<ul>
<li>TRS 1 to 3: 27 years at any age, or age 60 with 5 years.</li>
<li>TRS 4: 57 with 30 years, 60 with 10, or 65 with 5.</li>
</ul>
<h3>Reduced Pension</h3>
<ul>
<li>TRS 1 and 2: from age 55 with 5 years, 5% for each year short of 60 or of 27 years, whichever is fewer.</li>
<li>TRS 3: from 55 with 10 years, 6% on the same test.</li>
<li>TRS 4: from 57 with 10 years, reduced by up to 18%. TRS publishes only that limit. Inside it, this page estimates 6% for each year short of 60 or of 30 years. Ask TRS for the exact figure.</li>
</ul>
<h3>After Retiring</h3>
<ul>
<li>The pension rises 1.5% each July 1.</li>
<li>For TRS 4, the TRS board can adjust terms if funding falls short.</li>
</ul>
<h3>Leaving</h3>
<ul>
<li>Vesting takes 5 years. Vested means you have earned the right to a pension, even if you leave.</li>
<li>A refund is your own contributions plus interest (3% if you joined before July 1, 2008, otherwise 2.5%). It never includes the health contribution or the state's money. It is paid no sooner than 60 days after your last day, and it ends your membership.</li>
<li>A TRS 4 member with under 5 years gives up the employer's supplemental share.</li>
<li>A vested pension left in TRS uses the salary and service at leaving and gets no inflation increase while it waits.</li>
<li>Hired since July 1, 2008: TRS retiree health needs 15 years.</li>
</ul>
<h3>Returning To Teaching</h3>
<ul>
<li>With 5 years or more, your years stay in TRS while you are away. If you come back to a Kentucky classroom, they still count.</li>
<li>Under 5 years, membership ends after more than 3 straight years away. If you come back without having taken a refund, those years are restored.</li>
<li>If you take a refund and come back, you return as a new member. After a year back you can repay the refund with interest to restore those years.</li>
</ul>
<p class="small" id="rules-return-source">Source for these three rules: <a href="https://apps.legislature.ky.gov/law/statutes/statute.aspx?id=56063" target="_blank" rel="noopener noreferrer">Kentucky Revised Statutes 161.470 (apps.legislature.ky.gov, PDF)</a>. Reviewed November 18, 2026.</p>
<h3>Social Security, 2026</h3>
<ul>
<li>You need 40 credits. Each $1,890 of covered pay earns one credit, up to 4 a year. Covered pay is pay that has Social Security tax taken out.</li>
<li>The benefit uses your 35 highest years of covered pay. Teaching pay is not covered pay, so teaching years add nothing to that average. The pension covers those years.</li>
<li>It pays 90% of the first $1,286 of average monthly earnings, 32% up to $7,749 and 15% above.</li>
<li>Claiming at 62 pays 70%, at 67 100%, at 70 124%.</li>
<li>The Social Security Fairness Act, signed January 5, 2025, ended two older rules for benefits after December 2023: the Windfall Elimination Provision (WEP) and the Government Pension Offset (GPO). A teacher pension no longer reduces your own, spousal or survivor benefits.</li>
</ul>
<h3>Savings Plans, 2026</h3>
<ul>
<li>$24,500 a year across 403(b) and 401(k) plans, and a separate $24,500 in a 457(b).</li>
<li>Catch-up: $8,000 more at 50, or $11,250 at 60 to 63.</li>
<li>IRA: $7,500, or $8,600 at 50.</li>
<li>Kentucky Deferred Comp is the state 457(b) and 401(k) program, open to public school employees where the district takes part. Ask your district.</li>
</ul>
<h3>Taxes</h3>
<ul>
<li>A cash refund owes income tax, plus a 10% federal penalty before age 59 and a half unless you leave in or after the year you turn 55. State income tax may also apply. A direct rollover avoids these for now.</li>
<li>Kentucky taxes TRS pension earned after January 1, 1998 beyond a $31,110 exclusion. Kentucky does not tax Social Security.</li>
</ul>
<h3>What The Page Simplifies</h3>
<ul>
<li>Whole years and steady raises.</li>
<li>The basic pension, with no survivor option.</li>
<li>Sick leave credit is not added. Service you bought counts only if it is in the service number you enter.</li>
<li>Full retirement age for Social Security is 67.</li>
<li>The TRS 4 supplemental account grows at an assumed 4%.</li>
<li>Taxes and health costs are not subtracted.</li>
<li>Every amount is in today's dollars: adjusted for inflation so you can compare it with prices now.</li>
<li>Your monthly saving, and any extra saving the page suggests, rise with inflation each year.</li>
<li>Savings income is the yearly withdrawal you choose, kept level in today's dollars.</li>
<li>The salary you enter counts as this school year's. Stopping now counts only the years already finished.</li>
<li>TRS prorates the first 1.5% increase for a partial year. This page applies a full 1.5%.</li>
<li>Social Security is figured as if you claim after you stop working. Claiming before 67 while still working can reduce your checks.</li>
<li>A pension left in TRS is shown starting at the first age with no reduction. An earlier, reduced start may be possible; ask TRS.</li>
</ul>
<h3>Sources</h3>
<ul class="srclist">
<li><a href="https://trs.ky.gov/wp-content/uploads/2022/09/TRS-Basics-123-final.pdf" target="_blank" rel="noopener noreferrer">TRS Basics for TRS 1, TRS 2 and TRS 3 (trs.ky.gov, PDF)</a></li>
<li><a href="https://trs.ky.gov/wp-content/uploads/2021/12/TRS-Basics-4-final-202112.pdf" target="_blank" rel="noopener noreferrer">TRS Basics for TRS 4 (trs.ky.gov, PDF)</a></li>
<li><a href="https://trs.ky.gov/wp-content/uploads/2021/12/Service-Retirement-Information-Sheet-TRS4-FINAL-202303.pdf" target="_blank" rel="noopener noreferrer">TRS 4 Service Retirement (trs.ky.gov, PDF)</a></li>
<li><a href="https://trs.ky.gov/retired-members/plan/cost-of-living-adjustments/" target="_blank" rel="noopener noreferrer">TRS cost-of-living adjustments (trs.ky.gov)</a></li>
<li><a href="https://trs.ky.gov/how-your-trs-benefit-may-affect-your-social-security-benefit/" target="_blank" rel="noopener noreferrer">TRS and Social Security (trs.ky.gov)</a></li>
<li><a href="https://apps.legislature.ky.gov/law/statutes/chapter.aspx?id=37880" target="_blank" rel="noopener noreferrer">Kentucky Revised Statutes, Chapter 161, Teachers' Retirement (apps.legislature.ky.gov)</a></li>
<li><a href="https://apps.legislature.ky.gov/law/statutes/statute.aspx?id=56063" target="_blank" rel="noopener noreferrer">Kentucky Revised Statutes 161.470, membership, refunds and returning to teaching (apps.legislature.ky.gov, PDF)</a></li>
<li><a href="https://www.ssa.gov/OACT/cola/piaformula.html" target="_blank" rel="noopener noreferrer">Social Security benefit formula and its bend points (ssa.gov)</a></li>
<li><a href="https://www.ssa.gov/benefits/retirement/social-security-fairness-act.html" target="_blank" rel="noopener noreferrer">Social Security Fairness Act (ssa.gov)</a></li>
<li><a href="https://www.govinfo.gov/content/pkg/FR-2025-11-03/pdf/2025-19763.pdf" target="_blank" rel="noopener noreferrer">Social Security Administration, Cost-of-Living Increase and Other Determinations for 2026, Federal Register, November 3, 2025 (govinfo.gov, PDF)</a></li>
<li><a href="https://www.irs.gov/node/4953" target="_blank" rel="noopener noreferrer">IRS retirement topics: catch-up contributions (irs.gov)</a></li>
</ul>
<p class="small muted">These links open web pages outside this file. The page itself never goes online.</p>
</div>
</dialog>
<!-- ===== About ===== -->
<dialog id="dlg-about" aria-labelledby="dlg-about-title">
<div class="dlg__head">
<h2 id="dlg-about-title" tabindex="-1">About Full Credit</h2>
<button type="button" class="btn btn--quiet" data-close aria-label="Close About"><svg aria-hidden="true"><use href="#i-close"/></svg></button>
</div>
<div class="dlg__body">
<p>Full Credit is a planning page for Kentucky public school teachers (K-12) in the Teachers' Retirement System (TRS). Service credit is TRS's term for the years you have worked. The page shows what those years have earned, what changes if you leave teaching or change careers, and how to cover whatever the pension does not.</p>
<p>TRS estimates the pension and Social Security estimates its benefit. This page puts both next to your savings and shows what a career change does to all three.</p>
<p>The math runs through more than 100 automated checks against the published TRS and Social Security rules, and the page through more than 300 browser checks.</p>
<h3>For Education Only</h3>
<p>This page is not financial, tax or legal advice, and it is not connected to TRS or the Social Security Administration. It does not recommend any investment. Its numbers are estimates. Check your own figures with TRS at <span class="nowrap">800-618-1687</span> before you decide anything.</p>
<h3>Your Privacy</h3>
<p>Your numbers stay on this device. The page has no accounts, never asks for a password or login, and sends nothing anywhere. A security rule built into the file blocks it from loading or sending anything over the network. Save writes a small file to your own device, and Open reads it back.</p>
<h3>Credits</h3>
<p>Made by Noah Emery and Noah Crider for the Kentucky PFM Challenge.</p>
<p>Built with help from Claude by Anthropic.</p>
<p>Third-party libraries: none. The fonts are your device's own. The charts and icons are drawn inside this file. The calculation engine is the authors' own work.</p>
<h3>License</h3>
<pre>MIT License
Copyright (c) 2026 Noah Emery and Noah Crider
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</pre>
</div>
</dialog>
<!-- ===== Unsaved changes ===== -->
<dialog id="dlg-confirm" class="dlg--small" aria-labelledby="dlg-confirm-title" aria-describedby="dlg-confirm-text">
<div class="dlg__head">
<h2 id="dlg-confirm-title" tabindex="-1">Your Changes Are Not Saved</h2>
</div>
<div class="dlg__body">
<p id="dlg-confirm-text"></p>
</div>
<div class="dlg__foot">
<button type="button" class="btn btn--quiet" id="confirm-cancel">Cancel</button>
<button type="button" class="btn btn--secondary" id="confirm-go">Continue Without Saving</button>
<button type="button" class="btn btn--primary" id="confirm-save">Save First</button>
</div>
</dialog>
<!-- ===== Messages ===== -->
<dialog id="dlg-msg" class="dlg--small" aria-labelledby="dlg-msg-title" aria-describedby="dlg-msg-text">
<div class="dlg__head">
<h2 id="dlg-msg-title" tabindex="-1"></h2>
</div>
<div class="dlg__body">
<p id="dlg-msg-text"></p>
<p id="dlg-msg-more" class="small muted"></p>
</div>
<div class="dlg__foot">
<button type="button" class="btn btn--primary" data-close>OK</button>
</div>
</dialog>
<input type="file" id="file-input" accept=".json,application/json" class="sr" tabindex="-1" aria-hidden="true">
<!-- ENGINE START: calc.js, included unchanged. `node test.js` checks this same code. -->
<script id="engine">
/* ===== Full Credit KY: calculation engine (no page access) =====
Every rule below was last reviewed against TRS, Kentucky statutes, the
Social Security Administration and the IRS on November 12, 2026, and the
KRS 161.470 rules on November 18, 2026. Some come from Kentucky statute
rather than a TRS fact sheet. Sources are listed in the Rules And Sources
dialog on the page. */
var TG = (function () {
'use strict';
var RULES = {
year: 2026,
checked: 'November 12, 2026',
cola: 0.015, // TRS cost-of-living adjustment, each July 1
vestYears: 5, // years of service to qualify for any pension
healthYears: 15, // years needed for TRS retiree health (hired since July 1, 2008)
suppRate: 0.04, // assumed interest on the TRS 4 supplemental account
ss: { bend1: 1286, bend2: 7749, credit: 1890, wageBase: 184500, fra: 67, need: 40 },
limits: { deferral: 24500, catch50: 8000, catch6063: 11250, ira: 7500, iraCatch: 1100 },
tiers: {
1: { name: 'TRS 1', joined: 'before July 1, 2002', contrib: 0.12855, pension: 0.09105, health: 0.0375, interest: 0.03 },
2: { name: 'TRS 2', joined: 'July 1, 2002 through June 30, 2008', contrib: 0.12855, pension: 0.09105, health: 0.0375, interest: 0.03 },
3: { name: 'TRS 3', joined: 'July 1, 2008 through December 31, 2021', contrib: 0.12855, pension: 0.09105, health: 0.0375, interest: 0.025 },
4: { name: 'TRS 4', joined: 'on or after January 1, 2022', contrib: 0.1475, pension: 0.09, health: 0.0375, supp: 0.02, interest: 0.025 }
}
};
function num(x) { return typeof x === 'number' && isFinite(x) ? x : 0; }
/* Which TRS account type, from the month and year of entry. */
function tierOf(y, m) {
var k = y * 12 + (m - 1);
if (k < 2002 * 12 + 6) return 1;
if (k < 2008 * 12 + 6) return 2;
if (k < 2022 * 12) return 3;
return 4;
}
function basics(s) {
var infl = num(s.inflPct) / 100, raise = num(s.raisePct) / 100;
return {
age0: s.nowYear - s.birthYear,
tier: tierOf(s.entryYear, s.entryMonth),
infl: infl, raise: raise, g: (1 + raise) / (1 + infl),
ret: num(s.returnPct) / 100,
draw: Math.max(num(s.drawPct) / 100, 0.001)
};
}
function ready(s) {
if (!(s.birthYear > 1900) || !(s.entryYear > 1900) || !(s.salary > 0)) return false;
var a = s.nowYear - s.birthYear;
return a >= 18 && a <= 80;
}
/* Can a member with this age and service start a pension, and with what cut? */
function elig(tier, age, svc) {
var cut = null;
if (tier <= 3) {
if (svc >= 27 || (age >= 60 && svc >= 5)) return { ok: true, cut: 0 };
if (age >= 55 && svc >= (tier === 3 ? 10 : 5)) cut = (tier === 3 ? 0.06 : 0.05) * Math.min(60 - age, 27 - svc);
} else {
if ((age >= 57 && svc >= 30) || (age >= 60 && svc >= 10) || (age >= 65 && svc >= 5)) return { ok: true, cut: 0 };
if (age >= 57 && svc >= 10) cut = 0.06 * Math.min(60 - age, 30 - svc);
}
if (cut === null) return { ok: false, cut: 0 };
return { ok: true, cut: Math.max(0, cut) };
}
/* Share of final average salary paid per year of service, and in total. */
function mult(tier, age, svc) {
var rate;
if (tier === 4) {
var af = age <= 60 ? 1.70 : age >= 65 ? 1.90 : 1.70 + 0.04 * (age - 60);
var cf = svc >= 30 ? 0.5 : svc >= 20 ? 0.25 : 0;
rate = (af + cf) / 100;
return { rate: rate, pct: rate * svc, over30: 0 };
}
if (tier === 1) rate = 0.025;
else if (tier === 2) rate = svc < 10 ? 0.02 : 0.025;
else rate = svc <= 10 ? 0.017 : svc <= 20 ? 0.02 : svc <= 26 ? 0.023 : 0.025;
var extra = Math.max(0, svc - 30);
return { rate: rate, pct: rate * Math.min(svc, 30) + 0.03 * extra, over30: extra };
}
function fasYears(tier, age, svc) { return (tier <= 3 && age >= 55 && svc >= 27) ? 3 : 5; }
function salaryAt(s, k) { return s.salary * Math.pow(1 + num(s.raisePct) / 100, k); }
/* Year 0 is the salary typed in, for the school year in progress, so the
last salary earned is year t - 1. Stopping now uses last year's salary. */
function lastYear(t) { return t - 1; }
function fasNominal(s, t, n) {
var sum = 0, L = lastYear(t);
for (var j = 0; j < n; j++) sum += salaryAt(s, L - j);
return sum / n;
}
/* The pension if you stop teaching at sepAge. Amounts are today's dollars
at the first check. If you cannot draw right away, the pension waits
for the first age with no reduction, using the salary you left with. */
function pensionAt(s, sepAge) {
var b = basics(s), t = Math.max(0, sepAge - b.age0), svc = num(s.service) + t;
var out = { sepAge: sepAge, t: t, service: svc, tier: b.tier, vested: svc >= RULES.vestYears,
immediate: false, deferred: false, drawAge: null, cut: 0, rate: 0, pct: 0, annual: 0, monthly: 0,
payToday: s.salary * Math.pow(b.g, lastYear(t)), replace: 0, fasToday: 0, fasYears: 5 };
if (!out.vested) return out;
var e = elig(b.tier, sepAge, svc), drawAge = sepAge, cut = e.cut;
if (e.ok) out.immediate = true;
else {
out.deferred = true; drawAge = null; cut = 0;
for (var a = Math.ceil(sepAge); a <= 80; a++) {
var e2 = elig(b.tier, a, svc);
if (e2.ok && e2.cut === 0) { drawAge = a; break; }
}
if (drawAge === null) return out;
}
var n = fasYears(b.tier, drawAge, svc), fasN = fasNominal(s, t, n), m = mult(b.tier, drawAge, svc);
out.drawAge = drawAge; out.cut = cut; out.rate = m.rate; out.pct = m.pct; out.fasYears = n;
out.fasToday = fasN / Math.pow(1 + b.infl, t);
out.annual = fasN * m.pct * (1 - cut) / Math.pow(1 + b.infl, drawAge - b.age0);
out.monthly = out.annual / 12;
out.replace = out.payToday > 0 ? out.annual / out.payToday : 0;
return out;
}
/* Pension for each retirement age, for the chart. */
function pensionTable(s, toAge) {
var b = basics(s), rows = [], first = null, a;
for (a = b.age0; a <= 80; a++) if (elig(b.tier, a, num(s.service) + a - b.age0).ok) { first = a; break; }
var from = Math.max(b.age0, Math.min(first === null ? 60 : first - 1, 62, toAge || 99));
var to = Math.max(67, toAge || 0, from + 4);
for (a = from; a <= to; a++) {
var p = pensionAt(s, a);
rows.push({ age: a, service: p.service, ok: p.immediate, cut: p.cut, rate: p.rate, monthly: p.immediate ? p.monthly : 0, replace: p.immediate ? p.replace : 0 });
}
return { rows: rows, firstAge: first };
}
/* Your refundable TRS account at separation (dollars of that year). */
function account(s, t) {
var b = basics(s), T = RULES.tiers[b.tier], r = T.interest, c = T.pension, sr = RULES.suppRate, i, x;
var svc = num(s.service), full = Math.floor(svc), frac = svc - full;
var member = 0, sm = 0, se = 0, est = false;
if (s.acctBal > 0) member = s.acctBal;
else {
est = true;
for (i = 1; i <= full; i++) member += c * salaryAt(s, -i) * Math.pow(1 + r, i - 0.5);
if (frac > 0) member += frac * c * salaryAt(s, -(full + 1)) * Math.pow(1 + r, full);
}
if (b.tier === 4) {
if (s.suppBal > 0) { sm = s.suppBal / 2; se = s.suppBal / 2; }
else {
for (i = 1; i <= full; i++) { x = T.supp * salaryAt(s, -i) * Math.pow(1 + sr, i - 0.5); sm += x; se += x; }
if (frac > 0) { x = frac * T.supp * salaryAt(s, -(full + 1)) * Math.pow(1 + sr, full); sm += x; se += x; }
}
}
for (i = 0; i < t; i++) {
var sal = salaryAt(s, i);
member = member * (1 + r) + c * sal * (1 + r / 2);
if (b.tier === 4) {
sm = sm * (1 + sr) + T.supp * sal * (1 + sr / 2);
se = se * (1 + sr) + T.supp * sal * (1 + sr / 2);
}
}
return { member: member, suppMember: sm, suppEmployer: se, estimated: est };
}
/* Social Security estimate in today's dollars from a list of yearly
covered earnings. Uses the 2026 formula; years with no covered pay are zeros. */
function ownFactor(age) {
var m = Math.round((age - RULES.ss.fra) * 12);
if (m >= 0) return 1 + Math.min(m, 36) * (2 / 300);
m = -m;
return 1 - Math.min(m, 36) * (5 / 900) - Math.max(0, m - 36) * (5 / 1200);
}
function spouseFactor(age) {
var m = Math.round((RULES.ss.fra - age) * 12);
if (m <= 0) return 1;
return 1 - Math.min(m, 36) * (25 / 3600) - Math.max(0, m - 36) * (5 / 1200);
}
function ssCalc(years, claimAge, spousePIA) {
var S = RULES.ss, credits = 0, capped = [], i;
for (i = 0; i < years.length; i++) {
var pay = Math.min(num(years[i]), S.wageBase);
if (pay <= 0) continue;
credits += Math.min(4, Math.floor(pay / S.credit));
capped.push(pay);
}
capped.sort(function (a, b) { return b - a; });
var sum = 0;
for (i = 0; i < Math.min(35, capped.length); i++) sum += capped[i];
var aime = sum / 420;
var pia = 0.9 * Math.min(aime, S.bend1) + 0.32 * Math.max(0, Math.min(aime, S.bend2) - S.bend1) + 0.15 * Math.max(0, aime - S.bend2);
var insured = credits >= S.need, ownPIA = insured ? pia : 0;
var own = ownPIA * ownFactor(claimAge);
var spousal = Math.max(0, 0.5 * num(spousePIA) - ownPIA) * spouseFactor(claimAge);
return { credits: credits, coveredYears: capped.length, aime: aime, pia: pia, insured: insured, ownPIA: ownPIA, own: own, spousal: spousal, monthly: own + spousal };
}
function coveredYears(s, sepAge, nextPay, workUntil, includeTeaching) {
var b = basics(s), yrs = [], i, py = num(s.pastYears), full = Math.floor(py), frac = py - full;
for (i = 0; i < full; i++) yrs.push(num(s.pastPay));
if (frac > 0) yrs.push(num(s.pastPay) * frac);
var t = Math.max(0, sepAge - b.age0);
for (i = 0; i < t; i++) {
var pay = num(s.sidePay) + (includeTeaching ? s.salary * Math.pow(b.g, i) : 0);
if (pay > 0) yrs.push(pay);
}
if (includeTeaching) for (i = 1; i <= Math.floor(num(s.service)); i++) yrs.push(s.salary * Math.pow(b.g, -i));
if (nextPay > 0) for (i = sepAge; i < workUntil; i++) yrs.push(nextPay);
return yrs;
}
/* Future value of $1 a month for n months at monthly rate rm. */
function ann(rm, n) { return n <= 0 ? 0 : (Math.abs(rm) < 1e-9 ? n : (Math.pow(1 + rm, n) - 1) / rm); }
/* One whole plan: 'A' teaches until the planned retirement age,
'B' leaves early. Everything is monthly, in today's dollars. */
function evalPlan(s, which, o) {
o = o || {};
var b = basics(s);
var ret = (o.returnPct != null ? o.returnPct : num(s.returnPct)) / 100;
var sepAge = which === 'A' ? num(s.retireAge) : b.age0 + num(s.leaveIn);
if (sepAge < b.age0) sepAge = b.age0;
var nextPay = which === 'A' ? num(s.nextPayA) : num(s.nextPayB);
var workUntil = which === 'A' ? num(s.workUntilA) : num(s.workUntilB);
var hasNext = nextPay > 0 && workUntil > sepAge;
if (!hasNext) nextPay = 0;
var stopAge = hasNext ? workUntil : sepAge, t = sepAge - b.age0;
var p = pensionAt(s, sepAge), acct = account(s, t), defl = Math.pow(1 + b.infl, t);
var refundToday = (acct.member + acct.suppMember + (p.vested ? acct.suppEmployer : 0)) / defl;
var forfeitToday = p.vested ? 0 : acct.suppEmployer / defl;
var mode, forced = false;
if (p.vested && p.immediate) mode = 'retire';
else if (p.vested && p.drawAge !== null && s.acctChoice === 'leave') mode = 'deferred';
else if (s.acctChoice === 'cash') mode = 'cash';
else { mode = 'rollover'; forced = s.acctChoice === 'leave'; }
var hasPension = mode === 'retire' || mode === 'deferred';
var drawAge = hasPension ? p.drawAge : null, pen0 = hasPension ? p.monthly : 0;
var penaltyRate = sepAge < 55 ? 0.10 : 0, taxRate = num(s.fedBracket) / 100;
var cashLost = mode === 'cash' ? refundToday * Math.min(1, penaltyRate + taxRate) : 0;
var claimAge = num(s.claimAge) || RULES.ss.fra;
var ss = ssCalc(coveredYears(s, sepAge, nextPay, workUntil, false), claimAge, num(s.spousePIA));
var ssCov = ssCalc(coveredYears(s, sepAge, nextPay, workUntil, true), RULES.ss.fra, 0);
var ssMissed = Math.max(0, ssCov.ownPIA - ss.ownPIA);
var rReal = (1 + ret) / (1 + b.infl) - 1, rm = Math.pow(1 + rReal, 1 / 12) - 1;
var nY = stopAge - b.age0, nM = Math.round(nY * 12);
var fvOwn = num(s.balance) * Math.pow(1 + rReal, nY) + num(s.monthly) * ann(rm, nM);
var fvExtra = o.extraMonthly ? o.extraMonthly * ann(rm, Math.max(0, nM - 12 * (o.delayYears || 0))) : 0;
var fvRoll = mode === 'rollover' ? refundToday * Math.pow(1 + rReal, stopAge - sepAge) : 0;
var fvSupp = 0;
if (b.tier === 4 && hasPension) {
fvSupp = (acct.suppMember + acct.suppEmployer) * Math.pow(1 + RULES.suppRate, stopAge - sepAge) / Math.pow(1 + b.infl, stopAge - b.age0);
}
var pot = fvOwn + fvExtra + fvRoll + fvSupp, savMonthly = pot * b.draw / 12;
var basePay = Math.max(s.salary * Math.pow(b.g, lastYear(t)), nextPay);
var target = num(s.targetPct) / 100 * basePay / 12;
function at(x) {
var pen = (drawAge !== null && x >= drawAge) ? pen0 * Math.pow((1 + RULES.cola) / (1 + b.infl), x - drawAge) : 0;
var soc = x >= claimAge ? ss.monthly : 0;
var total = pen + soc + savMonthly;
return { age: x, pension: pen, ss: soc, savings: savMonthly, total: total, gap: Math.max(0, target - total) };
}
var allAge = Math.max(stopAge, drawAge || 0, ss.monthly > 0 ? claimAge : 0);
var ages = [stopAge];
if (allAge > stopAge) ages.push(allAge);
if (allAge < 85) ages.push(85);
var snaps = ages.map(at);
return { which: which, tier: b.tier, age0: b.age0, sepAge: sepAge, stopAge: stopAge, t: t, hasNext: hasNext, nextPay: nextPay,
pension: p, mode: mode, forced: forced, hasPension: hasPension, drawAge: drawAge, pensionMonthly: pen0,
acct: acct, refundToday: refundToday, forfeitToday: forfeitToday, cashLost: cashLost, penaltyRate: penaltyRate, taxRate: taxRate,
ss: ss, ssMissed: ssMissed, claimAge: claimAge,
pot: pot, potParts: { own: fvOwn, extra: fvExtra, rollover: fvRoll, supplemental: fvSupp }, savingsMonthly: savMonthly,
basePay: basePay, target: target, allAge: allAge, snaps: snaps, primary: at(allAge), at: at, nM: nM, rReal: rReal };
}
/* Extra monthly saving that closes the gap, at the chosen return and two
points either side, plus what waiting five years does to that number. */
function closeGap(s, which, atAge) {
var b = basics(s), rows = [], seen = {};
[num(s.returnPct) - 2, num(s.returnPct), num(s.returnPct) + 2].forEach(function (rp) {
if (rp < 0) rp = 0;
if (seen[rp]) return;
seen[rp] = true;
var e = evalPlan(s, which, { returnPct: rp });
var gap = e.at(atAge == null ? e.allAge : atAge).gap, needPot = gap * 12 / b.draw;
var rm = Math.pow(1 + e.rReal, 1 / 12) - 1, f = ann(rm, e.nM), f5 = ann(rm, e.nM - 60);
rows.push({ returnPct: rp, chosen: rp === num(s.returnPct), gap: gap, needPot: needPot,
extra: f > 0 ? needPot / f : null, extraWait5: f5 > 0 ? needPot / f5 : null });
});
return rows;
}
/* Service milestones that change what a year of teaching is worth. */
function milestones(s) {
var tier = tierOf(s.entryYear, s.entryMonth), svc = num(s.service), list = [];
function add(at, past, text) { list.push({ at: at, past: past, done: past ? svc > at : svc >= at, togo: Math.max(0, at - svc), text: text }); }
add(5, false, tier === 4
? 'You are vested. A pension is owed to you at 65, and the 2% your employer adds to your supplemental account is yours to keep.'
: 'You are vested. A pension is owed to you at 60 even if you leave.');
if (tier === 2) add(10, false, 'Your multiplier is 2.5% on every year instead of 2.0%.');
if (tier === 3) {
add(10, true, 'Your multiplier rises from 1.7% to 2.0% on every year.');
add(10, false, 'You can retire early at 55 with a reduced pension.');
add(15, false, 'You qualify for TRS retiree health coverage.');
add(20, true, 'Your multiplier rises from 2.0% to 2.3% on every year.');
add(26, true, 'Your multiplier rises from 2.3% to 2.5% on every year.');
}
if (tier <= 3) {
add(27, false, 'You can retire at any age with no reduction.');
add(30, true, 'Each year past 30 counts at 3.0%.');
}
if (tier === 4) {
add(10, false, 'You can draw a full pension at 60 instead of 65, or a reduced one from 57.');
add(15, false, 'You qualify for TRS retiree health coverage.');
add(20, false, 'A 0.25% career factor is added to your multiplier on every year.');
add(30, false, 'The career factor rises to 0.5% on every year, and you can retire at 57 with no reduction.');
}
list.sort(function (a, b) { return a.at - b.at || (a.past ? 1 : -1); });
return list;
}
return { RULES: RULES, tierOf: tierOf, basics: basics, ready: ready, elig: elig, mult: mult, fasYears: fasYears,
lastYear: lastYear, pensionAt: pensionAt, pensionTable: pensionTable, account: account, ssCalc: ssCalc, ownFactor: ownFactor,
spouseFactor: spouseFactor, coveredYears: coveredYears, ann: ann, evalPlan: evalPlan, closeGap: closeGap, milestones: milestones };
})();
if (typeof module !== 'undefined' && module.exports) module.exports = TG;
</script>
<!-- ENGINE END -->
<script id="app">
/* ===== Full Credit KY: the page (markup, copy, charts, save and open) =====
The math lives in the engine above (calc.js, global TG) and is never changed here. */
(function () {
'use strict';
/* =====================================================================
1. THE EXAMPLE TEACHER
Swap these numbers to show a real teacher. The fields are the same as
the `base` object in test.js. nowYear is set when the page opens.
===================================================================== */
var EXAMPLE = {
birthYear: 1996, entryYear: 2019, entryMonth: 8, service: 7, salary: 52000,
raisePct: 2.5, inflPct: 2.5, retireAge: 55,
acctBal: 0, suppBal: 0,
pastYears: 6, pastPay: 9000, sidePay: 0, spousePIA: 0, claimAge: 67,
leaveIn: 3, acctChoice: 'leave', nextPayA: 0, workUntilA: 67, nextPayB: 62000, workUntilB: 67,
fedBracket: 12, balance: 4000, monthly: 100, returnPct: 6, targetPct: 80, drawPct: 4, plan: 'A'
};
/* The Built For line on the cover's label. It describes the example teacher above, so change the two together. */
var BUILT_FOR = 'Built for a Kentucky public school teacher deciding whether to stay in the classroom. The example teacher has finished ' + EXAMPLE.service + ' school years.';
/* What "New" and "Clear Example" start from: no personal numbers, only
starting assumptions the teacher can change. The yearly return is one
of them: an empty return made every new plan look far worse than it is. */
var BLANK = {
birthYear: null, entryYear: null, entryMonth: null, service: null, salary: null,
raisePct: 2.5, inflPct: 2.5, retireAge: null,
acctBal: null, suppBal: null,
pastYears: null, pastPay: null, sidePay: null, spousePIA: null, claimAge: 67,
leaveIn: null, acctChoice: 'leave', nextPayA: null, workUntilA: 67, nextPayB: null, workUntilB: 67,
fedBracket: 12, balance: null, monthly: null, returnPct: 6, targetPct: 80, drawPct: 4, plan: 'A'
};
var NOW_YEAR = new Date().getFullYear();
var RULES = TG.RULES;
var KEYS = Object.keys(BLANK);
var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var FILE_APP = 'full-credit-ky';
var FILE_VERSION = 1;
var MAX_AGE = 80; // the engine looks no further than 80 for a first pension
var TEACH_CAP = 75; // "teach longer" and "work after teaching" stop looking here
/* =====================================================================
2. FIELDS: label, kind and allowed range for every number on the page.
The same table checks what you type and what a saved file contains.
===================================================================== */
function opts(list, labelFn) { return list.map(function (v) { return { value: v, label: labelFn ? labelFn(v) : String(v) }; }); }
function range(a, b) { var r = []; for (var i = a; i <= b; i++) r.push(i); return r; }
var FIELD = {
birthYear: { label: 'Year You Were Born', kind: 'year', min: NOW_YEAR - MAX_AGE, max: NOW_YEAR - 18, blank: true, ac: 'bday-year' },
service: { label: 'Years Of Service Credit', kind: 'int', min: 0, max: 60, blank: true, post: 'years',
hint: 'Count only finished school years. If you are partway through this one, leave it out.' },
entryMonth: { label: 'TRS Start Month', kind: 'select', blank: true, blankLabel: 'Choose',
options: opts(range(1, 12), function (m) { return MONTHS[m - 1]; }) },
entryYear: { label: 'TRS Start Year', kind: 'year', min: 1950, max: NOW_YEAR, blank: true,
hint: 'Your first day in TRS sets your account type.' },
salary: { label: 'Yearly Salary', kind: 'money', min: 1000, max: 500000, blank: true, full: true, hint: 'Before taxes.' },
raisePct: { label: 'Yearly Raise', kind: 'pct', min: 0, max: 10, hint: 'An average, counting step increases.' },
inflPct: { label: 'Yearly Inflation', kind: 'pct', min: 0, max: 10, hint: 'How fast prices rise.' },
retireAge: { label: 'Age You Stop Teaching', kind: 'int', min: 18, max: MAX_AGE, blank: true },
acctBal: { label: 'TRS Account Balance', kind: 'money', min: 0, max: 3000000, blank: true, full: true,
hint: 'From your annual statement. Leave it blank and the page estimates it from your salary.' },
suppBal: { label: 'TRS 4 Supplemental Balance', kind: 'money', min: 0, max: 1000000, blank: true, full: true,
hint: 'Only TRS 4 members have this account.' },
pastYears: { label: 'Years Of Other Work', kind: 'int', min: 0, max: 50, blank: true, post: 'years',
hint: 'So far, in jobs that paid Social Security tax, before or outside teaching.' },
pastPay: { label: 'Typical Pay Then', kind: 'money', min: 0, max: 500000, blank: true, post: 'a year',
hint: 'In those jobs, in today’s dollars.' },
sidePay: { label: 'Side Job While Teaching', kind: 'money', min: 0, max: 200000, blank: true, post: 'a year', full: true,
hint: 'Count only pay with Social Security tax taken out.' },
spousePIA: { label: 'Spouse’s Full Benefit', kind: 'money', min: 0, max: 6000, blank: true, post: 'a month', full: true,
hint: 'Their Social Security at 67, if you are married. A spousal benefit is the part of it you may be able to draw.' },
claimAge: { label: 'Age You Claim Social Security', kind: 'select', full: true, options: opts(range(62, 70)),
hint: 'Claiming at 62 pays 70% of the full amount, 67 pays 100% and 70 pays 124%.' },
leaveIn: { label: 'Leave Teaching In', kind: 'int', min: 0, max: 60, blank: true, post: 'years', full: true,
hint: '1 means you leave after finishing this school year.' },
acctChoice: { label: 'Your TRS Account If You Leave', kind: 'enum', options: ['leave', 'rollover', 'cash'] },
nextPayA: { label: 'Pay After Teaching', kind: 'money', min: 0, max: 1000000, blank: true, post: 'a year' },
workUntilA: { label: 'Until Age', kind: 'int', min: 18, max: MAX_AGE },
nextPayB: { label: 'New Work Pays', kind: 'money', min: 0, max: 1000000, blank: true, post: 'a year',
hint: 'Enter 0 if you would stop working.' },
workUntilB: { label: 'Until Age', kind: 'int', min: 18, max: MAX_AGE },
fedBracket: { label: 'Federal Tax Bracket', kind: 'select', full: true,
options: opts([10, 12, 22, 24, 32, 35, 37], function (v) { return v + '%'; }),
hint: 'Used only to estimate the tax on a cash refund.' },
balance: { label: 'Retirement Savings Now', kind: 'money', min: 0, max: 10000000, blank: true, full: true,
hint: 'Your 403(b), 457(b), 401(k) and IRA accounts together.' },
monthly: { label: 'You Save Each Month', kind: 'money', min: 0, max: 20000, blank: true, full: true,
hint: 'The page raises it with inflation each year.' },
returnPct: { label: 'Yearly Return', kind: 'pct', min: 0, max: 12, blank: true,
hint: 'Starts at 6%, an assumption you can change.' },
targetPct: { label: 'Target', kind: 'pct', min: 10, max: 150, post: '% of pay', full: true },
drawPct: { label: 'Yearly Withdrawal', kind: 'pct', min: 1, max: 10,
hint: 'The share of your savings you take out each year once work stops.' },
plan: { label: 'Plan Shown', kind: 'enum', options: ['A', 'B'] }
};
/* =====================================================================
3. SMALL HELPERS
===================================================================== */
var SVGNS = 'http://www.w3.org/2000/svg';
function $(id) { return document.getElementById(id); }
function setAttrs(n, attrs) {
if (!attrs) return n;
Object.keys(attrs).forEach(function (k) {
var v = attrs[k];
if (v === null || v === undefined || v === false) return;
if (k === 'text') n.textContent = String(v);
else if (k.slice(0, 2) === 'on' && typeof v === 'function') n.addEventListener(k.slice(2), v);
else n.setAttribute(k, v === true ? '' : String(v));
});
return n;
}
function add(n, kids) {
if (kids === null || kids === undefined || kids === false) return n;
if (Array.isArray(kids)) { kids.forEach(function (c) { add(n, c); }); return n; }
n.appendChild(typeof kids === 'object' ? kids : document.createTextNode(String(kids)));
return n;
}
function el(tag, attrs, kids) { return add(setAttrs(document.createElement(tag), attrs), kids); }
function sv(tag, attrs, kids) { return add(setAttrs(document.createElementNS(SVGNS, tag), attrs), kids); }
function clear(n) { while (n.firstChild) n.removeChild(n.firstChild); return n; }
function fill(n, kids) { return add(clear(n), kids); }
function show(n, on) { if (n) n.hidden = !on; }
function icon(id, cls) { return sv('svg', { class: cls || null, 'aria-hidden': 'true', focusable: 'false' }, sv('use', { href: '#' + id })); }
function swatch(cls, size) {
var s = size || 12;
var r = cls === 'f-left' ? sv('rect', { class: cls, x: 0.5, y: 0.5, width: s - 1, height: s - 1, rx: 2 }) : sv('rect', { class: cls, width: s, height: s, rx: 2 });
return sv('svg', { viewBox: '0 0 ' + s + ' ' + s, width: s, height: s, 'aria-hidden': 'true', focusable: 'false' }, r);
}
/* Text with {name} slots; {*name} is set in bold. Values are inserted as text, never as markup. */
function rich(tpl, v) {
var out = [], re = /\{(\*?)([A-Za-z0-9_]+)\}/g, last = 0, m;
v = v || {};
while ((m = re.exec(tpl))) {
if (m.index > last) out.push(tpl.slice(last, m.index));
var val = v[m[2]];
val = (val === null || val === undefined) ? '' : String(val);
out.push(m[1] ? el('strong', { text: val }) : val);
last = re.lastIndex;
}
if (last < tpl.length) out.push(tpl.slice(last));
return out;
}
function P(cls, tpl, v) { return el('p', { class: cls || null }, rich(tpl, v)); }
function num(x) { return typeof x === 'number' && isFinite(x) ? x : 0; }
function clamp(x, a, b) { return Math.min(b, Math.max(a, x)); }
function clone(o) { var c = {}; Object.keys(o).forEach(function (k) { c[k] = o[k]; }); return c; }
var NF0 = (typeof Intl !== 'undefined' && Intl.NumberFormat) ? new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }) : null;
function commas(n) { n = Math.round(num(n)); if (n === 0) n = 0; return NF0 ? NF0.format(n) : String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ','); }
function usd(x) { return '$' + commas(Math.max(0, num(x))); }
/* Lump sums read better rounded: nearest $100 from $10,000 up. */
function usdRound(x) { x = Math.max(0, num(x)); return x >= 10000 ? '$' + commas(Math.round(x / 100) * 100) : usd(x); }
function pctText(x, digits) {
var p = Math.pow(10, digits === undefined ? 1 : digits);
return String(Math.round(num(x) * p) / p);
}
function yrs(n) { n = Math.round(num(n) * 10) / 10; return n === 1 ? '1 year' : n + ' years'; }
function more(n, word) { return n === 1 ? '1 more ' + word : n + ' more ' + word + 's'; }
function joinAnd(a) {
if (a.length <= 1) return a.join('');
if (a.length === 2) return a[0] + ' and ' + a[1];
return a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1];
}
function monthName(m) { return MONTHS[clamp(Math.round(num(m)), 1, 12) - 1]; }
function debounce(fn, ms) { var t = null; return function () { clearTimeout(t); t = setTimeout(fn, ms); }; }
/* =====================================================================
4. STATE
===================================================================== */
var state = {
data: clone(EXAMPLE), // what the teacher has entered (null means blank)
isExample: true, // still showing the made-up teacher
dirty: false, // changed since the last save or open
step: 1,
status: ''
};
var D = null; // everything worked out from state.data, rebuilt on every change
/* The object the engine reads: blanks become zeros, nowYear is this year. */
function engineState(d) {
var s = { nowYear: NOW_YEAR };
KEYS.forEach(function (k) {
var f = FIELD[k];
if (f.kind === 'enum') s[k] = f.options.indexOf(d[k]) >= 0 ? d[k] : f.options[0];
else s[k] = num(d[k]);
});
if (!s.claimAge) s.claimAge = RULES.ss.fra;
if (!s.workUntilA) s.workUntilA = RULES.ss.fra;
if (!s.workUntilB) s.workUntilB = RULES.ss.fra;
if (!s.drawPct) s.drawPct = 4;
if (!s.entryMonth) s.entryMonth = 8;
return s;
}
function missingFields(d) {
var miss = [];
if (d.birthYear === null) miss.push('the year you were born');
if (d.service === null) miss.push('your years of service credit');
if (d.entryMonth === null || d.entryYear === null) miss.push('the month and year you started in TRS');
if (d.salary === null) miss.push('your yearly salary');
return miss;
}
/* First age with a pension and no early-retirement reduction. */
function firstFullAge(s) {
var b = TG.basics(s);
for (var a = b.age0; a <= MAX_AGE; a++) {
var e = TG.elig(b.tier, a, num(s.service) + a - b.age0);
if (e.ok && e.cut === 0) return a;
}
return null;
}
/* The TRS account choice (leave it, roll it over, take it as cash) belongs to Leave Teaching. Stay Teaching is always
worked out with the account left in TRS, so a pick made for leaving never changes what staying shows. */
function planInput(s, which) { return which === 'A' && s.acctChoice !== 'leave' ? withData(s, { acctChoice: 'leave' }) : s; }
function derive() {
var d = state.data, s = engineState(d);
var out = { d: d, s: s, ready: false, missing: missingFields(d) };
if (out.missing.length || !TG.ready(s)) {
if (!out.missing.length) out.missing.push('a birth year that makes you 18 to 80 this year');
return out;
}
var b = TG.basics(s);
out.ready = true;
out.age0 = b.age0;
out.tier = b.tier;
out.T = RULES.tiers[b.tier];
out.fullAge = firstFullAge(s);
out.retireAuto = d.retireAge === null;
s.retireAge = clamp(out.retireAuto ? (out.fullAge || 65) : d.retireAge, b.age0, MAX_AGE);
out.table = TG.pensionTable(s, s.retireAge);
out.pA = TG.pensionAt(s, s.retireAge);
out.A = TG.evalPlan(planInput(s, 'A'), 'A');
out.hasB = d.leaveIn !== null;
if (out.hasB) s.leaveIn = clamp(s.leaveIn, 0, MAX_AGE - b.age0);
out.B = out.hasB ? TG.evalPlan(s, 'B') : null;
/* Leave Teaching is unfinished until pay after teaching is entered. An empty box is not the same as 0. */
out.bOpen = out.hasB && d.nextPayB === null;
out.which = (d.plan === 'B' && out.hasB && !out.bOpen) ? 'B' : 'A';
out.sel = out.which === 'B' ? out.B : out.A;
out.miles = TG.milestones(s);
return out;
}
/* The checkpoint with the most left to plan for. */
function worstSnap(e) {
var w = e.snaps[0];
e.snaps.forEach(function (x) { if (x.gap > w.gap + 0.005) w = x; });
return w;
}
function maxGap(e) { return worstSnap(e).gap; }
function sourcesAt(x) {
var a = [];
if (x.pension >= 0.5) a.push('pension');
if (x.ss >= 0.5) a.push('Social Security');
if (x.savings >= 0.5) a.push('savings');
return a;
}
/* The three sources at one age as whole dollars that add up to the whole-dollar total. Rounding each one by itself
can leave the sum a dollar off. The pension and Social Security keep the figures the page shows everywhere else,
and the last source named takes the difference: savings, or Social Security when there are no savings. */
function wholeParts(x) {
var total = Math.round(x.total), out = { pension: x.pension >= 0.5 ? Math.round(x.pension) : 0, ss: x.ss >= 0.5 ? Math.round(x.ss) : 0, savings: 0 };
if (x.savings >= 0.5) out.savings = Math.max(0, total - out.pension - out.ss);
else if (out.ss) out.ss = Math.max(0, total - out.pension);
else if (out.pension) out.pension = total;
return out;
}
/* "cover" or "covers", to agree with the sources named. */
function coverVerb(a) { return (a.length === 1 && a[0] !== 'savings') ? 'covers' : 'cover'; }
function bringVerb(a) { return (a.length === 1 && a[0] !== 'savings') ? 'brings' : 'bring'; }
function snapKind(e, x) {
if (x.age === e.stopAge && x.age === e.allAge) return 'both';
if (x.age === e.stopAge) return 'stop';
if (x.age === e.allAge) return 'all';
return 'late';
}
function snapTitle(e, x) {
var k = snapKind(e, x);
if (k === 'both') return ['At ' + x.age, 'when work stops and every check is running'];
if (k === 'stop') return ['At ' + x.age, 'when work stops'];
if (k === 'all') return ['At ' + x.age, 'when every check is running'];
return ['At ' + x.age, 'after years of rising prices'];
}
/* =====================================================================
5. FORMS: build each field from the table above, check what is typed
===================================================================== */
var inputs = {}; // key -> [{ input, box, err }]
var renderQueued = false;
function showValue(key, v) {
var f = FIELD[key];
if (v === null || v === undefined) return '';
if (f.kind === 'money') return commas(v);
return String(v);
}
function rangeText(f) {
if (f.kind === 'year') return 'Enter a year from ' + f.min + ' to ' + f.max + '.';
if (f.kind === 'money') return 'Enter an amount from ' + usd(f.min) + ' to ' + usd(f.max) + '.';
if (f.kind === 'pct') return 'Enter a percent from ' + f.min + ' to ' + f.max + '.';
return 'Enter a whole number from ' + f.min + ' to ' + f.max + '.';
}
function unitForReader(f) {
if (f.kind === 'money') return 'dollars' + (f.post ? ' ' + f.post : '');
if (f.kind === 'pct') return f.post === '% of pay' ? 'percent of pay' : 'percent';
return f.post || '';
}
/* Turn typed text into a value. Returns { ok, value } or { ok: false, msg }. */
function parseField(key, raw) {
var f = FIELD[key];
raw = String(raw === null || raw === undefined ? '' : raw).trim();
if (f.kind === 'select') {
if (raw === '') return f.blank ? { ok: true, value: null } : { ok: false, msg: 'Choose one.' };
var sv2 = Number(raw);
return f.options.some(function (o) { return o.value === sv2; }) ? { ok: true, value: sv2 } : { ok: false, msg: 'Choose one.' };
}
if (raw === '') return f.blank ? { ok: true, value: null } : { ok: false, msg: rangeText(f) };
var t = raw.replace(/[$,%\s]/g, '');
if (!/^(\d+\.?\d*|\.\d+)$/.test(t)) return { ok: false, msg: rangeText(f) };
var n = Number(t);
if (!isFinite(n)) return { ok: false, msg: rangeText(f) };
if (f.kind === 'pct') n = Math.round(n * 100) / 100;
else if (f.kind === 'money') n = Math.round(n);
else if (Math.round(n) !== n) return { ok: false, msg: rangeText(f) };
if (n < f.min || n > f.max) return { ok: false, msg: rangeText(f) };
return { ok: true, value: n };
}
function setError(rec, msg) {
rec.err.textContent = msg || '';
if (msg) rec.input.setAttribute('aria-invalid', 'true'); else rec.input.removeAttribute('aria-invalid');
if (rec.box) rec.box.classList.toggle('is-invalid', !!msg);
}
function syncInputs(key, except) {
(inputs[key] || []).forEach(function (rec) {
if (rec.input === except) return;
rec.input.value = showValue(key, state.data[key]);
setError(rec, '');
});
}
function syncAllInputs() {
KEYS.forEach(function (k) { syncInputs(k, null); });
syncChoices();
}
function syncChoices() {
var d = state.data;
['plan-strip', 'plan-step3'].forEach(function (name) {
Array.prototype.forEach.call(document.querySelectorAll('input[name="' + name + '"]'), function (r) {
r.checked = r.value === ((D && D.ready) ? D.which : d.plan);
if (r.value === 'B') r.disabled = !(D && D.ready && D.hasB && !D.bOpen);
});
});
}
function setData(key, value, source) {
if (state.data[key] === value) return;
state.data[key] = value;
/* Leave Teaching cannot stay picked once its pay is emptied. */
if (key === 'nextPayB' && value === null && state.data.plan === 'B') state.data.plan = 'A';
state.dirty = true;
syncInputs(key, source || null);
scheduleRender();
}
function scheduleRender() {
if (renderQueued) return;
renderQueued = true;
var raf = window.requestAnimationFrame || function (fn) { return setTimeout(fn, 16); };
raf(function () { renderQueued = false; render(); });
}
function leaveExample() {
if (!state.isExample) return;
state.isExample = false;
setStatus('These numbers are now yours. Save keeps them in a file.');
}
function onField(key, rec, commit) {
var r = parseField(key, rec.input.value);
if (r.ok) {
setError(rec, '');
/* An emptied field is only taken as blank once you leave it, so the page does not jump while you retype. */
if (r.value !== null || commit || FIELD[key].kind === 'select') {
var before = state.data[key];
setData(key, r.value, rec.input);
/* A number typed over the example's makes the plan the teacher's own. The ruler and the age buttons
do not come through here: they only move the example about. */
if (state.data[key] !== before) leaveExample();
}
if (commit) rec.input.value = showValue(key, state.data[key]);
} else if (commit) {
setError(rec, r.msg);
}
}
function buildField(key, dup) {
var f = FIELD[key], id = 'f-' + key + (dup ? '-' + dup : ''), hintId = 'h-' + key + (dup ? '-' + dup : ''), errId = 'e-' + key + (dup ? '-' + dup : '');
var wrap = el('div', { class: 'field' + (f.full ? ' field--full' : ''), 'data-field': key });
var unit = unitForReader(f);
wrap.appendChild(el('label', { for: id }, [f.label, unit ? el('span', { class: 'sr', text: ' (' + unit + ')' }) : null]));
var rec = { input: null, box: null, err: null };
if (f.kind === 'select') {
rec.input = el('select', { id: id, class: 'select', 'aria-describedby': hintId + ' ' + errId });
if (f.blank) rec.input.appendChild(el('option', { value: '', text: f.blankLabel || 'Choose' }));
f.options.forEach(function (o) { rec.input.appendChild(el('option', { value: String(o.value), text: o.label })); });
wrap.appendChild(rec.input);
rec.input.addEventListener('change', function () { onField(key, rec, true); });
} else {
rec.box = el('div', { class: 'inputbox' });
if (f.kind === 'money') rec.box.appendChild(el('span', { class: 'inputbox__pre', 'aria-hidden': 'true', text: '$' }));
rec.input = el('input', {
id: id, type: 'text', inputmode: f.kind === 'pct' ? 'decimal' : 'numeric', autocomplete: f.ac || 'off',
spellcheck: 'false', 'aria-describedby': hintId + ' ' + errId
});
rec.box.appendChild(rec.input);
var post = f.kind === 'pct' ? (f.post || '%') : f.post;
if (post) rec.box.appendChild(el('span', { class: 'inputbox__post', 'aria-hidden': 'true', text: post }));
wrap.appendChild(rec.box);
rec.input.addEventListener('input', function () { onField(key, rec, false); });
rec.input.addEventListener('change', function () { onField(key, rec, true); });
rec.input.addEventListener('keydown', function (e) {
if (e.key === 'Enter') { e.preventDefault(); onField(key, rec, true); }
});
}
wrap.appendChild(el('p', { class: 'hint', id: hintId, text: f.hint || '' }));
rec.err = el('p', { class: 'field__error', id: errId, 'aria-live': 'polite' });
wrap.appendChild(rec.err);
(inputs[key] = inputs[key] || []).push(rec);
return wrap;
}
/* More service than the time since joining TRS can be right (bought service credit), so the page says so and moves on. */
var serviceNote = null, serviceCheck = null;
/* School years run July through June. The months from the start to the end of last June, as whole years. */
function finishedSchoolYears(startYear, startMonth, now) {
var endYear = now.getMonth() >= 6 ? now.getFullYear() : now.getFullYear() - 1;
return Math.max(0, Math.round((endYear * 12 + 6 - (startYear * 12 + startMonth - 1)) / 12));
}
/* A check line under the service box, from the TRS start date and today's date. It shows only when the start
date is filled, and it never changes what was typed. */
function renderServiceCheck() {
if (!serviceCheck) return;
var d = state.data, text = '';
if (d.entryMonth !== null && d.entryYear !== null) {
var n = finishedSchoolYears(d.entryYear, d.entryMonth, new Date()), month = monthName(d.entryMonth);
text = 'From ' + (/^[AO]/.test(month) ? 'an ' : 'a ') + month + ' ' + d.entryYear + ' start, that is about ' + (n === 1 ? '1 finished school year' : n + ' finished school years') + '.';
}
if (serviceCheck.textContent !== text) serviceCheck.textContent = text;
}
function renderServiceNote() {
renderServiceCheck();
if (!serviceNote) return;
var d = state.data, text = '';
if (d.service !== null && d.entryYear !== null) {
var now = new Date(), month = d.entryMonth === null ? 0 : d.entryMonth - 1;
var since = Math.max(0, (now.getFullYear() * 12 + now.getMonth() - (d.entryYear * 12 + month)) / 12);
if (d.service > since + 1) text = 'This is more service than the time since you joined TRS. That is fine if you bought service credit. If not, check your dates.';
}
if (serviceNote.textContent !== text) serviceNote.textContent = text;
}
function buildForms() {
Array.prototype.forEach.call(document.querySelectorAll('[data-fields]'), function (host) {
var dup = host.getAttribute('data-dup') || '';
host.getAttribute('data-fields').split(/\s+/).forEach(function (key) {
if (FIELD[key]) host.appendChild(buildField(key, dup));
if (key === 'service' && !dup) {
/* A note, not an error: it sits under the row, is read out politely, and never blocks the number. */
serviceCheck = el('p', { class: 'field__check', id: 'c-service' });
host.appendChild(serviceCheck);
serviceNote = el('p', { class: 'field__note', id: 'n-service', role: 'status' });
host.appendChild(serviceNote);
$('f-service').setAttribute('aria-describedby', $('f-service').getAttribute('aria-describedby') + ' c-service n-service');
}
});
});
Array.prototype.forEach.call(document.querySelectorAll('form'), function (form) {
form.addEventListener('submit', function (e) { e.preventDefault(); });
});
/* Plan and account choices */
Array.prototype.forEach.call(document.querySelectorAll('input[name="plan-strip"], input[name="plan-step3"]'), function (r) {
r.addEventListener('change', function () { if (r.checked) setData('plan', r.value, null); });
});
Array.prototype.forEach.call(document.querySelectorAll('input[name="acctChoice"]'), function (r) {
r.addEventListener('change', function () { if (r.checked) setData('acctChoice', r.value, null); });
});
/* Age you stop teaching: a number box with one-year buttons */
var age = $('f-retireAge');
function ageNow() { return D && D.ready ? D.s.retireAge : null; }
function setAge(n) {
if (!D || !D.ready) return;
setData('retireAge', clamp(Math.round(n), D.age0, MAX_AGE), null);
}
age.addEventListener('input', function () {
var n = Number(age.value);
if (D && D.ready && age.value !== '' && Math.round(n) === n && n >= D.age0 && n <= MAX_AGE) setData('retireAge', n, null);
});
age.addEventListener('change', function () { if (ageNow() !== null) age.value = String(ageNow()); });
$('age-down').addEventListener('click', function () { if (ageNow() !== null) setAge(ageNow() - 1); });
$('age-up').addEventListener('click', function () { if (ageNow() !== null) setAge(ageNow() + 1); });
/* The ruler at the top sets the same age. Arrow keys move it one year, as the browser does for any slider. */
var ruler = $('ruler-age');
ruler.addEventListener('input', function () { if (ruler.value !== '') { placeTab(); setAge(Number(ruler.value)); } });
}
/* "Your Numbers" folds away on small screens while the example is showing. */
var wideQuery = window.matchMedia ? window.matchMedia('(min-width: 1080px)') : { matches: true };
function setNumbersOpen(open) {
Array.prototype.forEach.call(document.querySelectorAll('details.numbers'), function (dt) {
dt.open = wideQuery.matches ? true : open;
var sm = dt.querySelector('summary');
if (sm) { if (wideQuery.matches) sm.setAttribute('tabindex', '-1'); else sm.removeAttribute('tabindex'); }
});
}
function watchNumbers() {
Array.prototype.forEach.call(document.querySelectorAll('details.numbers'), function (dt) {
dt.addEventListener('toggle', function () { if (wideQuery.matches && !dt.open) dt.open = true; });
});
var onChange = function () { setNumbersOpen(wideQuery.matches ? true : !state.isExample); drawCharts(); };
if (wideQuery.addEventListener) wideQuery.addEventListener('change', onChange);
else if (wideQuery.addListener) wideQuery.addListener(onChange);
}
/* =====================================================================
6. SAVE, OPEN, NEW
Your numbers go into a small file on your own device. Nothing is sent.
===================================================================== */
function fileLabel(key) {
if (key === 'workUntilA') return 'Stay Teaching: Work Until Age';
if (key === 'workUntilB') return 'Leave Teaching: Work Until Age';
return FIELD[key].label;
}
/* '' when the value is fine, otherwise a plain sentence saying what is wrong. */
function checkValue(key, v) {
var f = FIELD[key], name = fileLabel(key);
if (f.kind === 'enum') return f.options.indexOf(v) >= 0 ? '' : name + ' holds a choice this page does not know.';
if (v === null) return f.blank ? '' : name + ' is blank.';
if (typeof v !== 'number' || !isFinite(v)) return name + ' is not a number.';
if (f.kind === 'select') {
return f.options.some(function (o) { return o.value === v; }) ? '' : name + ' is ' + v + ', which is not one of the choices.';
}
if (f.kind !== 'pct' && Math.round(v) !== v) return name + ' is ' + v + '. It must be a whole number.';
if (v < f.min || v > f.max) {
var shown = f.kind === 'money' ? '$' + commas(v) : String(v);
if (v < 0) shown = (f.kind === 'money' ? '-$' + commas(-v) : String(v));
return name + ' is ' + shown + '. ' + rangeText(f).replace('Enter', 'It must be');
}
return '';
}
var UNCHANGED = 'Your numbers on the page have not been changed.';
/* Read the text of a file. Returns { ok: true, data, isExample } or { ok: false, title, text }. */
function readPlan(text) {
var obj;
try { obj = JSON.parse(text); } catch (e) {
return { ok: false, title: 'This Is Not A Full Credit File', text: 'The file could not be read as a saved plan. ' + UNCHANGED };
}
if (!obj || typeof obj !== 'object' || Array.isArray(obj) || obj.app !== FILE_APP) {
return { ok: false, title: 'This File Came From Somewhere Else', text: 'It was not saved by Full Credit, so the page cannot use it. ' + UNCHANGED };
}
if (typeof obj.version !== 'number' || obj.version > FILE_VERSION || obj.version < 1) {
return { ok: false, title: 'This File Needs A Newer Page', text: 'It was saved by a different version of Full Credit. ' + UNCHANGED };
}
var src = obj.data;
if (!src || typeof src !== 'object' || Array.isArray(src)) {
return { ok: false, title: 'This File Has No Plan In It', text: 'The saved numbers are not there. ' + UNCHANGED };
}
var data = {};
for (var i = 0; i < KEYS.length; i++) {
var k = KEYS[i];
if (!Object.prototype.hasOwnProperty.call(src, k)) {
return { ok: false, title: 'This File Is Incomplete', text: 'It has no entry for ' + fileLabel(k) + '. ' + UNCHANGED };
}
var problem = checkValue(k, src[k]);
if (problem) return { ok: false, title: 'This File Has A Number The Page Cannot Use', text: problem + ' ' + UNCHANGED };
data[k] = src[k];
}
return { ok: true, data: data, isExample: obj.isExample === true };
}
function pad2(n) { return (n < 10 ? '0' : '') + n; }
function saveFile() {
var now = new Date(), data = {};
KEYS.forEach(function (k) { data[k] = state.data[k]; });
var payload = { app: FILE_APP, version: FILE_VERSION, savedAt: now.toISOString(), isExample: state.isExample, data: data };
var name = 'full-credit-ky-' + now.getFullYear() + '-' + pad2(now.getMonth() + 1) + '-' + pad2(now.getDate()) + '.json';
var blob = new Blob([JSON.stringify(payload, null, 2) + '\n'], { type: 'application/json' });
var url = URL.createObjectURL(blob);
var a = el('a', { href: url, download: name, style: 'display:none' });
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(function () { URL.revokeObjectURL(url); }, 4000);
state.dirty = false;
setStatus('Saved as ' + name + ' in your downloads folder. Open brings it back.');
renderChrome();
stampSaved();
}
function showMessage(title, text, moreText) {
$('dlg-msg-title').textContent = title;
$('dlg-msg-text').textContent = text;
$('dlg-msg-more').textContent = moreText || '';
show($('dlg-msg-more'), !!moreText);
openDialog('dlg-msg');
}
function applyFileText(text, name) {
var r = readPlan(text);
if (!r.ok) { showMessage(r.title, r.text, 'Open works with files made by the Save button on this page.'); return; }
state.data = r.data;
state.isExample = r.isExample;
state.dirty = false;
stopAt = null; claimAt = null; // the what-if ages belong to the plan that was on the page, not to the file
motionReset();
setStatus('Opened ' + (name || 'your file') + '.');
setNumbersOpen(true);
render();
syncAllInputs();
}
function openFromFile(file) {
if (!file) return;
if (file.size > 1000000) {
showMessage('This File Is Too Large', 'A saved plan is a very small file. ' + UNCHANGED, 'Open works with files made by the Save button on this page.');
return;
}
var reader = new FileReader();
reader.onload = function () { applyFileText(String(reader.result || ''), file.name); };
reader.onerror = function () { showMessage('The File Could Not Be Read', 'Your device did not let the page read it. ' + UNCHANGED); };
reader.readAsText(file);
}
function startBlank(message) {
state.data = clone(BLANK);
state.isExample = false;
state.dirty = false;
stopAt = null; claimAt = null;
motionReset();
setStatus(message);
setNumbersOpen(true);
goStep(1, false);
render();
syncAllInputs();
var first = inputs.birthYear && inputs.birthYear[0];
if (first) first.input.focus();
}
function setStatus(text) { state.status = text || ''; }
/* Ask before replacing numbers that have not been saved. */
var pending = null;
function guard(what, fn) {
if (!state.dirty) { fn(); return; }
pending = fn;
$('dlg-confirm-text').textContent = what + ' replaces the numbers on the page. They have not been saved to a file yet.';
openDialog('dlg-confirm');
}
function wireFileActions() {
var input = $('file-input');
$('btn-save').addEventListener('click', saveFile);
/* Ctrl+S, or Cmd+S on a Mac, saves the plan, the same as the Save button. Without this the browser would offer to save the page itself. */
document.addEventListener('keydown', function (e) {
if ((e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey && (e.key === 's' || e.key === 'S')) {
e.preventDefault();
if (!e.repeat) saveFile();
}
});
$('btn-open').addEventListener('click', function () { guard('Opening a file', function () { input.click(); }); });
$('btn-new').addEventListener('click', function () { guard('Starting new', function () { startBlank('Started a new, blank plan.'); }); });
$('btn-clear-example').addEventListener('click', function () { guard('Clearing the example', function () { startBlank('The example is cleared. Add your own numbers.'); }); });
$('btn-mine').addEventListener('click', function () {
state.isExample = false;
state.dirty = true;
setStatus('These numbers are now yours. Save keeps them in a file.');
setNumbersOpen(true);
render();
});
input.addEventListener('change', function () {
var f = input.files && input.files[0];
input.value = '';
openFromFile(f);
});
$('confirm-cancel').addEventListener('click', function () { pending = null; closeDialog('dlg-confirm'); });
$('confirm-go').addEventListener('click', function () { var fn = pending; pending = null; closeDialog('dlg-confirm'); if (fn) fn(); });
$('confirm-save').addEventListener('click', function () { var fn = pending; pending = null; saveFile(); closeDialog('dlg-confirm'); if (fn) fn(); });
/* The browser asks before the page closes with numbers that are not saved. */
window.addEventListener('beforeunload', function (e) {
if (!state.dirty) return undefined;
e.preventDefault();
e.returnValue = '';
return '';
});
}
/* =====================================================================
7. DIALOGS AND STEPS
===================================================================== */
var openers = {};
function openDialog(id, opener) {
var dlg = $(id);
if (!dlg || dlg.open) return;
openers[id] = opener || document.activeElement;
if (typeof dlg.showModal === 'function') dlg.showModal(); else dlg.setAttribute('open', '');
var body = dlg.querySelector('.dlg__body');
if (body) body.scrollTop = 0;
var h = dlg.querySelector('h2');
if (h) h.focus();
fadeDialog(dlg);
}
function closeDialog(id) {
var dlg = $(id);
if (!dlg || !dlg.open) return;
if (typeof dlg.close === 'function') dlg.close(); else dlg.removeAttribute('open');
}
/* On a phone the less-used buttons sit under More. */
function setMoreOpen(open) {
var btn = $('btn-more'), menu = $('more-menu');
if (menu.hidden === !open) return;
menu.hidden = !open;
btn.setAttribute('aria-expanded', open ? 'true' : 'false');
}
function wireMore() {
var btn = $('btn-more'), menu = $('more-menu');
btn.addEventListener('click', function () {
setMoreOpen(menu.hidden);
if (!menu.hidden) menu.querySelector('button').focus();
});
/* Pause Motion inside the menu leaves it open, so its new label can be read where it was pressed. */
document.addEventListener('click', function (e) {
if (!btn.contains(e.target) && !(e.target.closest && e.target.closest('#more-menu [data-motion-toggle]'))) setMoreOpen(false);
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !menu.hidden) { setMoreOpen(false); btn.focus(); }
});
menu.addEventListener('focusout', function (e) { if (!menu.contains(e.relatedTarget) && e.relatedTarget !== btn) setMoreOpen(false); });
}
function wireDialogs() {
Array.prototype.forEach.call(document.querySelectorAll('[data-open]'), function (b) {
/* A button inside the More menu is gone once the menu shuts, so focus goes back to More when the dialog closes. */
var opener = b.getAttribute('data-opener') ? $(b.getAttribute('data-opener')) : b;
b.addEventListener('click', function () { openDialog(b.getAttribute('data-open'), opener); });
});
Array.prototype.forEach.call(document.querySelectorAll('dialog'), function (dlg) {
Array.prototype.forEach.call(dlg.querySelectorAll('[data-close]'), function (b) {
b.addEventListener('click', function () { closeDialog(dlg.id); });
});
dlg.addEventListener('click', function (e) { if (e.target === dlg && dlg.id !== 'dlg-confirm') closeDialog(dlg.id); });
dlg.addEventListener('close', function () {
if (dlg.id === 'dlg-confirm') pending = null;
var o = openers[dlg.id];
openers[dlg.id] = null;
if (o && typeof o.focus === 'function' && document.body.contains(o)) o.focus();
});
});
}
var STEP_TITLES = ['What You Have Earned', 'If Your Plans Change', 'Cover The Rest'];
/* Where the page rests with the summary at the top of the window: the lower edge of the book, less the summary bar's 6px tuck. */
function stripRest() {
return Math.max(0, Math.round(document.querySelector('.book').getBoundingClientRect().bottom + window.pageYOffset) + 6);
}
function goStep(n, moveFocus) {
n = clamp(n, 1, 3);
var cameFrom = document.querySelector('.stepbtn[aria-current="step"]');
state.step = n;
for (var i = 1; i <= 3; i++) show($('step-' + i), i === n);
Array.prototype.forEach.call(document.querySelectorAll('.stepbtn'), function (b) {
if (Number(b.getAttribute('data-step')) === n) b.setAttribute('aria-current', 'step'); else b.removeAttribute('aria-current');
});
var back = $('pager-back'), next = $('pager-next');
/* Step 1 has no Back and Step 3 no Next. The one that is left keeps its side on a laptop and takes the row on a phone. */
back.hidden = n <= 1;
next.hidden = n >= 3;
if (n > 1) back.querySelector('span').textContent = 'Back: ' + STEP_TITLES[n - 2];
if (n < 3) next.querySelector('span').textContent = 'Next: ' + STEP_TITLES[n];
drawCharts();
watchViews();
slideStepMark(cameFrom, document.querySelector('.stepbtn[aria-current="step"]'));
cautionsMoved();
if (moveFocus) {
/* Bring the summary and the top of the step back if the reader had scrolled past them. Steps 2 and 3 start
below the first screen, so from the top of the page they are brought up too. Step 1's result is already there. */
var top = stripRest();
if (window.pageYOffset > top || n > 1) window.scrollTo(0, top);
var h = $('step-' + n + '-title');
if (h) h.focus({ preventScroll: true });
}
}
function wireSteps() {
Array.prototype.forEach.call(document.querySelectorAll('.stepbtn'), function (b) {
b.addEventListener('click', function () { goStep(Number(b.getAttribute('data-step')), true); });
});
$('pager-back').addEventListener('click', function () { goStep(state.step - 1, true); });
$('pager-next').addEventListener('click', function () { goStep(state.step + 1, true); });
document.addEventListener('click', function (e) {
var t = e.target && e.target.closest ? e.target.closest('[data-go-step]') : null;
if (t) goStep(Number(t.getAttribute('data-go-step')), true);
});
}
/* =====================================================================
8. CHARTS: inline SVG, drawn to the width they have. No chart library.
Pension, Social Security and savings keep one color each everywhere.
===================================================================== */
var printing = false;
var PRINT_W = 640;
function widthOf(host, printW) { return printing ? (printW || PRINT_W) : Math.floor(host.clientWidth || 0); }
/* A clean axis top and step for money. */
function axis(maxV) {
var steps = [50, 100, 200, 250, 500, 1000, 2000, 2500, 5000, 10000, 20000, 25000, 50000, 100000, 250000];
maxV = Math.max(1, maxV);
for (var i = 0; i < steps.length; i++) {
if (maxV / steps[i] <= 5) return { step: steps[i], top: Math.ceil(maxV / steps[i] - 1e-9) * steps[i] };
}
return { step: maxV, top: maxV };
}
function axisLabel(v, top) { return top >= 10000 ? '$' + (v / 1000) + 'K' : '$' + commas(v); }
function topRounded(x, y, w, h, r) {
r = Math.max(0, Math.min(r, h, w / 2));
return 'M' + x + ',' + (y + h) + 'V' + (y + r) + 'Q' + x + ',' + y + ' ' + (x + r) + ',' + y + 'H' + (x + w - r) +
'Q' + (x + w) + ',' + y + ' ' + (x + w) + ',' + (y + r) + 'V' + (y + h) + 'Z';
}
function rightRounded(x, y, w, h, r) {
r = Math.max(0, Math.min(r, w, h / 2));
return 'M' + x + ',' + y + 'H' + (x + w - r) + 'Q' + (x + w) + ',' + y + ' ' + (x + w) + ',' + (y + r) + 'V' + (y + h - r) +
'Q' + (x + w) + ',' + (y + h) + ' ' + (x + w - r) + ',' + (y + h) + 'H' + x + 'Z';
}
function round1(x) { return Math.round(x * 10) / 10; }
/* One small tooltip per chart. Everything it says is also in the text and the table view. */
function tipFor(host) {
var t = host.querySelector('.tip');
if (!t) { t = el('div', { class: 'tip', hidden: true, 'aria-hidden': 'true' }); host.appendChild(t); }
return t;
}
function showTip(host, x, y, strong, lines) {
var t = tipFor(host), w = host.clientWidth || 300;
fill(t, [el('strong', { text: strong })].concat(lines.map(function (l) { return el('span', { text: l, style: 'display:block' }); })));
t.hidden = false;
var half = Math.min(125, t.offsetWidth / 2);
t.style.left = clamp(x, half + 2, Math.max(half + 2, w - half - 2)) + 'px';
t.style.top = Math.max(0, y - 10) + 'px';
}
function hideTip(host) { var t = host.querySelector('.tip'); if (t) t.hidden = true; }
/* ---- Chart 1: pension at each retirement age ---- */
function pensionRows() {
var s = D.s;
if (D.rows) return D.rows; // the chart and the ruler read the same rows, worked out once for each change
/* The engine's table can run past the last age the page plans for. Those ages are not offered. */
return D.rows = D.table.rows.filter(function (r) { return r.age <= MAX_AGE; }).map(function (r) {
var p = TG.pensionAt(s, r.age);
var kind = r.ok ? (r.cut > 0 ? 'reduced' : 'full') : (p.vested && p.drawAge !== null ? 'waits' : 'none');
return {
age: r.age, service: r.service, kind: kind, cut: r.cut,
value: r.ok ? r.monthly : (kind === 'waits' ? p.monthly : 0),
drawAge: r.ok ? r.age : p.drawAge, replace: p.replace
};
});
}
function rowNote(r) {
if (r.kind === 'full') return 'Full pension';
if (r.kind === 'reduced') return D.tier === 4 ? 'Reduced, estimated at ' + pctText(r.cut * 100, 0) + '%' : 'Reduced ' + pctText(r.cut * 100, 0) + '%';
if (r.kind === 'waits') return 'Waits until ' + r.drawAge;
return 'Under 5 years';
}
function drawPensionChart() {
var host = $('c1-plot'), W = widthOf(host);
if (!D || !D.ready || W < 200) return;
var rows = pensionRows(), sel = D.s.retireAge, small = W < 520;
var m = { l: 50, r: 6, t: 34, b: 60 }, ph = (small || printing) ? 180 : 220, H = m.t + ph + m.b, base = m.t + ph;
var pw = W - m.l - m.r, band = pw / rows.length, bw = Math.max(5, Math.min(24, band - (band > 22 ? 8 : 4)));
var ax = axis(Math.max.apply(null, rows.map(function (r) { return r.value; }).concat([100])));
function y(v) { return round1(base - (v / ax.top) * ph); }
var selRow = null;
rows.forEach(function (r) { if (r.age === sel) selRow = r; });
var svg = sv('svg', {
viewBox: '0 0 ' + W + ' ' + H, role: 'img',
'aria-label': 'Bar chart of your monthly pension if you stop teaching at each age from ' + rows[0].age + ' to ' + rows[rows.length - 1].age +
(selRow ? '. At ' + sel + ': ' + (selRow.value > 0 ? usd(selRow.value) + ' a month' : 'no pension yet') : '') + '. The table view lists every age.'
});
for (var v = 0; v <= ax.top + 1e-6; v += ax.step) {
svg.appendChild(sv('line', { class: v === 0 ? 'axisline' : 'gridline', x1: m.l, x2: W - m.r, y1: y(v), y2: y(v) }));
svg.appendChild(sv('text', { class: 't-axis', x: m.l - 8, y: y(v) + 4, 'text-anchor': 'end', text: axisLabel(v, ax.top) }));
}
var every = band >= 26 ? 1 : (band >= 14 ? 2 : 5);
rows.forEach(function (r, i) {
var x0 = m.l + i * band, cx = round1(x0 + band / 2), bx = round1(cx - bw / 2), on = r.age === sel;
var g = sv('g');
var bar = null;
if (r.value > 0) {
var yy = y(r.value), hh = Math.max(2, base - yy);
if (r.kind === 'waits') bar = sv('path', { class: 'col f-pension-wait', d: topRounded(bx + 1, base - hh + 1, bw - 2, hh - 1, 3) });
else bar = sv('path', { class: 'col ' + (on ? 'f-pension' : 'f-pension-soft'), d: topRounded(bx, base - hh, bw, hh, 4) });
if (on && r.kind === 'waits') bar.setAttribute('style', 'stroke-width:3');
} else {
bar = sv('line', { class: 'col axisline', x1: bx, x2: bx + bw, y1: base - 4, y2: base - 4, style: 'stroke-width:2' });
}
var hit = sv('rect', { class: 'hit', x: round1(x0), y: m.t - 12, width: round1(band), height: ph + 12 + 22 });
var tipText = function () {
showTip(host, cx, r.value > 0 ? y(r.value) : base - 12, r.value > 0 ? usd(r.value) + ' a month' : 'No pension yet',
['Stop at ' + r.age + ' with ' + yrs(r.service), rowNote(r)]);
bar.classList.add('is-hover');
};
hit.addEventListener('pointerenter', tipText);
hit.addEventListener('pointermove', tipText);
hit.addEventListener('pointerleave', function () { hideTip(host); bar.classList.remove('is-hover'); });
hit.addEventListener('click', function () { hideTip(host); setData('retireAge', r.age, null); });
g.appendChild(bar);
var showTick = on || (every === 1) || (every === 2 ? (i % 2 === 0) : (r.age % 5 === 0));
if (!on && every > 1 && selRow && Math.abs(r.age - sel) * band < 24) showTick = false;
if (showTick) g.appendChild(sv('text', { class: on ? 't-label' : 't-axis', x: cx, y: base + 18, 'text-anchor': 'middle', text: String(r.age) }));
if (on) {
g.appendChild(sv('path', { d: 'M' + (cx - 5) + ',' + (base + 28) + 'L' + cx + ',' + (base + 22) + 'L' + (cx + 5) + ',' + (base + 28) + 'Z', class: 'f-ink' }));
var label = r.value > 0 ? usd(r.value) : 'No pension yet';
var anchor = cx < 46 + m.l ? 'start' : (cx > W - 60 ? 'end' : 'middle');
var lx = anchor === 'start' ? bx : (anchor === 'end' ? bx + bw : cx);
g.appendChild(sv('text', { class: 't-label t-halo', x: lx, y: (r.value > 0 ? y(r.value) : base - 4) - 8, 'text-anchor': anchor, style: 'font-size:14px;font-weight:700', text: label }));
}
g.appendChild(hit);
svg.appendChild(g);
});
/* Under the ages: what kind of pension each stretch of ages gets, in words. */
var segs = [];
rows.forEach(function (r, i) {
var last = segs[segs.length - 1];
if (last && last.kind === r.kind) last.to = i; else segs.push({ kind: r.kind, from: i, to: i });
});
var words = { none: ['Under 5 years', 'Under 5'], waits: ['Waits', 'Waits'], reduced: ['Reduced', 'Red.'], full: ['Full pension', 'Full'] };
segs.forEach(function (sg) {
var x1 = m.l + sg.from * band + 3, x2 = m.l + (sg.to + 1) * band - 3, wseg = x2 - x1, by = base + 36;
var g2 = sv('g', { class: 'band' });
g2.appendChild(sv('line', { x1: round1(x1), x2: round1(x2), y1: by, y2: by }));
g2.appendChild(sv('line', { x1: round1(x1), x2: round1(x1), y1: by - 3, y2: by + 3 }));
g2.appendChild(sv('line', { x1: round1(x2), x2: round1(x2), y1: by - 3, y2: by + 3 }));
var w0 = words[sg.kind][0], w1 = words[sg.kind][1];
var text = w0.length * 7.2 <= wseg ? w0 : (w1.length * 7.2 <= wseg && w1 !== 'Red.' ? w1 : '');
if (text) g2.appendChild(sv('text', { class: 't-note', x: round1((x1 + x2) / 2), y: by + 17, 'text-anchor': 'middle', text: text }));
svg.appendChild(g2);
});
var oldTip = host.querySelector('.tip');
fill(host, svg);
if (oldTip) host.appendChild(oldTip);
hideTip(host);
/* The sentence under the chart says the same thing for the age picked. */
var ro = $('c1-readout');
if (selRow) {
if (selRow.kind === 'none') {
fill(ro, rich('Stop at {*age} with {svc} of service credit: no pension yet. A pension starts at 5 years.', { age: sel, svc: yrs(selRow.service) }));
} else if (selRow.kind === 'waits') {
fill(ro, rich('Stop at {*age} with {svc} of service credit: the pension waits in TRS and pays about {*amt} a month from age {draw}.',
{ age: sel, svc: yrs(selRow.service), amt: usd(selRow.value), draw: selRow.drawAge }));
} else {
fill(ro, rich('Stop at {*age} with {svc} of service credit: about {*amt} a month from {age}, {share}% of your pay at that point. {note}.',
{ age: sel, svc: yrs(selRow.service), amt: usd(selRow.value), share: pctText(selRow.replace * 100, 0), note: rowNote(selRow) }));
}
}
var lg = $('c1-legend'), anyWait = rows.some(function (r) { return r.kind === 'waits'; });
show(lg, anyWait);
if (anyWait) {
fill(lg, [
el('li', null, [sv('svg', { viewBox: '0 0 14 14', 'aria-hidden': 'true' }, sv('rect', { class: 'f-pension', width: 14, height: 14, rx: 2 })), 'Starts at that age']),
el('li', null, [sv('svg', { viewBox: '0 0 14 14', 'aria-hidden': 'true' }, sv('rect', { class: 'f-pension-wait', x: 1, y: 1, width: 12, height: 12, rx: 2 })), 'Waits in TRS and starts at a later age'])
]);
}
/* Table view: the same numbers, and another way to pick an age. */
var tb = el('tbody');
rows.forEach(function (r) {
var on = r.age === sel;
tb.appendChild(el('tr', { class: on ? 'is-on' : null }, [
el('th', { scope: 'row' }, el('button', {
type: 'button', class: 'agebtn', 'aria-pressed': on ? 'true' : 'false', 'data-fk': 'age-' + r.age,
'aria-label': 'Stop teaching at ' + r.age, text: String(r.age),
onclick: function () { setData('retireAge', r.age, null); }
})),
el('td', { text: String(r.service) }),
el('td', { text: r.value > 0 ? usd(r.value) : 'None yet' }),
el('td', { text: rowNote(r) })
]));
});
keepFocus($('c1-table'), function () {
fill($('c1-table'), el('table', { class: 'table' }, [
el('caption', { text: 'Monthly pension in today’s dollars if you stop teaching at each age. Pick an age to use it.' }),
el('thead', null, el('tr', null, [
el('th', { scope: 'col', text: 'Age' }), el('th', { scope: 'col', text: 'Years Of Service' }),
el('th', { scope: 'col', text: 'A Month' }), el('th', { scope: 'col', text: 'Kind' })
])),
tb
]));
});
}
/* ---- Chart 2: what the pension buys as prices rise ---- */
var colaKeyIndex = -1;
function colaPoints() {
var e = D.A, start = e.drawAge, end = Math.max(90, Math.min(95, start + 10)), pts = [];
for (var a = start; a <= end; a++) pts.push({ age: a, v: e.at(a).pension });
return pts;
}
function drawColaChart() {
var fig = $('c2'), host = $('c2-plot');
if (!D || !D.ready) return;
var e = D.A, has = e.hasPension && e.drawAge !== null && e.pensionMonthly >= 0.5;
show(fig, has);
if (!has) return;
var W = widthOf(host);
if (W < 200) return;
var pts = colaPoints(), v0 = pts[0].v, start = pts[0].age, end = pts[pts.length - 1].age, small = W < 520;
var m = { l: 50, r: 14, t: 30, b: 30 }, ph = small ? 150 : 180, H = m.t + ph + m.b, base = m.t + ph, pw = W - m.l - m.r;
var ax = axis(Math.max.apply(null, pts.map(function (p) { return p.v; })) * 1.04);
function X(a) { return round1(m.l + (a - start) / (end - start) * pw); }
function Y(v) { return round1(base - (v / ax.top) * ph); }
var falling = pts[pts.length - 1].v < v0 - 0.5, rising = pts[pts.length - 1].v > v0 + 0.5;
var p85 = null;
pts.forEach(function (p) { if (p.age === 85) p85 = p; });
var svg = sv('svg', {
viewBox: '0 0 ' + W + ' ' + H, role: 'img',
'aria-label': 'Line chart of what your pension buys, in today’s dollars, from age ' + start + ' to ' + end + '. ' + usd(v0) + ' at ' + start +
(p85 ? ', ' + usd(p85.v) + ' at 85' : '') + '. The table view lists the ages.'
});
for (var v = 0; v <= ax.top + 1e-6; v += ax.step) {
svg.appendChild(sv('line', { class: v === 0 ? 'axisline' : 'gridline', x1: m.l, x2: W - m.r, y1: Y(v), y2: Y(v) }));
svg.appendChild(sv('text', { class: 't-axis', x: m.l - 8, y: Y(v) + 4, 'text-anchor': 'end', text: axisLabel(v, ax.top) }));
}
pts.forEach(function (p) {
var isStart = p.age === start;
if (p.age % 5 === 0 || isStart) {
/* "Age 55" is about 44px wide and starts at the left edge. Leave out a later age that would run into it. */
if (!isStart && X(p.age) - X(start) < 58) return;
svg.appendChild(sv('text', { class: 't-axis', x: X(p.age), y: base + 18, 'text-anchor': isStart ? 'start' : 'middle', text: (isStart ? 'Age ' : '') + p.age }));
}
});
var d = pts.map(function (p, i) { return (i ? 'L' : 'M') + X(p.age) + ',' + Y(p.v); }).join('');
svg.appendChild(sv('path', { class: 'f-pension', d: d + 'L' + X(end) + ',' + base + 'L' + X(start) + ',' + base + 'Z', style: 'fill-opacity:.1' }));
/* What the first check buys, as a level line to compare against. */
svg.appendChild(sv('line', { x1: X(start), x2: X(end), y1: Y(v0), y2: Y(v0), class: 's-ink', 'stroke-width': 1 }));
/* The full note needs about 215px. On a plot narrower than that it would run into the dollar labels, so it is shortened. */
svg.appendChild(sv('text', { class: 't-note', x: X(end), y: Y(v0) + (rising ? 17 : -8), 'text-anchor': 'end',
text: (pw >= 230 ? 'What the first check buys: ' : 'First check: ') + usd(v0) }));
svg.appendChild(sv('path', { class: 's-pension', d: d, fill: 'none', 'stroke-width': 2, 'stroke-linejoin': 'round', 'stroke-linecap': 'round' }));
function dot(p) { return sv('circle', { class: 'f-pension s-paper', cx: X(p.age), cy: Y(p.v), r: 5, 'stroke-width': 2 }); }
svg.appendChild(dot(pts[0]));
if (p85) {
svg.appendChild(dot(p85));
svg.appendChild(sv('text', { class: 't-label', x: X(85), y: Y(p85.v) + (rising ? -12 : 22), 'text-anchor': 'middle', text: usd(p85.v) + ' at 85' }));
}
var cross = sv('g', { style: 'display:none' }, [
sv('line', { class: 'axisline s-ink', y1: m.t - 6, y2: base }),
sv('circle', { class: 'f-pension s-paper', r: 5, 'stroke-width': 2 })
]);
svg.appendChild(cross);
function pointAt(i) {
i = clamp(i, 0, pts.length - 1);
var p = pts[i];
cross.style.display = '';
cross.firstChild.setAttribute('x1', X(p.age)); cross.firstChild.setAttribute('x2', X(p.age));
cross.lastChild.setAttribute('cx', X(p.age)); cross.lastChild.setAttribute('cy', Y(p.v));
showTip(host, X(p.age), Y(p.v) - 4, usd(p.v) + ' a month', ['At age ' + p.age, 'Buys ' + pctText(v0 > 0 ? p.v / v0 * 100 : 0, 0) + '% of what the first check did']);
return p;
}
var over = sv('rect', { x: m.l, y: m.t - 6, width: pw, height: ph + 6, fill: 'transparent' });
function fromEvent(ev) {
var box = svg.getBoundingClientRect(), px = (ev.clientX - box.left) * (W / Math.max(1, box.width));
return Math.round((px - m.l) / pw * (end - start));
}
over.addEventListener('pointermove', function (ev) { pointAt(fromEvent(ev)); });
over.addEventListener('pointerdown', function (ev) { pointAt(fromEvent(ev)); });
over.addEventListener('pointerleave', function () { cross.style.display = 'none'; hideTip(host); });
svg.appendChild(over);
var oldTip = host.querySelector('.tip'), live = host.querySelector('.sr');
fill(host, svg);
if (oldTip) host.appendChild(oldTip);
if (!live) live = el('p', { class: 'sr', 'aria-live': 'polite' });
host.appendChild(live);
hideTip(host);
/* Keyboard: arrow keys read each age. */
host.setAttribute('tabindex', '0');
host.setAttribute('role', 'group');
host.setAttribute('aria-label', 'Pension buying power by age. Use the left and right arrow keys to read each age.');
colaKeyIndex = -1;
host.onkeydown = function (ev) {
var k = ev.key, i = colaKeyIndex;
if (k === 'ArrowRight' || k === 'ArrowUp') i = i < 0 ? 0 : i + 1;
else if (k === 'ArrowLeft' || k === 'ArrowDown') i = i < 0 ? 0 : i - 1;
else if (k === 'Home') i = 0;
else if (k === 'End') i = pts.length - 1;
else if (k === 'Escape') { cross.style.display = 'none'; hideTip(host); return; }
else return;
ev.preventDefault();
colaKeyIndex = clamp(i, 0, pts.length - 1);
var p = pointAt(colaKeyIndex);
live.textContent = 'Age ' + p.age + ': ' + usd(p.v) + ' a month, ' + pctText(v0 > 0 ? p.v / v0 * 100 : 0, 0) + '% of what the first check bought.';
};
host.onblur = function () { cross.style.display = 'none'; hideTip(host); };
var infl = num(D.s.inflPct), cola = RULES.cola * 100, sub = $('c2-sub');
var subText;
if (falling) {
subText = rich('Each July the pension rises {cola}%. With prices rising {infl}% a year, each check buys a little less than the one before: about {*late} of today’s dollars at {lateAge}, compared with {first} at {start}.',
{ cola: pctText(cola), infl: pctText(infl, 2), late: usd((p85 || pts[pts.length - 1]).v), lateAge: (p85 || pts[pts.length - 1]).age, first: usd(v0), start: start });
} else if (rising) {
subText = rich('Each July the pension rises {cola}%. With prices rising {infl}% a year, each check buys a little more than the one before.', { cola: pctText(cola), infl: pctText(infl, 2) });
} else {
subText = rich('Each July the pension rises {cola}%. With prices rising {infl}% a year, it keeps pace.', { cola: pctText(cola), infl: pctText(infl, 2) });
}
if (D.tier === 4) subText.push(' For TRS 4, the TRS board can adjust terms if funding falls short.');
fill(sub, subText);
var want = [start, 62, 67, 70, 75, 80, 85, 90, end].filter(function (a, i, arr) { return a >= start && a <= end && arr.indexOf(a) === i; }).sort(function (a, b) { return a - b; });
fill($('c2-table'), el('table', { class: 'table' }, [
el('caption', { text: 'What the pension buys at later ages, in today’s dollars.' }),
el('thead', null, el('tr', null, [el('th', { scope: 'col', text: 'Age' }), el('th', { scope: 'col', text: 'A Month' }), el('th', { scope: 'col', text: 'Share Of The First Check' })])),
el('tbody', null, want.map(function (a) {
var val = D.A.at(a).pension;
return el('tr', null, [el('th', { scope: 'row', text: String(a) }), el('td', { text: usd(val) }), el('td', { text: pctText(v0 > 0 ? val / v0 * 100 : 0, 0) + '%' })]);
}))
]));
}
/* ---- Coverage bars: income from each source against the target ---- */
var covJobs = [];
function covSvg(x, target, scaleMax, W, label) {
var H = 28, bh = 20, y0 = 4, usable = W - 2;
function X(v) { return round1(1 + (v / scaleMax) * usable); }
var svg = sv('svg', { viewBox: '0 0 ' + W + ' ' + H, role: 'img', 'aria-label': label });
var parts = [['pension', 'f-pension', 'Pension'], ['ss', 'f-ss', 'Social Security'], ['savings', 'f-savings', 'Savings']]
.filter(function (p) { return x[p[0]] >= 0.5; });
var cur = 0, hasLeft = x.gap >= 0.5;
parts.forEach(function (p, i) {
var x1 = X(cur), x2 = X(cur + x[p[0]]);
cur += x[p[0]];
var last = i === parts.length - 1, w = Math.max(2, x2 - x1 - (last && !hasLeft ? 0 : 2));
var node = (last && !hasLeft)
? sv('path', { class: 'part ' + p[1], d: rightRounded(x1, y0, w, bh, 4) })
: sv('rect', { class: 'part ' + p[1], x: x1, y: y0, width: w, height: bh });
node.appendChild(sv('title', { text: p[2] + ': ' + usd(x[p[0]]) + ' a month' }));
svg.appendChild(node);
});
if (hasLeft) {
var lx = X(x.total), lw = Math.max(3, X(target) - lx);
var left = sv('path', { class: 'part f-left', d: rightRounded(lx + 0.5, y0 + 0.5, lw - 1, bh - 1, 4) });
left.appendChild(sv('title', { text: 'Left to plan for: ' + usd(x.gap) + ' a month' }));
svg.appendChild(left);
}
var tx = clamp(X(target), 2, W - 2);
if (!hasLeft) svg.appendChild(sv('line', { x1: tx, x2: tx, y1: 0, y2: H, class: 's-paper', 'stroke-width': 6 }));
var tick = sv('line', { class: 'wantline', x1: tx, x2: tx, y1: 0, y2: H });
tick.appendChild(sv('title', { text: 'Target: ' + usd(target) + ' a month' }));
svg.appendChild(tick);
return svg;
}
function covLabel(x, target) {
var bits = [];
if (x.pension >= 0.5) bits.push('pension ' + usd(x.pension));
if (x.ss >= 0.5) bits.push('Social Security ' + usd(x.ss));
if (x.savings >= 0.5) bits.push('savings ' + usd(x.savings));
return 'At ' + x.age + ': ' + (bits.length ? bits.join(', ') : 'no income yet') + '. Total ' + usd(x.total) + ' against a target of ' + usd(target) + '. ' +
(x.gap >= 0.5 ? usd(x.gap) + ' left to plan for.' : 'Nothing left to plan for.');
}
/* One row: a title, the bar, each amount in words, and a one-line sum. */
function covRow(e, x, scaleMax, compact, printW) {
var title = snapTitle(e, x), host = el('div', { class: 'cov__bar' });
covJobs.push({ host: host, x: x, target: e.target, scaleMax: scaleMax, printW: printW || PRINT_W });
var nums = [];
if (x.pension >= 0.5) nums.push(el('li', null, [swatch('f-pension'), 'Pension ' + usd(x.pension)]));
if (x.ss >= 0.5) nums.push(el('li', null, [swatch('f-ss'), 'Social Security ' + usd(x.ss)]));
if (x.savings >= 0.5) nums.push(el('li', null, [swatch('f-savings'), 'Savings ' + usd(x.savings)]));
if (x.gap >= 0.5) nums.push(el('li', null, [swatch('f-left'), 'Left to plan for ' + usd(x.gap)]));
/* What comes in, the target it is set against, and what that leaves. The last age checked also says where the
target comes from: a share of the teaching pay, or of the new pay when that is higher. */
var last = x === e.snaps[e.snaps.length - 1];
var sum = rich('At {age} this plan brings in {*in} a month. The target is {want}' +
(last ? ', which is {pct}% of the {pay} {kind} pay' : '') + (x.gap >= 0.5 ? ', so {*left} is left to plan for.' : ', so all of it is covered.'),
{ age: x.age, in: usd(x.total), want: usd(e.target), pct: pctText(D.s.targetPct, 2), pay: usdRound(e.basePay),
kind: e.hasNext && e.nextPay > e.pension.payToday ? 'new' : 'teaching', left: usd(x.gap) });
return el('div', { class: 'cov__row' }, [
el('p', { class: 'cov__title' }, [title[0], el('span', { text: ', ' + title[1] })]),
host,
nums.length ? el('ul', { class: 'cov__nums' }, nums) : null,
compact ? null : el('p', { class: 'cov__sum' }, sum),
compact ? el('p', { class: 'cov__sum' }, sum) : null
]);
}
function drawCovBars() {
covJobs.forEach(function (j) {
if (!document.body.contains(j.host)) return;
var W = widthOf(j.host, j.printW);
if (W < 60) return;
fill(j.host, covSvg(j.x, j.target, j.scaleMax, W, covLabel(j.x, j.target)));
});
}
function covScale(evals) {
var mx = 1;
evals.forEach(function (e) {
if (!e) return;
mx = Math.max(mx, e.target);
e.snaps.forEach(function (x) { mx = Math.max(mx, x.total); });
});
return mx;
}
function covTable(evals, names) {
/* Measures down the side, one column per age checked, so it fits a phone. */
var cols = [];
evals.forEach(function (e, i) { if (e) e.snaps.forEach(function (x) { cols.push({ e: e, x: x, name: names[i] }); }); });
function line(label, fn, cls) {
return el('tr', { class: cls || null }, [el('th', { scope: 'row', text: label })].concat(cols.map(function (c) { return el('td', { text: fn(c) }); })));
}
return el('table', { class: 'table' }, [
el('caption', { text: 'A month, in today’s dollars.' }),
el('thead', null, el('tr', null, [el('th', { scope: 'col', text: 'Source' })].concat(cols.map(function (c) {
return el('th', { scope: 'col', text: (c.name ? c.name + ', ' : '') + 'Age ' + c.x.age });
})))),
el('tbody', null, [
line('Pension', function (c) { return usd(c.x.pension); }),
line('Social Security', function (c) { return usd(c.x.ss); }),
line('Savings', function (c) { return usd(c.x.savings); }),
line('All Income', function (c) { return usd(c.x.total); }, 'is-total'),
line('Target', function (c) { return usd(c.e.target); }),
line('Left To Plan For', function (c) { return usd(c.x.gap); }, 'is-total')
])
]);
}
function drawCharts() {
if (!D || !D.ready) return;
if (printing || state.step === 1) { drawPensionChart(); drawColaChart(); }
if (printing || state.step === 2) drawYears();
drawCovBars();
}
/* Rebuild part of the page without dropping the keyboard focus that was inside it. */
function keepFocus(container, fn) {
var a = document.activeElement, key = (a && container.contains(a) && a.getAttribute) ? a.getAttribute('data-fk') : null;
fn();
if (key) {
var again = container.querySelector('[data-fk="' + key + '"]');
if (again) again.focus({ preventScroll: true });
}
}
/* =====================================================================
9. WORDS: every sentence the page writes from your numbers
Lead with what has been earned. Say what is left to plan for beside
what is covered. Describe, do not judge.
===================================================================== */
function withData(s, changes) { var c = clone(s); Object.keys(changes).forEach(function (k) { c[k] = changes[k]; }); return c; }
function card(id, title, kids) {
return el('section', { class: 'card', 'aria-labelledby': id }, [el('h3', { id: id, text: title })].concat(kids));
}
function fact(label, value, sub) {
return el('div', null, [el('dt', { text: label }), el('dd', { text: value }), sub ? el('dd', { class: 'facts__sub', text: sub }) : null]);
}
function cautionBox(title, paras) {
return el('div', { class: 'caution' }, [icon('i-caution'), el('p', { class: 'caution__title', text: title })].concat(paras));
}
function emptyBox(text, withStepLink) {
var buttons = [
withStepLink ? el('button', { type: 'button', class: 'btn btn--secondary', 'data-go-step': '1', text: 'Go To Step 1' }) : null,
state.isExample ? null : el('button', { type: 'button', class: 'btn btn--secondary', 'data-show-example': '1', text: 'Show The Example' })
].filter(Boolean);
return [el('p', { text: text }), buttons.length ? el('div', { class: 'empty__actions' }, buttons) : null];
}
function phone() { return el('span', { class: 'nowrap', text: '800-618-1687' }); }
function exampleLine() {
return 'These numbers belong to a made-up teacher, born in ' + EXAMPLE.birthYear + ', who started in ' + monthName(EXAMPLE.entryMonth) + ' ' +
EXAMPLE.entryYear + ' and earns ' + usd(EXAMPLE.salary) + '. They are not yours yet.';
}
/* The Social Security side of the comparison: what the same salary would have earned. */
function ssCompare(e) {
if (!e.hasPension || e.drawAge === null || e.ssMissed < 0.5) return '';
var fra = RULES.ss.fra, later = Math.max(fra, e.drawAge);
var holds = e.at(later).pension >= e.ssMissed && e.at(Math.max(85, later)).pension >= e.ssMissed;
if (holds && e.drawAge < fra) return ' That is more than the {*ss} a month Social Security would pay on the same salary, and it starts at {draw} instead of ' + fra + '.';
if (holds) return ' That is more than the {*ss} a month Social Security would pay on the same salary.';
return ' Social Security on the same salary would pay about {*ss} a month from ' + fra + '.';
}
/* calc.js writes each milestone for a teacher who reaches it young. When the age it names has already
passed by the time the service is reached, say the same thing without that age. */
/* calc.js says a new multiplier applies "on every year". Say plainly that this includes the years already worked. */
function allYears(t) { return t.replace(' on every year', ' on all your years, including ones already worked'); }
function milestoneText(m, reachAge) {
var tier = D.tier;
if (m.at === 5 && tier <= 3 && reachAge > 60) return 'You are vested. A pension is owed to you even if you leave.';
if (m.at === 5 && tier === 4 && reachAge > 65) return 'You are vested. A pension is owed to you, and the 2% your employer adds to your supplemental account is yours to keep.';
if (m.at === 10 && !m.past && tier === 3 && reachAge > 55) {
return reachAge >= 60 ? 'No change at this age: a full pension already starts at 60.' : 'You can retire early with a reduced pension.';
}
if (m.at === 10 && tier === 4 && reachAge > 57) {
if (reachAge >= 65) return 'No change at this age: a full pension already starts at 65.';
return reachAge >= 60 ? 'You can draw a full pension right away instead of waiting for 65.' : 'You can draw a full pension at 60 instead of 65, or a reduced one right away.';
}
if (m.at === 30 && tier === 4 && reachAge > 57) return allYears('The career factor rises to 0.5% on every year.');
return allYears(m.text);
}
/* One more year: does it cross a service milestone, end a reduction, or change the salary average?
Returns what changes, with the pension before and after, or null when nothing does. */
function oneMoreYear(which) {
var e = which === 'B' ? D.B : D.A;
if (!e) return null;
var s = D.s, age = e.sepAge, p0 = e.pension, svc = p0.service;
if (age + 1 > MAX_AGE) return null;
var now = TG.milestones(withData(s, { service: svc })), next = TG.milestones(withData(s, { service: svc + 1 }));
var texts = [];
next.forEach(function (m, i) { if (m.done && now[i] && !now[i].done) texts.push(milestoneText(m, age + 1)); });
var p1 = TG.pensionAt(s, age + 1);
if (p0.immediate && p0.cut > 0 && p1.immediate && p1.cut === 0) texts.push('Your early-retirement reduction ends.');
if (D.tier <= 3 && p0.immediate && p1.immediate && p0.fasYears === 5 && p1.fasYears === 3) texts.push('Your final average salary uses your 3 highest salaries instead of 5.');
return texts.length ? { e: e, age: age, p0: p0, p1: p1, svc: svc, texts: texts } : null;
}
function headsUp(which) {
var y = oneMoreYear(which);
if (!y) return null;
var e = y.e, age = y.age, p0 = y.p0, p1 = y.p1, svc = y.svc, texts = y.texts;
var paras =[P(null, (which === 'A' ? 'Teaching' : 'Staying') + ' one more year, to age {age} with {svc} of service credit: ' + texts.join(' '), { age: age + 1, svc: yrs(svc + 1) })];
if (!p0.vested && p1.vested && p1.drawAge !== null) {
paras.push(P(null, 'At 5 years you can leave your money in TRS and collect about {*amt} a month for life from age {draw}, or still take the refund. A refund ends your TRS membership.',
{ amt: usd(p1.monthly), draw: p1.drawAge }));
if (e.forfeitToday >= 0.5) paras.push(P(null, 'Under 5 years you give up the 2% your employer added to your supplemental account, about {*amt}.', { amt: usdRound(e.forfeitToday) }));
} else if (p0.vested && p1.vested && p0.drawAge !== null && p1.drawAge !== null && Math.abs(p1.monthly - p0.monthly) >= 1) {
if (p0.deferred && p1.deferred) {
paras.push(P(null, 'The pension that waits for you would be about {*a1} a month instead of {a0}.', { a1: usd(p1.monthly), a0: usd(p0.monthly) }));
} else if (p0.deferred && p1.immediate) {
paras.push(P(null, 'Your pension could start right away at {age}: about {*a1} a month, instead of {a0} a month from age {draw}.',
{ age: age + 1, a1: usd(p1.monthly), a0: usd(p0.monthly), draw: p0.drawAge }));
} else {
paras.push(P(null, 'Your pension would be about {*a1} a month instead of {a0}.', { a1: usd(p1.monthly), a0: usd(p0.monthly) }));
}
}
return cautionBox('Heads-Up ' + (which === 'A' ? 'If You Stay' : 'If You Leave') + ': One More Year Crosses A Milestone', paras);
}
/* ---------- Summary strip ---------- */
function setTile(id, value, note) { $(id).textContent = value; $(id + '-note').textContent = note || ''; }
/* The strip's caption. "in" drops out on a phone, so the caption stays on one line beside the plan buttons where it can.
Where it cannot, it breaks after the comma and keeps "today's dollars" together. */
function stripCaption(when) {
return ['Monthly income' + when + ', ', el('span', { class: 'nowrap' }, [el('span', { class: 'strip__in', text: 'in ' }), 'today’s dollars'])];
}
function renderStrip() {
var unit = $('strip-unit');
if (!D || !D.ready) {
['strip-pension', 'strip-ss', 'strip-savings', 'strip-want', 'strip-left'].forEach(function (id) {
fill($(id), [el('span', { 'aria-hidden': 'true', text: '–' }), el('span', { class: 'sr', text: 'Not worked out yet' })]);
$(id + '-note').textContent = '';
});
fill(unit, stripCaption(''));
$('strip-plan').textContent = '';
return;
}
var e = D.sel, p = e.primary, w = worstSnap(e);
/* The plan buttons do not print, so the printed summary names its plan in words. */
$('strip-plan').textContent = D.which === 'B' ? 'Leave Teaching' : 'Stay Teaching';
setTile('strip-pension', usd(p.pension), e.hasPension && e.drawAge !== null ? 'from age ' + e.drawAge : 'none in this plan');
setTile('strip-ss', usd(p.ss), e.ss.monthly >= 0.5 ? 'from age ' + e.claimAge : Math.min(e.ss.credits, RULES.ss.need) + ' of ' + RULES.ss.need + ' credits');
setTile('strip-savings', usd(p.savings), 'from age ' + e.stopAge);
setTile('strip-want', usd(e.target), pctText(D.s.targetPct, 2) + '% of pay');
if (w.gap < 0.5) {
setTile('strip-left', '$0', 'at ' + joinAnd(e.snaps.map(function (x) { return String(x.age); })));
} else {
setTile('strip-left', usd(w.gap) + ' at ' + w.age,
e.snaps.filter(function (x) { return x !== w; }).map(function (x) { return usd(x.gap) + ' at ' + x.age; }).join(', '));
}
fill(unit, stripCaption(' at ' + e.allAge));
}
function renderChrome() {
show($('example-banner'), state.isExample);
show($('print-example'), state.isExample);
Array.prototype.forEach.call(document.querySelectorAll('[data-example-tag]'), function (t) { show(t, state.isExample); });
$('file-status').textContent = state.status;
fill($('btn-save'), state.dirty
? [el('span', { class: 'dot', 'aria-hidden': 'true' }), 'Save', el('span', { class: 'sr', text: ' (you have changes that are not saved)' })]
: 'Save');
renderStrip();
syncChoices();
}
/* ---------- Step 1: What You Have Earned ---------- */
/* Step 1's result for the age picked, said once at the top of the page: the pension as one big number with its unit,
and one sentence. num is '' when there is no pension to show. waits is true when the pension starts at a later age.
compare is the Social Security comparison, which opens the Step 1 panel below. */
function step1Result() {
var e = D.A, p = D.pA, s = D.s, age = s.retireAge, nowStop = age === D.age0;
var v = { age: age, svc: yrs(p.service), amt: usd(p.monthly), draw: p.drawAge, ss: usd(e.ssMissed), cut: pctText(p.cut * 100, 0), full: D.fullAge };
var r = { num: '', unit: '', say: '', compare: '', waits: false, v: v };
if (!p.vested) {
v.refund = usdRound(e.refundToday);
r.say = (nowStop ? 'You have {*svc} of service credit.' : 'At {age} you would have {*svc} of service credit.') +
' A pension starts at 5 years. Your own contributions plus interest, about {*refund}, stay yours either way.';
} else if (p.deferred) {
r.num = v.amt;
r.unit = 'a month, from age ' + p.drawAge;
r.waits = true;
r.say = (nowStop ? 'If you stop teaching now, at {age}, your {*svc} of service credit stay in TRS.' : 'Stop teaching at {age} and your {*svc} of service credit stay in TRS.') +
' They become a pension of about {*amt} a month for life, starting at {draw}.';
} else {
r.num = v.amt;
r.unit = 'a month';
r.say = nowStop
? 'If you stop teaching now, at {age}, your {*svc} of service credit pay a pension of about {*amt} a month for life.'
: 'Teaching until {age} earns you {*svc} of service credit and a pension of about {*amt} a month for life.';
if (p.cut > 0) {
r.say += (D.tier === 4
? ' That includes an early-retirement reduction, estimated here at {cut}%. TRS states it as up to 18%.'
: ' That includes an early-retirement reduction of {cut}%.') + (D.fullAge && D.fullAge > age ? ' From age {full} there is none.' : '');
}
/* The comparison used to follow the sentence above. It now stands alone, so it names the pension it means. */
r.compare = ssCompare(e).replace(/^ That is/, 'This pension is').replace(/^ /, '');
}
return r;
}
/* The first page of the book: the big number, its sentence, and the ruler that sets the age. */
/* The two cards under the big number: staying until the age on the ruler, beside leaving at the age set in Step 2.
Each leads with the monthly income once every check has started, then says what it is made of. */
function pathBig(amount, age, word) { return el('p', { class: 'path__big' }, [el('b', { text: usd(amount) }), ' a month ' + (word || 'from') + ' ' + age]); }
/* When a plan's income starts: its checks grouped by the age each begins, earliest first. One group means the
whole income starts together. An empty list means the plan brings in nothing at all. */
function incomeStart(e) {
var list = [], ages = [];
if (e.hasPension && e.pensionMonthly >= 0.5) list.push(['pension', e.drawAge]);
if (e.ss.monthly >= 0.5) list.push(['ss', e.claimAge]);
if (e.savingsMonthly >= 0.5) list.push(['savings', e.stopAge]);
list.forEach(function (x) { if (ages.indexOf(x[1]) < 0) ages.push(x[1]); });
return ages.sort(function (a, b) { return a - b; }).map(function (age) {
return { age: age, names: list.filter(function (x) { return x[1] === age; }).map(function (x) { return x[0]; }) };
});
}
var START_NAME = { pension: 'pension', ss: 'Social Security', savings: 'savings' };
/* The same, as one short line for a first-screen card, whose amount is given at one age, `at`. A start before
that age reads "The pension has been paying since 55.", so the start age is not taken for the age of the
amount. A start at that age reads "Starts at 67." When one check starts first: "The pension has been paying
since 60, the rest from 67." null when there is no income to speak of. */
function startLine(groups, at) {
function names(g) { return joinAnd(g.names.map(function (n) { return n === 'pension' ? 'the pension' : START_NAME[n]; })); }
/* "The pension has been paying since 55": a start before the card's age is said as something already running. */
function paying(g) { return (g.names.length === 1 && g.names[0] !== 'savings' ? ' has' : ' have') + ' been paying since ' + g.age; }
function when(g) { return g.age < at ? paying(g) : ' from ' + g.age; }
if (!groups.length) return null;
if (groups.length === 1 && groups[0].age >= at) return 'Starts at ' + groups[0].age + '.';
var text = groups.length === 1 ? names(groups[0]) + paying(groups[0])
: groups.length === 2 ? names(groups[0]) + when(groups[0]) + ', the rest' + (groups[1].age < at ? ' since ' : ' from ') + groups[1].age
: groups.map(function (g) { return names(g) + when(g); }).join(', ');
return text.charAt(0).toUpperCase() + text.slice(1) + '.';
}
function pathLine(tpl, v) { return P('path__line', tpl, v); }
function noPensionLine(e) {
if (!e.pension.vested) return 'A pension starts at 5 years of service credit.';
return e.mode === 'cash' ? 'The account is taken as cash, so no pension is drawn.' : 'The account is rolled over, so no pension is drawn.';
}
/* The pension as a part of the card's total, so at the same age as the total. When it started earlier it is worth
less by then in today's dollars, and a second line says what it starts at. */
function pathPension(e, also, at) {
var v = { at: usd(wholeParts(e.at(at)).pension), p: usd(e.pensionMonthly), d: e.drawAge };
if (e.drawAge < at) return [pathLine('Pension {at} a month by then, in today’s dollars' + also + '.', v), pathLine('The pension starts at {p} a month at {d}.', v)];
return [pathLine('Pension {p} a month' + (e.drawAge > e.sepAge ? ' from {d}' : '') + also + '.', v)];
}
function renderPaths() {
var ready = D && D.ready;
show($('paths'), ready);
if (!ready) return;
var A = D.A, B = D.B, stay = [], leave = [], both = D.hasB && !D.bOpen;
/* With both plans whole, the two amounts are given at one age, so they can be set side by side: the later of the
two ages at which each plan's last check has started. Each card then says when its own income starts. With
only the Stay plan whole there is nothing to set it beside, so it keeps its own age. */
var at = both ? Math.max(A.allAge, B.allAge) : A.allAge;
function head(e) {
var out = [pathBig(e.at(at).total, at, both ? 'at' : 'from')], start = startLine(incomeStart(e), at);
if (both && start) out.push(pathLine(start));
return out;
}
$('path-stay-title').textContent = 'Stay Until ' + A.sepAge;
stay = head(A).concat(A.hasPension ? pathPension(A, '', at) : [pathLine(noPensionLine(A))]);
fill($('path-stay-body'), stay);
if (!D.hasB) {
$('path-leave-title').textContent = 'If You Leave';
fill($('path-leave-body'), pathLine('Not set yet. Add when you might leave teaching in Step 2 to see it beside staying.'));
return;
}
$('path-leave-title').textContent = 'Leave At ' + B.sepAge;
if (D.bOpen) {
/* No pay after teaching yet, so there is no whole plan to total. Show what does not depend on a new job. */
if (B.hasPension) {
leave.push(pathBig(B.pensionMonthly, B.drawAge));
leave.push(pathLine('Pension only. Add your new job in Step 2 to see the full picture.'));
} else {
leave.push(pathLine(noPensionLine(B)));
leave.push(pathLine('Add your new job in Step 2 to see the full picture.'));
}
} else {
var ss = B.ss.monthly >= 0.5, work = B.hasNext ? 'your new work' : 'your other work';
leave = head(B);
if (B.hasPension) leave = leave.concat(pathPension(B, ss ? ', plus Social Security from ' + work : '', at));
else leave.push(pathLine((ss ? 'Social Security from ' + work + '. ' : '') + noPensionLine(B)));
}
/* The same test as Step 2's heads-up: one more year crosses a milestone. */
var y = oneMoreYear('B');
if (y && y.p1.vested && y.p1.drawAge !== null && y.p1.monthly >= 0.5) {
leave.push(pathLine('Staying to {age} makes the pension {p}.', { age: B.sepAge + 1, p: usd(y.p1.monthly) }));
}
fill($('path-leave-body'), leave);
}
function renderHero() {
var ready = D && D.ready;
show($('pick'), ready);
renderPaths();
if (!ready) {
show($('hero-line'), false);
show($('hero-next'), false);
$('hero-prompt').textContent = 'Add your numbers to see what your teaching years have earned.';
show($('hero-prompt'), true);
fill($('hero-say'), rich('The page still needs {list}.', { list: joinAnd(D ? D.missing : ['your numbers']) }));
return null;
}
var r = step1Result();
show($('hero-prompt'), false);
show($('hero-line'), !!r.num);
$('hero-num').textContent = r.num;
$('hero-unit').textContent = r.unit;
fill($('hero-say'), rich(r.say, r.v));
show($('hero-next'), r.waits);
renderRuler(r);
return r;
}
/* Up to three service milestones for the ruler, from the list the page already works out: the ones that open a
pension with no reduction or change the multiplier, each at the age this teacher reaches that many years.
A full pension comes first, then the others in order. One that would sit within two years of a flag already
chosen is left out, so "26 years" does not crowd "27 years". */
function rulerFlags(min, max) {
var svc0 = num(D.s.service), picked = [];
var list = D.miles.map(function (m) {
var full = /no reduction|full pension/.test(m.text), mult = /multiplier|career factor|counts at/.test(m.text);
/* A step "past" a number of years (the multiplier past 10 or 20) takes effect a year after that number is reached,
so its flag stands at the age the rise actually starts. */
var past = !!m.past, at = m.at + (past ? 1 : 0);
return { at: m.at, past: past, age: D.age0 + (at - svc0), full: full, ok: (full || mult) && at > svc0 };
}).filter(function (f) { return f.ok && f.age > min && f.age <= max; });
list.filter(function (f) { return f.full; }).concat(list.filter(function (f) { return !f.full; })).forEach(function (f) {
if (picked.length < 3 && !picked.some(function (q) { return Math.abs(q.age - f.age) < 3; })) picked.push(f);
});
/* "full pension" is said only where reaching the milestone is what opens one, at that age. */
picked.forEach(function (f) { f.opens = f.full && D.fullAge === f.age; });
return picked;
}
var rulerKey = '', flagNodes = [];
function renderRuler(r) {
var input = $('ruler-age'), rows = pensionRows(), sel = D.s.retireAge;
/* From today's age to the last age on the Step 1 chart, so the two always offer the same top end. */
var min = D.age0, max = Math.max(rows[rows.length - 1].age, sel, min), span = Math.max(1, max - min);
var flags = rulerFlags(min, max);
var key = [min, max].concat(flags.map(function (f) { return f.at + '@' + f.age + (f.opens ? '!' : ''); })).join(' ');
if (key !== rulerKey) {
rulerKey = key;
var ticks = [];
for (var a = min; a <= max; a++) ticks.push(el('i', { class: a % 5 === 0 ? 'five' : null }, a % 5 === 0 ? el('span', { text: String(a) }) : null));
fill($('ruler-ticks'), ticks);
flagNodes = flags.map(function (f) {
return el('span', { class: 'flag', 'data-age': f.age, 'data-opens': f.opens ? '1' : null, style: 'left:' + round1((f.age - min) / span * 100) + '%' },
el('b', null, [yrs(f.at), f.opens ? el('span', { class: 'flag__long', text: ', full pension' }) : null]));
});
/* Drawn in age order; fitFlags walks them in the order they were chosen. */
fill($('ruler-flags'), flagNodes.slice().sort(function (x, y) { return parseFloat(x.style.left) - parseFloat(y.style.left); }));
$('ruler-miles').textContent = flags.length ? 'Marked on the ruler: ' + joinAnd(flags.slice().sort(function (x, y) { return x.age - y.age; }).map(function (f) {
return (f.past ? 'more than ' : '') + yrs(f.at) + ' of service' + (f.opens ? ' and a full pension' : '') + ' at age ' + f.age;
})) + '.' : '';
input.min = String(min);
input.max = String(max);
fitFlags();
}
if (Number(input.value) !== sel) input.value = String(sel);
placeTab();
input.setAttribute('aria-valuetext', 'Stop teaching at ' + sel + ', ' +
(r.num ? r.num + ' a month' + (r.waits ? ' from age ' + r.v.draw : '') : 'no pension yet'));
}
/* The ink tab under the marker says the age the marker stands on. It is placed from the slider itself, so it
moves with the marker while it is dragged and does not wait for the page to redraw. */
function placeTab() {
var input = $('ruler-age'), tab = $('ruler-tab'), min = Number(input.min), span = Math.max(1, Number(input.max) - min);
tab.textContent = input.value;
tab.style.left = round1((Number(input.value) - min) / span * 100) + '%';
}
/* Keep the words above the ruler apart and on the ruler, at every width. The flag that opens a full pension goes
first and always keeps its reason. Its words sit centred on its mark where there is room; where there is not
they hang to the right of the mark, or to the left, whichever lets more of the other flags show. The others
take the room that is left, in the order they were chosen: centred, or hung to one side. One that still touches
is left out. Its milestone is still in Step 1's list. A flag's mark never moves from its age. */
function fitFlags() {
var host = $('ruler-flags'), ruler = host.parentNode.getBoundingClientRect(), GAP = 8;
if (!ruler.width) return;
var items = flagNodes.map(function (n) {
var b = n.firstChild;
n.hidden = false;
b.style.setProperty('--shift', '0px');
var box = b.getBoundingClientRect();
return { n: n, b: b, mid: (box.left + box.right) / 2, w: box.width, lead: n.getAttribute('data-opens') === '1' };
});
/* Where the words would be, [left, right], after sliding them by shift and then back onto the ruler. */
function at(it, shift) {
var left = it.mid - it.w / 2 + shift, right = left + it.w;
if (left < ruler.left) { right += ruler.left - left; left = ruler.left; }
else if (right > ruler.right) { left -= right - ruler.right; right = ruler.right; }
return [left, right];
}
function touches(a, b) { return a[0] < b[1] + GAP && a[1] > b[0] - GAP; }
function sides(it) { var hang = Math.max(0, it.w / 2 - 6); return [at(it, 0), at(it, hang), at(it, -hang)]; }
function put(it, where) { it.b.style.setProperty('--shift', round1(where[0] - (it.mid - it.w / 2)) + 'px'); }
var lead = items.filter(function (it) { return it.lead && it.w > 0; })[0];
var rest = items.filter(function (it) { return it !== lead; });
/* With the first flag's words in one place, where do the others go, and how many of them fit? */
function arrange(first) {
var taken = first ? [first] : [], spots = rest.map(function (it) {
var free = it.w > 0 ? sides(it).filter(function (where) { return !taken.some(function (q) { return touches(where, q); }); })[0] : null;
if (free) taken.push(free);
return free || null;
});
return { first: first, spots: spots, shown: spots.filter(Boolean).length };
}
var plans = lead ? sides(lead).map(arrange) : [arrange(null)], best = plans[0];
plans.forEach(function (p) { if (p.shown > best.shown) best = p; });
if (lead) put(lead, best.first);
rest.forEach(function (it, i) { if (best.spots[i]) put(it, best.spots[i]); else it.n.hidden = true; });
}
function step1Lead(r) {
var out = [];
if (r.compare) out.push(P('result', r.compare, r.v));
var note = 'Amounts are a month, in today’s dollars: adjusted for inflation so you can compare them with prices now.';
if (D.retireAuto) note += ' The page picked ' + r.v.age + (D.fullAge === r.v.age ? ', your first age with a full pension' : '') + '. Change it on the ruler or the chart.';
out.push(P('result-note', note));
return out;
}
function accountCard() {
var T = D.T, svc = num(D.s.service), vested = svc >= RULES.vestYears, tier = D.tier;
var split = tier === 4
? pctText(T.pension * 100, 3) + '% goes to your foundational pension and ' + pctText(T.supp * 100, 3) + '% to your supplemental account, where your employer adds another ' +
pctText(T.supp * 100, 3) + '%. The other ' + pctText(T.health * 100, 3) + '% goes to retiree health.'
: pctText(T.pension * 100, 3) + '% goes to the pension and ' + pctText(T.health * 100, 3) + '% to retiree health.';
return card('s1-acct-title', 'Your Account Type: ' + T.name, [
P(null, 'Your first day in TRS was in {month} {year}. {name} is for members who started {joined}.',
{ month: monthName(D.s.entryMonth), year: D.s.entryYear, name: T.name, joined: T.joined }),
el('dl', { class: 'facts', style: 'margin-top:16px' }, [
fact('Service credit so far', yrs(svc)),
fact('Vested', vested ? 'Yes' : 'At 5 years', vested ? 'You have earned the right to a pension, even if you leave.' : more(RULES.vestYears - svc, 'year') + ' to go. Vested means you have earned the right to a pension, even if you leave.'),
fact('You pay', pctText(T.contrib * 100, 3) + '% of pay', split)
]),
P('small', 'No Social Security tax comes out of TRS pay. That is by design: the pension takes its place.')
]);
}
function milesCard() {
var items = D.miles.map(function (m) {
var n = m.past ? m.togo + 1 : m.togo;
var label = m.past ? 'Past ' + m.at + ' years' : yrs(m.at);
return el('li', null, [
icon(m.done ? 'i-done' : 'i-ahead'),
el('p', { class: 'miles__when' }, [label, el('span', { text: m.done ? ', reached' : ', in ' + yrs(n) + ' at age ' + (D.age0 + n) })]),
el('p', { class: 'miles__what', text: milestoneText(m, m.done ? D.age0 : D.age0 + n) })
]);
});
return card('s1-miles-title', 'Service Milestones Ahead', [
P('small', 'Some years of service credit change what every year is worth.'),
el('ul', { class: 'miles', style: 'margin-top:16px' }, items)
]);
}
function earlyCard() {
var tier = D.tier, text;
if (tier === 4) text = 'A full pension starts at 57 with 30 years of service, at 60 with 10, or at 65 with 5. From 57 with 10 years you can take a reduced pension, lowered by up to 18%.';
else if (tier === 3) text = 'A full pension starts with 27 years of service at any age, or at 60 with 5 years. From 55 with 10 years you can take a reduced pension: 6% less for each year before 60 or under 27 years, whichever is fewer.';
else text = 'A full pension starts with 27 years of service at any age, or at 60 with 5 years. From 55 with 5 years you can take a reduced pension: 5% less for each year before 60 or under 27 years, whichever is fewer.';
var first = D.table.firstAge, full = D.fullAge, yours;
if (first === null || full === null) yours = P(null, 'With these numbers a pension would start after age 80, which is later than this page looks.');
else if (first === full) yours = P(null, 'With your numbers, a pension can first start at {*full}, and it is a full one.', { full: full });
else yours = P(null, 'With your numbers, a reduced pension can first start at {*first} and a full one at {*full}.', { first: first, full: full });
return card('s1-early-title', 'Full And Early Retirement', [P(null, text), yours]);
}
/* Pencil tally marks for the years of service: one for each year, in fives, the fifth across the other four. The
mark for a year at which the multiplier steps up is heavier. It is a picture of the number beside it, so screen
readers skip it. */
function tallyMarks(years) {
var n = Math.max(0, Math.floor(num(years))), heavy = {}, groups = [];
D.miles.forEach(function (m) { if (/multiplier|career factor|counts at/.test(m.text)) heavy[m.at + (m.past ? 1 : 0)] = true; });
for (var g = 0; g * 5 < n; g++) {
var svg = sv('svg', { viewBox: '0 0 26 18', width: 26, height: 18, focusable: 'false' });
for (var k = 1; k <= 5 && g * 5 + k <= n; k++) {
var year = g * 5 + k, cls = 'tally__mark s-ink' + (heavy[year] ? ' tally__mark--heavy' : ''), x = 4 + (k - 1) * 5;
svg.appendChild(k < 5 ? sv('line', { class: cls, 'data-year': year, x1: x + 0.8, y1: 2, x2: x, y2: 16 })
: sv('line', { class: cls + ' tally__mark--cross', 'data-year': year, x1: 1, y1: 13, x2: 24, y2: 5 }));
}
groups.push(svg);
}
return el('dd', { class: 'facts__sub tally', 'aria-hidden': 'true' }, groups);
}
function formulaCard() {
var p = D.pA, kids = [];
if (!p.vested) {
kids.push(P(null, 'A pension is your years of service credit, times a multiplier, times your final average salary: the average of your highest yearly salaries. It starts once you have 5 years of service credit.'));
kids.push(el('dl', { class: 'facts', style: 'margin-top:16px' }, [add(fact('Years of service credit at ' + p.sepAge, yrs(p.service)), tallyMarks(p.service))]));
return kids;
}
var m = TG.mult(D.tier, p.drawAge, p.service), rate = pctText(p.rate * 100, 2), rows = [];
kids.push(P(null, 'Years of service credit, times a multiplier, times your final average salary: the average of your ' + p.fasYears + ' highest yearly salaries. The multiplier is the share of that salary each year of service earns.'));
rows.push(add(fact('Years of service credit at ' + p.sepAge, String(p.service)), tallyMarks(p.service)));
rows.push(fact('Multiplier', D.tier === 4 ? rate + '% a year' : (m.over30 > 0 ? rate + '%, then 3.0%' : rate + '% a year'),
(D.tier === 4 ? 'The TRS 4 rate at age ' + p.drawAge + ' with ' + yrs(p.service) + '. ' : (m.over30 > 0 ? rate + '% for the first 30 years and 3.0% for each year past 30. ' : '')) +
'Together that is ' + pctText(p.pct * 100, 1) + '% of your final average salary.'));
rows.push(fact('Final average salary', usd(p.fasToday), 'The average of your ' + p.fasYears + ' highest yearly salaries. In today’s dollars, so it can read lower than your current pay.'));
if (p.cut > 0) rows.push(fact('Early-retirement reduction', pctText(p.cut * 100, 0) + '%', D.tier === 4 ? 'An estimate. TRS states the TRS 4 reduction as up to 18%.' : null));
if (p.deferred) {
rows.push(fact('Years it waits in TRS', String(p.drawAge - p.sepAge), 'It gets no inflation increase while it waits, so it buys less by the time it starts at ' + p.drawAge + '.'));
/* What the wait costs in today's dollars, from the rows above: the formula's amount less the pension shown,
each rounded as it is shown, so the rows add up to the dollar. */
var before = Math.round(p.fasToday * p.pct), less = before - Math.round(p.annual);
if (less >= 1) rows.push(fact('Inflation over ' + yrs(p.drawAge - p.sepAge) + ' of waiting', '−' + usd(less) + ' a year',
pctText(p.pct * 100, 1) + '% of ' + usd(p.fasToday) + ' is ' + usd(before) + ' a year. Less this, the pension is ' + usd(p.annual) + ' a year in today’s dollars.'));
}
rows.push(fact('Pension', usd(p.annual) + ' a year', usd(p.monthly) + ' a month for life, in today’s dollars at the first check.'));
kids.push(el('dl', { class: 'facts', style: 'margin-top:16px' }, rows));
return kids;
}
function renderStep1() {
var ready = D && D.ready;
show($('s1-empty'), !ready);
show($('c1'), ready);
show($('s1-formula'), ready);
show($('s1-early'), ready);
var result = renderHero();
if (!ready) {
show($('c2'), false);
fill($('s1-lead'), []);
fill($('s1-empty'), emptyBox('Your pension at each retirement age appears here once Your Numbers is filled in.', false));
fill($('s1-aside'), []);
return;
}
var lead = step1Lead(result), hu = headsUp('A');
if (hu) lead.splice(lead.length - 1, 0, el('div', { style: 'margin-top:16px' }, hu));
fill($('s1-lead'), lead);
fill($('s1-formula'), [el('h3', { id: 's1-formula-title', text: 'How This Pension Is Figured' })].concat(formulaCard()));
fill($('s1-early'), earlyCard());
fill($('s1-aside'), [accountCard(), milesCard()]);
var age = $('f-retireAge');
age.min = String(D.age0);
age.max = String(MAX_AGE);
if (document.activeElement !== age) age.value = String(D.s.retireAge);
$('age-down').disabled = D.s.retireAge <= D.age0;
$('age-up').disabled = D.s.retireAge >= MAX_AGE;
}
/* ---------- Step 2: If Your Plans Change ---------- */
function step2Lead() {
var A = D.A, B = D.B, pa = A.primary, srcA = sourcesAt(pa), v = {}, t;
v.ageA = A.sepAge; v.allA = A.allAge; v.totA = usd(pa.total); v.srcA = joinAnd(srcA); v.bring = bringVerb(srcA);
if (!srcA.length) t = 'Stay until {ageA} and no monthly income has started by age {allA}.';
else if (A.stopAge === A.allAge) t = 'Stay until {ageA} and your {srcA} {bring} in about {*totA} a month from age {allA}.';
else t = 'Stay until {ageA} and your {srcA} {bring} in about {*totA} a month by age {allA}, when every check is running.';
if (!D.hasB) return [P('result', t, v), P('result-note', 'To see Leave Teaching beside it, add when you might leave teaching in Your Numbers.')];
var p = B.pension, open = D.bOpen, tb;
v.ageB = B.sepAge; v.svcB = yrs(p.service); v.penB = usd(p.monthly); v.drawB = p.drawAge; v.refund = usdRound(B.refundToday);
v.taxes = usdRound(B.cashLost); v.penalty = B.penaltyRate > 0 ? 'the 10% federal penalty and ' : ''; v.stopB = B.stopAge;
v.rollM = usd(B.potParts.rollover * TG.basics(D.s).draw / 12);
var leave = B.sepAge === D.age0 ? 'Leave now, at {ageB},' : 'Leave at {ageB}';
/* What happens to the TRS account when the plan draws no pension from it. */
var account = '';
if (!B.hasPension) {
if (p.vested && B.mode === 'rollover') account = 'Your TRS account, about {*refund}, rolls over to your own retirement account.' + (open ? '' : ' It could pay about {*rollM} a month from age {stopB}.');
else if (p.vested) account = 'Your TRS account, about {*refund}, comes to you as cash. About {*taxes} of it goes to {penalty}income tax.';
else if (B.mode === 'cash') account = 'With {svcB} of service credit you take your own contributions and interest, about {*refund}, as cash: about {*taxes} of it goes to {penalty}income tax. A pension starts at 5 years of service credit, so this plan does not include one.';
else account = 'With {svcB} of service credit you take your own contributions and interest with you, about {*refund}, to roll into a retirement account. A pension starts at 5 years of service credit, so this plan does not include one.';
}
if (open) {
/* No pay after teaching yet, so there is no total to lead with. Say what leaving keeps. */
if (B.mode === 'retire') tb = leave + ' and your pension of about {*penB} a month starts right away.';
else if (B.mode === 'deferred') tb = leave + ' and you keep a pension of about {*penB} a month from age {drawB}.';
else if (p.vested) tb = leave + ' and y' + account.slice(1);
else if (B.mode === 'cash') tb = leave + ' with {svcB} of service credit and take your own contributions and interest, about {*refund}, as cash: about {*taxes} of it goes to {penalty}income tax. A pension starts at 5 years of service credit, so this plan does not include one.';
else tb = leave + ' with {svcB} of service credit and you take your own contributions and interest with you, about {*refund}, to roll into a retirement account. A pension starts at 5 years of service credit, so this plan does not include one.';
return [P('result', t + ' ' + tb, v), P('result-note', 'Leave Teaching is not finished yet. It still needs what you expect to earn after teaching, in Your Numbers.')];
}
/* Two short parts. First both totals at one age, so they can be set side by side: the later of the two ages at
which each plan's last check has started. Then when each path starts paying. The parts of each total are on
the plan cards below. */
var at = Math.max(A.allAge, B.allAge);
v.at = at; v.totA = usd(A.at(at).total); v.totB = usd(B.at(at).total);
t = 'At {at}, staying until {ageA} brings in about {*totA} a month and ' + (B.sepAge === D.age0 ? 'leaving now' : 'leaving at {ageB}') + ' about {*totB}.';
/* job is the age the new job ends when leaving has one: the Leave path is on a paycheck until then, and the
sentence says so before it says when the checks start. */
function startSay(who, groups, job) {
function names(g) { return joinAnd(g.names.map(function (n) { return n === 'pension' ? 'the pension' : START_NAME[n]; })); }
function verb(g) { return g.names.length === 1 && g.names[0] !== 'savings' ? ' starts' : ' start'; }
if (!groups.length) return job ? ' If you leave, you work your new job until ' + job + '.' : '';
if (groups.length === 1 && !job) return (who === 'stay' ? ' Staying' : ' Leaving') + ' pays from ' + groups[0].age + '.';
var parts = job ? ['you work your new job until ' + job] : [];
if (groups.length === 1) parts.push('your retirement income starts at ' + groups[0].age);
else {
parts.push(names(groups[0]) + verb(groups[0]) + ' at ' + groups[0].age);
if (groups.length === 2) parts.push('the rest at ' + groups[1].age);
else groups.slice(1).forEach(function (g) { parts.push(names(g) + ' at ' + g.age); });
}
return ' If you ' + who + ', ' + (parts.length > 2 ? parts.slice(0, -1).join(', ') + ' and ' + parts[parts.length - 1] : parts.join(job && groups.length === 1 ? ', and ' : ' and ')) + '.';
}
t += startSay('stay', incomeStart(A)) + startSay('leave', incomeStart(B), B.hasNext && B.stopAge > B.sepAge ? B.stopAge : null);
if (account) t += ' ' + account;
return [P('result', t, v)];
}
function planCard(which, e, scaleMax) {
var p = e.pension, on = D.which === which, open = which === 'B' && D.bOpen, penSub, ssSub, savSub;
var head = el('div', { class: 'plan__head' }, [
el('p', { class: 'plan__name', text: which === 'A' ? 'Stay Teaching' : 'Leave Teaching' }),
el('h4', { id: 'plan-' + which + '-title', style: 'font-size:20px', text: (which === 'A' ? 'Teach Until ' : 'Leave At ') + e.sepAge })
]);
if (e.mode === 'retire') penSub = 'For life, from age ' + e.drawAge + (p.cut > 0 ? ', after an early-retirement reduction of ' + pctText(p.cut * 100, 0) + '%.' : '.');
else if (e.mode === 'deferred') penSub = 'For life, from age ' + e.drawAge + '. It waits in TRS until then.';
else if (!p.vested) penSub = 'A pension starts at 5 years of service credit.';
else penSub = e.mode === 'cash' ? 'The account is taken as cash, so no pension is drawn.' : 'The account is rolled over, so no pension is drawn.';
if (open) {
/* Pay after teaching is not entered yet. Show only what does not depend on a new job:
the pension or the account, and the Social Security credits earned so far. */
var need = RULES.ss.need, openRows = [
fact('Years of service credit', String(p.service)),
fact('Pension', e.hasPension ? usd(e.pensionMonthly) + ' a month' : 'None', penSub)
];
if (!e.hasPension) openRows.push(fact('TRS account', 'About ' + usdRound(e.refundToday), 'Your own contributions plus interest, in today’s dollars.'));
openRows.push(fact('Social Security credits so far', Math.min(e.ss.credits, need) + ' of ' + need, 'From other work. New work would add to them.'));
return el('section', { class: 'card plan plan--open', 'aria-labelledby': 'plan-B-title' }, [
head,
el('dl', { class: 'facts' }, openRows),
el('p', { class: 'readout', id: 'plan-B-open', style: 'margin-top:0', text: 'Add what you expect to earn after teaching to finish this plan. Enter 0 if you would stop working.' })
]);
}
if (e.ss.monthly >= 0.5) ssSub = 'From age ' + e.claimAge + (e.ss.spousal >= 0.5 ? ', counting a spousal benefit of ' + usd(e.ss.spousal) + '.' : '.');
else ssSub = Math.min(e.ss.credits, RULES.ss.need) + ' of the ' + RULES.ss.need + ' credits needed so far.';
savSub = 'From about ' + usdRound(e.pot) + ' saved by age ' + e.stopAge +
(e.potParts.rollover >= 0.5 ? ', counting the rollover' : '') + (e.potParts.supplemental >= 0.5 ? ', counting your TRS 4 supplemental account' : '') + '.';
var rows = [
fact('Years of service credit', String(p.service)),
fact('Pension', e.hasPension ? usd(e.pensionMonthly) + ' a month' : 'None', penSub),
fact('Social Security', usd(e.ss.monthly) + ' a month', ssSub),
fact('Savings', usd(e.savingsMonthly) + ' a month', savSub)
];
if (e.hasNext) rows.push(fact(which === 'A' ? 'Work after teaching' : 'New work', usdRound(e.nextPay) + ' a year', 'Until age ' + e.stopAge + '.'));
else if (which === 'B') rows.push(fact('New work', 'None', 'This plan treats leaving at ' + e.sepAge + ' as the end of paid work.'));
/* The target follows pay, so a new job that pays more than teaching raises it. Say so on the Leave card, or the
higher target reads as leaving falling further from it. Only when the new job's pay is what sets the target. */
var stayTarget = D.A.target, newJobSets = which === 'B' && e.hasNext && e.nextPay >= e.basePay - 0.005 && usd(e.target) !== usd(stayTarget) && e.target > stayTarget;
rows.push(fact('Target', usd(e.target) + ' a month', pctText(D.s.targetPct, 2) + '% of ' + usdRound(e.basePay) + ' a year.' +
(newJobSets ? ' The target is higher here because the new job pays more: ' + usd(e.target) + ', not ' + usd(stayTarget) + '.' : '')));
return el('section', { class: 'card plan' + (on ? ' is-on' : ''), 'aria-labelledby': 'plan-' + which + '-title' }, [
head,
el('dl', { class: 'facts' }, rows),
el('div', { class: 'cov' }, e.snaps.map(function (x) { return covRow(e, x, scaleMax, true, 300); })),
el('button', {
type: 'button', class: 'btn btn--secondary no-print', 'aria-pressed': on ? 'true' : 'false', 'data-fk': 'use-' + which, style: 'align-self:flex-start',
text: on ? 'Shown In The Summary' : 'Show In The Summary',
onclick: function () { setData('plan', which, null); }
})
]);
}
function ssBlock(name, e, soFar) {
var need = RULES.ss.need, c = e.ss.credits, have = Math.min(c, need), kids = [];
kids.push(el('h4', { text: name }));
if (soFar) kids.push(P('small', 'Counted from other work so far. New work would add to this.'));
kids.push(el('div', { class: 'meter' }, [
el('div', { class: 'meter__label' }, [el('span', { text: c >= need ? 'All ' + need + ' credits earned' : 'Credits toward ' + need }), el('b', { text: have + ' of ' + need })]),
sv('svg', { viewBox: '0 0 100 8', preserveAspectRatio: 'none', width: '100%', height: 10, role: 'img', style: 'border-radius:5px;overflow:hidden',
'aria-label': have + ' of ' + need + ' Social Security credits' }, [
sv('rect', { class: 'f-ss-soft', width: 100, height: 8 }),
sv('rect', { class: 'f-ss', width: round1(have / need * 100), height: 8 })
])
]));
if (e.ss.insured) {
kids.push(P(null, 'Your own benefit is about {*own} a month at {claim}.', { own: usd(e.ss.own), claim: e.claimAge }));
kids.push(el('dl', { class: 'facts' }, [62, 67, 70].map(function (a) {
return fact('If you claim at ' + a, usd(e.ss.ownPIA * TG.ownFactor(a)) + ' a month');
})));
} else {
var left = need - c;
kids.push(P(null, '{n} to qualify for a benefit of your own. That is about {y} of work that pays Social Security tax.', { n: more(left, 'credit'), y: yrs(Math.ceil(left / 4)) }));
}
if (num(D.s.spousePIA) > 0) {
if (e.ss.spousal >= 0.5) kids.push(P(null, 'A spousal benefit adds about {*sp} a month at {claim}: half of your spouse’s full benefit, less your own' +
(e.claimAge < RULES.ss.fra ? ', then reduced for claiming before ' + RULES.ss.fra : '') + '.', { sp: usd(e.ss.spousal), claim: e.claimAge }));
else kids.push(P(null, 'Your own benefit is larger than half of your spouse’s, so a spousal benefit adds nothing here.'));
}
return el('div', { class: 'ssblock' }, kids);
}
function renderAccount() {
var host = $('s2-account'), B = D.B, on = D.hasB && B.mode !== 'retire';
show(host, on);
if (!on) return;
var s = D.s, p = B.pension, vested = p.vested;
var eRoll = TG.evalPlan(withData(s, { acctChoice: 'rollover' }), 'B'), eCash = TG.evalPlan(withData(s, { acctChoice: 'cash' }), 'B');
var rollM = eRoll.potParts.rollover * TG.basics(s).draw / 12, net = Math.max(0, eCash.refundToday - eCash.cashLost);
var effective = (!vested && s.acctChoice === 'leave') ? 'rollover' : s.acctChoice;
Array.prototype.forEach.call(host.querySelectorAll('input[name="acctChoice"]'), function (r) {
r.checked = r.value === effective;
if (r.value === 'leave') r.disabled = !vested;
});
fill($('s2-account-intro'), rich('When you leave at {age}, your TRS account holds your own contributions plus interest: about {*amt} in today’s dollars{est}. It never includes the health contribution or the state’s money. You choose what happens to it.',
{ age: B.sepAge, amt: usdRound(B.refundToday), est: B.acct.estimated ? ', estimated from your salary' : '' }));
if (vested) {
/* Each card names the age its income starts, and the pension says it is for life. */
$('acct-leave-big').textContent = usd(p.monthly) + ' a month for life';
$('acct-leave-when').textContent = 'Pension starts at ' + p.drawAge;
$('acct-leave-text').textContent = 'Your account stays in TRS. The pension gets no inflation increase while it waits, and this amount already counts that.';
$('acct-leave-back').textContent = 'Your years stay in TRS while you are away. If you come back to a Kentucky classroom, they still count.';
} else {
$('acct-leave-big').textContent = 'Opens at 5 years';
$('acct-leave-when').textContent = '';
$('acct-leave-text').textContent = 'Leaving money in TRS for a pension takes 5 years of service credit. You would have ' + yrs(p.service) + '.';
$('acct-leave-back').textContent = '';
}
/* Coming back: with 5 years or more the years wait in TRS. The under-5 rule is in the heads-up below. A rollover
and cash are both a withdrawal, so both end the years and both can be repaid after a year back. (KRS 161.470) */
show($('acct-leave-back'), vested);
$('acct-rollover-back').textContent = 'A rollover also ends your TRS years, the same as cash. If you come back, you return as a new member. After a year back you can repay the amount with interest to restore these years.';
$('acct-cash-back').textContent = 'If you come back, you return as a new member. After a year back you can repay the refund with interest to restore these years.';
$('acct-rollover-big').textContent = usdRound(eRoll.refundToday) + ' moves with you';
$('acct-rollover-when').textContent = D.bOpen ? 'Income starts when work stops' : 'Income starts at ' + eRoll.stopAge;
/* What a rollover could pay depends on when work stops, so it waits until Leave Teaching has its pay. */
/* The yearly return and the tax bracket start as the page's own guesses. Until the teacher changes one, the cards
say so, and where to change it. What a rollover pays depends on the return, so that line says it is not guaranteed. */
var guess = ', a starting guess from Your Numbers';
$('acct-rollover-text').textContent = 'Into your own retirement account, with no tax now.' + (D.bOpen ? '' : ' ' +
(D.d.returnPct === null ? 'With no yearly return entered' : D.d.returnPct === BLANK.returnPct ? 'At a ' + pctText(s.returnPct, 2) + '% yearly return' + guess + ',' : 'At your ' + pctText(s.returnPct, 2) + '% yearly return') +
' it could pay about ' + usd(rollM) + ' a month from age ' + eRoll.stopAge + '. Not guaranteed.');
$('acct-cash-big').textContent = usdRound(net) + ' to spend';
$('acct-cash-text').textContent = 'After about ' + usdRound(eCash.cashLost) + ' goes to ' + (eCash.penaltyRate > 0 ? 'the 10% federal penalty and ' : '') +
(D.d.fedBracket === BLANK.fedBracket ? 'income tax at a ' + pctText(s.fedBracket, 0) + '% bracket' + guess : 'income tax at your ' + pctText(s.fedBracket, 0) + '% bracket') +
'. State income tax may also apply. The page counts it as spent, so it is not in your retirement income.';
var notes = [];
if (vested && effective !== 'leave') {
var paras = [P(null, 'A refund ends your TRS membership. The pension that would wait for you, about {*amt} a month for life from age {draw}, ends with it.', { amt: usd(p.monthly), draw: p.drawAge })];
if (effective === 'cash') paras.push(P(null, 'A refund owes income tax, plus a 10% federal penalty unless you leave in or after the year you turn 55. A direct rollover avoids both for now.'));
notes.push(cautionBox('Heads-Up: A Refund Cannot Be Undone', paras));
} else if (!vested) {
var np = [P(null, 'A refund ends your TRS membership. If you may return to a Kentucky public school within 3 years, you can leave the money in TRS and keep your service credit. Under 5 years, membership ends after more than 3 straight years away. If you come back without having taken a refund, those years are restored.')];
if (B.forfeitToday >= 0.5) np.push(P(null, 'Under 5 years you give up the 2% your employer added to your supplemental account, about {*amt}. At 5 years it is yours to keep.', { amt: usdRound(B.forfeitToday) }));
if (effective === 'cash') np.push(P(null, 'A refund owes income tax, plus a 10% federal penalty unless you leave in or after the year you turn 55. A direct rollover avoids both for now.'));
notes.push(cautionBox(effective === 'cash' ? 'Heads-Up: Cash Cannot Be Undone' : 'Heads-Up: Before You Take A Refund', np));
}
notes.push(el('p', { class: 'small muted' }, ['TRS pays a refund no sooner than 60 days after your last day. Ask TRS for the exact amount: ', phone(), '.']));
fill($('s2-account-notes'), notes.map(function (n, i) { return i ? el('div', { style: 'margin-top:12px' }, n) : n; }));
}
/* ---------- Step 2: staying beside leaving, with work stopping at the same age ----------
A what-if at the top of the step. For every stop age, from the year after Leave Teaching leaves teaching up to 70, the
engine runs twice: staying (teach until that age, then stop) and leaving (teach until the leaving age,
then the new job until that age). The two are measured by everything each path brings in from the stop age
through 85, in today's dollars: twelve months at each age, added up, and rounded as the page shows it. The box
starts at the age just before the lead switches from one path to the other, or at the ruler's age when it never
does. A second what-if sets the age Social Security starts, in this table only. It does not move the box.
Neither age is one of Your Numbers: they move nothing else on the page and they are not saved. */
var EVEN_TOP = 70; // the last stop age compared
var EVEN_END = 85; // totals run from the stop age through this age
var EVEN_SAME = 0.05; // within this share of the larger amount, the two read as "about the same"
var EVEN_WORD = { stay: 'staying', leave: 'leaving' };
var stopAt = null; // the age typed in Stop Working At. null means the box follows the page's own starting age.
var claimAt = null; // the age picked in Social Security Starts At. null means it follows the age in Your Numbers.
var EVEN_CLAIMS = [62, 67, 70];
var evenShown = null; // the age the table is showing now
var evenMemo = { key: '', list: null };
/* '' when the comparison can be shown, otherwise one line saying what it needs. */
function evenNeeds() {
var what = 'Staying beside leaving, with work stopping at the same age, ';
if (!D || !D.ready) return what + 'appears here once Step 1 is filled in.';
if (!D.hasB) return what + 'appears here once you add when you might leave teaching, in Your Numbers.';
if (D.bOpen) return what + 'appears here once you add what you expect to earn after teaching, in Your Numbers.';
if (!(num(D.s.nextPayB) > 0)) return what + 'needs new work to compare. Leave Teaching has $0 entered for new work.';
if (D.B.sepAge + 1 > EVEN_TOP) return what + 'looks at stop ages up to ' + EVEN_TOP + '. If you leave, you stop teaching at ' + D.B.sepAge + ', so there is no stop age to compare.';
return '';
}
/* The age Social Security starts in this table: the one picked here, or else the one in Your Numbers. */
function evenClaim() { return claimAt === null ? D.s.claimAge : claimAt; }
/* A total as the page writes it: to the nearest $100 from $10,000, the same rounding as usdRound. */
function evenRound(x) { return x >= 10000 ? Math.round(x / 100) * 100 : Math.round(x); }
/* Everything one path brings in from the stop age through 85, in today's dollars: twelve months at each age, added up. */
function evenTotal(e, age) {
var sum = 0;
for (var a = age; a <= EVEN_END; a++) sum += 12 * e.at(a).total;
return sum;
}
/* 'stay' or 'leave' for the larger of two amounts, or 'same' when they are within 5% of the larger one. */
function evenSide(a, b) { return Math.abs(a - b) <= EVEN_SAME * Math.max(a, b) ? 'same' : (a > b ? 'stay' : 'leave'); }
/* Both paths at one stop age. Staying has no work after teaching here, so the two stop work in the same year.
The measure is each path's total from the stop age through 85, as the table shows it. `at` is the age the
table sets the two monthly amounts side by side at: the later of the two ages at which each path's last check
has started. Comparing each path at its own age would set, say, 60 beside 67. */
function evenAt(age, claim) {
var stay = TG.evalPlan(planInput(withData(D.s, { retireAge: age, nextPayA: 0, claimAge: claim }), 'A'), 'A'), leave = TG.evalPlan(withData(D.s, { workUntilB: age, claimAge: claim }), 'B');
var a = evenRound(evenTotal(stay, age)), b = evenRound(evenTotal(leave, age));
return { age: age, stay: stay, leave: leave, at: Math.max(stay.allAge, leave.allAge), totals: [a, b], diff: a - b, side: evenSide(a, b) };
}
/* Every stop age in range, worked out once for each change to Your Numbers or to the age Social Security starts.
Moving the ruler does not change it. */
function evenList() {
var claim = evenClaim(), key = JSON.stringify(withData(D.s, { retireAge: 0, nextPayA: 0, workUntilA: 0, workUntilB: 0, plan: '', claimAge: claim }));
if (evenMemo.key !== key) {
var list = [];
for (var a = D.B.sepAge + 1; a <= EVEN_TOP; a++) list.push(evenAt(a, claim));
evenMemo = { key: key, list: list };
}
return evenMemo.list;
}
/* The stop ages as ranges, in age order: [{ side, from, to }], where side is 'stay', 'leave' or 'same'. */
function evenRuns(list) {
var runs = [];
list.forEach(function (r) {
var last = runs[runs.length - 1];
if (last && last.side === r.side) last.to = r.age; else runs.push({ side: r.side, from: r.age, to: r.age });
});
return runs;
}
/* The age the box starts at, and the line on where the lead changes.
The lead switches where one path starts to bring in more after the other had. Ages where the two are about the
same have no leader, so a switch can run across them. The box starts at the age just before a switch. With
several switches it is the one whose starting age is nearest the ruler's age, and the later one on a tie. When
the lead never switches the box starts at the ruler's age.
The line says only what the totals say. It walks every range in age order: which path brings in more first, then each age
at which that changes. */
var EVEN_AHEAD = { stay: 'staying brings in more', leave: 'leaving brings in more', same: 'the two are about the same' };
function evenStudy(list, rulerAge) {
var min = list[0].age, max = list[list.length - 1].age, runs = evenRuns(list), parts = [], switches = [], leader = null;
runs.forEach(function (run, i) {
var say = EVEN_AHEAD[run.side], first = say.charAt(0).toUpperCase() + say.slice(1);
if (run.side !== 'same') {
if (leader && leader !== run.side) switches.push(run);
leader = run.side;
}
if (runs.length === 1) parts.push(first + (min === max ? ' at stop age ' + min : ' at every stop age from ' + min + ' to ' + max) + '.');
else if (i === 0) parts.push(first + (run.from === run.to ? ' at stop age ' + run.from : ' at stop ages ' + run.from + ' to ' + run.to) + '.');
else parts.push((run.from === run.to ? 'At ' : 'From ') + run.from + ', ' + say + '.');
});
var out = { min: min, max: max, text: parts.join(' '), switched: switches.length > 0 };
if (out.switched) {
var pick = switches[0];
switches.forEach(function (sw) { if (Math.abs(sw.from - 1 - rulerAge) <= Math.abs(pick.from - 1 - rulerAge)) pick = sw; });
out.age = pick.from - 1;
/* Why there, in the words of the line above: the end of a close stretch, or the last age before the other path brings in more. */
out.why = list[out.age - min].side === 'same' ? 'the last stop age where the two are about the same' : 'the last stop age before ' + EVEN_AHEAD[pick.side];
} else {
out.age = clamp(rulerAge, min, max);
out.why = rulerAge >= min && rulerAge <= max ? 'the age on the ruler' : 'the age nearest the ruler';
}
return out;
}
/* The headline for the age in the box, two lines. The first: which path brings in more from that stop age through
85, and by how much: the difference between the two totals as the table shows them. The second, when the pay
until then differs by more than 5%: which path pays more in paychecks over the years the two differ, from the
year Leave Teaching leaves teaching to the stop age, in today's dollars. The two figures are never added together, and
neither line gives a verdict. */
function evenPay(r, list) {
var years = list.filter(function (x) { return x.age <= r.age; }).map(function (x) { return x.stay.pension.payToday; });
var teach = evenRound(years.reduce(function (sum, x) { return sum + x; }, 0)), work = evenRound(r.leave.nextPay * years.length);
return { side: evenSide(teach, work), more: Math.abs(teach - work) };
}
function evenSay(r, list) {
var pay = evenPay(r, list), v = { age: r.age, end: EVEN_END, who: EVEN_WORD[r.side], more: usd(Math.abs(r.diff)), payWho: EVEN_WORD[pay.side], pay: usd(pay.more) };
var lines = [el('span', { class: 'even__line' }, rich(r.side === 'same' ? 'After work stops at {age}, the two paths bring in about the same through age {end}.' : 'After work stops at {age}, {who} brings in about {*more} more through age {end}.', v))];
if (pay.side !== 'same') lines.push(' ', el('span', { class: 'even__line' }, rich('Until then, {payWho} pays about {*pay} more in paychecks.', v)));
return lines;
}
/* Teaching pay from this school year to the last one taught, in today's dollars. One figure when raises keep pace with prices. */
function evenTeachPay(e) {
var from = usdRound(D.s.salary), to = usdRound(e.pension.payToday);
return from === to ? from + ' a year' : from + ' to ' + to + ' a year';
}
/* What starts at one age after work has stopped: a pension, Social Security, or both. The pension is named as
"the Leave pension" or "the Stay pension" when it starts there on one path while the other path's pension is
already running, so the label is not read as being about both columns. */
function evenStart(r, age) {
var cols = [r.stay, r.leave], pen = cols.map(function (e) { return e.hasPension && e.drawAge === age && age > r.age; });
var soc = cols.some(function (e) { return e.ss.monthly > 0 && e.claimAge === age && age > r.age; }), whose = '';
if (pen[1] && !pen[0] && r.stay.hasPension && r.stay.drawAge < age) whose = 'Leave ';
if (pen[0] && !pen[1] && r.leave.hasPension && r.leave.drawAge < age) whose = 'Stay ';
var anyPen = pen[0] || pen[1], pension = 'the ' + whose + 'pension';
return anyPen && soc ? pension + ' and Social Security start' : (anyPen ? pension + ' starts' : (soc ? 'Social Security starts' : ''));
}
/* The ages after the stop age at which a check starts on either path, in order. The last one is the shared age. */
function evenSteps(r) {
var steps = [];
[r.stay, r.leave].forEach(function (e) {
if (e.hasPension && e.drawAge > r.age) steps.push(e.drawAge);
if (e.ss.monthly > 0 && e.claimAge > r.age) steps.push(e.claimAge);
});
return steps.filter(function (a, k) { return steps.indexOf(a) === k; }).sort(function (a, b) { return a - b; });
}
/* The two boxes under the sentences: what each path gives at this stop age that the other does not.
Four things are looked at, always in this order, and each goes to the path it favours:
a. income that starts sooner: the first age the path pays anything at all, savings included
b. more each month in a stretch of the years before both paths are fully paying, one for each stretch
c. more each month from the age both paths are fully paying
d. more each month at 85
Pay while working is in the headline above, not in a box.
Monthly amounts are the whole dollars the table shows. Two amounts within 5% of the larger go in neither box.
A box takes the first three it is given. Every line can be checked against a row of the table below.
No figure is in bold: one line gives a whole amount and another a difference, and bold would weigh them unevenly. */
function evenGives(r, list) {
var S = r.stay, L = r.leave, out = { stay: [], leave: [] }, steps = evenSteps(r), i;
function give(side, tpl, v) { if (side !== 'same') out[side].push(rich(tpl, v)); }
function month(e, age) { return Math.round(e.at(age).total); }
function first(e) { for (var a = r.age; a <= EVEN_END; a++) if (e.at(a).total >= 0.5) return a; return null; }
var fromS = first(S), fromL = first(L);
if (fromS !== null && fromL !== null && fromS !== fromL) {
var n = Math.abs(fromS - fromL);
give(fromS < fromL ? 'stay' : 'leave', 'Income {n} sooner, from {age}', { n: n + (n === 1 ? ' year' : ' years'), age: Math.min(fromS, fromL) });
}
for (i = 0; i < steps.length; i++) {
var from = i ? steps[i - 1] : r.age, a = month(S, from), b = month(L, from);
give(evenSide(a, b), '{x} a month from {a} to {b}, against {y}', { x: usd(Math.max(a, b)), a: from, b: steps[i], y: usd(Math.min(a, b)) });
}
[[r.at, '{d} more a month from {age}'], [EVEN_END, '{d} more a month at {age}']].forEach(function (x) {
var a = month(S, x[0]), b = month(L, x[0]);
give(evenSide(a, b), x[1], { d: usd(Math.abs(a - b)), age: x[0] });
});
/* Pay while working is not a box line: the headline's second line says it, so it is not said twice. */
return { stay: out.stay.slice(0, 3), leave: out.leave.slice(0, 3) };
}
/* The rows of the table for one stop age. Every money row sets the two paths side by side at one age, and a total
always comes with its parts at that same age, in whole dollars that add up to it.
After the stop age come the years before every check has started: one row for each step, from the age it starts
until the next pension or Social Security check begins. Then the row at the first age both paths have every
check running, which says when each check began, the row at 85, and the row the sentence is about: each
path's total from the stop age through 85. */
function evenRows(r) {
var S = r.stay, L = r.leave, pct = pctText(D.s.targetPct, 2), steps = [], rows, i;
function money(x) { return { big: usd(x.total), parts: wholeParts(x), note: x.total < 0.5 ? 'No check has started yet.' : '' }; }
function target(e) { return { big: usd(e.target), note: pct + '% of ' + usdRound(e.basePay) + ' a year' }; }
/* At the shared age: the amount, its parts, when each check began, and why there is no pension when there is none. */
function all(e) {
var c = money(e.at(r.at)), since = [];
if (e.hasPension) since.push('Pension since ' + e.drawAge);
if (e.ss.monthly >= 0.5) since.push('Social Security since ' + e.claimAge);
if (since.length) c.since = since.join(', ') + '.';
if (!e.hasPension) c.note = noPensionLine(e);
return c;
}
steps = evenSteps(r);
rows = [
{ label: 'Your working years', stay: { text: S.pension.service + ' teaching' }, leave: { text: L.pension.service + ' teaching + ' + (r.age - L.sepAge) + ' new job' } },
{ label: 'Pay until then', stay: { text: evenTeachPay(S) }, leave: { text: (L.t >= 1 ? evenTeachPay(L) + ', then ' : '') + usdRound(L.nextPay) + ' a year' } }
];
for (i = 0; i < steps.length; i++) {
var from = i ? steps[i - 1] : r.age, until = evenStart(r, steps[i]) + ' at ' + steps[i];
var row = { label: 'Each month from ' + from + ' until ' + until, gap: true, stay: money(S.at(from)), leave: money(L.at(from)) };
var a = row.stay.parts, b = row.leave.parts;
/* Savings only, and the same on both paths: say so once, under the label, so the two equal amounts are not a puzzle. */
if (a.savings > 0 && a.savings === b.savings && !a.pension && !a.ss && !b.pension && !b.ss) row.both = 'The same on both paths. Only savings pay until ' + until + '.';
rows.push(row);
}
rows.push({ label: 'Each month at ' + r.at + ', when ' + (evenStart(r, r.at) || 'work stops'), shared: true, stay: all(S), leave: all(L) });
rows.push({ label: 'Each month at ' + EVEN_END, stay: money(S.at(EVEN_END)), leave: money(L.at(EVEN_END)) });
rows.push({ label: 'Total from ' + r.age + ' through ' + EVEN_END, key: true, stay: { big: usdRound(r.totals[0]) }, leave: { big: usdRound(r.totals[1]) } });
rows.push({ label: 'Target (' + pct + '% of pay)', stay: target(S), leave: target(L) });
return rows;
}
function evenParts(w) {
return [['pension', 'f-pension', 'Pension'], ['ss', 'f-ss', 'Social Security'], ['savings', 'f-savings', 'Savings']].filter(function (p) { return w[p[0]] > 0; });
}
function evenCell(c) {
var parts = c.parts ? evenParts(c.parts) : [];
return el('div', { class: 'even__cell', role: 'cell' }, [
c.text ? el('p', { class: 'even__text', text: c.text }) : null,
c.big ? el('p', { class: 'even__amt' }, el('b', { text: c.big })) : null,
parts.length ? el('ul', { class: 'even__parts' }, parts.map(function (p) { return el('li', null, [swatch(p[1]), p[2] + ' ' + usd(c.parts[p[0]])]); })) : null,
c.since ? el('p', { class: 'even__note even__since', text: c.since }) : null,
c.note ? el('p', { class: 'even__note', text: c.note }) : null
]);
}
/* The same cell as one line of words, for the table view. */
function evenCellText(c) {
var parts = c.parts ? evenParts(c.parts).map(function (p) { return (p[0] === 'ss' ? p[2] : p[2].toLowerCase()) + ' ' + usd(c.parts[p[0]]); }).join(', ') : '';
return (c.text || c.big) + (parts ? ': ' + parts : '') + (c.since ? '. ' + c.since : '') + (c.note ? (c.since ? ' ' : '. ') + c.note : '');
}
/* ---------- Play The Years ----------
The two paths of the comparison, laid along the years from the stop age in the box to 85. It reads the same
two results the table reads (r.stay and r.leave: the stop age in the box, the Social Security age picked, and
Stay with its account left in TRS), and every amount it shows is one of their at(age) figures. A band is drawn
over the ages where a source pays, so it starts where that check starts. The hatched band covers the ages
where something is left against that path's target.
The marker starts and rests at the stop age, where the years begin. Play The Years moves it from there to 85
in about six seconds, and a run ends at 85 with the button reading Replay. With motion off the marker rests at
the stop age too, and the button puts it straight at 85, where a run would end. Either way it can be dragged or
moved with the arrow keys. */
var YEARS_LANES = [['pension', 'f-pension', 'Pension'], ['ss', 'f-ss', 'Social Security'], ['savings', 'f-savings', 'Savings'], ['gap', 'f-left', 'Left To Plan For']];
var YEARS_MS = 6000;
var years = { r: null, stop: null, age: EVEN_END, played: false, fx: null };
function yearsThumb() { return parseFloat(window.getComputedStyle($('years')).getPropertyValue('--thumb')) || 30; }
/* Where an age stands across a plot W wide: the same sum the browser uses for a slider's marker, so the two agree. */
function yearsX(age, W, T) { return T / 2 + (age - years.r.age) / (EVEN_END - years.r.age) * (W - T); }
/* The stretches of ages, [from, to], at which one part of a path's income is at least half a dollar a month. */
function yearsRuns(e, key) {
var runs = [], open = null;
for (var a = years.r.age; a <= EVEN_END; a++) {
if (e.at(a)[key] >= 0.5) { if (open) open[1] = a; else runs.push(open = [a, a]); } else open = null;
}
return runs;
}
function drawYears() {
var r = years.r;
if (!r || $('s2-even').hidden) return;
var T = yearsThumb(), STRIP = 24, LANE = 30, BAND = 11;
[['stay', r.stay, 'Stay Teaching'], ['leave', r.leave, 'Leave Teaching']].forEach(function (t) {
var host = $('years-svg-' + t[0]), W = widthOf(host), e = t[1];
if (W < 120) return;
var X = function (age) { return round1(yearsX(age, W, T)); };
var lanes = YEARS_LANES.map(function (l) { return { key: l[0], cls: l[1], name: l[2], runs: yearsRuns(e, l[0]) }; }).filter(function (l) { return l.runs.length; });
var H = STRIP + lanes.length * LANE + 4, said = [];
var svg = sv('svg', { viewBox: '0 0 ' + W + ' ' + H, role: 'img' });
/* The names go in the layer over the marker. The track's own label already says them to a screen reader. */
var names = sv('svg', { class: 'ytrack__names', viewBox: '0 0 ' + W + ' ' + H, 'aria-hidden': 'true', focusable: 'false' });
svg.appendChild(sv('rect', { class: 'yruler', x: 0.5, y: 0.5, width: W - 1, height: STRIP - 1, rx: 3 }));
for (var a = r.age; a <= EVEN_END; a++) {
var five = a % 5 === 0;
svg.appendChild(sv('line', { class: 'ytick' + (five ? ' ytick--five' : ''), x1: X(a), x2: X(a), y1: 1, y2: five ? 10 : 6 }));
if (five) svg.appendChild(sv('text', { class: 'ynum', x: X(a), y: STRIP - 4, 'text-anchor': 'middle', text: String(a) }));
}
lanes.forEach(function (lane, i) {
var top = STRIP + i * LANE + 4, first = lane.runs[0][0];
/* The name stands above the start of its band. Near the right end it is set flush with the place the marker rests. */
var nameW = lane.name.length * 6.9, nx = X(first), end = nx + nameW > W - T;
var row = 'yrow-' + t[0] + '-' + i;
names.appendChild(sv('clipPath', { id: row }, sv('rect', { x: 0, y: top - 4, width: W, height: 19 })));
names.appendChild(sv('text', { class: 'yname', x: end ? W - T - 2 : nx, y: top + 11, 'text-anchor': end ? 'end' : 'start', 'clip-path': 'url(#' + row + ')', text: lane.name }));
lane.runs.forEach(function (run) {
/* A check that is still paying at 85 runs to the edge. One that ends sooner stops where the next age starts. */
var x1 = X(run[0]), x2 = run[1] >= EVEN_END ? W : X(run[1] + 1), band = lane.key === 'gap'
? sv('rect', { class: lane.cls, x: x1 + 0.5, y: top + 15.5, width: Math.max(2, x2 - x1 - 1), height: BAND - 1 })
: sv('rect', { class: lane.cls, x: x1, y: top + 15, width: Math.max(2, x2 - x1), height: BAND });
band.appendChild(sv('title', { text: lane.name + (run[1] >= EVEN_END ? ' from ' + run[0] : ' from ' + run[0] + ' to ' + run[1]) }));
svg.appendChild(band);
});
said.push(lane.name + ' ' + lane.runs.map(function (run) { return run[1] >= EVEN_END ? 'from ' + run[0] : 'from ' + run[0] + ' to ' + run[1]; }).join(' and '));
});
svg.setAttribute('aria-label', t[2] + ', ages ' + r.age + ' to ' + EVEN_END + ': ' + (said.length ? said.join(', ') : 'no income') + '.');
fill(host, [svg, names]);
});
yearsPlace();
}
/* Put the two halves of the marker on the age now showing. */
function yearsPlace() {
var plot = $('years-svg-stay'), W = Math.floor(plot.clientWidth || 0), marks = document.querySelectorAll('.years__mark');
if (!years.r) return;
/* On paper the tracks are drawn to another width, so there the marker is placed by its share of that width. */
var T = yearsThumb(), share = (yearsX(years.age, PRINT_W, T) / PRINT_W).toFixed(5);
Array.prototype.forEach.call(marks, function (m) { m.style.setProperty('--at', share); });
if (W < 120) return;
var x = round1(yearsX(years.age, W, T) - T / 2);
Array.prototype.forEach.call(marks, function (m) { m.style.transform = 'translateX(' + x + 'px)'; });
}
/* The age on the marker's tab and each path's total at that age. settled is false only while Play The Years is
running: then what a screen reader is given stays as it was, and it gets the age the marker ends on. */
function yearsShow(age, settled) {
var r = years.r, input = $('years-age'), a = usd(r.stay.at(age).total), b = usd(r.leave.at(age).total);
years.age = age;
$('years-tab').textContent = String(age);
$('years-sum-stay').textContent = a;
$('years-sum-leave').textContent = b;
if (settled === false) return;
$('years-say-stay').textContent = a;
$('years-say-leave').textContent = b;
if (Number(input.value) !== age) input.value = String(age);
input.setAttribute('aria-valuetext', 'Age ' + age + '. Stay Teaching ' + a + ' a month. Leave Teaching ' + b + ' a month.');
yearsPlace();
}
/* Stop a run of Play The Years where it stands. done is true when it reached 85 or was ended early by Pause Motion,
and then the marker goes to 85. Once a run has been started the button reads Replay, however the run ended, so
the same presses leave the same page with motion on and off. */
function yearsStop(done) {
var fx = years.fx;
if (!fx) return;
years.fx = null;
dropEffect(fx);
window.cancelAnimationFrame(fx.frame);
fx.anims.forEach(function (a) { try { a.cancel(); } catch (e) { /* already over */ } });
years.played = true;
yearsShow(done ? EVEN_END : years.age);
$('years-play').textContent = years.played ? 'Replay' : 'Play The Years';
}
function yearsPlay() {
var r = years.r, marks = document.querySelectorAll('.years__mark'), W = Math.floor($('years-svg-stay').clientWidth || 0);
if (!r) return;
yearsStop(false);
if (!motionOn || !marks[0].animate || W < 120) { // no motion: straight to where it would end
years.played = true;
yearsShow(EVEN_END);
$('years-play').textContent = 'Replay';
return;
}
var T = yearsThumb(), x0 = round1(yearsX(r.age, W, T) - T / 2), x1 = round1(yearsX(EVEN_END, W, T) - T / 2), span = EVEN_END - r.age;
/* Underneath, the marker is already at 85 and a screen reader has the figures for 85. The run plays over that. */
yearsShow(EVEN_END);
var fx = { anims: [], frame: 0, finish: function () { yearsStop(true); } };
Array.prototype.forEach.call(marks, function (m) {
/* It fills backwards, so until the browser starts its clock the marker stands at the stop age, not where it will end. */
fx.anims.push(m.animate([{ transform: 'translateX(' + x0 + 'px)' }, { transform: 'translateX(' + x1 + 'px)' }], { duration: YEARS_MS, easing: 'linear', fill: 'backwards' }));
});
/* The run is over when its animation has finished or been stopped, not when it has no progress to give: until the
browser starts its clock (a frame or two after the press, and a moment ahead of the frame's own time) there is
none, and the marker waits at the stop age. */
var step = function () {
if (years.fx !== fx) return;
var a = fx.anims[0], t = a.effect ? a.effect.getComputedTiming().progress : null;
if (!a.effect || a.playState === 'finished' || a.playState === 'idle') { yearsStop(true); return; }
if (t !== null && t !== undefined) {
var age = Math.min(EVEN_END, r.age + Math.floor(t * span + 1e-6));
if (age !== years.age) yearsShow(age, false);
}
fx.frame = window.requestAnimationFrame(step);
};
years.fx = fx;
effects.push(fx);
yearsShow(r.age, false);
fx.frame = window.requestAnimationFrame(step);
}
/* Called each time the comparison is drawn. A new stop age starts the block over, with the marker at that age. */
function renderYears(r) {
if (!r) { yearsStop(false); years.r = null; years.stop = null; return; }
var fresh = years.stop !== r.age, input = $('years-age');
if (fresh) yearsStop(false);
years.r = r;
if (fresh) { years.stop = r.age; years.age = r.age; years.played = false; $('years-play').textContent = 'Play The Years'; }
input.min = String(r.age);
input.max = String(EVEN_END);
drawYears();
yearsShow(years.age, years.fx ? false : undefined);
}
function wireYears() {
var input = $('years-age');
$('years-play').addEventListener('click', yearsPlay);
/* A hand on the marker ends a run where it stands, so the keys and the pointer start from the age then showing. */
var take = function () { if (years.fx) yearsStop(false); };
input.addEventListener('pointerdown', take);
input.addEventListener('keydown', take);
input.addEventListener('input', function () { take(); if (years.r && input.value !== '') yearsShow(clamp(Math.round(Number(input.value)), years.r.age, EVEN_END)); });
/* Paper shows the marker where it stands. A run in flight is ended first, at 85. */
window.addEventListener('beforeprint', function () { if (years.r) yearsStop(true); });
}
/* spoken is true when the reader has just moved the box: a screen reader then hears the two amounts. */
function renderEven(spoken) {
var need = evenNeeds(), line = $('s2-even-need');
show($('s2-even'), !need);
show(line, !!need);
if (line.textContent !== need) line.textContent = need;
if (need) { evenShown = null; renderYears(null); motionAfterEven(); return; }
var list = evenList(), study = evenStudy(list, D.s.retireAge), min = study.min, max = study.max;
/* A typed age is kept while it is in range. One equal to the page's own starting age goes back to following it. */
if (claimAt !== null && claimAt === D.s.claimAge) claimAt = null;
if (stopAt !== null && (stopAt < min || stopAt > max || stopAt === study.age)) stopAt = null;
var age = stopAt === null ? study.age : stopAt, r = list[age - min], S = r.stay, L = r.leave, rows = evenRows(r);
var input = $('f-stopAt'), back = $('even-back'), claim = evenClaim(), mine = D.s.claimAge;
evenShown = age;
/* The choices are 62, 67 and 70, and the age in Your Numbers when it is none of those, so the picker can start on it. */
var seg = $('claim-seg'), ages = EVEN_CLAIMS.concat(EVEN_CLAIMS.indexOf(mine) < 0 ? [mine] : []).sort(function (x, y) { return x - y; });
if (seg.getAttribute('data-ages') !== ages.join(' ')) {
seg.setAttribute('data-ages', ages.join(' '));
fill(seg, ages.map(function (a) { return el('label', null, [el('input', { type: 'radio', name: 'claim-even', value: String(a) }), el('span', { text: String(a) })]); }));
}
Array.prototype.forEach.call(seg.querySelectorAll('input'), function (radio) { radio.checked = Number(radio.value) === claim; });
$('h-claimAt').textContent = '67 pays the full amount. 62 pays less and 70 pays more.' + (claim === mine ? '' : ' Your Numbers has ' + mine + '.');
input.min = String(min);
input.max = String(max);
if (document.activeElement !== input) input.value = String(age);
$('stop-down').disabled = age <= min;
$('stop-up').disabled = age >= max;
/* The line beside the box says where the page opens the box and why. Once the box is somewhere else, by a typed
age or because the picker changed where the lead switches, it names that age as the break-even the link goes to. */
$('h-stopAt').textContent = min === max ? 'Only ' + min + ' can be compared.'
: (study.switched && stopAt !== null ? 'Break-even is ' : 'Opens on ') + study.age + ', ' + study.why + '. Any age from ' + min + ' to ' + max + '.';
back.textContent = study.switched ? 'Back to break-even' : 'Back to ' + study.age;
show(back, stopAt !== null);
fill($('even-say'), evenSay(r, list));
$('even-where').textContent = study.text;
/* Said once, wherever the comparison calls the two paths about the same: the headline, the range line or the line beside the box. */
show($('even-same'), /about the same/.test($('even-say').textContent + ' ' + study.text + ' ' + $('h-stopAt').textContent));
var gives = evenGives(r, list);
[['stay', 'give-stay'], ['leave', 'give-leave']].forEach(function (g) {
fill($(g[1]), gives[g[0]].length ? el('ul', null, gives[g[0]].map(function (line) { return el('li', null, line); }))
: el('p', { class: 'even__none', text: 'After work stops, no monthly amount is higher on this path.' }));
});
var cols = [
{ name: 'Stay Teaching', how: 'Teach until ' + age },
{ name: 'Leave For New Work', how: (L.sepAge === D.age0 ? 'Leave now' : 'Teach until ' + L.sepAge) + ', then new work until ' + age }
];
fill($('even-grid'), [el('div', { class: 'even__row even__row--head', role: 'row' }, [
el('div', { class: 'even__corner', role: 'columnheader' }, el('span', { class: 'sr', text: 'What Is Compared' }))
].concat(cols.map(function (c) { return el('div', { class: 'even__col', role: 'columnheader' }, [el('b', { text: c.name }), el('span', { text: c.how })]); })))].concat(rows.map(function (row) {
return el('div', { class: 'even__row' + (row.key ? ' is-key' : '') + (row.gap ? ' is-gap' : '') + (row.shared ? ' is-shared' : ''), role: 'row' }, [
el('div', { class: 'even__label', role: 'rowheader' }, [row.label, row.both ? el('span', { class: 'even__both', text: row.both }) : null]), evenCell(row.stay), evenCell(row.leave)]);
})));
/* The caption follows the picker. When the age here is not the one in Your Numbers, it says which the plans below use. */
var cap = 'Today’s dollars. ' + (S.ss.monthly >= 0.5 || L.ss.monthly >= 0.5
? 'Social Security starts at ' + claim + (claim === mine ? ', the age in Your Numbers.' : ' here.')
: 'No Social Security is owed on either path at this stop age.') +
' The plans below use the ages you set in Your Numbers and Step 2' + (claim === mine ? '.' : ', with Social Security at ' + mine + '.');
$('even-cap').textContent = cap;
/* Why a pension reads lower in the row at 85 than in the row it starts in: the page's own two figures. */
var raise = RULES.cola * 100, infl = num(D.s.inflPct), why = '';
if (S.hasPension || L.hasPension) {
why = 'The pension reads ' + (infl > raise ? 'lower at later ages' : (infl < raise ? 'higher at later ages' : 'the same at every age')) + ' because it rises ' + pctText(raise) + '% a year ' +
(infl === raise ? 'and prices rise ' : 'while prices rise ') + pctText(infl, 2) + '% a year, the Yearly Inflation in Your Numbers.';
}
$('even-why').textContent = why;
show($('even-why'), !!why);
fill($('even-table'), el('table', { class: 'table table--words' }, [
el('caption', { text: 'Work stops at ' + age + ' in both columns. ' + cap + (why ? ' ' + why : '') }),
el('thead', null, el('tr', null, [el('th', { scope: 'col', text: 'What Is Compared' })].concat(cols.map(function (c) { return el('th', { scope: 'col', text: c.name }); })))),
el('tbody', null, [el('tr', null, [el('th', { scope: 'row', text: 'The path' })].concat(cols.map(function (c) { return el('td', { text: c.how }); })))].concat(rows.map(function (row) {
return el('tr', { class: row.key ? 'is-total' : null }, [el('th', { scope: 'row', text: row.label + (row.both ? '. ' + row.both : '') }), el('td', { text: evenCellText(row.stay) }), el('td', { text: evenCellText(row.leave) })]);
})))
]));
if (spoken) {
$('even-live').textContent = 'Social Security starts at ' + claim + '. ' + $('even-say').textContent;
}
renderYears(r);
motionAfterEven();
}
/* The Stop Working At box, its one-year buttons, the link back and the Social Security picker. None of them goes
through setData: both ages are what-ifs, so they do not mark the plan as changed, end the example or reach the
saved file. */
function wireEven() {
var input = $('f-stopAt'), err = $('e-stopAt');
function take(n) {
if (evenShown === null || Math.round(n) !== n || n < Number(input.min) || n > Number(input.max)) return false;
stopAt = n;
err.textContent = '';
renderEven(true);
return true;
}
/* A whole age in range moves the table as it is typed. Anything else waits: "4" may be on its way to "49". */
input.addEventListener('input', function () { err.textContent = ''; if (input.value !== '') take(Number(input.value)); });
input.addEventListener('change', function () {
if (evenShown === null) return;
if (input.value !== '' && !take(Number(input.value))) err.textContent = 'Enter a whole number from ' + input.min + ' to ' + input.max + '.';
input.value = String(evenShown);
});
function nudge(by) { if (evenShown !== null) { take(evenShown + by); input.value = String(evenShown); } }
$('stop-down').addEventListener('click', function () { nudge(-1); });
$('stop-up').addEventListener('click', function () { nudge(1); });
/* The link hides itself once the box is back, so the keyboard's place moves to the box. */
$('even-back').addEventListener('click', function () { stopAt = null; err.textContent = ''; renderEven(true); input.value = String(evenShown); input.focus(); });
/* The age Social Security starts, in this table only. It works everything out again for the stop age already in
the box, which stays where it is: only the link back picks a new age. Picking the age in Your Numbers goes
back to following it. */
$('claim-seg').addEventListener('change', function (e) {
var n = Number(e.target && e.target.value);
if (evenShown === null || !(n >= 62 && n <= 70)) return;
stopAt = evenShown;
claimAt = n === D.s.claimAge ? null : n;
renderEven(true);
input.value = String(evenShown);
});
}
function renderStep2() {
var ready = D && D.ready;
renderEven(false);
show($('s2-empty'), !ready);
show($('s2-main'), ready);
if (!ready) {
fill($('s2-lead'), [P('result', 'This step needs four numbers from Step 1.'), P('result-note', 'This step compares staying with leaving teaching, once the page knows {list}.', { list: joinAnd(D ? D.missing : ['your numbers']) })]);
fill($('s2-empty'), emptyBox('Stay Teaching and Leave Teaching appear here side by side once Step 1 is filled in.', true));
fill($('s2-aside'), []);
fill($('s2-rules'), []);
show($('s2-account'), false);
$('s2-plana-note').textContent = 'If you would work somewhere else after you retire from teaching, add it here. Count only work that pays Social Security tax.';
if ($('h-leaveIn')) $('h-leaveIn').textContent = FIELD.leaveIn.hint + ' Leave it blank if you plan to stay. Add a number of years to see what happens if you leave.';
return;
}
var A = D.A, B = D.B, lead = step2Lead();
['A', 'B'].forEach(function (w) { var hu = headsUp(w); if (hu) lead.push(el('div', { style: 'margin-top:16px' }, hu)); });
fill($('s2-lead'), lead);
var Bdone = D.bOpen ? null : B, scaleMax = covScale([A, Bdone]);
keepFocus($('s2-plans'), function () {
fill($('s2-plans'), [
planCard('A', A, scaleMax),
D.hasB ? planCard('B', B, scaleMax) : el('section', { class: 'card plan', 'aria-labelledby': 'plan-B-title' }, [
el('div', { class: 'plan__head' }, [el('p', { class: 'plan__name', text: 'Leave Teaching' }), el('h4', { id: 'plan-B-title', style: 'font-size:20px', text: 'Not Set Yet' })]),
el('p', { text: 'If you might leave teaching or change careers, add how many years from now in Your Numbers. This card then fills in beside Stay Teaching.' })
])
]);
});
fill($('c3-table'), covTable([A, Bdone], ['Stay Teaching', 'Leave Teaching']));
renderAccount();
var ssKids = [
el('h3', { id: 's2-ss-title', text: 'Social Security From Other Work' }),
P(null, 'Teaching pay earns no Social Security, by design. Other work does: jobs before teaching, a side job, or work after you leave. You need {need} credits to qualify. Each {per} of covered pay earns one credit, up to 4 a year. Covered pay is pay with Social Security tax taken out.',
{ need: RULES.ss.need, per: usd(RULES.ss.credit) }),
ssBlock(D.hasB ? 'Stay Teaching' : 'Your Plan', A)
];
if (D.hasB) ssKids.push(ssBlock('Leave Teaching', B, D.bOpen));
ssKids.push(el('p', { class: 'small', style: 'margin-top:16px',
text: 'Your teacher pension does not reduce these benefits. The Social Security Fairness Act ended those reductions for benefits after December 2023.' }));
$('s2-plana-note').textContent = 'If you stay, you teach until ' + A.sepAge + '. Change that age in Step 1. If you would then work somewhere else, add it here. Count only work that pays Social Security tax.';
var hint = $('h-leaveIn');
if (hint) hint.textContent = FIELD.leaveIn.hint + ' ' + (D.hasB ? 'Your number puts you at age ' + B.sepAge + ', with ' + yrs(B.pension.service) + ' of service credit.'
: 'Leave it blank if you plan to stay. Add a number of years to see what happens if you leave.');
var list = [
'Vesting takes 5 years. Vested means you have earned the right to a pension, even if you leave.',
'A pension left in TRS uses your salary and service on the day you leave. It gets no inflation increase while it waits.'
];
if (D.tier >= 3) list.push('TRS retiree health coverage needs ' + RULES.healthYears + ' years of service.');
list.push('Under 5 years, membership ends after more than 3 straight years away. If you come back without having taken a refund, those years are restored.');
list.push('A refund is your own contributions plus interest. It ends your membership.');
fill($('s2-aside'), [el('section', { class: 'card', id: 's2-ss', 'aria-labelledby': 's2-ss-title' }, ssKids)]);
fill($('s2-rules'), [
card('s2-rules-title', 'What Leaving Changes', [el('ul', { class: 'miles' }, list.map(function (t) { return el('li', { style: 'grid-template-columns:minmax(0,1fr)' }, el('p', { class: 'miles__what', style: 'grid-column:1', text: t })); })),
el('p', { class: 'small', style: 'margin-top:12px' }, [el('button', { type: 'button', class: 'linkbtn', 'data-open-rules': '1', text: 'See Rules And Sources' })])])
]);
}
/* ---------- Step 3: Cover The Rest ---------- */
function step3Lead(e) {
var snaps = e.snaps, want = usd(e.target), out = [], prev = null;
var allZero = snaps.every(function (x) { return x.gap < 0.5; });
var sameSrc = snaps.every(function (x) { return sourcesAt(x).join() === sourcesAt(snaps[0]).join(); });
if (allZero && sameSrc && sourcesAt(snaps[0]).length) {
var src0 = sourcesAt(snaps[0]);
return [P('result', '{when}, your {src} {cover} all of the {*want} a month target.',
{ when: snaps.length > 1 ? 'At ' + joinAnd(snaps.map(function (x) { return String(x.age); })).replace(/ and /, ' and at ') : 'At ' + snaps[0].age, src: joinAnd(src0), cover: coverVerb(src0), want: want })];
}
var parts = [], vals = {};
snaps.forEach(function (x, i) {
var src = sourcesAt(x), kind = snapKind(e, x), k = 'n' + i;
var when = kind === 'stop' ? 'When work stops at ' + x.age : (kind === 'all' ? 'At ' + x.age + ', when every check is running' : 'At ' + x.age);
vals[k + 'cov'] = usd(Math.min(x.total, e.target)); vals[k + 'left'] = usd(x.gap); vals[k + 'src'] = joinAnd(src); vals[k + 'cover'] = coverVerb(src);
var they = prev !== null && src.length > 1 && src.join() === prev;
var comma = kind === 'all' ? ',' : (i === 0 ? ',' : '');
if (i === 0) {
if (!src.length) parts.push(when + ', no pension, Social Security or savings income has started. The full {*want} a month target is left to plan for.');
else if (x.gap < 0.5) parts.push(when + ', your {' + k + 'src} {' + k + 'cover} all of the {*want} a month target.');
else parts.push(when + ', your {' + k + 'src} {' + k + 'cover} {*' + k + 'cov} of the {want} a month target. {*' + k + 'left} is left to plan for.');
} else if (!src.length) {
parts.push(when + comma + ' nothing has started yet, and the full {*want} is left to plan for.');
} else if (x.gap < 0.5) {
parts.push(when + comma + (they ? ' they cover all of it.' : ' your {' + k + 'src} {' + k + 'cover} all of it.'));
} else {
parts.push(when + comma + (they ? ' they cover {*' + k + 'cov} of it, and {*' + k + 'left} is left to plan for.' : ' your {' + k + 'src} {' + k + 'cover} {*' + k + 'cov} of it, and {*' + k + 'left} is left to plan for.'));
}
prev = src.join();
});
vals.want = want;
out.push(P('result', parts.join(' '), vals));
var first = snaps[0], last = snaps[snaps.length - 1];
if (e.hasPension && last.gap > first.gap + 1 && last.pension < e.pensionMonthly - 1) {
out.push(P('result-note', 'The amount left grows with age because the pension rises {cola}% a year while prices here rise {infl}%.', { cola: pctText(RULES.cola * 100), infl: pctText(D.s.inflPct, 2) }));
}
return out;
}
/* Smallest later age at which teaching (Stay Teaching) or leaving (Leave Teaching) covers it. */
function teachLonger() {
var s = D.s, which = D.which, e = D.sel, start = e.sepAge, best = null;
for (var a = start + 1; a <= TEACH_CAP; a++) {
var e2 = which === 'A' ? TG.evalPlan(planInput(withData(s, { retireAge: a }), 'A'), 'A') : TG.evalPlan(withData(s, { leaveIn: a - D.age0 }), 'B');
var g = maxGap(e2);
if (best === null || g < best.gap - 0.005) best = { age: a, gap: g, e: e2 };
if (g < 0.5) return { found: true, age: a, e: e2 };
}
return best ? { found: false, age: best.age, gap: best.gap, e: best.e, wsnap: worstSnap(best.e) } : null;
}
/* Smallest "work until" age at which other work covers it. */
function workLonger(pay) {
var s = D.s, which = D.which, e = D.sel, payKey = which === 'A' ? 'nextPayA' : 'nextPayB', untilKey = which === 'A' ? 'workUntilA' : 'workUntilB';
var from = Math.max(e.sepAge, e.hasNext ? e.stopAge : e.sepAge) + 1, best = null;
for (var u = from; u <= TEACH_CAP; u++) {
var ch = {}; ch[payKey] = pay; ch[untilKey] = u;
var e2 = TG.evalPlan(planInput(withData(s, ch), which), which), g = maxGap(e2);
if (best === null || g < best.gap - 0.005) best = { until: u, gap: g, e: e2 };
if (g < 0.5) return { found: true, until: u, e: e2 };
}
return best ? { found: false, until: best.until, gap: best.gap, e: best.e } : null;
}
function renderWays(e, w) {
var s = D.s, which = D.which, gap = w.gap, need = gap >= 0.5;
$('s3-ways-sub').textContent = need
? 'Each one is set against the ' + usd(gap) + ' a month at ' + w.age + ' by itself. You can also mix them.'
: 'Your plan already covers the income target at every age checked. These show what each choice would add.';
/* Way 1: save more */
var save = [];
if (!need) {
save.push(el('p', { class: 'way__big', text: 'Nothing more needed' }));
save.push(P(null, 'This plan covers the income target at every age the page checks.'));
} else {
var rows = TG.closeGap(planInput(s, which), which, w.age), mid = null;
rows.forEach(function (r) { if (r.chosen) mid = r; });
/* The most a teacher can put in a 403(b) and a 457(b) together in a year, at their age now. */
var L = RULES.limits, catchUp = (D.age0 >= 60 && D.age0 <= 63) ? L.catch6063 : (D.age0 >= 50 ? L.catch50 : 0);
var yearLimit = 2 * L.deferral + 2 * catchUp;
var yearSaved = mid && mid.extra !== null ? (num(s.monthly) + mid.extra) * 12 : 0;
var pastLimit = yearSaved > yearLimit ? P(null, (num(s.monthly) > 0 ? 'With what you save now, that' : 'That') +
' comes to {*yr} a year, more than the {limit} the yearly limits allow at {age}, so teaching longer or working after teaching can cover part of it.',
{ yr: usdRound(yearSaved), limit: usd(yearLimit), age: D.age0 }) : null;
if (!mid || mid.extra === null) {
save.push(el('p', { class: 'way__big', text: 'No working years to save in' }));
save.push(P(null, 'In this plan work stops now, so there are no months left to add savings. The other two ways still apply.'));
} else if (mid.extra > s.salary / 12) {
/* More than a month's pay: say so plainly, and leave out the lines that would only repeat it. */
save.push(el('p', { class: 'way__big' }, [usd(mid.extra) + ' more a month', el('small', { text: 'That is more than your pay of ' + usd(s.salary / 12) + ' a month, so saving does not cover it by itself before work stops at ' + e.stopAge + '.' })]));
save.push(pastLimit || P(null, 'The other two ways bring this number down, and a mix can cover it.'));
save.push(P('small muted', 'In today’s dollars. The page does not recommend any investment.'));
} else {
/* An empty box and a typed 0 both mean no growth, but only the 0 is something the teacher chose. */
var payMonth = s.salary / 12, noReturn = D.d.returnPct === null, zeroReturn = D.d.returnPct === 0;
var spread = rows.length === 3 && rows[0].returnPct === mid.returnPct - 2 && rows[2].returnPct === mid.returnPct + 2;
/* The share is of the pay in the plan shown: the new job's pay for Leave Teaching when it has one, teaching pay otherwise. */
var newPay = which === 'B' && num(s.nextPayB) > 0, sharePay = newPay ? s.nextPayB : s.salary;
save.push(el('p', { class: 'way__big' }, [usd(mid.extra) + ' more a month', el('small', { text: 'About ' + pctText(mid.extra * 12 / sharePay * 100, 0) + '% of your ' + (newPay ? 'new job’s ' : '') + 'pay, from now until work stops at ' + e.stopAge + '.' })]));
if (mid.extraWait5 === null) save.push(P(null, 'No more than 5 working years are left in this plan, so there is no room to wait.'));
else if (mid.extraWait5 > payMonth) save.push(P(null, 'Starting 5 years from now, it becomes {*amt} a month, which is more than your pay of {pay} a month.', { amt: usd(mid.extraWait5), pay: usd(payMonth) }));
else save.push(P(null, 'Starting 5 years from now, it becomes {*amt} a month.', { amt: usd(mid.extraWait5) }));
if (pastLimit) save.splice(1, 0, pastLimit);
save.push(el('table', { class: 'table' }, [
el('caption', { text: spread ? 'The same goal at two points lower and higher.' : 'The same goal at other yearly returns.' }),
el('thead', null, el('tr', null, [el('th', { scope: 'col', text: 'Yearly Return' }), el('th', { scope: 'col', text: 'Extra A Month' })])),
el('tbody', null, rows.map(function (r) {
return el('tr', { class: r.chosen ? 'is-on' : null }, [
/* In a narrow card the note goes under the rate whole, and is not cut in two. */
el('th', { scope: 'row' }, [pctText(r.returnPct, 2) + '%', r.chosen ? ' ' : null,
r.chosen ? el('span', { class: 'nowrap', text: noReturn ? '(none entered)' : (zeroReturn ? '(your choice)' : '(used here)') }) : null]),
el('td', { text: r.extra === null ? 'None' : usd(r.extra) })
]);
}))
]));
save.push(P('small muted', 'In today’s dollars, so raise it with inflation each year. The page does not recommend any investment.'));
}
}
fill($('way-save-body'), save);
/* Way 2: teach longer */
var teach = [], t = need ? teachLonger() : null;
if (!need) {
teach.push(el('p', { class: 'way__big', text: 'Nothing more needed' }));
var pNext = e.sepAge + 1 <= MAX_AGE ? TG.pensionAt(s, e.sepAge + 1) : null;
if (pNext && pNext.vested && pNext.drawAge !== null && e.pension.drawAge !== null && pNext.monthly - e.pension.monthly >= 1) {
teach.push(P(null, 'One more year of teaching would still raise the pension by about {*amt} a month.', { amt: usd(pNext.monthly - e.pension.monthly) }));
} else teach.push(P(null, 'This plan covers the income target at every age the page checks.'));
} else if (!t) {
teach.push(P(null, 'This plan already runs to age ' + TEACH_CAP + ', as far as the page looks.'));
} else if (t.found) {
var extraYears = t.age - e.sepAge;
/* With Leave picked this way means staying past the leaving date, which is another plan and not a fix to this one.
It says so, and that the other two ways keep the date. */
var other = which === 'B' ? ' That is a different plan. The other two ways keep your leaving date.' : '';
teach.push(el('p', { class: 'way__big' }, [(which === 'A' ? 'Teach until ' + t.age : 'If you stayed until ' + t.age + ' instead'), el('small', { text: more(extraYears, 'year') + ' than this plan, for ' + yrs(t.e.pension.service) + ' of service credit.' })]));
teach.push(t.e.hasPension
? P(null, 'Your pension would be about {*amt} a month from age {draw}, and that covers it.' + other, { amt: usd(t.e.pensionMonthly), draw: t.e.drawAge })
: P(null, 'That covers it.' + other));
} else {
teach.push(el('p', { class: 'way__big' }, [(which === 'A' ? 'Teaching until ' : 'Leaving at ') + t.age + ' narrows it', el('small', { text: 'To ' + usd(t.gap) + ' a month at ' + t.wsnap.age + '. It does not cover all of it.' })]));
teach.push(P(null, 'The page looks no further than age ' + TEACH_CAP + '. Pairing this with one of the other ways covers the rest.'));
}
/* A later last day can change the pay that the target is figured from. Say so when it does. */
if (t && Math.abs(t.e.target - e.target) >= 1) {
teach.push(P('small', 'The target would then be {want} a month: {pct}% of {pay} a year.', { want: usd(t.e.target), pct: pctText(s.targetPct, 2), pay: usdRound(t.e.basePay) }));
}
fill($('way-teach-body'), teach);
/* Way 3: work after teaching */
var work = [];
show($('way-work-a'), which === 'A');
show($('way-work-b'), which === 'B');
if (e.hasNext) {
work.push(P(null, 'This plan already has ' + (which === 'A' ? 'work after teaching' : 'new work') + ': {*pay} a year until age {until}.', { pay: usdRound(e.nextPay), until: e.stopAge }));
if (!need) work.push(el('p', { class: 'way__big', text: 'Nothing more needed' }));
else {
var wl = workLonger(e.nextPay);
if (wl && wl.found) work.push(el('p', { class: 'way__big' }, ['Work until ' + wl.until, el('small', { text: more(wl.until - e.stopAge, 'year') + ' at the same pay covers it.' })]));
/* No later age brings the amount down by a whole dollar: more years at this pay add nothing here, so it does not say "narrows". */
else if (wl && Math.round(wl.gap) >= Math.round(gap)) work.push(P(null, 'Working longer at the same pay does not change it.'));
else if (wl) work.push(el('p', { class: 'way__big' }, ['Working until ' + wl.until + ' narrows it', el('small', { text: 'To ' + usd(wl.gap) + ' a month. It does not cover all of it.' })]));
else work.push(P(null, 'This plan already works to age ' + TEACH_CAP + ', as far as the page looks.'));
}
} else {
/* No pay after teaching yet: no made-up example, only the two boxes and one line asking for them. */
var payIn = num(which === 'A' ? s.nextPayA : s.nextPayB) > 0;
work.push(P(null, payIn
? 'Work after teaching counts once Until Age is later than {age}, the age this plan stops teaching.'
: (need ? 'Add what you expect to earn after teaching, and the age you would work until, to see what it covers.'
: 'Add what you expect to earn after teaching, and the age you would work until, to see what it changes.'), { age: e.sepAge }));
}
fill($('way-work-body'), work);
}
function renderTodo(e, w) {
var items = [], which = D.which, B = D.B, need = w.gap >= 0.5;
items.push(['Compare these numbers with your TRS annual statement, then ask TRS for a benefit estimate: ', phone(), '.']);
if (need) items.push('Choose how to cover the ' + usd(w.gap) + ' a month at ' + w.age + ': save more, teach longer, work after teaching, or a mix.');
else items.push('This plan covers the income target at every age checked. Look again when your pay, your plans or prices change.');
if (which === 'B' && (headsUp('B') || !B.pension.vested)) items.push('Before you set a last day, ask TRS what one more year of service credit would change.');
else if (which === 'A' && headsUp('A')) items.push('Before you set a retirement date, ask TRS what one more year of service credit would change.');
if (which === 'A' && D.hasB && (headsUp('B') || !B.pension.vested)) items.push('If you leave instead, ask TRS what one more year of service credit would change before you set a last day.');
if (which === 'B' && (B.mode === 'rollover' || B.mode === 'cash')) items.push('Before any refund, ask TRS for the exact amount and how a direct rollover works. A refund ends your membership.');
if (which === 'B' && B.mode !== 'retire') items.push('Ask TRS which account type applies if you return to teaching later.');
var eSS = e.ss;
if (eSS.insured) items.push('Check the ' + usd(eSS.monthly) + ' a month of Social Security shown here against your own Social Security statement.');
else if (eSS.credits > 0 || num(D.s.spousePIA) > 0) items.push('Check your Social Security credits on your own Social Security statement. The page counts ' + eSS.credits + ' of ' + RULES.ss.need + '.');
if (need) items.push('Ask your district office which 403(b) and 457(b) plans it offers. Kentucky Deferred Comp is the state program.');
items.push('Save this plan to a file, and open it again when something changes.');
fill($('s3-todo'), items.map(function (t) { return el('li', null, [el('span', { class: 'todo__box', 'aria-hidden': 'true' }), el('span', null, t)]); }));
$('s3-todo-printhead').textContent = (which === 'A' ? 'Stay Teaching' : 'Leave Teaching') + (state.isExample ? ' (example)' : '') + ': pension ' + usd(e.primary.pension) + ', Social Security ' + usd(e.primary.ss) + ', savings ' + usd(e.primary.savings) +
', target ' + usd(e.target) + ', left to plan for ' + (need ? usd(w.gap) + ' at ' + w.age : '$0') + '. A month, in today’s dollars.';
}
function renderStep3() {
var ready = D && D.ready;
show($('s3-empty'), !ready);
show($('s3-main'), ready);
$('s3-plan-note').textContent = !ready ? '' : (!D.hasB ? 'Leave opens once you add a leaving date in Step 2.'
: (D.bOpen ? 'Leave opens once you add what you expect to earn after teaching in Step 2.' : ''));
var th = $('h-targetPct');
if (!ready) {
fill($('s3-lead'), [P('result', 'This step needs four numbers from Step 1.'), P('result-note', 'This step sets your income against your income target, once the page knows {list}.', { list: joinAnd(D ? D.missing : ['your numbers']) })]);
fill($('s3-empty'), emptyBox('Your income at each age, and three ways to cover the rest, appear here once Step 1 is filled in.', true));
fill($('s3-aside'), []);
if (th) th.textContent = 'A share of your pay when you stop working.';
return;
}
var e = D.sel, w = worstSnap(e), s = D.s;
fill($('s3-lead'), step3Lead(e));
$('c4-title').textContent = (D.which === 'A' ? 'Stay Teaching' : 'Leave Teaching') + ': Income Against Your Target';
var scaleMax = covScale([e]);
fill($('c4-rows'), e.snaps.map(function (x) { return covRow(e, x, scaleMax, false, PRINT_W); }));
fill($('c4-table'), covTable([e], ['']));
renderWays(e, w);
renderTodo(e, w);
if (th) th.textContent = pctText(s.targetPct, 2) + '% of ' + usdRound(e.basePay) + ' a year is ' + usd(e.target) + ' a month.';
var potKids = [P(null, 'By age {stop} your savings reach about {*pot} in today’s dollars' + (num(s.returnPct) > 0 ? ' at a {r}% yearly return' : '') + '. Taking out {draw}% a year gives about {*sav} a month.',
{ stop: e.stopAge, pot: usdRound(e.pot), r: pctText(s.returnPct, 2), draw: pctText(s.drawPct, 2), sav: usd(e.savingsMonthly) })];
if (D.d.returnPct === 0) potKids.push(P('small', 'You entered a 0% yearly return, so the page shows no growth.'));
else if (!(num(s.returnPct) > 0)) potKids.push(P('small', 'No yearly return is entered, so the page shows no growth. Add your own choice in Your Numbers.'));
if (e.potParts.rollover >= 0.5) potKids.push(P('small', 'That counts about ' + usdRound(e.potParts.rollover) + ' from the TRS rollover.'));
if (e.potParts.supplemental >= 0.5) potKids.push(P('small', 'That counts about ' + usdRound(e.potParts.supplemental) + ' from your TRS 4 supplemental account, at an assumed 4% a year.'));
potKids.push(P('small muted', 'The yearly return is an assumption you can change. The page does not recommend any investment.'));
var L = RULES.limits;
fill($('s3-aside'), [
card('s3-pot-title', 'How Your Savings Are Counted', potKids),
card('s3-room-title', 'Room To Save In ' + RULES.year, [el('ul', { class: 'miles' }, [
'403(b) and 401(k) plans together: up to ' + usd(L.deferral) + ' a year.',
'457(b) plan: a separate ' + usd(L.deferral) + ' a year.',
'From age 50: ' + usd(L.catch50) + ' more. At 60 to 63: ' + usd(L.catch6063) + ' more.',
'IRA: ' + usd(L.ira) + ' a year, or ' + usd(L.ira + L.iraCatch) + ' from age 50.',
'Kentucky Deferred Comp is the state 457(b) and 401(k) program, open to public school employees where the district takes part. Ask your district.'
].map(function (t) { return el('li', { style: 'grid-template-columns:minmax(0,1fr)' }, el('p', { class: 'miles__what', style: 'grid-column:1', text: t })); }))])
]);
}
/* The numbers behind a printed plan. */
function renderPrintNumbers() {
var host = $('print-numbers');
if (!D || !D.ready) { fill(host, []); return; }
var d = state.data, rows = [];
KEYS.forEach(function (k) {
var f = FIELD[k], v = d[k];
if (v === null || v === undefined || f.kind === 'enum' || k === 'retireAge') return;
if (f.kind === 'money' && f.blank && v === 0) return;
var shown = f.kind === 'money' ? usd(v) + (f.post ? ' ' + f.post : '') : (f.kind === 'pct' ? v + (f.post || '%') : (k === 'entryMonth' ? monthName(v) : (k === 'fedBracket' ? v + '%' : String(v) + (f.post ? ' ' + f.post : ''))));
rows.push(fact(fileLabel(k), shown));
});
rows.push(fact('Age You Stop Teaching', String(D.s.retireAge)));
fill(host, [el('h2', { style: 'font-size:15pt;margin-top:14px', text: 'Numbers Used' }), el('dl', { class: 'facts', style: 'margin-top:8px' }, rows)]);
}
/* =====================================================================
10. MOTION: an optional layer over the finished page
The page is always drawn in its finished state first. An effect then plays over it and ends in that same state,
so with motion off (html[data-motion="off"]) nothing here runs and nothing looks different.
Whether motion is on is kept in memory only: nothing is stored on the device.
===================================================================== */
var ROOT = document.documentElement;
var motionOn = ROOT.getAttribute('data-motion') === 'on';
var effects = []; // every effect in flight, as { finish: function } so one call can end them all
/* The three lengths and the one curve come from the style sheet's tokens, so there is one place to change them. */
var MS = { fast: 120, mid: 220, slow: 420 }, EASE = 'cubic-bezier(.2, .8, .2, 1)';
function readTokens() {
try {
var cs = window.getComputedStyle(ROOT);
['fast', 'mid', 'slow'].forEach(function (k) { var v = parseFloat(cs.getPropertyValue('--m-' + k)); if (v > 0) MS[k] = v; });
var curve = cs.getPropertyValue('--ease').trim();
if (/^cubic-bezier\(/.test(curve)) EASE = curve;
} catch (e) { /* keep the values above */ }
}
function dropEffect(fx) { var i = effects.indexOf(fx); if (i >= 0) effects.splice(i, 1); }
/* End every effect now, each in its finished state. */
function finishMotion() {
effects.slice().forEach(function (fx) { try { fx.finish(); } catch (e) { /* already over */ } });
effects = [];
if (document.getAnimations) document.getAnimations().forEach(function (a) { try { a.finish(); } catch (e) { try { a.cancel(); } catch (e2) { /* gone */ } } });
}
/* The opening is built by its own script just after the top line, so that it covers the window before the rest of
the page is first drawn. Here it is one more effect: Pause Motion, printing, New, Open and the example end it. */
function introNode() { var o = $('intro'); return o && typeof o.finish === 'function' ? o : null; }
function setMotion(on) {
motionOn = !!on;
ROOT.setAttribute('data-motion', motionOn ? 'on' : 'off');
if (!motionOn) finishMotion();
Array.prototype.forEach.call(document.querySelectorAll('[data-motion-toggle]'), function (b) { b.textContent = motionOn ? 'Pause Motion' : 'Play Motion'; });
}
/* One effect that only moves or fades: a Web Animation with no fill, so when it ends the node is back in the
state its styles give it, which is the state the page shows with motion off. Returns null when motion is off. */
function play(node, frames, ms, more, done) {
if (!motionOn || printing || !node || !node.animate) return null;
var o = { duration: ms, easing: EASE, fill: 'backwards' };
if (more) Object.keys(more).forEach(function (k) { o[k] = more[k]; });
var anim = node.animate(frames, o), over = false;
var end = function () { if (over) return; over = true; dropEffect(fx); if (done) done(); };
var fx = { finish: function () { try { anim.finish(); } catch (e) { /* already over */ } end(); } };
anim.onfinish = anim.oncancel = end;
effects.push(fx);
return anim;
}
function fadeIn(node, ms, more) { return play(node, [{ opacity: 0 }, { opacity: 1 }], ms || MS.mid, more); }
/* ---- Numbers that roll ----
When an amount changes, the page first writes the new amount, as always. Then a copy laid over it counts from
the amount that was showing to the new one. Both ends are the page's own figures: nothing is worked out here.
A change that arrives while a count is running starts from the number then showing, so counts never queue.
Only dollar amounts count. Ages and years are simply shown. */
var MONEY = /\$\d[\d,]*/g;
var rollMemo = {}; // key -> the finished text last seen there
var rolls = {}; // key -> the count in flight
var rollFrom = {}; // key -> where a count that was just stopped had reached, for the count that takes over
var rollFrame = 0;
function moneyIn(text) { return (String(text).match(MONEY) || []).map(function (t) { return Number(t.replace(/[$,]/g, '')); }); }
/* The words round the amounts, with every number taken out: two lines of the same shape say the same thing with other figures. */
function shapeOf(text) { return String(text).replace(MONEY, '$').replace(/\d+/g, '#'); }
/* The one piece of text in a node that may also hold a drawing, such as a color swatch. */
function onlyText(node) {
var found = null, n = 0;
Array.prototype.forEach.call(node.childNodes, function (c) { if (c.nodeType === 3 && c.nodeValue.trim()) { found = c; n++; } else if (c.nodeType === 1 && c.textContent.trim()) n++; });
return n === 1 ? found : null;
}
function rollTick() {
rollFrame = 0;
Object.keys(rolls).forEach(function (key) {
/* A count is over when its clock has finished or been stopped, or its place has gone from the page. A clock that
has not started yet gives no progress, and the count waits at its first number. */
var fx = rolls[key], a = fx.anim, t = a.effect ? a.effect.getComputedTiming().progress : null;
if (!a.effect || a.playState === 'finished' || a.playState === 'idle' || !fx.wrap.isConnected) { fx.finish(); return; }
if (t === null || t === undefined) t = 0;
fx.to.forEach(function (to, i) {
var v = Math.round(fx.from[i] + (to - fx.from[i]) * t);
if (v !== fx.values[i]) { fx.values[i] = v; fx.counts[i].textContent = '$' + commas(v); }
});
});
if (Object.keys(rolls).length) rollFrame = window.requestAnimationFrame(rollTick);
}
/* node holds text with one or more dollar amounts, already finished. key names the place, so the amounts can be
followed from one drawing of the page to the next even when the node itself is made again.
Returns 'rolled', or 'changed' when the text is new but cannot count (other words, or no amounts), or 'same'. */
function rollTo(key, node, strict, starts, lead) {
var from = rollFrom[key] || null, live = !!from;
delete rollFrom[key];
/* lead: the amount is the node's opening words, with a smaller line after it that is left alone. */
var tn = node ? (lead ? (node.firstChild && node.firstChild.nodeType === 3 ? node.firstChild : null) : onlyText(node)) : null;
/* A line can be written in several pieces of text and nothing else. It counts as one line, and its own pieces are
put back when the count ends, so the line is set exactly as it was. */
var pieces = node && !tn && !lead ? Array.prototype.slice.call(node.childNodes) : [];
if (pieces.length < 2 || !pieces.every(function (c) { return c.nodeType === 3; })) pieces = [];
var text = node ? (tn ? tn.nodeValue : (lead ? '' : node.textContent)) : null, before = rollMemo[key];
if (text === null) { delete rollMemo[key]; return 'same'; }
rollMemo[key] = text;
var changed = before !== undefined && before !== text, to = moneyIn(text), words = !strict || !changed || shapeOf(before) === shapeOf(text);
if (!from && changed) from = moneyIn(before);
/* The count is drawn in the finished amount's box. A count with more digits than that amount would be wider than
the box and run over the words after it, so a count coming down from a longer number starts at the largest
number that fits ($999 on the way to $789). */
if (from && from.length === to.length) from = from.map(function (v, i) { return Math.min(v, Math.pow(10, String(to[i]).length) - 1); });
var can = from && to.length > 0 && from.length === to.length && words && to.some(function (v, i) { return v !== from[i]; });
if (!motionOn || printing || !can || (!tn && !pieces.length) || !node.animate || !node.getClientRects().length) return changed ? 'changed' : 'same';
var end = /^(right|end)$/.test(window.getComputedStyle(node).textAlign), counts = [], kids = [], last = 0, i = 0, m;
MONEY.lastIndex = 0;
while ((m = MONEY.exec(text))) {
if (m.index > last) kids.push(text.slice(last, m.index));
var count = el('span', { text: '$' + commas(from[i]) });
var over = el('span', { class: 'roll' + (end ? ' roll--end' : ''), 'aria-hidden': 'true' }, count);
var final = el('span', { class: 'rollbox__final', text: m[0] });
kids.push(el('span', { class: 'rollbox' }, end ? [final, over] : [over, final]));
counts.push(count);
last = MONEY.lastIndex; i++;
}
if (last < text.length) kids.push(text.slice(last));
var wrap = el('span', { class: 'rolltext' }, kids);
/* Everything above only reads the page. The change itself waits until every amount in the batch has been read. */
starts.push(function () {
if (tn) node.replaceChild(wrap, tn); else { pieces.forEach(function (c) { node.removeChild(c); }); node.appendChild(wrap); }
/* The animation is the clock, eased by the page's one curve. It changes nothing by itself: the count is the effect.
It fills backwards, so until the browser starts its clock (which can be a frame or two after this, and a moment
ahead of the frame's own time) it reads as the start of the count, not as no count at all. */
var fx = { wrap: wrap, counts: counts, from: from, to: to, values: from.slice(),
anim: wrap.animate([{ opacity: 1 }, { opacity: 1 }], { duration: MS.slow, easing: EASE, fill: 'backwards' }) };
fx.finish = function () {
if (rolls[key] === fx) delete rolls[key];
dropEffect(fx);
try { fx.anim.cancel(); } catch (e) { /* already over */ }
if (!wrap.parentNode) return;
if (tn) wrap.parentNode.replaceChild(document.createTextNode(text), wrap);
else { pieces.forEach(function (c) { wrap.parentNode.insertBefore(c, wrap); }); wrap.parentNode.removeChild(wrap); }
};
rolls[key] = fx;
effects.push(fx);
if (!rollFrame) rollFrame = window.requestAnimationFrame(rollTick);
});
return 'rolled';
}
/* A batch of amounts, as [key, node, strict]: stop the counts in flight, read every node, then change the page.
Reading and changing in turn would make the browser lay the page out again for each amount. */
function rollMany(items) {
items.forEach(function (it) { var live = rolls[it[0]]; if (live) { rollFrom[it[0]] = live.values.slice(); live.finish(); } });
var starts = [], out = items.map(function (it) { return rollTo(it[0], it[1], it[2], starts, it[3]); });
starts.forEach(function (fn) { fn(); });
return out;
}
/* The first screen and the summary: the big figure, the Stay and Leave card amounts and the five summary amounts. */
var ROLL_FIRST = [['hero', '#hero-num'], ['stay', '#path-stay-body .path__big b'], ['leave', '#path-leave-body .path__big b'], ['strip-pension', '#strip-pension'],
['strip-ss', '#strip-ss'], ['strip-savings', '#strip-savings'], ['strip-want', '#strip-want'], ['strip-left', '#strip-left']];
function rollList(list) { rollMany(list.map(function (x) { return [x[0], document.querySelector(x[1]), false]; })); }
/* Step 3's Save More card: the amount to save, the amounts in its sentences and the table of other returns count to
their new values when Stay or Leave is switched or the yearly return changes. An amount that was not there
before is simply shown. */
var saveKeys = [];
function rollSaveMore() {
var items = [], big = document.querySelector('#way-save-body .way__big');
if (big) items.push(['save-big', big, true, true]);
Array.prototype.forEach.call(document.querySelectorAll('#way-save-body p strong'), function (n) { items.push(['save-strong-' + shapeOf(n.parentNode.textContent), n, true]); }); // by its sentence, so one sentence's amount never counts into another's
Array.prototype.forEach.call(document.querySelectorAll('#way-save-body td'), function (n, i) { items.push(['save-td-' + i, n, true]); });
var keys = items.map(function (it) { return it[0]; });
saveKeys.forEach(function (k) { if (keys.indexOf(k) < 0) delete rollMemo[k]; });
saveKeys = keys;
rollMany(items);
}
/* Step 2's comparison, after it is drawn again for a new stop age or Social Security age. The figures in the two
boxes and in the table count to their new values. A line whose words changed, not only its figures, fades in.
The headline cross-fades: a copy of the old one fades out over the new one as it fades in. The copy is laid over
the headline's own corner and takes no room. */
var evenSayWas = null, evenKeys = [];
function motionAfterEven() {
var say = $('even-say'), shown = !$('s2-even').hidden && say.getClientRects().length > 0, items = [], lines = [];
['give-stay', 'give-leave'].forEach(function (g) {
var list = document.querySelectorAll('#' + g + ' li, #' + g + ' .even__none'), was = rollMemo[g + '-n'];
Array.prototype.forEach.call(list, function (li, i) { items.push([g + '-' + i, li, true]); lines.push({ li: li, added: was !== undefined && i >= was }); });
for (var k = list.length; k < (was || 0); k++) delete rollMemo[g + '-' + k];
rollMemo[g + '-n'] = list.length;
});
var seen = {};
Array.prototype.forEach.call(document.querySelectorAll('#even-grid .even__row:not(.even__row--head)'), function (row) {
var name = 'even-' + shapeOf(row.querySelector('.even__label').firstChild.nodeValue || '');
seen[name] = (seen[name] || 0) + 1;
Array.prototype.forEach.call(row.querySelectorAll('.even__cell'), function (cell, c) {
Array.prototype.forEach.call(cell.querySelectorAll('.even__amt b, .even__parts li'), function (n, j) { items.push([name + '-' + seen[name] + '-' + c + '-' + j, n, true]); });
});
});
/* An amount that is not in the table this time is forgotten, so if its row comes back it is simply shown and does not count from an old figure. */
var here = {};
items.forEach(function (it) { here[it[0]] = true; });
evenKeys.forEach(function (k) { if (!here[k]) delete rollMemo[k]; });
evenKeys = Object.keys(here);
var how = rollMany(items);
if (shown) lines.forEach(function (x, i) { if (how[i] === 'changed' || x.added) fadeIn(x.li); });
var was = evenSayWas;
evenSayWas = $('s2-even').hidden ? null : say.cloneNode(true);
if (motionOn && shown && was && was.textContent !== say.textContent) {
var ghost = el('span', { class: 'ghost', 'aria-hidden': 'true' });
Array.prototype.forEach.call(was.childNodes, function (c) { ghost.appendChild(c.cloneNode(true)); });
Array.prototype.forEach.call(say.children, function (line) { fadeIn(line); });
say.appendChild(ghost);
var gone = function () { if (ghost.parentNode) ghost.parentNode.removeChild(ghost); };
if (!play(ghost, [{ opacity: 1 }, { opacity: 0 }], MS.mid, { fill: 'forwards' }, gone)) gone();
}
}
/* ---- The Saved stamp ----
After a save the word Saved is pressed onto the page just under the Save button: it lands slightly large and
settles, holds about a second, then fades. It is fixed to the window. A second save while it shows starts it over. */
var stampFx = null;
function stampSaved() {
var stamp = $('saved-stamp'), btn = $('btn-save').getBoundingClientRect();
if (stampFx) stampFx.finish();
if (!motionOn || printing || !stamp.animate) return;
stamp.hidden = false;
var w = stamp.offsetWidth, wide = document.documentElement.clientWidth;
stamp.style.left = Math.round(clamp(btn.left + btn.width / 2 - w / 2, 8, Math.max(8, wide - w - 8))) + 'px';
stamp.style.top = Math.round(Math.max(8, btn.bottom + 4)) + 'px';
var at = 'rotate(-4deg) scale(1)';
/* Each stamp puts itself away, and only itself: the end of an earlier one is reported a frame late and must not hide this one. */
var fx = {}, away = function () { if (stampFx === fx) { stamp.hidden = true; stampFx = null; } };
var anim = play(stamp, [{ opacity: 0, transform: 'rotate(-4deg) scale(1.3)', easing: EASE }, { opacity: 1, transform: at, offset: 0.09 }, { opacity: 1, transform: at, offset: 0.84 }, { opacity: 0, transform: at }],
1400, { easing: 'linear', fill: 'none' }, away);
fx.finish = function () { try { anim.finish(); } catch (e) { /* over */ } away(); };
stampFx = anim ? fx : null;
if (!anim) stamp.hidden = true;
}
/* ---- Milestone flags ----
When the marker goes up to or past the age a flag stands at, the flag's words do one small pop, and its mark and
the ruler's tick under it thicken and darken for a moment. Only the flag that was crossed moves, and only on
the way up: sliding down past a flag does nothing. */
var rulerWas = null, rulerKeyWas = '';
function flagsCrossed(a, b) {
var min = Number($('ruler-age').min), ticks = $('ruler-ticks').children;
var words = 'translateX(calc(-50% + var(--shift, 0px)))'; // where fitFlags put the words. The pop keeps it.
flagNodes.forEach(function (n) {
var age = Number(n.getAttribute('data-age')), tick = ticks[age - min];
if (n.hidden || !(b > a && age > a && age <= b)) return; // going up only: sliding down past a flag does nothing
play(n.firstChild, [{ transform: words + ' scale(1)' }, { transform: words + ' scale(1.12)', offset: 0.4 }, { transform: words + ' scale(1)' }], MS.slow);
play(n, [{ transform: 'scaleX(1)' }, { transform: 'scaleX(3)', offset: 0.4 }, { transform: 'scaleX(1)' }], MS.slow, { pseudoElement: '::after' });
if (tick) {
var base = tick.className === 'five' ? 1 : 0.8;
play(tick, [{ opacity: base, transform: 'scaleX(1)' }, { opacity: 1, transform: 'scaleX(2.5)', offset: 0.4 }, { opacity: base, transform: 'scaleX(1)' }], MS.slow, { pseudoElement: '::before' });
}
});
}
/* ---- Bars that fill ----
Each time one of a step's bars comes into view, the bar grows from zero to its value: the pension chart's bars
from their foot, an income bar from the left one source after another with the hatched Left To Plan For part
last, and the credits bar from the left. It plays again only after the bar has fully left the window (or its
step was closed), so a small scroll that keeps any of it in view does not start it over. A bar is never
hidden to wait for this: it is drawn whole, and the effect starts as its box reaches the window's edge. */
var seenOnce = {}, viewWatch = null, viewJobs = null, cardWatch = null, cardJobs = null;
var barIn = {}, barStep = null; // bar key -> true while that bar is in view and has played (or was seen with motion off)
function fillBars(host) {
Array.prototype.forEach.call(host.querySelectorAll('path.col'), function (bar, i) {
play(bar, [{ transform: 'scaleY(0)' }, { transform: 'scaleY(1)' }], MS.slow, { delay: i * 8 });
});
var parts = host.querySelectorAll('.part'), solid = 0;
Array.prototype.forEach.call(parts, function (part) {
var left = part.classList.contains('f-left');
play(part, [{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], left ? MS.slow : MS.mid, { delay: left ? solid * 110 + 60 : solid * 110 });
if (!left) solid++;
});
var credits = host.querySelector('rect.f-ss:not(.part)');
if (credits && !parts.length) play(credits, [{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], MS.slow);
}
/* ---- Show Your Work ----
The first time Step 1 is open and How This Pension Is Figured comes into view, its rows appear one after
another, each with a pencil stroke drawn along the rule above it, ending on the pension. About 1.2 seconds in
all. Every row is on the page from the start: this only fades and slides what is already there. */
function showWork(card) {
var rows = card.querySelectorAll('dl.facts > div'), n = rows.length;
if (n < 2) return;
var gap = (1200 - MS.mid) / (n - 1);
Array.prototype.forEach.call(rows, function (row, i) {
play(row, [{ opacity: 0, transform: 'translateX(-6px)' }, { opacity: 1, transform: 'translateX(0)' }], MS.mid, { delay: i * gap });
if (i) play(row, [{ opacity: 1, transform: 'scaleX(0)' }, { opacity: 1, transform: 'scaleX(1)', offset: 0.6 }, { opacity: 0, transform: 'scaleX(1)' }], MS.slow, { delay: i * gap, pseudoElement: '::before' });
});
}
/* ---- Pencil underline ----
Once the opening has ended, a pencil line is drawn under the bold amount in the first screen's sentence, held a
moment and faded. Once. The sentence is written again on every change, so a change made while it plays simply ends it. */
function pencilLine() {
if (!motionOn) return;
var amount = null;
Array.prototype.forEach.call($('hero-say').querySelectorAll('strong'), function (b) { if (/^\$\d/.test(b.textContent)) amount = b; });
if (!amount || !amount.getClientRects().length) return;
amount.classList.add('penciled');
play(amount, [{ opacity: 1, transform: 'scaleX(0)', easing: EASE }, { opacity: 1, transform: 'scaleX(1)', offset: 0.25 }, { opacity: 1, transform: 'scaleX(1)', offset: 0.8 }, { opacity: 0, transform: 'scaleX(1)' }],
1700, { delay: 0, easing: 'linear', pseudoElement: '::after' });
}
/* ---- Marker glide ----
A click on the ruler away from the marker puts the marker on that age at once, as the browser does. To the eye
it glides: a copy slides from the old place to the new one with the age tab, and the amounts roll as they do
for any move. A drag is not a click: once the pointer moves, the copy is dropped and the marker is under the hand. */
var glideFx = null;
function glideMarker(from, to) {
var input = $('ruler-age'), ruler = input.parentNode, tab = $('ruler-tab'), min = Number(input.min), span = Math.max(1, Number(input.max) - min);
var T = parseFloat(window.getComputedStyle($('pick')).getPropertyValue('--thumb')) || 30, W = ruler.clientWidth;
if (glideFx) glideFx.finish();
if (!motionOn || !W || !ruler.animate) return;
var x = function (age) { return round1((age - min) / span * (W - T)); }, ghost = el('div', { class: 'ruler__ghost', 'aria-hidden': 'true' });
ruler.appendChild(ghost);
input.classList.add('is-gliding');
var over = false, fx = { finish: function () { if (over) return; over = true; glideFx = null; input.classList.remove('is-gliding'); if (ghost.parentNode) ghost.parentNode.removeChild(ghost); } };
glideFx = fx;
if (!play(ghost, [{ transform: 'translateX(' + x(from) + 'px)' }, { transform: 'translateX(' + x(to) + 'px)' }], MS.mid, { fill: 'forwards' }, fx.finish)) { fx.finish(); return; }
play(tab, [{ transform: 'translateX(calc(-50% + ' + round1(x(from) - x(to)) + 'px))' }, { transform: 'translateX(-50%)' }], MS.mid);
}
function wireGlide() {
var input = $('ruler-age'), press = null;
input.addEventListener('pointerdown', function (e) { press = { value: Number(input.value), x: e.clientX, moved: false }; });
input.addEventListener('pointermove', function (e) { if (press && !press.moved && Math.abs(e.clientX - press.x) > 3) { press.moved = true; if (glideFx) glideFx.finish(); } });
window.addEventListener('pointerup', function () { press = null; });
window.addEventListener('pointercancel', function () { press = null; });
/* The browser moves the marker as the button goes down, before any drag. That first move is the click. */
input.addEventListener('input', function () {
if (!press || press.moved || input.value === '' || Number(input.value) === press.value) return;
glideMarker(press.value, Number(input.value));
press.value = Number(input.value);
});
}
/* ---- Dialogs and disclosures ----
About and Rules And Sources fade in with the dimmed page behind them. See Every Number, Table View and Your
Numbers fade their contents in when the reader opens them. Opening one from the script (for printing, or to
follow the width of the window) does not. */
function fadeDialog(dlg) {
if (!dlg || (dlg.id !== 'dlg-about' && dlg.id !== 'dlg-rules')) return;
play(dlg, [{ opacity: 0, transform: 'translateY(8px)' }, { opacity: 1, transform: 'translateY(0)' }], MS.mid);
try { play(dlg, [{ opacity: 0 }, { opacity: 1 }], MS.mid, { pseudoElement: '::backdrop' }); } catch (e) { /* no backdrop to fade in this browser */ }
}
function wireDisclosures() {
document.addEventListener('click', function (e) {
var sm = e.target && e.target.closest ? e.target.closest('summary') : null, box = sm ? sm.parentNode : null;
if (!box || !box.matches || !box.matches('details.evenall, details.tview, details.numbers')) return;
/* The browser opens the box after this click. Look on the next frame, before it is drawn open. */
window.requestAnimationFrame(function () {
if (box.open) Array.prototype.forEach.call(box.children, function (c) { if (c !== sm) fadeIn(c); });
});
});
}
/* ---- Step indicator ----
The ink fill of the active step tab slides from the tab that was active to the one just picked. */
function slideStepMark(from, to) {
if (!started || !motionOn || !from || !to || from === to) return;
var nav = document.querySelector('nav.steps'), base = nav.getBoundingClientRect(), a = from.getBoundingClientRect(), b = to.getBoundingClientRect();
if (!a.width || !b.width) return;
var mark = el('span', { class: 'steps__mark', 'aria-hidden': 'true', style: 'left:' + round1(b.left - base.left) + 'px;top:' + round1(b.top - base.top) + 'px;width:' + round1(b.width) + 'px;height:' + round1(b.height) + 'px' });
nav.appendChild(mark);
var gone = function () { if (mark.parentNode) mark.parentNode.removeChild(mark); };
var start = 'translate(' + round1(a.left - b.left) + 'px, ' + round1(a.top - b.top) + 'px) scale(' + (a.width / b.width).toFixed(4) + ', ' + (a.height / b.height).toFixed(4) + ')';
if (!play(mark, [{ transform: start, opacity: 1 }, { transform: 'translate(0, 0) scale(1, 1)', opacity: 0 }], MS.mid, { fill: 'forwards' }, gone)) gone();
}
/* ---- Calm heads-up ----
When a change to the numbers makes a heads-up box appear, it fades in and settles a few pixels into place. When a
change makes one go away, the box that was there fades out where it stood, laid over the page without taking
room. Nothing else is done to a heads-up: no pulse and no change of color. Opening a step does not count, only
a change to the numbers. */
var cautionWas = null;
function cautionsNow() {
var main = $('main'), base = main.getBoundingClientRect(), now = {};
Array.prototype.forEach.call(main.querySelectorAll('.caution:not(.caution--leaving)'), function (c) {
var host = c.closest('[id]'), title = c.querySelector('.caution__title'), key = (host ? host.id : '') + '|' + (title ? title.textContent : ''), r = c.getBoundingClientRect();
now[key] = { node: c, shown: r.width > 0, left: r.left - base.left, top: r.top - base.top, width: r.width };
});
return now;
}
/* A step was opened or the window changed size: which boxes are showing, and where, is read again. Nothing plays. */
function cautionsMoved() { if (cautionWas) cautionWas = cautionsNow(); }
function cautionsAfterRender() {
var main = $('main'), now = cautionsNow();
if (cautionWas && motionOn && !printing) {
Object.keys(now).forEach(function (key) {
if (!cautionWas[key] && now[key].shown) play(now[key].node, [{ opacity: 0, transform: 'translateY(6px)' }, { opacity: 1, transform: 'translateY(0)' }], MS.slow);
});
Object.keys(cautionWas).forEach(function (key) {
var was = cautionWas[key], ghost = was.node;
if (now[key] || !was.shown || ghost.isConnected) return; // the old box left the page with its wrapper when the page was drawn again
ghost.className += ' caution--leaving';
ghost.setAttribute('aria-hidden', 'true');
ghost.style.left = round1(was.left) + 'px'; ghost.style.top = round1(was.top) + 'px'; ghost.style.width = round1(was.width) + 'px';
main.appendChild(ghost);
var gone = function () { if (ghost.parentNode) ghost.parentNode.removeChild(ghost); };
if (!play(ghost, [{ opacity: 1 }, { opacity: 0 }], MS.mid, { fill: 'forwards' }, gone)) gone();
});
}
cautionWas = now;
}
/* ---- Service credit tally ----
The first time the tally is in view its marks are drawn one after another. After that, when the ruler adds
years, only the new marks are drawn. Fewer years simply shows fewer marks. */
var tallyWas = null;
function drawTally(host, from) {
Array.prototype.forEach.call(host.querySelectorAll('.tally__mark'), function (mark, i) {
if (i < from) return;
play(mark, [{ transform: 'scale(0)' }, { transform: 'scale(1)' }], MS.fast, { delay: (i - from) * (from ? 30 : 22) });
});
}
function tallyAfterRender() {
var host = document.querySelector('#s1-formula .tally'), n = host ? host.querySelectorAll('.tally__mark').length : null;
if (host && seenOnce['s1-tally'] && tallyWas !== null && n > tallyWas && host.getClientRects().length) drawTally(host, tallyWas);
tallyWas = n;
}
/* ---- First reveal ----
A card below the first screen fades up a few pixels the first time it is scrolled to. It is never hidden to
wait for that: every card is drawn whole from the start, so there is nothing to show "anyway" if the browser's
observer were slow or missing. The effect starts when the card's top is within 48px of the window's lower edge,
so the card comes into view already part way through it. A card that is in view when its step opens does not play. */
function revealCard(card) { play(card, [{ opacity: 0, transform: 'translateY(10px)' }, { opacity: 1, transform: 'translateY(0)' }], MS.slow); }
/* Things that play when they come into view while their step is open: the bars each time they come back, the
rest the first time only. Nothing is hidden to wait for its turn: each is drawn whole, and its effect starts as
its box reaches the window's edge. Seeing one with motion off counts as seeing it, so it does not play until it
has left the window and come back (a bar) or ever (the rest). */
function watchViews() {
if (!window.IntersectionObserver || !window.Map) return;
if (viewWatch) viewWatch.disconnect();
var jobs = [], sec = $('step-' + state.step);
/* A step that was closed took its bars out of the window, so they all play when it opens again. */
if (barStep !== state.step) { barIn = {}; barStep = state.step; }
if (state.step === 1) {
jobs.push(['c1', $('c1-plot'), fillBars, 'bar']); jobs.push(['s1-formula', $('s1-formula'), showWork]);
if (document.querySelector('#s1-formula .tally')) jobs.push(['s1-tally', document.querySelector('#s1-formula .tally'), function (host) { drawTally(host, 0); }]);
}
var perCard = {};
Array.prototype.forEach.call(sec.querySelectorAll('.cov__bar'), function (n) {
var card = n.closest('.plan'), name = card ? card.getAttribute('aria-labelledby') : 'step';
perCard[name] = (perCard[name] || 0) + 1;
jobs.push(['s' + state.step + '-cov-' + name + '-' + perCard[name], n, fillBars, 'bar']);
});
Array.prototype.forEach.call(sec.querySelectorAll('.meter svg'), function (n, i) { jobs.push(['s' + state.step + '-meter-' + i, n, fillBars, 'bar']); });
Array.prototype.forEach.call(sec.querySelectorAll('.card, .chart'), function (n, i) { jobs.push(['s' + state.step + '-card-' + i, n, revealCard, 'card']); });
jobs = jobs.filter(function (j) { return j[3] === 'bar' || !seenOnce[j[0]]; });
if (cardWatch) cardWatch.disconnect();
if (!jobs.length) return;
viewJobs = new Map();
/* The cards have a watcher and a list of their own: a card can also be something else that plays once, as How
This Pension Is Figured is. A card already in view the first time it is looked at is counted as seen and left alone. */
cardJobs = new Map();
cardWatch = cardWatch || new IntersectionObserver(function (entries) {
entries.forEach(function (en) {
var job = cardJobs.get(en.target);
if (!job) return;
var first = !job.looked;
job.looked = true;
if (!en.isIntersecting) return;
cardWatch.unobserve(en.target);
if (seenOnce[job[0]]) return;
seenOnce[job[0]] = true;
if (!first) job[2](en.target);
});
}, { rootMargin: '0px 0px 48px 0px' });
viewWatch = viewWatch || new IntersectionObserver(function (entries) {
entries.forEach(function (en) {
var job = viewJobs.get(en.target);
if (!job) return;
/* A bar: not intersecting means no part of it is in the window, and only then may it play again. A bar
drawn again while it is in view (a ruler move, a new number) is a new node with the same key, and does not play. */
if (job[3] === 'bar') {
if (!en.isIntersecting) { barIn[job[0]] = false; return; }
if (barIn[job[0]]) return;
barIn[job[0]] = true;
job[2](en.target);
return;
}
if (!en.isIntersecting) return;
viewWatch.unobserve(en.target);
if (seenOnce[job[0]]) return;
seenOnce[job[0]] = true;
job[2](en.target);
});
});
jobs.forEach(function (j) { if (j[3] === 'card') { cardJobs.set(j[1], j); cardWatch.observe(j[1]); } else { viewJobs.set(j[1], j); viewWatch.observe(j[1]); } });
}
/* Called after every drawing of the page. */
function motionAfterRender() {
rollList(ROLL_FIRST);
rollSaveMore();
cautionsAfterRender();
tallyAfterRender();
watchViews();
var age = D && D.ready ? D.s.retireAge : null;
/* Only when the same flags are standing as last time. New numbers can move the age and the flags together, and that is not the marker crossing one. */
if (rulerWas !== null && age !== null && age !== rulerWas && rulerKey === rulerKeyWas) flagsCrossed(rulerWas, age);
rulerWas = age;
rulerKeyWas = rulerKey;
}
/* A different plan altogether (a file opened, New, the example brought back): end everything and forget the old
amounts, so the new plan is simply shown and nothing counts from one teacher's number to another's. */
function motionReset() {
finishMotion();
rollMemo = {};
evenSayWas = null;
rulerWas = null;
cautionWas = null;
tallyWas = null;
years.stop = null; // Play The Years starts over for the new plan
}
function wireMotion() {
readTokens();
setMotion(motionOn);
Array.prototype.forEach.call(document.querySelectorAll('[data-motion-toggle]'), function (b) {
b.addEventListener('click', function () { setMotion(!motionOn); });
});
/* If the device starts asking for less motion while the page is open, stop. Play Motion can still turn it back on. */
var less = window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : null;
var onLess = function () { if (less.matches) setMotion(false); };
if (less && less.addEventListener) less.addEventListener('change', onLess);
else if (less && less.addListener) less.addListener(onLess);
wireDisclosures();
wireGlide();
/* Paper shows every effect finished. */
window.addEventListener('beforeprint', finishMotion);
var intro = introNode();
if (intro) {
var introFx = { finish: function () { intro.finish(); } };
effects.push(introFx);
intro.addEventListener('introend', function () { dropEffect(introFx); });
}
}
/* =====================================================================
11. PUTTING IT ON THE PAGE
===================================================================== */
var liveRegion = null, announceTimer = null, started = false;
function announce() {
if (!started || !liveRegion) return;
clearTimeout(announceTimer);
announceTimer = setTimeout(function () {
/* Step 1's result is the big number and its sentence at the top of the page. */
var r = state.step === 1 ? $('hero') : $('s' + state.step + '-lead').querySelector('.result');
liveRegion.textContent = r ? r.textContent.replace(/\s+/g, ' ').trim() : '';
}, 1200);
}
function render() {
try { D = derive(); }
catch (err) { D = { d: state.data, s: engineState(state.data), ready: false, missing: ['numbers the page can work with'] }; }
covJobs = [];
renderChrome();
renderServiceNote();
renderStep1();
renderStep2();
renderStep3();
renderPrintNumbers();
drawCharts();
motionAfterRender();
announce();
}
function init() {
$('built-for').textContent = BUILT_FOR;
fill($('print-example'), [el('strong', { text: 'Example. ' }), exampleLine()]);
liveRegion = el('p', { class: 'sr', role: 'status', 'aria-live': 'polite' });
document.body.appendChild(liveRegion);
buildForms();
wireFileActions();
wireMore();
wireDialogs();
wireSteps();
wireEven();
wireYears();
wireMotion();
watchNumbers();
document.addEventListener('click', function (e) {
var t = e.target && e.target.closest ? e.target : null;
if (!t) return;
if (t.closest('[data-show-example]')) {
guard('Showing the example', function () {
state.data = clone(EXAMPLE); state.isExample = true; state.dirty = false; stopAt = null; claimAt = null;
motionReset();
setStatus('The example is showing again.');
render(); syncAllInputs();
});
} else if (t.closest('[data-open-rules]')) openDialog('dlg-rules', t.closest('[data-open-rules]'));
});
$('btn-print-all').addEventListener('click', function () { window.print(); });
$('btn-print-todo').addEventListener('click', function () { document.documentElement.classList.add('print-todo'); window.print(); });
var openedForPrint = [];
window.addEventListener('beforeprint', function () {
printing = true;
openedForPrint = [];
Array.prototype.forEach.call(document.querySelectorAll('details.tview, details.evenall'), function (dt) { if (!dt.open) { dt.open = true; openedForPrint.push(dt); } });
drawCharts();
});
window.addEventListener('afterprint', function () {
printing = false;
openedForPrint.forEach(function (dt) { dt.open = false; });
openedForPrint = [];
document.documentElement.classList.remove('print-todo');
drawCharts();
});
window.addEventListener('resize', debounce(function () { if (!printing) { drawCharts(); fitFlags(); cautionsMoved(); } }, 150));
setNumbersOpen(!state.isExample);
render();
syncAllInputs();
var m = /^#step-([123])$/.exec(window.location.hash || '');
goStep(m ? Number(m[1]) : 1, false);
started = true;
/* The pencil line waits for the opening to end, however it ends: a moment later, so the page has come through.
Ended by Pause Motion or for paper, it finds motion off or the page printing, and draws nothing. */
var intro = introNode();
if (intro) intro.addEventListener('introend', function () { window.setTimeout(pencilLine, 200); });
else window.setTimeout(pencilLine, 300);
}
/* A small read-only handle so the page can be checked by a script. It cannot change anything. */
window.fullCreditKY = {
version: FILE_VERSION,
snapshot: function () { return JSON.parse(JSON.stringify({ data: state.data, isExample: state.isExample, dirty: state.dirty, step: state.step })); },
/* Whether motion is on, how many effects are in flight, and whether the opening is showing. */
motion: function () { return { on: motionOn, running: effects.length, intro: !!introNode() }; }
};
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init();
})();
</script>
</body>
</html>
Websites this page contacts when it runs — fonts, chart libraries, data. Found by reading its source.
Published on Globefin under the MIT License. You may copy, change, and reuse this page, including commercially — just keep the notice below with it.
Copyright © 2026 Noah Emery. Licensed under the MIT License. Published on Globefin.
Provided as is, without warranty. Any external libraries it loads keep their own licences. Terms →
Scripts run, but the demo has its own throwaway origin. It can't read your session or cookies, can't reach the page around it, and can't navigate your tab. Don't enter real passwords or personal data into any demo.