/* Keep a habit going after you miss a day. Loaded after articles.css, for this article only.

   The colour rule carries the argument. Orange is a habit given up: the days after one miss, planned
   and never done. That is the leak. Indigo is what the plan gives back: every day after the first
   five that still happened, in full or small. A day simply missed is grey, in both pictures, because
   one miss is not the problem. Nothing else on the page is orange or indigo. */

.a-hero h1, .a-body h2, .a-body h3 { text-wrap: balance; }
.a-hero .lead, .a-body p, .a-body li, .a-body dd, .a-done span, .a-table td { text-wrap: pretty; }
.hb-vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* A person before the picture, in one line, so the two weeks still clear the fold. */
.hb-by { margin-top: 18px; }
.hb-by img { width: 32px; height: 32px; }
.hb-by strong { display: inline; margin-right: 0.6em; }

/* ---------- The set piece: one habit, two weeks, one bar a day ----------
   The plan is the markup, so no JS still gets the whole picture. tool.js adds is-before to show the
   two weeks without a plan, draws them in one day at a time, then lets the plan fill them back in. */
.hb-fig { position: relative; margin: 22px 0 0; padding: clamp(14px, 2.6vw, 24px); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow-float); display: grid; gap: 16px; min-width: 0; }
.hb-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hb-toggle { padding: 0.5em 0.95em; border: 0; border-radius: 999px; background: var(--grid); color: var(--ink); font: 700 0.8125rem/1.2 var(--sans); cursor: pointer; transition: background-color 0.2s; }
.hb-toggle:hover { background: var(--rule); }
.hb-toggle[hidden] { display: none; }
.hb-toggle:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }

/* Two sentences in one place, the plan's by default, so no JS still reads true. */
.hb-b4, .hb-b4k, .hb-b4n { display: none; }
.is-before .hb-b4 { display: inline; }
.is-before .hb-b4k { display: flex; }
.is-before .hb-b4n { display: block; }
.is-before .hb-af, .is-before .hb-afk, .is-before .hb-afn { display: none; }

.hb-stage { position: relative; min-width: 0; }
/* One row of 14 days. Column 8 is a narrow gap between the weeks, so week 2 starts at column 9. The
   week labels, the notes and the days share these columns, so a note sits over the days it names. */
.hb-weeks { display: grid; gap: 6px; min-width: 0; }
.hb-wks, .hb-notes, .hb-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 10px repeat(7, minmax(0, 1fr)); column-gap: 4px; min-width: 0; }
.hb-wks span { font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.12em; line-height: 1.2; text-transform: uppercase; color: var(--ink-hint); }
.hb-w2 { grid-column-start: 9; }

/* A note flags its first day with a line. The one that covers many days is a bracket over all of them. */
.hb-notes { min-height: 2.6rem; align-items: end; margin-bottom: 2px; }
.hb-note { grid-row: 1; align-self: end; padding: 0 0 2px 7px; border-left: 2px solid currentColor; font-size: 0.75rem; font-weight: 700; line-height: 1.25; color: var(--ink-2); text-wrap: balance; }
.hb-note.is-leak { color: var(--lift-ink); }
.hb-note.is-back { color: var(--primary-deep); }
.hb-note.is-span { position: relative; padding: 0 2px 6px; border-left: 0; border-bottom: 2px solid currentColor; }
.hb-note.is-span::before, .hb-note.is-span::after { content: ""; position: absolute; bottom: -6px; width: 2px; height: 6px; background: currentColor; }
.hb-note.is-span::before { left: 0; }
.hb-note.is-span::after { right: 0; }
.hb-nd { display: none; font-style: normal; }

.hb-days { list-style: none; margin: 0; padding: 0; row-gap: 0; }
.a-hero .hb-days { padding: 0; }
.hb-d { display: grid; gap: 6px; min-width: 0; }
.hb-d > b { font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.04em; line-height: 1.2; text-align: center; text-transform: uppercase; color: var(--ink-hint); }

