@layer base, components, palette, responsive;

@font-face {
  font-family: "Bodoni Moda";
  src: url("./assets/bodoni-moda-regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Lora;
  src: url("./assets/lora.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "BIZ UDPMincho";
  src: url("./assets/biz-udp-mincho-regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "BIZ UDPMincho";
  src: url("./assets/biz-udp-mincho-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

@layer base {
  :root {
    color-scheme: light;
    --font-heading: "Bodoni Moda", Georgia, "Times New Roman", serif;
    --page-title-size: clamp(1.82rem, 6.8vw, 2.27rem);
    --font-number: Lora, Georgia, "Times New Roman", serif;
    --font-text: "BIZ UDPMincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
    font-family: var(--font-text);
    font-size: 16px;
    color: #293d30;
    background: #e6ebdf;
    --ink: #293d30;
    --muted: #59675a;
    --sage: #456550;
    --paper: #f8f5ea;
    --white: #fffdf6;
    --line: #d5d8c7;
    --card-plain: #fffefa;
    --calendar-frame-ink: #647164;
  }

  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  html, body, #shell, dialog, .today-scroll, .habit-history-list, .backup-habits,
  #app.stats, #app.stats * {
    touch-action: manipulation;
  }
  body { margin: 0; min-inline-size: 280px; }
  button, input, select { font: inherit; }
  button { color: inherit; cursor: pointer; }
  :focus-visible { outline: 2px solid #315d46; outline-offset: 3px; }
  h1, h2, h3, p { margin: 0; }
  h2 { font-size: 1.06rem; letter-spacing: .035em; }
  h3 { font-size: .92rem; }
  time, .figures, .year-month { font-variant-numeric: tabular-nums; }
  .date-number, .year-month, .day-number, .history-day, .ring { font-family: var(--font-number); }
  select.picker-select { font-family: Lora, var(--font-text); }
  .ring .no-target-days { font-family: var(--font-text); }
}

@property --angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

@layer components {
  #shell {
    max-width: 540px;
    margin-inline: auto;
    min-height: 100dvh;
    background: radial-gradient(ellipse at 7% 0%, #e5eadb 0, transparent 30%), var(--paper);
    box-shadow: 0 0 45px #263c2814;
  }

  #app {
    padding: max(18px, env(safe-area-inset-top)) 18px calc(76px + env(safe-area-inset-bottom));
  }

  #app.home {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    height: 100dvh;
    padding-bottom: calc(63px + env(safe-area-inset-bottom));
  }

  .apphead {
    display: flex;
    min-height: 62px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    margin-bottom: 15px;
    gap: 8px;
  }

  .apphead.decorated {
    position: relative;
    border-bottom-color: transparent;
  }
  .apphead.decorated::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    bottom: -5px;
    pointer-events: none;
  }
  .apphead.decorated::after, .records-divider {
    height: 9px;
    background: url("./assets/title-divider.svg") center / 100% 100% no-repeat;
  }
  .apphead.decorated .settings-title, .history-section h2 {
    font-family: var(--font-heading);
    font-weight: 400;
  }
  .apphead.decorated .settings-title { font-size: var(--page-title-size); }
  .brand, .apphead.decorated .settings-title, .habit-history-panel .dialog-header h2 { letter-spacing: -.063em; }

  .brand {
    font: normal var(--page-title-size) / 1.1 var(--font-heading);
    color: #304a37;
    white-space: nowrap;
  }

  .brand-wrap { display: flex; align-items: center; gap: 8px; }

  .heading-illustration {
    display: block;
    inline-size: 42px;
    block-size: auto;
    flex: none;
    pointer-events: none;
  }

  .icon-button, .bare, .text-button {
    border: 0;
    background: transparent;
    min-height: 44px;
    padding: 6px 9px;
  }

  .icon-button {
    min-width: 44px;
    border-radius: 10px;
    color: var(--sage);
    font-size: 1.32rem;
  }

  .gear {
    position: relative;
    isolation: isolate;
    display: grid;
    place-items: center;
    inline-size: 44px;
    block-size: 44px;
    padding: 0;
  }
  .gear::before {
    content: "";
    position: absolute;
    inset: 3px;
    z-index: -1;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fdfbf3;
  }
  .gear-symbol { line-height: 1; }
  .text-button { text-decoration: underline; text-underline-offset: 3px; color: var(--sage); font-size: .875rem; }
  .danger { color: #8a494e; }
  .delete-habit-name { font-weight: 700; overflow-wrap: anywhere; }
  .habit-edit-operations { display: flex; flex-wrap: wrap; align-items: center; }

  .today-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 9px;
  }

  .today-title h2 { font-family: var(--font-heading); font-weight: 400; }
  .today-title time { color: var(--muted); font-size: .82rem; white-space: nowrap; }
  .today-scroll { min-height: 0; overflow: auto; padding: 2px; margin: -2px -2px 12px; }
  .today-scroll:empty { margin-bottom: 10px; min-height: 2px; }

  .habit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .habit-card {
    min-width: 0;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 9px;
    border: 1px solid var(--habit-color);
    border-radius: 9px;
    color: var(--habit-ink);
    background: var(--card-plain);
    text-align: start;
  }
  .habit-card.is-done { background: var(--habit-tint); }
  .today-scroll .habit-card.is-done { box-shadow: inset 0 0 0 1px var(--habit-color); }
  .habit-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border-radius: 6px;
    background: var(--habit-tint);
    font-family: Georgia, serif;
    font-size: 1.08rem;
  }
  .habit-icon img { width: 26px; height: 26px; object-fit: contain; }
  .habit-name { display: block; min-width: 0; font-weight: 700; line-height: 1.16; font-size: .875rem; }
  .name-line { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

  .calendar, .section-panel, .install {
    border: 1px solid var(--line);
    border-radius: 15px;
    background: #fffdf7d9;
  }
  .calendar {
    container-type: inline-size;
    position: relative;
    margin-block-end: 5px;
    padding: 2px 7px 8px;
    border-color: transparent;
    background: var(--card-plain);
  }
  .calendar-frame {
    --corner-width: 69.206px;
    --corner-height: 79.692px;
    /* Use the same source-image stem axis and frame edge at both corners. */
    --corner-outside-x: calc(var(--corner-width) * 124 / 858 - .22px);
    --corner-outside-top: 13.83px;
    --corner-outside-bottom: 13.75px;
    --corner-join-x-upper: calc(var(--corner-width) - var(--corner-outside-x) - 4.5px);
    --corner-join-x-lower: calc(var(--corner-width) - var(--corner-outside-x) - 4.64px);
    --corner-join-y-upper: calc(var(--corner-height) - var(--corner-outside-top) - .4px);
    --corner-join-y-lower: calc(var(--corner-height) - var(--corner-outside-bottom) - .4px);
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    pointer-events: none;
  }
  /* Open the two corners where the stems take over the border. */
  .calendar-frame > span {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 1px solid var(--calendar-frame-ink);
    clip-path: polygon(var(--corner-join-x-upper) 0, 100% 0, 100% calc(100% - var(--corner-join-y-lower)),
      calc(100% - var(--corner-join-x-lower)) calc(100% - var(--corner-join-y-lower)),
      calc(100% - var(--corner-join-x-lower)) 100%, 0 100%, 0 var(--corner-join-y-upper),
      var(--corner-join-x-upper) var(--corner-join-y-upper));
  }
  .calendar-frame::before, .calendar-frame::after {
    content: "";
    position: absolute;
    z-index: 1;
    width: var(--corner-width);
    height: var(--corner-height);
    background: url("./assets/calendar-botanical.png") 0 0 / 100% 100% no-repeat;
    /* Hide the source's separate horizontal rule where the frame takes over. */
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 84%, 8% 84%, 8% 80%, 0 80%);
  }
  .calendar-frame::before {
    top: calc(-1 * var(--corner-outside-top));
    left: calc(-1 * var(--corner-outside-x));
    transform: translate3d(.34px, 0, 0) rotate(180deg);
  }
  .calendar-frame::after {
    right: calc(-1 * var(--corner-outside-x));
    bottom: calc(-1 * var(--corner-outside-bottom));
    transform: translate3d(-.34px, 0, 0);
  }
  .monthbar { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; }
  .calendar .monthbar {
    --next-month-inset: clamp(4px, calc(50cqi - 145px), 44px);
    position: relative;
  }
  .calendar .monthbar > .icon-button { position: absolute; inset-block: 0; z-index: 1; }
  .calendar .monthbar > .icon-button:first-child {
    inset-inline-start: var(--next-month-inset);
    padding-inline: 15px 3px;
  }
  .calendar .monthbar > .icon-button:last-child {
    inset-inline-end: var(--next-month-inset);
    padding-inline: 3px 15px;
  }
  .monthbar-center { position: relative; display: grid; justify-items: center; }
  .calendar .monthbar-center { grid-column: 2; pointer-events: none; }
  .calendar .monthbar-center > button { pointer-events: auto; }
  .year-month { min-height: 44px; font-weight: 650; color: var(--sage); white-space: nowrap; }
  .month-today {
    position: absolute;
    inset-block: 0;
    inset-inline-start: min(calc(50% + 59px), calc(100% - 42px));
    inline-size: 42px;
    padding: 0;
    font: 500 .71rem / 1 var(--font-number);
    color: var(--sage);
    text-decoration: underline;
    text-underline-offset: 2px;
  }
  .calendar .month-today {
    inset-inline-start: min(calc(50% + 59px), calc(100% - 42px - var(--next-month-inset)));
  }
  @media (max-width: 345px) {
    /* Keep the two 44px tap targets in place, with the glyphs clear of the leaves. */
    .calendar .monthbar > .icon-button:first-child { padding-inline: 25px 3px; }
    .calendar .monthbar > .icon-button:last-child { padding-inline: 3px 25px; }
  }
  @media (max-width: 315px) {
    .monthbar-center .year-month { padding-inline: 3px; margin-inline-end: 14px; }
    .calendar .monthbar { --next-month-inset: 2px; }
  }
  @media (max-width: 300px) {
    .apphead.decorated, .apphead.decorated .brand-wrap { gap: 2px; }
  }
  .down { display: inline-block; width: .36em; height: .36em; border: solid currentColor; border-width: 0 1px 1px 0; transform: translate(5px, -3px) rotate(45deg); }
  .weekdays, .days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .calendar .days { grid-template-rows: repeat(6, 44px); }
  .weekdays {
    padding-block: 4px 7px;
    border-bottom: 1px solid var(--line);
    text-align: center;
    font-size: .78rem;
    color: var(--muted);
  }

  .day {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 44px;
    gap: 2px;
    padding: 1px 0 2px;
    border: 0;
    background: transparent;
    color: var(--ink);
    border-radius: 7px;
    font-size: .875rem;
  }

  .day-number { display: grid; place-items: center; height: 24px; min-width: 24px; border: 1px solid transparent; border-radius: 50%; }
  .day[aria-current="date"] .day-number { font-weight: 700; background: #e9edde; }
  .day.is-all .day-number {
    background: url("./assets/all-habits-done.svg") center / contain no-repeat border-box;
  }
  .day.is-future { color: #667366; }

  .dots { display: flex; flex-wrap: wrap; justify-content: center; width: 27px; gap: 2px; }
  .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--habit-color); }
  .day.many-dots .dots { width: 33px; gap: 1px; }
  .day.many-dots .dot { width: 3px; height: 3px; }

  #tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    margin-inline: auto;
    max-width: 540px;
    border-top: 1px solid #cbd3c1;
    padding: 3px 14px max(5px, env(safe-area-inset-bottom));
    background: #f5f4e9;
    z-index: 2;
  }

  #tabs button { position: relative; border: 0; background: transparent; min-height: 44px; font-size: .9rem; }
  #tabs button[aria-current="page"] { font-weight: 700; color: #365943; }
  #tabs button[aria-current="page"]::after {
    content: "";
    position: absolute;
    width: 23px;
    height: 2px;
    border-radius: 4px;
    background: #668669;
    bottom: 4px;
    left: calc(50% - 11.5px);
  }

  .section-panel { padding: 12px 14px; margin-bottom: 12px; }
  .section-panel h2 { margin-bottom: 8px; }
  .stats-grid, .history-calendars { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 9px; }
  .stats-chart-area { position: relative; isolation: isolate; margin: 3px 0 27px; }
  .stats-chart-area-empty { margin-block: 0; }
  .stats-chart-area-empty.history-open { min-block-size: 10rem; margin-block-start: 3px; }
  .record-tools {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    font-size: .76rem;
  }
  .history-trigger {
    position: relative;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
  }
  .history-trigger::before {
    content: "";
    position: absolute;
    inset: 4px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--white);
  }
  .history-trigger img { position: relative; }
  .records-divider { margin-block-end: 9px; }
  .stats-grid.three, .history-calendars.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat { min-width: 0; text-align: center; color: var(--habit-ink); }
  .stat-title {
    display: grid;
    align-content: end;
    min-block-size: 2.32em;
    margin: 0 0 5px;
  }
  .ring-toggle {
    display: block;
    width: min(100%, 120px);
    aspect-ratio: 1;
    margin: 0 auto 5px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    perspective: 420px;
    touch-action: manipulation;
  }
  .three .ring-toggle { width: min(100%, 102px); }
  .ring-turn {
    display: block;
    position: relative;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 860ms cubic-bezier(.18, .76, .28, 1);
  }
  .show-ring-back .ring-turn { transform: rotateY(180deg); }
  .ring, .ring-back {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    border-radius: 50%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    color: var(--habit-ink);
  }
  .ring {
    isolation: isolate;
    background: var(--white);
  }
  .ring-back {
    gap: 4px;
    padding-inline: 5px;
    transform: rotateY(180deg);
    border: 3px solid var(--habit-color);
    background: var(--habit-tint);
    text-align: center;
  }
  .ring-start {
    font: 600 clamp(.72rem, 3.3vw, .94rem) / 1.15 var(--font-number);
    white-space: nowrap;
  }
  .ring-pause { color: var(--muted); font-size: .72rem; white-space: nowrap; }
  .ring::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    z-index: -2;
    background: conic-gradient(var(--habit-color) var(--angle), var(--habit-tint) 0);
    transition: --angle 700ms cubic-bezier(.26,.56,.23,1);
  }

  .ring.grown::before { --angle: var(--target-angle); }
  .ring::after { content: ""; position: absolute; inset: 6px; border-radius: inherit; z-index: -1; background: var(--white); }
  .ring .figures { white-space: nowrap; line-height: 1.25; }
  .ring .achieved-count { font-size: 1.16rem; font-weight: 700; }
  .ring .target-count { font-size: .73rem; color: var(--muted); }
  .ring .no-target-days { font-size: .76rem; }
  .ring small { font-size: .715rem; margin-top: 2px; }
  .ring .rate { font-size: .875rem; font-weight: 600; }
  .three .ring .achieved-count { font-size: clamp(.91rem, 4.2vw, 1.08rem); }
  .three .ring .target-count { font-size: clamp(.59rem, 2.8vw, .72rem); }
  .three .ring .rate { font-size: clamp(.78rem, 3.4vw, .875rem); }
  .stat .lifetime { font-size: .78rem; color: var(--muted); white-space: nowrap; }

  .ring.bounce.grown::before {
    transition: none;
    animation: settle-arc 1520ms ease-in-out both;
  }
  @keyframes settle-arc {
    0% { --angle: 0deg; animation-timing-function: linear; }
    54% {
      --angle: var(--target-angle);
      animation-timing-function: cubic-bezier(.14, .73, .34, 1);
    }
    65% { --angle: calc(var(--target-angle) - min(12deg, var(--target-angle) * .16)); }
    78%, 100% { --angle: var(--target-angle); }
    87% { --angle: calc(var(--target-angle) - min(2.3deg, var(--target-angle) * .03)); }
  }
  .sublabel { color: var(--muted); font-size: .81rem; line-height: 1.55; }
  .history-section { margin: 0 0 14px; }
  .history-section h2 { margin-bottom: 8px; }
  .habit-history { min-width: 0; text-align: center; }
  .habit-history .stat-title { color: var(--habit-ink); }
  .history-weekdays, .history-grid {
    display: grid;
    inline-size: min(92%, 142px);
    margin-inline: auto;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    justify-items: center;
    gap: 1px 0;
    font-variant-numeric: tabular-nums;
  }
  .history-weekdays { margin-bottom: 4px; font-size: .71rem; color: var(--muted); }
  .history-day {
    display: grid;
    place-items: center;
    width: min(100%, 20px);
    aspect-ratio: 1;
    border-radius: 50%;
    font-size: .71rem;
    line-height: 1;
    color: var(--ink);
  }
  .three .history-weekdays { font-size: clamp(.59rem, 2.7vw, .73rem); }
  .three .history-day { font-size: calc(clamp(.59rem, 2.7vw, .73rem) - .05rem); }
  .history-day.done { background: color-mix(in srgb, var(--habit-color) 75%, white); }
  .history-day.future { color: #67746a; }
  .history-day.outside { color: #67746a; text-decoration: underline dotted; text-underline-offset: 2px; }
  summary { min-height: 44px; padding: 10px 5px; font-weight: 650; cursor: pointer; }
  .back-row { min-height: 44px; margin-bottom: 4px; }
  .settings-title { font-size: 1.3rem; line-height: 1.25; }
  .editor, .restore-box { padding: 12px; border-radius: 10px; background: #f6f5eb; border: 1px solid var(--line); }
  .list-row { display: flex; align-items: center; border-bottom: 1px solid #e4e4d7; gap: 4px; }
  .list-habit {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 8px;
    min-width: 0;
    text-align: start;
  }
  button.list-habit { color: var(--habit-ink, var(--ink)); }
  .list-row[data-reorder-id] {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  .reorder-handle { touch-action: none; user-select: none; -webkit-touch-callout: none; min-width: 44px; min-height: 44px; color: var(--muted); }
  .list-row.dragging, .list-row.drop-settling {
    position: relative;
    z-index: 1;
    border-radius: 8px;
    background: var(--card-plain);
  }
  .list-row.dragging {
    pointer-events: none;
    transform: translateY(var(--drag-offset, 0px));
    box-shadow: 0 5px 14px #293d3030;
  }
  .list-row.drop-before, .list-row.drop-after { position: relative; }
  .list-row.drop-before::after, .list-row.drop-after::after {
    content: "";
    position: absolute;
    z-index: 2;
    inset-inline: 0;
    height: 2px;
    border-radius: 2px;
    background: var(--sage);
    pointer-events: none;
  }
  .list-row.drop-before::after { top: 0; }
  .list-row.drop-after::after { bottom: 0; }
  button.list-habit .name-line { font-size: .9rem; }
  .editor label { display: block; font-size: .88rem; }
  .editor input[type="text"], .picker-select {
    background: var(--white);
    border: 1px solid #c2c9b8;
    border-radius: 7px;
    color: var(--ink);
    width: 100%;
    min-height: 44px;
    padding: 6px 9px;
    margin-block: 4px;
  }
  .palette-options { display: grid; grid-template-columns: repeat(5, 1fr); margin-block: 6px; }
  .swatch { min-height: 44px; border: 0; display: grid; place-items: center; background: transparent; }
  .swatch::before { content: ""; width: 23px; height: 23px; background: var(--habit-color); border-radius: 50%; }
  .swatch[aria-pressed="true"]::before { outline: 2px solid var(--habit-ink); outline-offset: 2px; }
  .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 12px; }
  .primary, .secondary {
    background: var(--sage);
    border: 1px solid var(--sage);
    color: white;
    border-radius: 8px;
    min-height: 44px;
    padding: 7px 15px;
    font-weight: 650;
    font-size: .875rem;
  }
  .secondary { background: var(--white); border-color: var(--line); color: var(--sage); }
  .preview-card { width: min(100%, 184px); margin-block: 4px; }
  .error-text { color: #883b42; font-size: .84rem; line-height: 1.55; }
  .addon { margin-top: 10px; }
  .install { padding: 23px 18px; margin-top: 32px; }
  .install h1 { margin-bottom: 20px; }
  .install h2 { margin-bottom: 10px; }
  .install ol { padding-left: 24px; line-height: 1.8; }
  .install img { width: 58px; height: 58px; border-radius: 13px; margin-bottom: 8px; }

  dialog {
    width: min(440px, calc(100% - 28px));
    max-height: min(88dvh, 640px);
    padding: 15px;
    background: var(--white);
    color: var(--ink);
    border: 1px solid #aebda9;
    border-radius: 15px;
    box-shadow: 0 12px 50px #273d3237;
  }
  dialog::backdrop { background: #253b305c; }
  .dialog-header { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
  .habit-history-panel {
    position: absolute;
    z-index: 1;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #aebda9;
    border-radius: 15px;
    background: var(--white);
  }
  .habit-history-panel::before {
    content: "";
    position: absolute;
    right: 2px;
    bottom: -1px;
    width: min(46%, 158px);
    height: 72%;
    background: url("./assets/history-botanical.svg") right bottom / contain no-repeat;
    opacity: .77;
    pointer-events: none;
  }
  .habit-history-panel .dialog-header, .habit-history-list { position: relative; }
  .habit-history-group h3, .habit-history-entry-title, .habit-history-entry li {
    text-shadow: 0 0 3px var(--white), 1px 0 1px var(--white), -1px 0 1px var(--white);
  }
  .habit-history-panel .dialog-header {
    flex: none;
    min-block-size: 52px;
    padding: 4px 14px;
    border-bottom: 1px solid var(--line);
  }
  .habit-history-panel .dialog-header h2 { font: normal 1.55rem / 1.2 var(--font-heading); }
  .habit-history-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 6px 14px 16px;
    font-size: .875rem;
  }
  .habit-history-list:focus-visible { outline-offset: -3px; }
  .habit-history-group h3 { color: var(--sage); padding-block: 12px 6px; border-block-end: 1px solid var(--line); }
  .habit-history-group.ended { margin-block-start: 8px; }
  .habit-history-entry {
    padding-block: 9px;
  }
  .habit-history-entry-title { display: flex; align-items: baseline; gap: 8px; }
  .habit-history-entry-title h4 { min-width: 0; }
  .habit-history-total {
    flex: none;
    color: var(--muted);
    font: .78rem var(--font-number);
    white-space: nowrap;
  }
  .habit-history-entry h4 { margin: 0; overflow-wrap: anywhere; font-size: .88rem; line-height: 1.5; }
  .habit-history-entry ol { list-style: none; padding: 0; margin: 3px 0 0 8px; }
  .habit-history-entry li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 3px;
    padding-block: 2px;
  }
  .habit-history-entry time { font-family: var(--font-number); white-space: nowrap; }
  .habit-history-current { color: var(--sage); font-size: .76rem; margin-left: 4px; }
  .dialog-section { margin-top: 8px; }
  .dialog-section h3 { margin-bottom: 7px; }
  .dialog-section + .dialog-section { border-top: 1px solid var(--line); padding-top: 10px; }
  .backup-filename, .backup-habits { overflow-wrap: anywhere; }
  .backup-habits { max-block-size: 25dvh; overflow: auto; overscroll-behavior: contain; }
  .picker-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }

  #notice {
    position: fixed;
    z-index: 9;
    inset-inline: 12px;
    margin-inline: auto;
    bottom: calc(58px + env(safe-area-inset-bottom));
    max-width: 490px;
    border-radius: 9px;
    padding: 9px 12px;
    background: #f4e6e1;
    color: #723d42;
    border: 1px solid #ccaaa9;
    font-size: .86rem;
    line-height: 1.5;
    pointer-events: none;
  }
}

@layer palette {
  .tone-sage { --habit-ink: #3d624b; --habit-color: #91ad99; --habit-tint: #e3eee3; }
  .tone-rose { --habit-ink: #754c4a; --habit-color: #c69f9e; --habit-tint: #f4e5e3; }
  .tone-blue { --habit-ink: #416377; --habit-color: #91afc0; --habit-tint: #e1edf3; }
  .tone-greige { --habit-ink: #63564a; --habit-color: #b5aa9c; --habit-tint: #eee9df; }
  .tone-lavender { --habit-ink: #675477; --habit-color: #b0a3bc; --habit-tint: #ece7f0; }
  .tone-tea { --habit-ink: #6b562f; --habit-color: #c6b395; --habit-tint: #f3eade; }
  .tone-mint { --habit-ink: #416659; --habit-color: #a1bcb2; --habit-tint: #e1eee8; }
  .tone-yellow { --habit-ink: #6d5b2d; --habit-color: #d4c38e; --habit-tint: #f5efd7; }
  .tone-clay { --habit-ink: #774f3f; --habit-color: #ba9885; --habit-tint: #f2e5df; }
  .tone-olive { --habit-ink: #515d39; --habit-color: #a0a788; --habit-tint: #e8ecdf; }
}

@layer responsive {
  @media (max-width: 365px) {
    #app { padding-inline: 12px; }
    .habit-card { gap: 6px; padding-inline: 6px; }
    .habit-icon { width: 28px; height: 28px; flex-basis: 28px; }
    .section-panel { padding-inline: 9px; }
  }

  @media (max-height: 700px) {
    .apphead { min-height: 46px; margin-bottom: 8px; }
    .today-title { margin-bottom: 5px; }
    .today-scroll { margin-bottom: 7px; }
    .calendar { padding-bottom: 3px; }
  }

  @media (max-height: 520px) {
    #app.home { height: auto; min-height: 100dvh; }
  }

  @media (prefers-reduced-motion: reduce) {
    .ring::before { transition: none; }
    .ring.bounce.grown::before { animation: none; }
    .ring-turn, .show-ring-back .ring-turn, .ring-back { transform: none; transition: none; }
    #app:not(.show-ring-back) .ring-back, .show-ring-back .ring { visibility: hidden; }
  }
}

