/* Day Sheet. Grid paper, black ink, red pen for notes. */
:root {
  --paper: #fbfaf5;
  --paper-raised: #ffffff;
  --grid: #e3e6ea;
  --ink: #1c1c1e;
  --ink-soft: #5d5d64;
  --ink-faint: #9a9aa1;
  --rule: #d6d8dc;
  --red: #c4362b;
  --red-soft: #fbe9e7;
  --focus: #1c1c1e;
  --cell: 24px;
  --row: 48px;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151517;
    --paper-raised: #1f1f22;
    --grid: #232327;
    --ink: #ececee;
    --ink-soft: #a6a6ad;
    --ink-faint: #6d6d74;
    --rule: #33333a;
    --red: #ff6f61;
    --red-soft: #3a1f1c;
    --focus: #ececee;
    color-scheme: dark;
  }
}
/* The sun/moon switch overrides the device setting. */
:root[data-theme="dark"] {
    --paper: #151517;
    --paper-raised: #1f1f22;
    --grid: #232327;
    --ink: #ececee;
    --ink-soft: #a6a6ad;
    --ink-faint: #6d6d74;
    --rule: #33333a;
    --red: #ff6f61;
    --red-soft: #3a1f1c;
    --focus: #ececee;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-attachment: local;
  min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* --- Masthead ------------------------------------------------------------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 0;
}
.top__inner { max-width: 640px; margin: 0 auto; }
.datebar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; min-height: 52px; }
.datebar__step {
  width: 44px; height: 44px; border: 0; background: none;
  font-size: 26px; line-height: 1; color: var(--ink-soft); border-radius: 50%;
}
.datebar__date {
  border: 0; background: none; padding: 4px 0;
  font-size: 24px; font-weight: 700; letter-spacing: 0.02em; text-align: center;
}
.datebar__today {
  border: 1px solid var(--rule); background: var(--paper-raised);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600;
}
.datebar h1 { grid-column: 1 / -1; margin: 0; font-size: 24px; font-weight: 700; text-align: center; }

