:root {
  --accent: #2F6FEB;
  --accent-soft: #EEF3FE;
  --accent-ring: #B7CCF8;
  --ink: #1B1F24;
  --ink-2: #454C56;
  --muted: #6B7280;
  --faint: #9CA3AF;
  --canvas: #F4F5F7;
  --sheet: #FFFFFF;
  --line: #E5E7EB;
  --hair: #F0F1F4;
  --hover: #F9FAFB;
  --hover-line: #D5D9DF;
  --wash: rgba(27, 31, 36, 0.06);
  --ring: #C9CED6;
  --foot: #FAFBFC;
  --button: #F1F2F4;
  --danger: #C5221F;
  --danger-soft: #FDECEA;
  --legio: #38761D;
  --gold-lo: #7A5A1C;
  --gold-ink: #9C7428;
  --gold-hi: #D9B45C;
  --nudge: #DBA23A;
  --nudge-fill: #FBF1D9;

  --empty: #F1F3F4;
  --empty-past: #C4C8CE;
  --empty-today: #E2E5E9;
  --done: #93C47D;
  --done-ink: #38761D;
  --partial: #B0D382;
  --partial-ink: #326A1A;
  --miss: #DD7E6B;
  --miss-ink: #85200C;
  --off-day: repeating-linear-gradient(135deg, #3C4043 0 4px, #5F6368 4px 8px);

  --score-good: #6AA84F;
  --score-good-ink: #274E13;
  --score-mid: #F1C232;
  --score-mid-ink: #5C3F00;
  --score-bad: #CC4125;
  --score-bad-ink: #5B0F00;
  --i-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%2338761D' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 6l8 8M14 6l-8 8'/%3E%3C/svg%3E");
  --i-slash: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23326A1A' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M14 6l-8 8'/%3E%3C/svg%3E");
  --i-cross: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5.5 10h9' stroke='%2385200C' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");

  --head-row: 30px;
  --date-row: 36px;
  --body-row: 40px;
  --rail: 28px;
  --rail-gap: 8px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 12px 32px -16px rgba(16, 24, 40, 0.14);
  --shadow-fab: 0 2px 8px -2px rgba(16, 24, 40, 0.18), 0 0 0 1px rgba(16, 24, 40, 0.06);
  --shadow-fab-hover: 0 4px 12px -2px rgba(16, 24, 40, 0.22), 0 0 0 1px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --accent: #5B8DEF;
  --accent-soft: rgba(91, 141, 239, 0.18);
  --accent-ring: #3D5F9F;
  --ink: #E6E8EB;
  --ink-2: #C3C8CF;
  --muted: #9098A3;
  --faint: #6B727D;
  --canvas: #0F1114;
  --sheet: #181B20;
  --line: #2B2F36;
  --hair: #22252B;
  --hover: #20242A;
  --hover-line: #3A3F47;
  --wash: rgba(255, 255, 255, 0.08);
  --ring: #4A5059;
  --foot: #1C1F24;
  --button: #262A31;
  --danger: #F28B82;
  --danger-soft: rgba(242, 139, 130, 0.14);
  --legio: #93C47D;
  --gold-lo: #B8913F;
  --gold-ink: #E9C877;
  --gold-hi: #FFF7DD;
  --nudge: var(--gold-ink);
  --nudge-fill: var(--empty-today);

  --empty: #21252A;
  --empty-past: #3A3F47;
  --empty-today: #2C3138;
  --done: #7FAF69;
  --partial: #A0C474;
  --miss: #CF7462;
  --off-day: repeating-linear-gradient(135deg, #2A2D31 0 4px, #4A4F55 4px 8px);

  --score-good: #5E9A45;
  --score-mid: #D9AE2C;
  --score-bad: #B83B22;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
  --shadow-fab: 0 2px 8px -2px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--line);
  --shadow-fab-hover: 0 4px 12px -2px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--hover-line);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif, "Apple Color Emoji", "Noto Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  padding: clamp(24px, 3vw, 44px) clamp(12px, 2vw, 32px) 56px;
  touch-action: manipulation;
}

html { -webkit-tap-highlight-color: transparent; }

/* The banner styles its own host as a block, which would beat the browser's [hidden]. */
legio-offer[hidden] { display: none; }

.wrap {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding-right: calc(var(--rail) + var(--rail-gap));
}

/* Header */

/* The sheet sets the page's width; the header fits in whatever that is. */
.topbar {
  contain: inline-size;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 32px;
  margin-bottom: 20px;
  padding-left: calc(var(--rail) + var(--rail-gap));
  flex-wrap: wrap;
}

.title {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  min-height: 20px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--muted);
}

.brand.member::before { display: none; }

.brand::before {
  --h-cell: linear-gradient(var(--score-good), var(--score-good));
  --h-off: repeating-linear-gradient(135deg, #3C4043 0 1.5px, #5F6368 1.5px 3px);
  content: "";
  flex: none;
  width: 20px;
  height: 20px;
  background:
    var(--h-cell) 0 0 / 6px 6px no-repeat,
    var(--h-cell) 0 7px / 6px 6px no-repeat,
    var(--h-cell) 0 14px / 6px 6px no-repeat,
    var(--h-cell) 14px 0 / 6px 6px no-repeat,
    var(--h-cell) 14px 7px / 6px 6px no-repeat,
    var(--h-cell) 14px 14px / 6px 6px no-repeat,
    linear-gradient(var(--partial), var(--partial)) 7px 7px / 6px 6px no-repeat,
    var(--h-off) 7px 0 / 6px 6px no-repeat,
    var(--h-off) 7px 14px / 6px 6px no-repeat;
}

h1 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--ink);
}

