:root {
  --navy: #16213A;
  --gold: #E9B949;
  --gold-light: #F3D58A;
  --sage: #8FB895;
  --bg: #F4F8F4;
  --surface: #FFFFFF;
  --line: #DAE6DB;
  --text: #16213A;
  --muted: #55655B;
  --p4-bg: #E5F0E6;
  --p4-text: #3F6F48;
  --kb: 0px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1829;
    --surface: #18243A;
    --line: #26344B;
    --text: #E8EEF0;
    --muted: #9CACBB;
    --p4-bg: #2A3F33;
    --p4-text: #BFD8C3;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* Header */
.top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  background: var(--navy);
  color: #fff;
}
.top__title { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.02em; white-space: nowrap; }
.top__count { margin-left: 2px; color: var(--gold); font-variant-numeric: tabular-nums; }
.top__tools { display: flex; align-items: center; gap: 6px; min-width: 0; }
.lines-btn {
  flex: none;
  min-height: 34px;
  padding: 0 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}
.sort { display: flex; gap: 2px; padding: 2px; border-radius: 9px; background: rgba(255, 255, 255, .12); }
.sort__btn {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  color: #D5DEE8;
}
.sort__btn[aria-pressed="true"] { background: var(--gold); color: var(--navy); }

/* Task list: rows are kept as tight as a comfortable tap allows */
.list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.rows { margin: 0; padding: 0; list-style: none; }
.row { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.row__main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 2px 0 2px 8px;
  text-align: left;
}
.row__main:active, .row__tick:active { background: var(--line); }
.row__text {
  flex: 1;
  min-width: 0;
  line-height: 18px;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}
.lines-3 .row__text { -webkit-line-clamp: 3; }
.row__age { flex: none; width: 44px; text-align: right; line-height: 13px; font-variant-numeric: tabular-nums; }
.row__age b { display: block; font-size: 13px; font-weight: 650; }
.row__age small { display: block; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.row__tick { flex: none; width: 40px; display: grid; place-items: center; color: var(--muted); }
.row__tick span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
}
.row__tick svg { width: 14px; height: 14px; stroke-width: 2.6; opacity: 0; }
.row--flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--gold-light); } to { background: transparent; } }
.row--done .row__text { color: var(--muted); text-decoration: line-through; }
.row--done .row__tick span { background: var(--sage); border-color: var(--sage); color: var(--navy); }
.row--done .row__tick svg { opacity: 1; }

/* Priority colours run honey to sage to outline */
.pri {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.p1 { background: var(--gold); color: var(--navy); }
.p2 { background: var(--gold-light); color: var(--navy); }
.p3 { background: var(--sage); color: var(--navy); }
.p4 { background: var(--p4-bg); color: var(--p4-text); }
.p5 { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1.5px var(--line); }

.empty { margin: 0; padding: 40px 28px; text-align: center; color: var(--muted); line-height: 1.45; }
.done-toggle {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  text-align: left;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}

/* Bottom bar */
.bar {
  flex: none;
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 8px;
  padding: 7px 10px calc(env(safe-area-inset-bottom) + 7px);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.bar__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1.5px var(--line);
}
.bar__btn--speak { background: var(--gold); color: var(--navy); box-shadow: none; }

/* Add and edit sheet */
.scrim { position: fixed; inset: 0; z-index: 10; background: rgba(10, 16, 30, .5); }
.sheet {
  position: fixed;
  z-index: 11;
  left: 50%;
  bottom: var(--kb);
  width: 100%;
  max-width: 600px;
  transform: translateX(-50%);
  max-height: calc(100dvh - var(--kb) - env(safe-area-inset-top));
  overflow-y: auto;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px);
  border-radius: 16px 16px 0 0;
  background: var(--surface);
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet__head h2 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.sheet__close { display: grid; place-items: center; width: 34px; height: 34px; margin-right: -6px; color: var(--muted); }
.field { position: relative; }
.field textarea {
  display: block;
  width: 100%;
  min-height: 66px;
  padding: 9px 46px 9px 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming into the field */
  line-height: 22px;
  resize: none;
}
.field__mic {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--muted);
}
.field__mic[aria-pressed="true"] { background: var(--gold); color: var(--navy); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(233, 185, 73, .3); } }
.status { min-height: 18px; margin: 6px 2px; font-size: 13px; line-height: 18px; color: var(--muted); }
.pri-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pri-opt { height: 46px; border-radius: 23px; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pri-opt[aria-pressed="true"] { outline: 2.5px solid var(--text); outline-offset: 2px; }
.pri-scale { display: flex; justify-content: space-between; margin: 4px 2px 0; font-size: 12px; color: var(--muted); }
.edit__meta { margin: 10px 2px 8px; font-size: 13px; color: var(--muted); }
.edit__actions { display: flex; align-items: center; justify-content: space-between; }
.link-btn { min-height: 40px; padding: 0 2px; font-size: 14px; font-weight: 550; color: var(--muted); text-decoration: underline; }
.save-btn { min-height: 40px; padding: 0 26px; border-radius: 10px; background: var(--gold); color: var(--navy); font-weight: 600; }

/* Moving to the new address */
.moved {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--gold-light);
  color: var(--navy);
  font-size: 14px;
  line-height: 1.3;
}
.moved span { min-width: 0; overflow-wrap: anywhere; }
.moved button { flex: none; min-height: 40px; padding: 0 12px; border-radius: 10px; background: var(--navy); color: #fff; font-weight: 600; }
.steps { margin: 4px 2px 10px; padding-left: 20px; line-height: 1.45; }
.steps li { margin-bottom: 6px; }
.steps a { color: inherit; font-weight: 600; }
#moveTitle:focus { outline: none; }
#moveSheet textarea { padding-right: 10px; }
#pasteLink { margin-top: 8px; min-height: 44px; text-decoration: underline; }
.save-btn--wide { width: 100%; min-height: 46px; }

/* Undo toast */
.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 70px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 24px);
  padding: 4px 6px 4px 14px;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(10, 16, 30, .3);
}
.toast span { overflow: hidden; text-overflow: ellipsis; }
.toast button { min-height: 34px; padding: 0 10px; color: var(--gold); font-weight: 650; }

@media (prefers-reduced-motion: reduce) {
  .row--flash, .field__mic[aria-pressed="true"] { animation: none; }
}
