/* ------------------------------------------------------------------ fonts */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url(../fonts/nunito-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url(../fonts/nunito-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #173a32;
  --card: #fdfdfa;
  --card-past: #f2f4ef;
  --strip: #eef1eb;
  --text: #1b2a25;
  --muted: #7d8a84;
  --line: #e7ebe5;
  --accent: #1d7a58;
  --accent-soft: #dcefe5;
  --today: #b27100;
  --today-soft: #fdeec4;
  --today-line: #f2b930;
  --num: #edf0ea;
  --num-today: #fbe3a0;
  --warn: #c1561c;
  --warn-soft: #fbeadf;
  --holiday: #c0443c;
  --check: #bcc5bf;
  --panel: #fdfdfa;
  --panel-hi: #eff2ec;
  --panel-line: #e5e9e3;
  --shade: rgba(8, 24, 20, 0.45);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1a16;
    --card: #182a23;
    --card-past: #14241e;
    --strip: #1d3029;
    --text: #e6eee9;
    --muted: #7f928a;
    --line: #213530;
    --accent: #4cc08f;
    --accent-soft: #1d3a2f;
    --today: #f5c04a;
    --today-soft: #3a3118;
    --today-line: #f5c04a;
    --num: #1b2c26;
    --num-today: #4a3d1a;
    --warn: #f0a060;
    --warn-soft: #3a2a20;
    --holiday: #ef8a80;
    --check: #4a5f57;
    --panel: #17271f;
    --panel-hi: #20332b;
    --panel-line: #263a32;
    --shade: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  font-family: 'Nunito', -apple-system, system-ui, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button:focus-visible, .switch input:focus-visible, .field input:focus-visible { outline: 2px solid var(--today-line); outline-offset: 2px; }
button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.ico {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-user-select: none;
  user-select: none;
}

/* ------------------------------------------------------------------ header */
.top {
  flex: none;
  height: 50px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 4px;
  color: #fff;
}

.brand {
  justify-self: start;
  padding: 10px 12px;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  font-size: 17px;
  font-weight: 700;
}
.title .caret { width: 14px; height: 14px; stroke-width: 2; opacity: 0.7; }

.chip {
  font-size: 11px;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.16);
}

.icon { padding: 10px 12px; display: grid; place-items: center; position: relative; }
.menu-btn { justify-self: end; }
.warn-dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 2px var(--bg);
}

/* ------------------------------------------------------------------ weeks */
.weeks {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  overflow: clip; /* not scrollable even by focus(), so weeks never drift sideways */
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  touch-action: pan-y;
}

.track {
  display: flex;
  width: 300%;
  height: 100%;
  will-change: transform;
}
.track.anim { transition: transform 0.3s cubic-bezier(0.22, 0.8, 0.3, 1); }

.week {
  width: calc(100% / 3);
  height: 100%;
  padding: 0 6px;
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: repeat(6, minmax(0, 1fr));
  grid-template-areas:
    "d1 d2"
    "d1 d2"
    "d3 d4"
    "d3 d4"
    "d5 d6"
    "d5 d7";
}
.d1 { grid-area: d1; } .d2 { grid-area: d2; } .d3 { grid-area: d3; } .d4 { grid-area: d4; }
.d5 { grid-area: d5; } .d6 { grid-area: d6; } .d7 { grid-area: d7; }

/* ------------------------------------------------------------------ day card */
.day {
  position: relative;
  display: flex;
  min-height: 0;
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  overflow: clip;
  transition: box-shadow 0.15s;
}
.day.past { background: var(--card-past); }
.day.target, .day.today.target { box-shadow: 0 0 0 2px var(--accent); }