/* One day: a slot of the same height every day, so the bar's height is how much of the habit happened. */
.hb-t { position: relative; display: block; height: 6.25rem; border-radius: 9px; background: var(--paper); box-shadow: inset 0 0 0 1px var(--rule); }
.hb-t i { position: absolute; left: 3px; right: 3px; bottom: 3px; height: calc((100% - 6px) * var(--h, 1)); border-radius: 6px; background: var(--ink-2); transition: height 0.5s var(--ease), background-color 0.4s var(--ease); transition-delay: calc(var(--i) * 55ms); }
/* Planned and given up: an empty, dashed orange outline where the bar would be. Dashed, so it reads as
   a place held for something that never came, not as a day picked out. */
.hb-t::before { content: ""; position: absolute; inset: 3px; border-radius: 6px; background: #FFFBF5; outline: 1.5px dashed var(--lift); outline-offset: -1.5px; opacity: 0; transition: opacity 0.3s; }
/* Missed: an empty ring at the foot of the day. Grey, in both pictures. */
.hb-t::after { content: ""; position: absolute; left: 50%; bottom: 9px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; box-shadow: inset 0 0 0 2px #9AA0C0; opacity: 0; transition: opacity 0.3s; }

/* With the plan (the default) */
.hb-d[data-a="small"] i { --h: 0.15; background: var(--primary); }
.hb-d[data-a="back"] i { background: var(--primary); }
.hb-d[data-a="miss"] i { --h: 0; }
.hb-fig:not(.is-before) .hb-d[data-a="miss"] .hb-t::after { opacity: 1; }

/* Without a plan */
.is-before .hb-t i { --h: 1; background: var(--ink-2); transition-delay: 0s; }
.is-before .hb-d[data-b="miss"] i, .is-before .hb-d[data-b="gone"] i, .is-before .hb-d.is-ahead i { --h: 0; }
.is-before .hb-d[data-b="gone"]:not(.is-ahead) .hb-t::before { opacity: 1; }
.is-before .hb-d[data-b="miss"]:not(.is-ahead) .hb-t::after { opacity: 1; }
.is-before .hb-d[data-b="gone"]:not(.is-ahead) > b { color: var(--lift-ink); }
.is-before .hb-note { animation: hb-in 0.4s var(--ease) both; }
@keyframes hb-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hb-read { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hb-read > div { display: grid; gap: 4px; padding: 12px 14px; border-radius: 12px; background: var(--paper); min-width: 0; }
.hb-read .eyebrow { color: var(--ink-hint); }
.hb-read b { font-family: var(--serif); font-size: clamp(1.6rem, 1.35rem + 1vw, 2.1rem); font-weight: 700; line-height: 1.05; color: var(--primary-deep); }
.hb-read small { font-size: 0.8125rem; line-height: 1.3; color: var(--ink-hint); }
.is-before .hb-read b { color: var(--lift-ink); }

.hb-key { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; padding: 0; list-style: none; font-size: 0.875rem; line-height: 1.3; color: var(--ink-2); }
.a-hero .hb-key { padding: 0; }
.hb-key li { display: flex; align-items: center; gap: 7px; }
.hb-key li.hb-b4k { display: none; }
.is-before .hb-key li.hb-b4k { display: flex; }
.hb-key i { width: 14px; height: 14px; border-radius: 4px; }
.hb-key .k-full { background: var(--ink-2); }
.hb-key .k-miss { border-radius: 50%; box-shadow: inset 0 0 0 2px #9AA0C0; }
.hb-key .k-gone { background: #FFFBF5; outline: 1.5px dashed var(--lift); outline-offset: -1.5px; }
.hb-key .k-back { background: var(--primary); }
.hb-key .k-small { height: 5px; margin-top: 9px; border-radius: 2px; background: var(--primary); }
.hb-cap { margin-top: 14px; font-size: 0.9375rem; line-height: 1.5; color: var(--ink-hint); }

/* ---------- Cards and fields ---------- */
.hb-card { padding: clamp(14px, 2.4vw, 20px); border-radius: 18px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule); display: grid; gap: 10px; min-width: 0; }
.hb-lab { font-size: 0.875rem; font-weight: 700; line-height: 1.3; color: var(--ink); }
.hb-card input, .hb-tool input { width: 100%; min-width: 0; padding: 0.65em 0.8em; border: 1px solid var(--rule); border-radius: 12px; background: var(--paper); color: var(--ink); font: 500 1.0625rem/1.4 var(--sans); transition: border-color 0.2s, box-shadow 0.2s; }
.hb-card input:focus, .hb-tool input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 108, 248, 0.25); }
.hb-card input::placeholder { color: var(--ink-hint); }

/* The one dark surface in the reading column: this is where the reader stops reading and writes. */
.hb-tool { padding: clamp(16px, 2.6vw, 26px); border-radius: 22px; background: var(--night); color-scheme: dark; display: grid; gap: 12px; min-width: 0; }
.hb-tool .hb-lab { color: var(--on-night); }
.hb-tool input { border-color: var(--night-line); background: var(--night-2); color: var(--on-night); }
.hb-tool input::placeholder { color: var(--on-night-2); }
.hb-tool .hb-say { color: var(--on-night); }
.hb-tool .hb-say.is-leak { color: var(--lift-ring); }
.hb-actions { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.hb-text { padding: 0.2em 0; border: 0; background: none; color: var(--on-night); font: 600 0.9375rem/1.2 var(--sans); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.hb-text:hover { color: #fff; }
.hb-tool button:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.a-body .hb-tool .fine { line-height: 1.5; color: var(--on-night-2); }
.hb-empty { padding: 14px 16px; border-radius: 14px; background: var(--night-2); font-size: 1rem; line-height: 1.5; color: var(--on-night-2); }

.hb-say { font-size: 0.9375rem; line-height: 1.5; color: var(--ink-2); overflow-wrap: anywhere; }
.hb-say[hidden] { display: none; }
.hb-say.is-leak { color: var(--lift-ink); }

.hb-ask { display: grid; gap: 8px; margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--rule); }

/* Moments to pick from: they fill the field, which stays the reader's to edit. */
.hb-chips, .hb-stops { display: flex; flex-wrap: wrap; gap: 6px; }
.hb-chips button, .hb-stops button { min-height: 2.5rem; padding: 0.45em 0.85em; border: 0; border-radius: 999px; background: var(--paper); box-shadow: inset 0 0 0 1px var(--rule); color: var(--ink-2); font: 600 0.875rem/1.2 var(--sans); text-align: left; cursor: pointer; transition: background-color 0.2s, box-shadow 0.2s, color 0.2s; }
.hb-chips button:hover, .hb-stops button:hover { box-shadow: inset 0 0 0 2px #B5BAD2; }
.hb-chips button:focus-visible, .hb-stops button:focus-visible, .hb-seg button:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.hb-chips [aria-pressed="true"], .hb-stops [aria-pressed="true"] { background: var(--night); box-shadow: none; color: #fff; }

.hb-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 12rem)); gap: 4px; }
.hb-seg button { min-height: 2.5rem; padding: 0.3em 0.7em; border: 0; border-radius: 10px; background: var(--paper); box-shadow: inset 0 0 0 1px var(--rule); color: var(--ink-2); font: 700 0.875rem/1.15 var(--sans); cursor: pointer; transition: background-color 0.2s, box-shadow 0.2s, color 0.2s; }
.hb-seg button:hover { box-shadow: inset 0 0 0 2px #B5BAD2; }
.hb-seg [aria-pressed="true"] { background: var(--night); box-shadow: none; color: #fff; }

.hb-other { display: grid; gap: 8px; }
.hb-other[hidden] { display: none; }
.hb-other .hb-lab + input { margin-bottom: 4px; }
.hb-change { display: grid; gap: 4px; margin-top: 4px; padding: 14px 16px; border-radius: 14px; background: var(--paper); min-width: 0; }
.a-body .hb-change .eyebrow { color: var(--ink-hint); }
.hb-ct { font-size: 1.0625rem; font-weight: 600; line-height: 1.45; color: var(--ink); overflow-wrap: anywhere; }
.hb-ct.is-hint { font-weight: 500; color: var(--ink-hint); }

/* ---------- Step 2: a time slides, a moment moves with the day ---------- */
/* One late morning, two ways to say when. Each row: what it was tied to, the morning as a bar, what happened. */
.hb-slide { margin: 4px 0; display: grid; gap: 14px; }
.hb-sl-day { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; line-height: 1.3; text-transform: uppercase; color: var(--ink-hint); }
.hb-sl-row { display: grid; grid-template-columns: 12.5rem minmax(0, 1fr); grid-template-areas: "h tr" ". cap"; gap: 6px 16px; align-items: center; }
.hb-sl-h { grid-area: h; font-size: 1rem; font-weight: 600; line-height: 1.3; color: var(--ink-2); }
.hb-sl-h b { color: var(--ink); }
/* The bar runs from 6 to 11 in the morning, so one hour is 20 of its 100. */
.hb-sl-track { grid-area: tr; position: relative; height: 40px; border-radius: 10px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule); overflow: hidden; }
.hb-sl-sleep { position: absolute; top: 0; bottom: 0; left: 0; width: calc(var(--w) * 1%); display: flex; align-items: center; padding-left: 12px; background: repeating-linear-gradient(135deg, var(--grid) 0 6px, #E4E7F3 6px 12px); box-shadow: inset -1px 0 0 #D4D8EA; }
.hb-sl-sleep em { font-style: normal; font-size: 0.8125rem; font-weight: 700; line-height: 1; color: var(--ink-2); }
.hb-sl-blk { position: absolute; top: 6px; bottom: 6px; left: calc(var(--x) * 1%); width: calc(100% / 15); min-width: 14px; border-radius: 6px; background: var(--ink-2); }
.hb-sl-blk.is-leak { background: #FFF8EF; outline: 2px dashed var(--lift); outline-offset: -2px; }
.hb-sl-blk.is-back { background: var(--primary); }
.hb-sl-cup { position: absolute; top: 11px; bottom: 11px; left: calc(var(--x) * 1%); width: 6px; margin-left: -3px; border-radius: 3px; background: var(--ink); }
.hb-sl-cap { grid-area: cap; font-size: 0.9375rem; font-weight: 600; line-height: 1.35; color: var(--ink-2); }
.hb-sl-cap.is-leak { color: var(--lift-ink); }
.hb-sl-cap.is-back { color: var(--primary-deep); }

/* ---------- Step 3: what a bad day leaves room for ---------- */
.hb-fit { margin: 4px 0; display: grid; gap: 18px; }
/* The words and the verdict sit together on the left, so the verdict is never far from its bar. */
.hb-fit-row { display: grid; grid-template-columns: 12.5rem minmax(0, 1fr); grid-template-areas: "l tr" "say tr"; column-gap: 16px; row-gap: 2px; align-items: center; }
.hb-fit-l { grid-area: l; align-self: end; font-size: 0.9375rem; font-weight: 600; line-height: 1.3; color: var(--ink); }
.hb-fit-l span { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--ink-hint); }
.hb-fit-say { grid-area: say; align-self: start; }
.hb-fit-tr { grid-area: tr; }
/* The track is 30 minutes wide: the most room this picture gives the habit. */
.hb-fit-tr { position: relative; height: 34px; }
.hb-fit-room { position: absolute; top: 0; bottom: 0; left: 0; width: calc(var(--w) * 1%); border-radius: 8px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule); outline: 1.5px dashed #9AA0C0; outline-offset: -1.5px; }
.hb-fit-blk { position: absolute; top: 7px; bottom: 7px; left: 4px; width: calc(var(--w) * 1% - 8px); min-width: 10px; border-radius: 5px; background: var(--ink-2); }
/* Too big for the day: the part inside the room stays grey, the part sticking out is the leak. */
.hb-fit-blk.is-over { left: 4px; width: calc(var(--w) * 1%); background: linear-gradient(90deg, var(--ink-2) 0 calc(var(--in) * 100%), #FFF8EF calc(var(--in) * 100%) 100%); box-shadow: inset 0 0 0 1.5px var(--lift); }
.hb-fit-blk.is-small { background: var(--primary); }
.hb-fit-say { font-size: 0.875rem; font-weight: 700; line-height: 1.3; color: var(--ink-2); }
.hb-fit-say.is-leak { color: var(--lift-ink); }
.hb-fit-say.is-back { color: var(--primary-deep); }
.hb-fit-key { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; line-height: 1.4; color: var(--ink-2); }
.hb-fit-key i { flex: none; width: 18px; height: 14px; border-radius: 4px; outline: 1.5px dashed #9AA0C0; outline-offset: -1.5px; }

/* ---------- Step 5: the plan, on one card ---------- */
.hb-plan { display: grid; gap: 14px; padding: clamp(18px, 3vw, 28px); border-radius: 22px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--night); min-width: 0; }
.a-body .hb-plan .eyebrow { color: var(--ink-hint); }
.hb-main { font-family: var(--serif); font-size: clamp(1.45rem, 1.2rem + 1vw, 1.95rem); font-weight: 700; line-height: 1.18; color: var(--ink); overflow-wrap: anywhere; text-wrap: balance; }
.hb-rules { display: grid; gap: 0; margin: 0; }
.hb-rules > div { display: grid; grid-template-columns: 12rem minmax(0, 1fr); gap: 4px 18px; padding: 12px 0; border-top: 1px solid var(--rule); }
.hb-rules dt { font-size: 0.875rem; font-weight: 700; line-height: 1.4; color: var(--ink); overflow-wrap: anywhere; }
.hb-rules dd { margin: 0; font-size: 1rem; line-height: 1.5; color: var(--ink-2); overflow-wrap: anywhere; }
.hb-gap { color: var(--ink-hint); font-style: italic; }
.a-step .a-code.is-tall pre { max-height: none; white-space: pre-wrap; overflow-wrap: anywhere; }

/* The trouble table gives its middle column room, and the two check cards keep their own heights. */
@media (min-width: 641px) {
  [data-sec="trouble"] .a-table td:first-child { width: 27%; }
  [data-sec="trouble"] .a-table td:nth-child(2) { width: 31%; }
}
[data-sec="checked"] .a-proof { align-items: start; }

/* ---------- Phones: each figure is drawn again for the narrow screen ----------
   The two weeks stay one row, as a strip of thin days, so the whole argument fits on one screen. The
   notes move under the strip as a short list that names its day. The two ways to say when stack, and
   the room-for-it rows put their words above the bar and the verdict under it. */
@media (max-width: 640px) {
  .hb-weeks { display: flex; flex-direction: column; gap: 6px; }
  .hb-wks, .hb-days { grid-template-columns: repeat(7, minmax(0, 1fr)) 4px repeat(7, minmax(0, 1fr)); column-gap: 2px; }
  .hb-t { height: 4.75rem; border-radius: 6px; }
  .hb-t i { left: 2px; right: 2px; bottom: 2px; height: calc((100% - 4px) * var(--h, 1)); border-radius: 4px; }
  .hb-t::before { inset: 2px; border-radius: 4px; }
  .hb-t::after { width: 10px; height: 10px; margin-left: -5px; bottom: 6px; }
  .hb-d { gap: 4px; }
  .hb-d > b { letter-spacing: 0; }
  .hb-d > b span { display: none; }
  .hb-notes { order: 3; grid-template-columns: minmax(0, 1fr); min-height: 0; gap: 6px; margin: 6px 0 0; }
  .hb-note, .hb-note.is-span { grid-column: auto !important; grid-row: auto; padding: 0 0 0 8px; border-left: 2px solid currentColor; border-bottom: 0; font-size: 0.8125rem; }
  .hb-note.is-span::before, .hb-note.is-span::after { display: none; }
  .hb-nd { display: inline; font-weight: 600; }
  .hb-read > div { padding: 10px 12px; }
  .hb-key { gap: 5px 14px; font-size: 0.8125rem; }

  .hb-sl-row { grid-template-columns: minmax(0, 1fr); grid-template-areas: "h" "tr" "cap"; }
  .hb-fit-row { grid-template-columns: minmax(0, 1fr); grid-template-areas: "l" "tr" "say"; row-gap: 6px; }
  .hb-fit-l span { display: inline; margin-left: 4px; }
  .hb-fit-say { margin-bottom: 6px; }
  .hb-rules > div { grid-template-columns: minmax(0, 1fr); }
  .hb-seg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .hb-toggle, .hb-t i, .hb-t::before, .hb-t::after, .hb-chips button, .hb-stops button, .hb-seg button { transition: none !important; }
  .is-before .hb-note { animation: none; }
}