h1 .year {
  font-weight: 400;
  color: var(--faint);
}

/* Squad: you, your squad mates and a + to invite more, one tap to see anyone's sheet. */
.squad {
  display: flex;
  gap: 4px;
  margin: 0 0 12px;
  padding-left: calc(var(--rail) + var(--rail-gap) - 4px);
}

.face {
  display: grid;
  place-items: center;
  padding: 4px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.face:hover .pic { box-shadow: inset 0 0 0 1px var(--tone, var(--line)), 0 0 0 3px var(--wash); }

.face .pic {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--tone-fill, var(--button));
  box-shadow: inset 0 0 0 1px var(--tone, var(--line));
  color: var(--muted);
  overflow: hidden;
  transition: box-shadow 0.12s;
}

.face .pic b { font-size: 16px; font-weight: 600; color: var(--tone, var(--muted)); }
/* A skull on the face of anyone who didn't track yesterday. */
.face { position: relative; }
.face .skull {
  position: absolute;
  right: 0;
  bottom: 0;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--canvas);
  color: var(--ink);
}
.face .skull svg { width: 14px; height: 14px; }
.face.add .pic { background: none; box-shadow: none; outline: 1.5px dashed var(--line); outline-offset: -1.5px; }
.face.add:hover .pic { outline-color: var(--faint); box-shadow: 0 0 0 3px var(--wash); }
.face .pic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.face[aria-current="true"] .pic { box-shadow: 0 0 0 2px var(--canvas), 0 0 0 3.5px var(--faint); }

/* Someone else's sheet is for looking at. */
body.viewing .row-rail > * { visibility: hidden; }
body.viewing .legend .hint { display: none; }

.title-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.week-nav,
.sheet-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.week-nav:not(:has(button:not([hidden]))) { display: none; }

.week-nav button,
.sheet-actions button,
.goal-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--sheet);
  box-shadow: var(--shadow-sm);
  color: var(--ink-2);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.12s, border-color 0.12s;
}

.week-nav button:hover,
.sheet-actions button:hover,
.goal-add:hover { background: var(--hover); border-color: var(--hover-line); }

.week-nav button[hidden] { display: none; }

/* Stepping weeks is occasional, so the arrows stay quiet beside the week. */
.week-nav .week-step {
  width: 32px;
  padding: 0;
  justify-content: center;
  border-color: transparent;
  background: none;
  box-shadow: none;
  color: var(--faint);
}

.week-nav .week-step:hover { background: var(--wash); border-color: transparent; color: var(--ink); }
.week-step svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.week-step:not([hidden]) + .week-step { margin-left: -6px; }

.sheet-actions button[hidden] { display: none; }
#use-routine::before { content: none; }

.sheet-actions button::before {
  content: "+";
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  color: var(--muted);
}

/* Goals */

/* A list jotted on ruled lines in the page's free space, not a panel of its own. */
.week-goals {
  --goal-row: 32px;
  display: flex;
  flex-direction: column;
  align-self: start;
  width: 280px;
  margin-bottom: 20px;
}

body.viewing .week-goals:not(:has(.goal-chip)) { display: none; }

.goal-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  box-sizing: border-box;
  min-height: var(--goal-row);
  /* A one-line goal is exactly one row: its 20px of content plus the line under it. */
  padding: calc((var(--goal-row) - 21px) / 2) 0;
  border-bottom: 1px solid var(--line);
}

/* The words come first; at the end of the line, a soft box takes a / or an x.
   The button reaches past the box so it's easy to hit without crowding the line. */
.goal-chip .goal-mark {
  --box: 18px;
  position: relative;
  order: 1;
  flex: none;
  width: 26px;
  height: 20px;
  margin-right: -4px;
  padding: 0;
  border: 0;
  cursor: pointer;
  font-size: 0;
  color: var(--muted);
  background: transparent;
}

.goal-chip .goal-mark::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--box);
  height: var(--box);
  translate: -50% -50%;
  border-radius: 5px;
  background: var(--wash);
  transition: background-color 0.12s;
}

.goal-chip .goal-mark:hover::before { background: color-mix(in srgb, var(--ink) 11%, transparent); }

.goal-chip .goal-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  -webkit-mask: center / 12px no-repeat;
  mask: center / 12px no-repeat;
}

.goal-chip .goal-mark[data-v=""]::after { display: none; }
.goal-chip .goal-mark[data-v="x"]::after { -webkit-mask-image: var(--i-check); mask-image: var(--i-check); }
.goal-chip .goal-mark[data-v="/"]::after { -webkit-mask-image: var(--i-slash); mask-image: var(--i-slash); }

/* Crossed off, like on paper. */
.goal-chip:has(.goal-mark[data-v="x"]) .goal-text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--faint);
  text-decoration-thickness: 1.5px;
}

/* Long goals wrap rather than hide behind an ellipsis. */
.goal-chip .goal-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  color: var(--ink);
  outline: none;
  overflow-wrap: anywhere;
}

/* Blank lines, waiting to be written on. */
.week-goals .goal-add {
  height: var(--goal-row);
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  color: transparent;
}

.week-goals .goal-add:hover { background: transparent; }
.week-goals .goal-add { cursor: text; }

/* Sheet */

.sheet-layout {
  display: flex;
  align-items: flex-start;
  width: max-content;
  max-width: 100%;
}

.sheet-card {
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: auto;
}