.strip {
  flex: none;
  width: 26px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  background: var(--strip);
  border-left: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.strip .wd { order: 2; flex: none; font-weight: 800; }
.strip .nd {
  order: 1;
  min-height: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
  font-style: italic;
  color: var(--muted);
}
.day.today { box-shadow: inset 0 0 0 2px var(--today-line); }
.day.today .strip { background: var(--today-soft); border-left-color: var(--today-line); }
.day.today .strip .wd { color: var(--today); }

.content {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.holiday {
  flex: none;
  padding: 6px 8px 2px;
  font-size: 11px;
  font-style: italic;
  color: var(--holiday);
}

.overdue {
  flex: none;
  margin: 6px 6px 2px;
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11.5px;
  line-height: 1.3;
  text-align: left;
}

.tasks {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 2px 0 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.tasks::-webkit-scrollbar { display: none; }

.num {
  position: absolute;
  right: 8px;
  bottom: 2px;
  z-index: 0;
  font-size: 54px;
  font-weight: 300;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: var(--num);
  pointer-events: none;
}
.num small { font-size: 38%; letter-spacing: 0; margin-right: 3px; }
.d6 .num, .d7 .num { font-size: 40px; }
.day.today .num { color: var(--num-today); }

/* ------------------------------------------------------------------ task */
.task {
  flex: none;
  display: flex;
  align-items: flex-start;
  padding: 5px 6px 5px 0;
  border-bottom: 1px solid var(--line);
  -webkit-touch-callout: none;
}

.check {
  flex: none;
  width: 26px;
  height: 20px;
  display: grid;
  place-items: center;
  color: var(--check);
}
.check .ico { width: 16px; height: 16px; stroke-width: 1.7; }
.task.done .check { color: var(--accent); }

.text { flex: 1; min-width: 0; }

/* Auto-growing textarea: the hidden ::after copy sizes the cell.
   When not editing, .view shows the same text on top, with times in bold. */
.grow { display: grid; }
.grow::after {
  content: attr(data-value) ' ';
  visibility: hidden;
  white-space: pre-wrap;
}
.grow::after,
.grow textarea,
.grow .view {
  grid-area: 1 / 1 / 2 / 2;
  margin: 0;
  padding: 1px 0;
  border: 0;
  font-size: 14px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.grow textarea {
  resize: none;
  overflow: hidden;
  background: transparent;
  outline: none;
  pointer-events: none; /* the row handles taps; long-press stays free for dragging */
  -webkit-user-select: text;
  user-select: text;
  caret-color: var(--accent);
}
.task:not(.editing) .grow textarea { color: transparent; }
.task.editing .grow textarea { pointer-events: auto; }
.task.editing .grow .view { visibility: hidden; }
.grow .view { white-space: pre-wrap; pointer-events: none; }
.grow .view b { font-weight: 800; color: var(--warn); }
.task.done .view, .task.done.editing textarea { color: var(--muted); text-decoration: line-through; }

.marker {
  flex: none;
  height: 2px;
  margin: -1px 8px -1px 22px;
  border-radius: 2px;
  background: var(--accent);
  position: relative;
}
.marker::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* The empty area under the tasks: tap to add. */
.add { flex: 1 0 2.4em; display: flex; }
.add textarea {
  flex: 1;
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  cursor: text;
}

/* ------------------------------------------------------------------ expanded day */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  padding: calc(env(safe-area-inset-top) + 56px) 12px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--shade);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.day.big {
  flex: 1;
  flex-direction: column;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.day.big .strip {
  width: auto;
  height: 46px;
  padding: 0 16px;
  writing-mode: horizontal-tb;
  transform: none;
  border-left: 0;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
}
.day.big.today .strip { border-bottom-color: var(--today-line); }
.day.big .strip .wd { order: 1; }
.day.big .strip .nd { order: 2; font-size: 14px; }
.day.big .holiday { padding: 10px 16px 0; font-size: 13px; }
.day.big .overdue { margin: 10px 12px 2px; font-size: 13px; padding: 8px 10px; }
.day.big .task { padding: 9px 12px 9px 4px; }
.day.big .check { width: 34px; height: 24px; }
.day.big .check .ico { width: 20px; height: 20px; }
.day.big .grow::after, .day.big .grow textarea, .day.big .grow .view { font-size: 17px; }
.day.big .num { font-size: 120px; right: 14px; }

/* ------------------------------------------------------------------ dragging */
.app.dragging { cursor: grabbing; }
.ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  padding: 7px 10px 7px 26px;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  line-height: 1.3;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.ghost.done { color: var(--muted); text-decoration: line-through; }

.edge {
  position: fixed;
  top: 50%;
  z-index: 40;
  width: 28px;
  height: 140px;
  margin-top: -70px;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  pointer-events: none;
  transition: background 0.15s, width 0.15s;
}
.edge.left { left: 0; border-radius: 0 14px 14px 0; }
.edge.right { right: 0; border-radius: 14px 0 0 14px; }
.edge.on { background: var(--accent); width: 34px; }

/* ------------------------------------------------------------------ sheets */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--shade);
  -webkit-user-select: none;
  user-select: none;
}

.picker {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 52px);
  left: 50%;
  width: min(340px, calc(100% - 24px));
  transform: translateX(-50%);
  padding: 10px;
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  touch-action: pan-y;
}
.picker-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
}
.picker-head .icon { color: var(--muted); }
.picker-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  width: 100%;
  border-radius: 10px;
}
.picker-row.shown { background: var(--panel-hi); }
.picker-row span {
  position: relative;
  isolation: isolate;
  padding: 9px 0 11px;
  text-align: center;
  font-size: 15px;
}
.picker-row span:nth-child(n + 6) { color: var(--muted); }
.picker-row.heads span { padding: 6px 0; font-size: 11px; font-weight: 700; color: var(--muted); }
.picker-row span.holiday { color: var(--holiday); }
.picker-row span.muted { opacity: 0.35; }
.picker-row span.today { color: #1b2a25; font-weight: 800; }
.picker-row span.today::before {
  content: '';
  position: absolute;
  inset: 3px 6px;
  z-index: -1;
  border-radius: 10px;
  background: var(--today-line);
}
.picker-row span.has::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: var(--warn);
}
.picker-row span.today.has::after { background: #1b2a25; }
.picker-today {
  width: 100%;
  margin-top: 6px;
  padding: 11px;
  border-radius: 12px;
  background: var(--panel-hi);
  font-weight: 800;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88%;
  overflow-y: auto;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 18px);
  border-radius: 22px 22px 0 0;
  background: var(--panel);
  color: var(--text);
}
.grabber {
  width: 38px;
  height: 5px;
  margin: 0 auto 6px;
  border-radius: 3px;
  background: var(--panel-line);
}
.sheet h3 {
  margin: 22px 4px 2px;
  font-size: 14px;
  font-weight: 800;
  color: var(--muted);
}
.sheet .hint { margin: 4px 4px 6px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.sheet .hint b { color: var(--text); }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--panel-line);
  font-size: 16px;
  text-align: left;
}
.row small, .row .status { font-size: 14px; color: var(--muted); white-space: nowrap; }
.row:disabled { opacity: 0.45; cursor: default; }

.switch input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 48px;
  height: 29px;
  margin: 0;
  border-radius: 15px;
  background: var(--panel-line);
  transition: background 0.2s;
}
.switch input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::before { transform: translateX(19px); }

.field input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--panel-hi);
  font-size: 16px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

.pair { border-bottom: 0; }
.pair button, .pair .as-button {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  background: var(--panel-hi);
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}
.message { margin: 12px 4px 0; font-size: 14px; color: var(--accent); }

/* ------------------------------------------------------------------ transitions */
.fade-enter-active, .fade-leave-active { transition: opacity 0.18s; }
.fade-enter-from, .fade-leave-to { opacity: 0; }

.sheet-enter-active, .sheet-leave-active { transition: background-color 0.25s; }
.sheet-enter-active .sheet, .sheet-leave-active .sheet { transition: transform 0.25s cubic-bezier(0.22, 0.8, 0.3, 1); }
.sheet-enter-from, .sheet-leave-to { background-color: transparent; }
.sheet-enter-from .sheet, .sheet-leave-to .sheet { transform: translateY(100%); }