/* Week strip: yesterday, today, five ahead. */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 2px 0 6px; }
.week__day {
  display: grid; justify-items: center; gap: 1px; padding: 4px 0 5px;
  border: 1px solid transparent; border-radius: 8px; color: var(--ink); text-decoration: none;
}
.week__dow { font-size: 12px; color: var(--ink-soft); }
.week__num { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.week__dot { width: 5px; height: 5px; border-radius: 50%; background: var(--red); }
.week__dot--none { visibility: hidden; }
.week__day--today { border-color: var(--ink); }
.week__day[aria-current="date"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.week__day[aria-current="date"] .week__dow { color: var(--paper); }
.week__day[aria-current="date"] .week__dot { background: var(--paper); }
.tabs { display: flex; gap: 4px; align-items: center; }
.theme {
  flex: none; width: 40px; height: 40px; border: 0; background: none; color: var(--ink-soft);
  display: grid; place-items: center; border-radius: 50%;
}
.theme svg { width: 20px; height: 20px; }
.tabs a {
  flex: 1; text-align: center; padding: 10px 0 11px;
  color: var(--ink-soft); text-decoration: none; font-weight: 600; font-size: 15px;
  border-bottom: 3px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px calc(120px + env(safe-area-inset-bottom)); }

/* --- Next up -------------------------------------------------------------- */
.next {
  background: var(--paper-raised); border: 2px solid var(--ink); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 16px;
  display: grid; grid-template-columns: auto 40px 1fr; gap: 0 8px; align-items: center;
}
.next__box { width: 40px; height: 48px; border: 0; background: none; padding: 0; display: grid; place-items: center; }
.next__box svg { width: 28px; height: 28px; }
.next__text { display: grid; gap: 1px; min-width: 0; }
.next__num { font-size: 40px; font-weight: 800; line-height: 1; min-width: 1.2em; text-align: center; }
.next__label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.next__title { font-size: 20px; font-weight: 700; }
.next__sub { color: var(--ink-soft); font-size: 15px; }
.next--empty { display: block; color: var(--ink-soft); border-style: dashed; border-width: 1px; font-size: 15px; }

.btn {
  min-height: 44px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--paper-raised); font-weight: 600; font-size: 16px;
}
.btn--ink { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn--red { color: var(--red); }
.btn--grow { flex: 1; }
.btn--small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: 0.45; cursor: default; }

/* --- Toolbar -------------------------------------------------------------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 4px; min-height: 40px; }
.toolbar__count { color: var(--ink-soft); font-size: 14px; }
.toolbar__btns { display: flex; gap: 8px; }
.planbar {
  background: var(--red-soft); color: var(--ink); border-left: 3px solid var(--red);
  border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; font-size: 15px;
}
.planbar__actions { display: flex; gap: 8px; margin-bottom: 8px; }

/* --- The sheet ------------------------------------------------------------ */
.list, .kids { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 32px 40px minmax(0, 1fr) auto; align-items: center;
  min-height: var(--row);
}
.row__num {
  font-weight: 700; font-size: 18px; text-align: right; padding-right: 6px;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.row__box { width: 40px; height: var(--row); border: 0; background: none; padding: 0; display: grid; place-items: center; }
.row__box svg { width: 24px; height: 24px; display: block; }
.row__body {
  border: 0; background: none; text-align: left; padding: 8px 4px; min-height: var(--row);
  display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; row-gap: 2px;
}
.row__time { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row__title { overflow-wrap: anywhere; }
.row__step { color: var(--ink-soft); font-size: 14px; overflow-wrap: anywhere; }
.row__slug {
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  border: 1px solid var(--ink-faint); border-radius: 4px; padding: 0 5px; color: var(--ink-soft);
}
.row__moved {
  color: var(--red); font-weight: 700; white-space: nowrap; text-decoration: underline;
  text-underline-offset: 3px; min-height: var(--row); padding: 0 6px 0 8px; display: flex; align-items: center;
}
.row__more {
  width: 44px; height: var(--row); border: 0; background: none; color: var(--ink); font-size: 24px;
}
.row__slug--set { background: var(--tag); border-color: var(--tag); color: #111; }
.caps { text-transform: uppercase; }
.caps::placeholder { text-transform: none; }
.tagpick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.tagpick__label { width: 100%; font-size: 13px; color: var(--ink-soft); }
.tagpick button {
  min-height: 36px; padding: 0 10px; border-radius: 6px; font-size: 14px; font-weight: 700;
  border: 2px solid var(--tag); background: none;
}
.tagpick button[aria-pressed="true"] { background: var(--tag); color: #111; }
.row--cancelled .row__title, .row--moved .row__title { color: var(--ink-faint); }
.row--cancelled .row__title { text-decoration: line-through; text-decoration-thickness: 1px; }
.row--done .row__title { color: var(--ink-soft); }

.kids { grid-column: 2 / -1; margin: -4px 0 6px; padding-left: 12px; border-left: 2px solid var(--rule); }
.kids .row { grid-template-columns: 28px 40px minmax(0, 1fr) auto; min-height: 44px; }
.kids .row__num { font-size: 15px; color: var(--ink-soft); }
.kids__add { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0 8px 40px; }
.kids__keep { width: 100%; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); min-height: 36px; }
.kids__add .kids__keep input { flex: none; width: 20px; height: 20px; min-height: 0; margin: 0; }
.kids__add input {
  flex: 1; min-width: 0; min-height: 36px; padding: 0 10px; font-size: 16px;
  border: 1px solid var(--rule); border-radius: 6px; background: var(--paper-raised);
}

.plan .row__body, .plan .row__box { cursor: copy; }
.row__grip {
  width: 44px; height: var(--row); border: 0; background: none; color: var(--ink-soft);
  font-size: 20px; touch-action: none; cursor: grab;
}
.row--dragging { background: var(--paper-raised); box-shadow: 0 4px 16px rgb(0 0 0 / 0.15); border-radius: 6px; position: relative; z-index: 2; }
.plan .row:not([data-num]) .row__num::after { content: "·"; color: var(--ink-faint); }

.empty { color: var(--ink-soft); padding: 16px 0; }
.calslot {
  margin-top: 20px; border: 1px dashed var(--rule); border-radius: var(--radius);
  padding: 10px 12px; color: var(--ink-faint); font-size: 14px;
}

/* --- Carry-over ----------------------------------------------------------- */
.carry {
  background: var(--paper-raised); border: 1px solid var(--rule); border-left: 3px solid var(--red);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 16px;
}
.carry h2 { margin: 0 0 4px; font-size: 16px; }
.carry p { margin: 0 0 8px; color: var(--ink-soft); font-size: 14px; }
.carry__row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 8px 0; border-top: 1px solid var(--rule); }
.carry__title small { color: var(--ink-soft); font-weight: 600; margin-right: 6px; }
.carry__actions { display: flex; gap: 6px; }

/* --- Routines ------------------------------------------------------------- */
.card {
  display: block; width: 100%; text-align: left; background: var(--paper-raised);
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
}
.card h3 { margin: 0 0 2px; font-size: 18px; }
.card p { margin: 0; color: var(--ink-soft); font-size: 14px; }

/* --- Add bar -------------------------------------------------------------- */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--paper); border-top: 1px solid var(--rule);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}
.addbar form { max-width: 640px; margin: 0 auto; display: flex; gap: 8px; }
.suggest { max-width: 640px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.addbar input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 12px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper-raised);
  font-size: 17px;
}
.iconbtn {
  width: 48px; height: 48px; flex: none; border-radius: 8px; border: 1px solid var(--rule);
  background: var(--paper-raised); display: grid; place-items: center;
}
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn--ink { background: var(--ink); color: var(--paper); border-color: var(--ink); font-size: 26px; line-height: 1; }
.iconbtn--rec { background: var(--red); color: #fff; border-color: var(--red); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .iconbtn--rec { animation: none; } }

/* --- Bottom sheet --------------------------------------------------------- */
dialog.sheet {
  width: 100%; max-width: 640px; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 16px 16px 0 0; background: var(--paper-raised); color: var(--ink);
  max-height: 88dvh;
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.35); }
.sheet__in { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 88dvh; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-soft); margin: 12px 0 4px; }
.sheet input[type="text"], .sheet input[type="time"], .sheet input[type="date"], .sheet textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--paper); font-size: 17px;
}
.sheet textarea { min-height: 96px; resize: vertical; }
.sheet .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet .btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.sheet .seg { display: flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.sheet .seg button { flex: 1; min-height: 44px; border: 0; background: none; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px; }
.sheet .seg button + button { border-left: 1px solid var(--rule); }
.sheet .seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.sheet .seg svg { width: 18px; height: 18px; }
.sheet hr { border: 0; border-top: 1px solid var(--rule); margin: 16px 0 4px; }
.sheet .note { color: var(--ink-soft); font-size: 14px; margin: 6px 0 0; }
.days { display: flex; gap: 6px; }
.days button {
  flex: 1; min-height: 44px; border: 1px solid var(--rule); border-radius: 8px; background: none; font-weight: 700;
}
.days button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.prop { display: grid; grid-template-columns: 28px 1fr; gap: 8px; padding: 10px 0; border-top: 1px solid var(--rule); }
.prop input { width: 22px; height: 22px; margin: 2px 0 0; }
.prop__when { font-size: 13px; font-weight: 700; color: var(--red); }
.prop__title { font-weight: 700; }
.prop ul { margin: 4px 0 0; padding-left: 18px; color: var(--ink-soft); font-size: 15px; }
.said { margin: 0 0 8px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: 608px; margin: 0 auto; background: var(--ink); color: var(--paper);
  padding: 12px 14px; border-radius: 8px; font-size: 15px;
}

/* --- Login ---------------------------------------------------------------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .form {
  width: min(24rem, 100%); background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 28px 20px;
}
.login h1 { margin: 0 0 4px; font-size: 26px; }
.login p { margin: 0 0 20px; color: var(--ink-soft); }
.login .note { color: var(--ink-soft); font-size: 15px; margin-top: 12px; }
.login input {
  width: 100%; min-height: 48px; padding: 0 12px; margin-bottom: 12px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); font-size: 17px;
}
.login .btn { width: 100%; }
.login .err { color: var(--red); margin: 0 0 12px; }

/* --- Time strip ----------------------------------------------------------- */
.daygrid { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; align-items: start; }
.dayright { min-width: 0; }
.strip {
  position: sticky; top: calc(var(--top-h, 180px) + 8px);
  display: block; width: 44px; padding: 0; margin-top: 4px;
  border: 0; border-right: 1px solid var(--rule); background: none; cursor: pointer;
}
.strip > span { position: absolute; display: block; }
.strip__h {
  left: 0; width: 18px; height: 24px; line-height: 24px; text-align: right;
  font-size: 11px; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums;
}
.strip__bar { width: 5px; border-radius: 2px; }
.strip__bar--line { opacity: 0.8; }
.strip__now { left: 0; right: -4px; height: 2px; margin-top: -1px; background: var(--red); }
.strip__now::before {
  content: ""; position: absolute; left: -3px; top: -2px; width: 6px; height: 6px; border-radius: 50%; background: var(--red);
}
.allday { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); }
.allday--warn { color: var(--red); }
.allday__ev { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ev { display: grid; grid-template-columns: 6px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--rule); }
.ev__bar { align-self: stretch; border-radius: 3px; }
.ev__body small { color: var(--ink-soft); }
.ev__add { width: 44px; height: 44px; font-size: 24px; line-height: 1; font-weight: 400; }