table {
  width: max-content;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

col.slot { width: 76px; }
col.weight { width: 52px; }
col.day { width: 76px; }

th, td {
  padding: 0 8px;
  height: var(--body-row);
  border: 0;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

thead th {
  font-weight: 500;
  text-overflow: clip;
}

.row-blue th {
  height: var(--head-row);
  padding-top: 10px;
  vertical-align: bottom;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.row-band th {
  height: var(--date-row);
  box-shadow: inset 0 -1px 0 var(--line);
}

.row-band th:not([data-day]) {
  vertical-align: middle;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.row-band th.slot { text-align: right; padding-right: 12px; }
.row-band th.habit { text-align: left; padding-left: 18px; }

.row-band th[data-day] {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.row-band th[data-day] .date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
}

.row-band th[data-day] .date .wide-only { font-weight: 500; color: var(--faint); }

.row-blue th.today { color: var(--accent); }

.row-band th.today .date {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px -2px rgba(47, 111, 235, 0.6);
}

.row-band th.today .date .wide-only { color: rgba(255, 255, 255, 0.8); }

.center { text-align: center; }
.left { text-align: left; }
.right { text-align: right; }

.habit {
  font-weight: 450;
  white-space: nowrap;
  min-width: 80px;
  max-width: 220px;
  width: 220px;
  padding-right: 28px;
  overflow: hidden;
  text-overflow: ellipsis;
}

td.habit:focus { text-overflow: clip; }

/* Long habit names wrap onto a second line instead of hiding behind an ellipsis. */
tbody td.habit {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.3;
  padding-top: 7px;
  padding-bottom: 7px;
}

.habit.strong { font-weight: 650; }

.r-white { --tone: #CDD2D9; --tone-fill: #FFFFFF; --tone-ink: var(--ink); }
.r-neutral { --tone: #A3AAB4; --tone-fill: #F3F4F6; --tone-ink: #3F4650; }
.r-dark { --tone: #2B2F36; --tone-fill: #E7E9EC; --tone-ink: #1B1F24; }
.r-red { --tone: #D8707F; --tone-fill: #FBE9EB; --tone-ink: #8C2A3C; }
.r-gold { --tone: #DBA23A; --tone-fill: #FBF1D9; --tone-ink: #6B4A0C; }
.r-green { --tone: #88AE72; --tone-fill: #EEF5E8; --tone-ink: #36592A; }
.r-teal { --tone: #47A2B3; --tone-fill: #E4F2F5; --tone-ink: #1B5864; }
.r-blue { --tone: #6690DA; --tone-fill: #E8EFFC; --tone-ink: #264A8C; }
.r-purple { --tone: #9282CC; --tone-fill: #EFEBFA; --tone-ink: #4A3A8E; }

[data-theme="dark"] .r-white { --tone: #5A616B; --tone-fill: var(--sheet); --tone-ink: var(--ink); }
[data-theme="dark"] .r-neutral { --tone: #7C848F; --tone-fill: #22252A; --tone-ink: #C3C8CF; }
[data-theme="dark"] .r-dark { --tone: #D5D9DF; --tone-fill: #2C3037; --tone-ink: #F1F3F5; }
[data-theme="dark"] .r-red { --tone: #D8707F; --tone-fill: #35202A; --tone-ink: #F2B8C1; }
[data-theme="dark"] .r-gold { --tone: #DBA23A; --tone-fill: #342B17; --tone-ink: #F0D08C; }
[data-theme="dark"] .r-green { --tone: #88AE72; --tone-fill: #202C1C; --tone-ink: #BFDCAE; }
[data-theme="dark"] .r-teal { --tone: #47A2B3; --tone-fill: #172C33; --tone-ink: #A3D6E0; }
[data-theme="dark"] .r-blue { --tone: #6690DA; --tone-fill: #1C2640; --tone-ink: #B4C9F0; }
[data-theme="dark"] .r-purple { --tone: #9282CC; --tone-fill: #27223B; --tone-ink: #CBC1EE; }

tbody td {
  box-shadow: inset 0 1px 0 var(--hair);
}

tbody tr:first-child td { box-shadow: none; }

tr[data-id] td.meta {
  position: relative;
  padding-left: 14px;
  background: linear-gradient(var(--tone), var(--tone)) 0 0 / 4px 100% no-repeat var(--tone-fill);
  color: var(--tone-ink);
}

tbody td.slot {
  padding: 0 12px 0 8px;
  vertical-align: top;
  text-align: right;
  text-overflow: clip;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

tbody td.slot.same { box-shadow: none; }
tbody td.slot.same:not(:focus, .is-cursor) { color: transparent; }
tbody td.slot[data-editing] { color: var(--ink); }

th.weight,
td.weight {
  padding-left: 4px;
  padding-right: 4px;
}

.weight-icon {
  display: none;
  width: 13px;
  height: 13px;
  vertical-align: -1px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
  color: var(--faint);
}

td.weight {
  background: var(--tone-fill);
  color: var(--tone-ink);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

tr.is-hover td.meta,
tr.is-hover td.weight { filter: brightness(0.97); }

/* Marks */

.mark {
  position: relative;
  z-index: 0;
  padding: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: pan-y;
  color: transparent;
  outline: none;
}

.mark::before {
  content: "";
  position: absolute;
  inset: 0 0 1px 1px;
  z-index: -1;
  background: var(--empty) center / 14px no-repeat;
}

.mark[data-v=""][data-when="past"]::before { background-color: var(--empty-past); }
.mark[data-v=""][data-when="today"]::before { background-color: var(--empty-today); }
.mark[data-v="x"]::before { background-color: var(--done); background-image: var(--i-check); }
.mark:not([data-v=""], [data-v="x"], [data-v="/"], [data-v="-"], [data-v="_"]) { color: var(--done-ink); }
.mark:not([data-v=""], [data-v="x"], [data-v="/"], [data-v="-"], [data-v="_"])::before { background-color: var(--done); }
.mark[data-v="/"]::before { background-color: var(--partial); background-image: var(--i-slash); }
.mark[data-v="-"]::before { background-color: var(--miss); background-image: var(--i-cross); }
.mark[data-v="_"]::before { background: var(--off-day); }
.mark[contenteditable="true"] { color: var(--done-ink); caret-color: var(--done-ink); cursor: text; user-select: text; -webkit-user-select: text; }
.mark[contenteditable="true"]::before { background: var(--done); box-shadow: inset 0 0 0 2px var(--accent); }

/* Marking is the most frequent action, so its motion is a press, not a show:
   the fill settles from just under full size. Clearing only fades the old fill. */
.mark.arrive::before { animation: mark-arrive 0.12s cubic-bezier(0.2, 0, 0, 1); }

@keyframes mark-arrive {
  from { transform: scale(0.94); }
}

/* A tap on an off day meets a closed door: a small shake, and nothing changes. */
.mark.locked::before { animation: mark-locked 0.18s ease-in-out; }

@keyframes mark-locked {
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

.mark.leave::after {
  content: "";
  position: absolute;
  inset: 0 0 1px 1px;
  z-index: -1;
  pointer-events: none;
  background: var(--done) center / 14px no-repeat;
  animation: mark-leave 0.12s ease-out forwards;
}
.mark.leave[data-was="x"]::after { background-image: var(--i-check); }
.mark.leave[data-was="/"]::after { background-color: var(--partial); background-image: var(--i-slash); }
.mark.leave[data-was="-"]::after { background-color: var(--miss); background-image: var(--i-cross); }
.mark.leave[data-was="_"]::after { background: var(--off-day); }

@keyframes mark-leave {
  to { opacity: 0; }
}

td[data-field] {
  cursor: default;
  line-height: var(--body-row);
}

.mark:focus-visible::before { box-shadow: inset 0 0 0 2px var(--accent); }
td[data-field]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.mark.is-cursor::before { box-shadow: inset 0 0 0 2px var(--accent); }
td[data-field].is-cursor { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Until the very first mark, today's top cell beckons in Legio gold */
.mark.first-nudge { z-index: 2; overflow: visible; }
.mark.first-nudge[data-v=""]::before {
  background-color: var(--nudge-fill);
  animation: first-nudge 1.8s ease-in-out infinite;
}

@keyframes first-nudge {
  50% { box-shadow: inset 0 0 0 2px var(--nudge), 0 0 14px -2px color-mix(in srgb, var(--nudge) 70%, transparent); }
}

/* Once ever: the first fully marked day gets an Elden Ring style banner. Drama is allowed
   here only because it never repeats. */
.felled {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  pointer-events: none;
  --felled: var(--score-bad);
  animation: felled-fade 4.2s ease forwards;
}

.felled::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: min(240px, 34vh);
  transform: translateY(-50%);
  background: linear-gradient(to bottom, transparent, rgb(0 0 0 / 0.9) 25%, rgb(0 0 0 / 0.9) 75%, transparent);
}

.felled-title {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 0 16px;
  text-align: center;
}

.felled-title b,
.felled-title b::after {
  font-family: Cinzel, Georgia, serif;
  font-weight: 700;
  /* Sized by title length (--len), so every title fits on one line at any width. */
  font-size: min(68px, (100vw - 32px) / (var(--len) * 0.74));
  letter-spacing: 0.08em;
  line-height: 1.1;
  white-space: nowrap;
  color: color-mix(in srgb, var(--felled) 70%, white);
  text-shadow: 0 2px 4px rgb(0 0 0 / 0.9), 0 0 28px color-mix(in srgb, var(--felled) 50%, transparent);
}

.felled-title b { position: relative; animation: felled-in 1.6s cubic-bezier(0.2, 0.7, 0.2, 1) both; }

.felled-title b::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  opacity: 0;
  animation: felled-ghost 2.2s ease-out 0.3s both;
}

.felled.mid { --felled: var(--score-mid); }
.felled.good { --felled: var(--score-good); }

@keyframes felled-fade {
  0% { opacity: 0; }
  8%, 78% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes felled-in {
  from { opacity: 0; transform: scale(1.06); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

@keyframes felled-ghost {
  0% { opacity: 0.3; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.35); }
}

/* A selected cell takes text before it's being edited, its text quietly selected. */
td[data-field][contenteditable="true"]:not([data-editing]) { caret-color: transparent; cursor: default; }
td[data-field][contenteditable="true"]:not([data-editing])::selection,
td[data-field][contenteditable="true"]:not([data-editing]) *::selection { background: transparent; }

td[data-field][data-editing] {
  cursor: text;
  outline: none;
  background: var(--sheet);
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* Row tools (desktop rail) */

.row-rail {
  flex: none;
  width: calc(var(--rail) + var(--rail-gap));
  display: flex;
  flex-direction: column;
  padding-top: calc(1px + var(--head-row) + var(--date-row));
}

.row-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: var(--body-row);
  padding-right: var(--rail-gap);
  opacity: 0;
  transition: opacity 0.12s;
}

.row-tools:hover,
.row-tools.is-hover,
.row-tools:focus-within,
.row-tools.is-picking,
.row-tools.drag-over { opacity: 1; }

.row-tools button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  transition: background-color 0.12s, color 0.12s;
}

.row-tools button:hover,
.row-tools.is-picking .drag { color: var(--ink-2); background: var(--wash); }

.row-tools .drag {
  cursor: grab;
  letter-spacing: -1px;
  font-size: 14px;
}

.row-tools .drag:active { cursor: grabbing; }

/* The mark menu follows the platform: an iOS style list under a held cell,
   a compact macOS style menu at the cursor. */
.mark-menu {
  position: fixed;
  z-index: 30;
  min-width: 190px;
  padding: 5px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--sheet) 82%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 0 0 0.5px color-mix(in srgb, var(--ink) 18%, transparent), 0 10px 32px -6px rgba(16, 24, 40, 0.28), 0 2px 6px rgba(16, 24, 40, 0.08);
  animation: mark-menu-in 0.12s cubic-bezier(0.2, 0, 0, 1);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mark-menu[hidden] { display: none; }

@keyframes mark-menu-in {
  from { opacity: 0; transform: scale(0.96); }
}

.mark-menu button {
  display: grid;
  grid-template-columns: 16px 1fr auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 28px;
  padding: 0 8px 0 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: default;
  outline: none;
}

.mark-menu button::before { content: ""; }
.mark-menu button[aria-checked="true"]::before { content: "✓"; font-size: 12px; font-weight: 700; }
.mark-menu button > span { grid-column: 2; }

.mark-menu button:hover,
.mark-menu button:focus-visible,
.mark-menu button.is-over { background: var(--accent); color: #fff; }

.mark-menu kbd {
  min-width: 0;
  height: auto;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
}

.mark-menu button:is(:hover, :focus-visible, .is-over) kbd { color: rgba(255, 255, 255, 0.8); }

.mark-menu i {
  grid-column: 4;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--empty) center / 12px no-repeat;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
  color: var(--done-ink);
}

.mark-menu [data-v="x"] i { background-color: var(--done); background-image: var(--i-check); box-shadow: none; }
.mark-menu [data-v="/"] i { background-color: var(--partial); background-image: var(--i-slash); box-shadow: none; }
.mark-menu [data-v="-"] i { background-color: var(--miss); background-image: var(--i-cross); box-shadow: none; }
.mark-menu [data-v="_"] i { background: var(--off-day); box-shadow: none; }
.mark-menu [data-v="#"] i { background-color: var(--done); box-shadow: none; }

.mark-menu hr {
  height: 1px;
  margin: 5px 6px;
  border: 0;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
}

.mark.is-menu::before { box-shadow: inset 0 0 0 2px var(--accent); }

@media (pointer: coarse) {
  .mark-menu {
    min-width: 230px;
    padding: 0;
    border-radius: 13px;
    overflow: hidden;
  }

  .mark-menu button {
    grid-template-columns: 18px 1fr auto;
    height: 44px;
    padding: 0 14px 0 12px;
    border-radius: 0;
    font-size: 16px;
  }

  .mark-menu button + button { box-shadow: inset 0 0.5px 0 color-mix(in srgb, var(--ink) 14%, transparent); }
  .mark-menu kbd { display: none; }
  .mark-menu i { grid-column: 3; width: 22px; height: 22px; background-size: 14px; font-size: 10px; }
  .mark-menu hr { height: 7px; margin: 0; background: color-mix(in srgb, var(--ink) 8%, transparent); }

  .mark-menu button:hover,
  .mark-menu button:focus-visible { background: none; color: var(--ink); }
  .mark-menu button:active,
  .mark-menu button.is-over { background: color-mix(in srgb, var(--ink) 10%, transparent); color: var(--ink); }
}

/* The habit menu keeps colors in a submenu, as native menus do: it flies
   out to the side at a desktop cursor and takes the menu's place on touch. */
.row-menu {
  position: fixed;
  z-index: 30;
  animation: mark-menu-in 0.12s cubic-bezier(0.2, 0, 0, 1);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.row-menu[hidden] { display: none; }
.row-menu .mark-menu { position: static; animation: none; }

.row-menu .mark-menu button { grid-template-columns: 1fr auto; padding-left: 10px; }
.row-menu .mark-menu button::before { display: none; }
.row-menu .mark-menu button > span { grid-column: 1; }
.row-menu .mark-menu i { grid-column: 2; background: none; box-shadow: none; color: inherit; }
.row-menu svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.row-menu .danger { color: var(--danger); }
.row-menu .mark-menu button:disabled { color: var(--faint); }
.row-menu .mark-menu button.danger:is(:hover, :focus-visible) { background: var(--danger); color: #fff; }

.row-menu [data-action="colors"] { grid-template-columns: 1fr auto auto; }
.row-menu [data-action="colors"] i { grid-column: 3; }

.row-menu .dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--tone);
}

.row-menu .r-white .dot,
.row-menu .dot.r-white { background: var(--tone-fill); box-shadow: inset 0 0 0 1.5px var(--tone); }

.row-menu .row-colors { display: none; position: absolute; top: 0; left: calc(100% + 2px); }
.row-menu.show-colors .row-colors { display: block; }
.row-menu.flip .row-colors { left: auto; right: calc(100% + 2px); }
.row-menu.show-colors [data-action="colors"] { background: var(--accent); color: #fff; }

.row-menu .row-colors button { grid-template-columns: 16px 1fr auto; padding-left: 6px; }
.row-menu .row-colors button::before { display: block; }
.row-menu .row-colors button > span { grid-column: 2; }
.row-menu .row-colors .dot { grid-column: 3; }
.row-menu .menu-back,
.row-menu .menu-back + hr { display: none; }

@media (pointer: coarse) {
  .row-menu svg { width: 18px; height: 18px; }
  .row-menu .dot { width: 16px; height: 16px; }
  .row-menu .mark-menu button { padding: 0 16px; }
  .row-menu .mark-menu button.danger:is(:hover, :focus-visible) { background: none; color: var(--danger); }
  .row-menu .mark-menu button.danger:is(:active, .is-over) { color: var(--danger); }

  .row-menu .row-colors { position: static; }
  .row-menu.show-colors #row-main { display: none; }
  .row-menu.show-colors [data-action="colors"] { background: none; color: var(--ink); }
  .row-menu .row-colors button { grid-template-columns: 18px 1fr auto; padding: 0 16px 0 12px; }
  .row-menu .menu-back { display: grid; grid-template-columns: auto 1fr; gap: 6px; font-weight: 600; }
  .row-menu .menu-back i { grid-column: 1; }
  .row-menu .menu-back > span { grid-column: 2; }
  .row-menu .menu-back + hr { display: block; }

  /* A held habit is lifted, not selected: its text only selects once it's being edited. */
  tbody td[data-field]:not([contenteditable="true"]) {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
}

tr.is-lifted td[data-field="habit"] { box-shadow: inset 0 0 0 2px var(--accent); }

/* Carrying a held row: it follows the finger and the others make way. */
tbody.is-sorting tr { transition: transform 0.12s cubic-bezier(0.2, 0, 0, 1); }
tbody.is-sorting tr.is-dragging { position: relative; z-index: 3; transition: none; filter: drop-shadow(0 8px 16px rgba(16, 24, 40, 0.22)); }
tbody.is-sorting tr.is-dragging.is-dropping { transition: transform 0.12s cubic-bezier(0.2, 0, 0, 1); }
tbody.is-sorting tr.is-dragging td { box-shadow: none; }
tbody.is-sorting tr.is-dragging td:not(.meta, .weight) { background-color: var(--sheet); }

@media (prefers-reduced-motion: reduce) {
  .mark-menu,
  .row-menu { animation: none; }
  tbody.is-sorting tr { transition: none; }
}

tr.dragging,
.row-tools.dragging { opacity: 0.45; }
tr.drag-over td,
.row-tools.drag-over { box-shadow: inset 0 2px 0 var(--accent); }

/* Score row */

tfoot td {
  height: var(--body-row);
  background: var(--foot);
  box-shadow: inset 0 1px 0 var(--line);
}

tfoot .score-label {
  text-align: right;
  padding-left: 18px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

tfoot td.slot { overflow: visible; }

.day-score {
  position: relative;
  z-index: 0;
  padding: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.day-score:empty::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 2px;
  margin: -1px 0 0 -6px;
  border-radius: 1px;
  background: var(--line);
}

.day-score::before {
  content: "";
  position: absolute;
  inset: 1px 0 0 1px;
  z-index: -1;
}

.day-score.bad { color: var(--score-bad-ink); }
.day-score.mid { color: var(--score-mid-ink); }
.day-score.good { color: var(--score-good-ink); }
.day-score.bad::before { background: var(--score-bad); }
.day-score.mid::before { background: var(--score-mid); }
.day-score.good::before { background: var(--score-good); }

/* The day's last mark completes it: the score fades in rather than appearing cold */
.day-score.arrive { animation: score-arrive 0.18s cubic-bezier(0.2, 0, 0, 1); }

@keyframes score-arrive {
  from { opacity: 0; transform: scale(0.96); }
}

/* Legend */

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin-top: 18px;
  padding-left: calc(var(--rail) + var(--rail-gap));
  font-size: 12.5px;
  color: var(--muted);
}

.sheet-actions { margin-right: auto; }

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.swatch i {
  width: 18px;
  height: 18px;
  border-radius: 2px;
  font-size: 0;
  background: var(--empty) center / 14px no-repeat;
}

.swatch .x { background-color: var(--done); background-image: var(--i-check); }
.swatch .slash { background-color: var(--partial); background-image: var(--i-slash); }
.swatch .dash { background-color: var(--miss); background-image: var(--i-cross); }
.swatch .off-day { background: var(--off-day); }
.swatch .blank { background-color: var(--empty-past); }

.undo-toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 6px 6px 6px 16px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--ink);
  color: var(--sheet);
  box-shadow: var(--shadow-fab);
  font-size: 14px;
  transform: translateX(-50%);
  transition:
    opacity 0.2s ease,
    transform 0.5s cubic-bezier(0.32, 0.72, 0, 1),
    display 0.5s allow-discrete;
}

/* Rises into place; sinks away quicker than it came. */
.undo-toast[hidden] {
  display: none;
  opacity: 0;
  transform: translate(-50%, 10px) scale(0.96);
  transition:
    opacity 0.18s ease-in,
    transform 0.2s ease-in,
    display 0.2s allow-discrete;
}

@starting-style {
  .undo-toast:not([hidden]) {
    opacity: 0;
    transform: translate(-50%, 24px) scale(0.94);
  }
}

.undo-toast.nudge { animation: undo-nudge 0.35s cubic-bezier(0.32, 0.72, 0, 1); }

@keyframes undo-nudge {
  40% { transform: translateX(-50%) scale(1.04); }
}

.undo-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.undo-toast button {
  flex: none;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--sheet) 16%, transparent);
  color: var(--sheet);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s, transform 0.12s;
}

.undo-toast button:hover { background: color-mix(in srgb, var(--sheet) 24%, transparent); }
.undo-toast button:active { transform: scale(0.94); }

.undo-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 3px;
  background: color-mix(in srgb, var(--sheet) 45%, transparent);
  transform-origin: left;
  animation: undo-timer linear forwards;
}

@keyframes undo-timer { to { transform: scaleX(0); } }

@media (prefers-reduced-motion: reduce) {
  .undo-toast,
  .undo-toast[hidden] { transition: none; }
  .undo-toast.nudge { animation: none; }
  .mark.first-nudge[data-v=""]::before { animation: none; box-shadow: inset 0 0 0 2px var(--nudge); }
  .felled-title b { animation: none; }
  .felled-title b::after { display: none; }
}

.account-button {
  position: absolute;
  top: 20px;
  right: 20px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--sheet);
  color: var(--muted);
  box-shadow: var(--shadow-fab);
  cursor: pointer;
  transition: color 0.12s, box-shadow 0.12s, transform 0.12s;
}

.account-button:hover {
  color: var(--ink);
  box-shadow: var(--shadow-fab-hover);
}

.account-button:active { transform: scale(0.94); }

.account-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.inapp-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 8px 8px 8px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--sheet);
  font-size: 14px;
}

.inapp-bar[hidden] { display: none; }
.inapp-bar span { flex: 1; }

.inapp-bar button {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}

.sm-only { display: none; }

/* Dialogs */

.sheet-dialog {
  width: min(420px, calc(100% - 24px));
  max-width: 100%;
  padding: 20px;
  border: 0;
  border-radius: 16px;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 24px 48px -12px rgba(16, 24, 40, 0.28), 0 0 0 1px rgba(16, 24, 40, 0.04);
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  transition:
    opacity 0.16s ease,
    transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
    overlay 0.2s allow-discrete,
    display 0.2s allow-discrete;
}

.sheet-dialog[open] {
  opacity: 1;
  transform: none;
}

@starting-style {
  .sheet-dialog[open] {
    opacity: 0;
    transform: translateY(6px) scale(0.97);
  }
}

.sheet-dialog::backdrop {
  background: rgba(17, 24, 39, 0.4);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition:
    opacity 0.2s ease,
    overlay 0.2s allow-discrete,
    display 0.2s allow-discrete;
}

.sheet-dialog[open]::backdrop { opacity: 1; }

@starting-style {
  .sheet-dialog[open]::backdrop { opacity: 0; }
}

.sheet-dialog form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0;
}

.dialog-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.sheet-dialog input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--sheet);
}

.sheet-dialog input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.sheet-dialog button {
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--button);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
}

.sheet-dialog button:disabled { opacity: 0.35; cursor: default; }
.sheet-dialog button.primary { background: var(--accent); color: #fff; font-weight: 600; }
.sheet-dialog button.danger { color: var(--danger); }

.dialog-actions {
  display: flex;
  gap: 8px;
}

.dialog-actions .primary { margin-left: auto; }

.dialog-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-2);
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sheet-dialog .menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: auto;
  min-height: 48px;
  padding: 8px 12px;
  background: transparent;
  text-align: left;
}

.sheet-dialog .menu-item:hover { background: var(--hover); }
.menu-item > span:first-child { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.menu-item small { font-size: 12px; font-weight: 400; color: var(--muted); }
.menu-item .chevron { color: var(--faint); font-size: 18px; }

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 500;
}

.segmented {
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--button);
}

.sheet-dialog .segmented button {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.sheet-dialog .segmented button[aria-checked="true"] {
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}

/* On wide screens the goals take the corner beside the squad and the title, so the sheet starts high. */
@media (min-width: 641px) {
  .wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 24px;
  }

  .wrap > * { grid-column: 1 / -1; }
  .inapp-bar { grid-row: 1; }
  /* A big squad wraps beside the goals rather than widening the page past the sheet. */
  .squad { grid-row: 2; grid-column: 1; flex-wrap: wrap; contain: inline-size; }
  .topbar { grid-row: 3; grid-column: 1; align-self: start; }
  .week-goals { grid-row: 2 / 4; grid-column: 2; }
  .sheet-layout { grid-row: 4; }
  .legend { grid-row: 5; }
  legio-offer { grid-row: 6; }
}

/* When the sheet nearly fills the window the menu button takes the top corner, so the goals start at the title. */
@media (min-width: 641px) and (max-width: 900px) {
  .squad { grid-column: 1 / -1; }
  .week-goals { grid-row: 3 / 4; }
}

/* With room to spare the list sits right of the sheet, its lines running on from the sheet's rows. */
@media (min-width: 1360px) {
  .wrap { column-gap: 32px; }
  .squad,
  .topbar { grid-column: 1 / -1; }
  /* The legend belongs to the sheet, so it ends where the sheet does. */
  .sheet-layout,
  .legend { grid-column: 1; }
  .week-goals {
    --goal-row: var(--body-row);
    grid-row: 4;
    grid-column: 2;
    width: 240px;
    margin: 0;
  }

  /* Room for the sheet's header, so the first line runs on from the first habit. */
  .week-goals::before {
    content: "";
    height: calc(1px + var(--head-row) + var(--date-row));
  }
}

/* On wide screens the menu hangs under its button instead of sitting mid-screen. */
@media (min-width: 641px) {
  #account-dialog {
    inset: 64px 20px auto auto;
    width: 300px;
    margin: 0;
    padding: 8px;
  }

  #account-dialog::backdrop { background: transparent; backdrop-filter: none; }
}

.link-code-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.link-code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.link-qr {
  width: 168px;
  height: 168px;
  padding: 8px;
  border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.link-qr:empty { visibility: hidden; }
.link-qr svg { display: block; width: 100%; height: 100%; }
.link-note { margin: 0; font-size: 12px; color: var(--muted); }
.link-done { margin: 0; font-size: 15px; font-weight: 500; color: var(--legio); }

.link-or {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--faint);
}

.link-or::before,
.link-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.sheet-dialog #link-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.link-error { margin: 0; font-size: 13px; color: var(--danger); }
.link-error[hidden],
#link-dialog [hidden] { display: none; }

.keys-group {
  margin: 0;
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 8px 16px;
  align-items: center;
  font-size: 13px;
}

.keys-title {
  margin: 4px 0 -4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.keys-group dt {
  display: flex;
  gap: 4px;
}

.keys-group dd { margin: 0; color: var(--ink-2); }

/* Read out, never seen: the save status. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

kbd {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--sheet);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 19px;
  text-align: center;
  color: var(--ink-2);
}

@media (hover: none) {
  .sheet-card {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .sheet-card [contenteditable="true"] {
    user-select: text;
    -webkit-user-select: text;
  }
}

/* Narrow desktop */

@media (max-width: 1120px) {
  col.day { width: 56px; }
  col.weight { width: 36px; }
  .month,
  .weight-label { display: none; }
  .weight-icon { display: inline-block; }
}

/* Phone */

@media (max-width: 640px) {
  :root {
    --head-row: 26px;
    --date-row: 34px;
    --body-row: 48px;
  }

  body { padding: 0 0 88px; }

  .wide-only,
  .sheet-dialog .wide-only { display: none; }
  .sm-only { display: revert; }

  .wrap {
    width: auto;
    padding-right: 0;
  }

  .topbar,
  .legend { padding: 0 16px; }

  .topbar {
    gap: 14px;
    margin-bottom: 16px;
  }

  /* The squad stays on screen like an app's top bar, with the menu beside it. */
  .account-button { position: fixed; top: 11px; right: 12px; z-index: 21; }

  .squad {
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 3px;
    margin: 0 0 8px;
    padding: 12px 56px 10px 15px;
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--canvas);
    transition: box-shadow 0.12s;
  }

  .squad::-webkit-scrollbar { display: none; }
  .face { flex: none; }
  .squad.stuck { box-shadow: 0 1px 0 var(--line); }
  /* In TikTok's or Instagram's browser the bar's own × stays clear of the fixed menu button. */
  .inapp-bar { margin: 8px 60px 8px 16px; }
  .face { padding: 1px; }
  .face .pic { width: 32px; height: 32px; }
  .face .pic b { font-size: 14px; }
  .title { flex: 1 1 100%; }
  /* Full-size tap targets that don't make the row taller than the title, so squad sheets line up. */
  .title-row .week-nav { margin-block: -4px; }
  h1 { flex: none; font-size: 26px; gap: 8px; }
  .title-row { gap: 12px; }

  .week-goals { --goal-row: 40px; width: auto; margin: 0 16px 16px; }
  /* Height is scarce here: the written lines and one blank to write on, and on someone else's sheet only what they wrote. */
  .week-goals .goal-add ~ .goal-add,
  body.viewing .week-goals .goal-add { display: none; }

  .goal-chip { padding-block: 4px; align-items: center; }
  .goal-chip .goal-mark { --box: 24px; width: 36px; height: 36px; margin: -8px -6px; }
  .goal-chip .goal-mark::before { border-radius: 6px; }
  .goal-chip .goal-mark::after { -webkit-mask-size: 15px; mask-size: 15px; }
  .goal-chip .goal-text { font-size: 15px; line-height: 20px; }

  .goal-add,
  .week-nav button,
  .sheet-actions button { height: 36px; font-size: 14px; }

  .row-rail { display: none; }

  .sheet-layout,
  .sheet-card { width: 100%; }

  .sheet-card {
    padding-right: 10px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  table {
    width: 100%;
    table-layout: fixed;
  }

  col.slot { width: 56px; }
  col.habit { width: auto; }
  col.weight { width: 30px; }
  col.day { width: 56px; }

  th, td { padding: 0 2px; }

  .row-blue th,
  .row-band th:not([data-day]) { font-size: 10px; letter-spacing: 0.04em; }
  .row-blue th { padding-top: 8px; }
  .row-band th.slot { padding-right: 8px; }
  .row-band th.habit { padding-left: 12px; }
  .row-band th[data-day] .date { padding: 0 8px; }
  thead th[data-day] { padding: 0; }

  td[data-field] { line-height: 1.3; }

  td.habit,
  th.habit {
    width: auto;
    min-width: 0;
    max-width: none;
    padding: 7px 6px 7px 12px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  td.habit {
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 13.5px;
  }

  tr[data-id] td.meta { padding-left: 12px; }

  tbody td.slot {
    padding: 0 8px 0 4px;
    line-height: var(--body-row);
    font-size: 11px;
  }

  th.weight,
  td.weight { padding: 0 2px; }

  td.mark { padding: 0; }
  .mark::before { background-size: 17px; }

  td[data-field]:focus:not(:focus-visible),
  .mark:focus:not(:focus-visible) { outline: none; }

  tfoot .score-label { padding-left: 12px; font-size: 10px; letter-spacing: 0.04em; }
  tfoot td.slot { padding-left: 10px; }

  .legend { gap: 10px 14px; margin-top: 16px; }
  .sheet-actions { flex-basis: 100%; }

  .hint {
    flex-basis: 100%;
    font-size: 12px;
    line-height: 1.5;
    color: var(--faint);
  }

  .sheet-dialog {
    width: 100%;
    margin: auto 0 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
    opacity: 1;
    transform: translateY(100%);
    transition:
      transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
      overlay 0.28s allow-discrete,
      display 0.28s allow-discrete;
  }

  @starting-style {
    .sheet-dialog[open] {
      opacity: 1;
      transform: translateY(100%);
    }
  }

  .sheet-dialog .sheet-panel { padding: 24px 20px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet-dialog,
  .sheet-dialog::backdrop { transition: none; }
}
