/* ---------- Theme tokens ---------- */
:root,
:root[data-theme="nebula"] {
  --body-bg: #efe7d8;
  --paper: #fffdf8;
  --surface: #ffffff;
  --surface-2: #fbf8f1;
  --surface-hover: #f3edf9;
  --now-bg: #f5eeff;
  --done-bg: #e4dfd3;
  --eraser-bg: #f1eee6;
  --ink: #3a3630;
  --ink-soft: #7c7469;
  --muted: #b3a99a;
  --line: #e7e0d3;
  --ring: #cfc7b8;
  --accent: #8b5cf6;
  --accent-soft: #ece3fc;
  --accent-soft-hover: #ddccf9;
  --shadow: 0 10px 30px rgba(60, 50, 30, 0.12);
  --radius: 14px;
}

:root[data-theme="deepspace"] {
  --body-bg: #e8eef7;
  --paper: #fdfeff;
  --surface: #ffffff;
  --surface-2: #f2f6fb;
  --surface-hover: #e7f0fb;
  --now-bg: #eaf6ff;
  --done-bg: #dde3ea;
  --eraser-bg: #eef2f6;
  --ink: #29323f;
  --ink-soft: #647a91;
  --muted: #a7b3c2;
  --line: #dce5f0;
  --ring: #c3d3e6;
  --accent: #2f8bef;
  --accent-soft: #ddecfd;
  --accent-soft-hover: #c6e0fc;
  --shadow: 0 10px 30px rgba(30, 60, 90, 0.12);
  --radius: 14px;
}

:root[data-theme="blossom"] {
  --body-bg: #fbe9ef;
  --paper: #fffbfc;
  --surface: #ffffff;
  --surface-2: #fdf2f5;
  --surface-hover: #fde3ec;
  --now-bg: #fff0f5;
  --done-bg: #ecdfe3;
  --eraser-bg: #f7edf0;
  --ink: #40323a;
  --ink-soft: #9b7a86;
  --muted: #cfa9b7;
  --line: #f3d9e2;
  --ring: #f0c3d3;
  --accent: #ec6ea5;
  --accent-soft: #fbdeeb;
  --accent-soft-hover: #f7c6de;
  --shadow: 0 10px 30px rgba(140, 40, 80, 0.12);
  --radius: 14px;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Malgun Gothic", "Segoe UI", sans-serif;
}

html {
  background-color: var(--body-bg);
}

body {
  display: flex;
  justify-content: center;
  padding: 28px 16px 60px;
  background-color: var(--body-bg);
  transition: background-color 0.3s ease;
}

.notebook {
  position: relative;
  width: 100%;
  max-width: 1180px;
  background: var(--paper);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 22px 28px 28px 46px;
  border: 1px solid var(--line);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.spiral {
  position: absolute;
  left: -4px;
  top: 24px;
  bottom: 24px;
  width: 28px;
  background-image: radial-gradient(circle, var(--ring) 0 4px, transparent 5px);
  background-size: 28px 26px;
  background-repeat: repeat-y;
  opacity: 0.6;
  pointer-events: none;
}

.page { position: relative; }

/* ---------- Page-turn animation (date navigation) ---------- */
@keyframes pageTurnNext {
  0%   { transform: perspective(1400px) rotateY(0deg); box-shadow: none; }
  35%  { transform: perspective(1400px) rotateY(-6deg); box-shadow: -26px 0 34px -22px rgba(0, 0, 0, 0.32); }
  100% { transform: perspective(1400px) rotateY(0deg); box-shadow: none; }
}
@keyframes pageTurnPrev {
  0%   { transform: perspective(1400px) rotateY(0deg); box-shadow: none; }
  35%  { transform: perspective(1400px) rotateY(6deg); box-shadow: 26px 0 34px -22px rgba(0, 0, 0, 0.32); }
  100% { transform: perspective(1400px) rotateY(0deg); box-shadow: none; }
}
.page.turning-next { animation: pageTurnNext 0.4s ease; transform-origin: left center; }
.page.turning-prev { animation: pageTurnPrev 0.4s ease; transform-origin: right center; }

/* ---------- Font mode ---------- */
:root[data-font="pen"] .quote-box textarea,
:root[data-font="pen"] .priority-text,
:root[data-font="pen"] .braindump-item .txt,
:root[data-font="pen"] .tb-cell,
:root[data-font="pen"] .tb-block-text {
  font-family: "Nanum Pen Script", cursive;
  font-size: 1.25em;
  letter-spacing: 0.02em;
}
:root[data-font="brush"] .quote-box textarea,
:root[data-font="brush"] .priority-text,
:root[data-font="brush"] .braindump-item .txt,
:root[data-font="brush"] .tb-cell,
:root[data-font="brush"] .tb-block-text {
  font-family: "Nanum Brush Script", cursive;
  font-size: 1.3em;
  letter-spacing: 0.02em;
}
:root[data-font="gaegu"] .quote-box textarea,
:root[data-font="gaegu"] .priority-text,
:root[data-font="gaegu"] .braindump-item .txt,
:root[data-font="gaegu"] .tb-cell,
:root[data-font="gaegu"] .tb-block-text {
  font-family: "Gaegu", cursive;
  font-size: 1.1em;
}
:root[data-font="poor"] .quote-box textarea,
:root[data-font="poor"] .priority-text,
:root[data-font="poor"] .braindump-item .txt,
:root[data-font="poor"] .tb-cell,
:root[data-font="poor"] .tb-block-text {
  font-family: "Poor Story", cursive;
  font-size: 1.1em;
}

.font-select {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}
.font-select:hover { background: var(--surface-hover); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.brand {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 0.15s ease;
}
.nav-btn:hover { background: var(--accent-soft-hover); }
.nav-btn:active { transform: scale(0.92); }

.date-display {
  border: none;
  background: transparent;
  font-size: 17px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
}
.date-display:hover { background: var(--surface-hover); }
#dateLabel.holiday { color: #d1445a; }

.today-btn {
  border: 1px solid var(--ring);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-soft);
  margin-left: 4px;
}
.today-btn:hover { background: var(--surface-hover); }
.today-btn.active {
  background: var(--accent);
  color: #171331;
  border-color: var(--accent);
  font-weight: 700;
}

/* ---------- Theme switcher ---------- */
.theme-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
}
.theme-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 0 0 1px var(--line);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.theme-swatch:hover { transform: scale(1.1); }
.theme-swatch.selected {
  border-color: var(--paper);
  box-shadow: 0 0 0 2px var(--accent);
}
.theme-swatch[data-theme="nebula"] { background: radial-gradient(circle at 30% 30%, #e3d3ff, #8b5cf6 65%, #5b32c9); }
.theme-swatch[data-theme="deepspace"] { background: radial-gradient(circle at 30% 30%, #cfe6ff, #2f8bef 65%, #1c5fb0); }
.theme-swatch[data-theme="blossom"] { background: radial-gradient(circle at 30% 30%, #ffd9e8, #ec6ea5 65%, #c1447d); }

/* ---------- Quote of the day ---------- */
.quote-of-day {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-style: italic;
  margin: 2px 2px 12px;
  line-height: 1.55;
}
.qod-author {
  font-style: normal;
  color: var(--muted);
  font-size: 11.5px;
}

/* ---------- Weekday strip ---------- */
.weekday-strip {
  display: flex;
  gap: 10px;
  margin: 6px 2px 18px;
  font-size: 13px;
  color: var(--ink-soft);
}
.weekday-strip .wd {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.weekday-strip .wd.active {
  background: var(--accent);
  color: #171331;
  font-weight: 700;
}

/* ---------- Achievement stats ---------- */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 2px 18px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat-label {
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.stat-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

/* ---------- Mood check-in ---------- */
.mood-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 0 2px 18px;
}
.mood-label {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-right: 2px;
}
.mood-picker {
  display: flex;
  gap: 4px;
}
.mood-btn {
  border: 1px solid transparent;
  background: transparent;
  font-size: 19px;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.12s ease, transform 0.12s ease, background 0.12s ease;
}
.mood-btn:hover { opacity: 0.85; }
.mood-btn.selected {
  opacity: 1;
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: scale(1.12);
}
.mood-compare {
  font-size: 12px;
  color: var(--ink-soft);
  margin-left: auto;
}

/* ---------- Calendar popover ---------- */
.calendar-popover {
  position: absolute;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 30;
  width: 280px;
}
.calendar-popover.hidden { display: none; }

.install-hint {
  position: fixed;
  top: 70px;
  right: 20px;
  max-width: 300px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  z-index: 60;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}
.install-hint.hidden { display: none; }
.install-hint-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink-soft);
}
.install-hint b { color: var(--accent); }
@media (max-width: 760px) {
  .install-hint { right: 10px; left: 10px; max-width: none; top: 64px; }
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 700;
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-day {
  position: relative;
  border: none;
  background: transparent;
  height: 34px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}
.cal-day:hover { background: var(--surface-hover); }
.cal-day.muted { color: var(--muted); }
.cal-day.today { border: 1px solid var(--accent); }
.cal-day.selected { background: var(--accent); color: #171331; font-weight: 700; }
.cal-day .dot {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}
.cal-day.selected .dot { background: #171331; }
.cal-day.holiday:not(.selected) { color: #d1445a; font-weight: 700; }
.cal-day.holiday .dot { background: #d1445a; }

/* ---------- Layout ---------- */
.board {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}

/* ---------- Month view ---------- */
.month-view.hidden { display: none; }
.month-view-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.month-view-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--ink);
  min-width: 120px;
  text-align: center;
}
.month-view-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.month-view-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.mv-day {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 4px 3px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: background 0.15s ease;
}
.mv-day:hover { background: var(--surface-hover); }
.mv-day.muted { opacity: 0.4; }
.mv-day.today { border-color: var(--accent); }
.mv-day.selected { box-shadow: 0 0 0 2px var(--accent) inset; }
.mv-daynum {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-soft);
}
.mv-day.today .mv-daynum { color: var(--accent); }
.mv-day.holiday .mv-daynum { color: #d1445a; }
.mv-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  min-height: 6px;
}
.mv-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sc, var(--accent));
  flex-shrink: 0;
}
.mv-dot.done { opacity: 0.4; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.left-col { display: flex; flex-direction: column; gap: 16px; }

.quote-box textarea {
  width: 100%;
  border: none;
  resize: none;
  font-size: 13px;
  color: var(--ink-soft);
  font-style: italic;
  background: transparent;
  outline: none;
  font-family: inherit;
}
.quote-hint {
  margin: -4px 0 8px;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- Priorities ---------- */
.priorities-list {
  list-style: none;
  counter-reset: pr;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.priority-slot {
  counter-increment: pr;
  min-height: 38px;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 8px 8px 8px 34px;
  font-size: 14px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  cursor: grab;
}
.priority-slot::before {
  content: counter(pr);
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.priority-text {
  flex: 1;
  min-width: 0;
  outline: none;
  cursor: text;
  word-break: break-word;
}
.priority-text:empty::after {
  content: attr(data-placeholder);
  color: var(--muted);
}
.priority-slot.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.priority-slot.dragging { opacity: 0.5; }
.priority-recur-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.1s;
  flex-shrink: 0;
  padding: 2px;
}
.priority-slot:hover .priority-recur-btn { opacity: 1; }
.priority-recur-btn:hover { color: var(--accent); }
.priority-recur-btn.active { opacity: 1; color: var(--accent); }

/* ---------- Brain dump ---------- */
.add-item-form {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.add-item-form input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
.add-item-form input::placeholder { color: var(--muted); }
.add-item-form input:focus { border-color: var(--accent); }
.add-btn {
  border: none;
  background: var(--accent);
  color: #171331;
  width: 30px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.add-btn:hover { opacity: 0.9; }

.bd-input-wrap { position: relative; }
.bd-suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: -6px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.bd-suggest.hidden { display: none; }
.bd-suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
}
.bd-suggest-item:hover { background: var(--surface-hover); }
.bd-suggest-item .freq {
  color: var(--muted);
  font-size: 10.5px;
  flex-shrink: 0;
}

.braindump-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 360px;
  overflow-y: auto;
}
.braindump-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 4px;
  border-radius: 8px;
  cursor: grab;
  font-size: 13.5px;
}
.braindump-item:hover { background: var(--surface-hover); }
.braindump-item.dragging { opacity: 0.4; }
.braindump-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}
.braindump-item .txt {
  flex: 1;
  word-break: break-word;
  cursor: text;
  border-radius: 4px;
}
.braindump-item .txt[contenteditable="true"] {
  background: var(--surface-hover);
  padding: 0 4px;
  outline: 1px solid var(--accent);
}
.braindump-item.done .txt {
  text-decoration: line-through;
  color: var(--muted);
}
.bd-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--sc, transparent);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.bd-color-dot:hover { transform: scale(1.2); }
.bd-recur-badge {
  font-size: 11px;
  flex-shrink: 0;
}
.braindump-item .del-btn,
.braindump-item .sched-btn,
.braindump-item .recur-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.1s;
  flex-shrink: 0;
}
.braindump-item:hover .del-btn,
.braindump-item:hover .sched-btn,
.braindump-item:hover .recur-btn { opacity: 1; }
.braindump-item .del-btn:hover,
.braindump-item .sched-btn:hover,
.braindump-item .recur-btn:hover { color: var(--accent); }

.bd-schedule-menu {
  position: fixed;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}
.bd-schedule-menu input[type="date"],
.bd-schedule-menu input[type="time"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
.bd-schedule-confirm {
  border: none;
  background: var(--accent);
  color: #171331;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.bd-schedule-confirm:hover { opacity: 0.9; }

.hint {
  font-size: 11.5px;
  color: var(--muted);
  margin: 10px 2px 0;
}

/* ---------- Time box ---------- */
.timebox-card { padding: 14px 16px 18px; }
.timebox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.timebox-header h3 { margin: 0; }

.pen-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pen-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  background: var(--c, var(--eraser-bg));
  cursor: pointer;
  padding: 0;
  font-size: 11px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.pen-swatch.eraser { background: var(--eraser-bg); }
.pen-swatch.selected { box-shadow: 0 0 0 2px var(--accent); transform: scale(1.08); }
.pen-mode-btn {
  border: 1px solid var(--ring);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12.5px;
  cursor: pointer;
  margin-left: 4px;
  color: var(--ink-soft);
}
.pen-mode-btn.active {
  background: var(--accent);
  color: #171331;
  border-color: var(--accent);
  font-weight: 700;
}
.pen-group-swatches {
  display: flex;
  align-items: center;
  gap: 6px;
}
.group-manage-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px dashed var(--ring);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.group-manage-btn:hover { background: var(--surface-hover); }

.group-manage-popover {
  position: fixed;
  z-index: 60;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.group-manage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.group-manage-header h4 { margin: 0; font-size: 13.5px; color: var(--ink); }
.group-manage-close {
  border: none;
  background: transparent;
  font-size: 16px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 2px;
}
.group-manage-close:hover { color: var(--ink); }
.group-manage-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.group-manage-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.group-manage-row input[type="color"] {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: none;
}
.group-manage-row input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
.group-manage-row input[type="text"]:focus { border-color: var(--accent); }
.group-manage-row .group-del-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
  padding: 4px;
}
.group-manage-row .group-del-btn:hover { color: #d1445a; }
.group-add-btn {
  width: 100%;
  margin-top: 8px;
  border: 1px dashed var(--ring);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
}
.group-add-btn:hover { background: var(--surface-hover); }

.timebox-scroll {
  max-height: 640px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.timebox-grid {
  display: flex;
  flex-direction: column;
  position: relative;
}

.tb-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  height: 32px;
  border-bottom: 1px dashed var(--line);
  position: relative;
}
.tb-row.tb-row-hourend { border-bottom: 1px solid var(--ring); }
.tb-row:last-child { border-bottom: none; }
.tb-row.now-row { background: var(--now-bg); }
.tb-row.now-row::before {
  content: "";
  position: absolute;
  left: 52px;
  right: 0;
  top: 0;
  height: 2px;
  background: var(--accent);
  z-index: 3;
}

.tb-hour-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  color: var(--ink-soft);
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.tb-cell {
  height: 100%;
  padding: 4px 6px;
  font-size: 12.5px;
  outline: none;
  cursor: text;
  line-height: 1.35;
  word-break: break-word;
  transition: background 0.1s ease;
  position: relative;
  overflow: hidden;
  color: var(--ink);
}
.tb-cell.covered { cursor: default; }
.tb-cell.drag-over { outline: 2px solid var(--accent); outline-offset: -2px; }
.tb-cell:focus { background: var(--surface-2); }

.timebox-grid.pen-active .tb-cell:not(.covered) { cursor: crosshair; }
.timebox-grid.pen-active .tb-block { cursor: crosshair; }

/* ---------- Time box blocks (absolutely positioned, resizable cards) ---------- */
.tb-blocks-layer {
  position: absolute;
  top: 0;
  left: 52px;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 2;
}

.tb-block {
  position: absolute;
  left: 4px;
  right: 4px;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--bc, #f3e9da);
  color: #2a2440;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: grab;
  font-size: 12.5px;
  line-height: 1.3;
  overflow: hidden;
  pointer-events: auto;
}
.tb-block:active { cursor: grabbing; }
.tb-block.dragging { opacity: 0.35; }
.tb-block.resizing { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45); z-index: 4; }
.tb-block.drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }
.tb-block-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.tb-block-text {
  outline: none;
  word-break: break-word;
  user-select: none;
  cursor: text;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
.tb-block-recur-badge {
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1.3;
}
.tb-block-text[contenteditable="true"] {
  user-select: text;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 4px;
  padding: 0 2px;
}
.tb-block-desc {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.3;
  color: #2a2440;
  opacity: 0.65;
  word-break: break-word;
}
.tb-block-del {
  border: none;
  background: rgba(255, 255, 255, 0.55);
  color: #2a2440;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tb-block:hover .tb-block-del { opacity: 1; }
.tb-block-del:hover { background: #fff; }

.tb-block-done {
  border: none;
  background: rgba(255, 255, 255, 0.55);
  color: #2a2440;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tb-block:hover .tb-block-done { opacity: 1; }
.tb-block-done:hover { background: #fff; }
.tb-block.done .tb-block-done { background: rgba(255, 255, 255, 0.15); color: var(--ink-soft); }

.tb-block-recur {
  border: none;
  background: rgba(255, 255, 255, 0.55);
  color: #2a2440;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tb-block:hover .tb-block-recur { opacity: 1; }
.tb-block-recur:hover { background: #fff; }

.tb-block-handle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 34px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  border-radius: 6px;
  color: rgba(0, 0, 0, 0.3);
  font-size: 9px;
  line-height: 1;
  transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.tb-block-handle-top { top: -10px; }
.tb-block-handle-bottom { bottom: -10px; }
.tb-block-handle-top::before { content: "▲"; }
.tb-block-handle-bottom::before { content: "▼"; }
.tb-block-handle:hover { color: rgba(0, 0, 0, 0.55); background: rgba(255, 255, 255, 0.55); }
.tb-block-handle.armed {
  color: #2a2440;
  background: #fff;
  transform: translateX(-50%) scale(1.25);
}
.timebox-grid.pen-active .tb-block-handle { cursor: crosshair; }

.tb-block.done {
  background: var(--done-bg) !important;
  color: var(--ink-soft);
  box-shadow: none;
}
.tb-block.done .tb-block-text {
  text-decoration: line-through;
  color: var(--ink-soft);
}
.tb-block.done .tb-block-desc {
  color: var(--ink-soft);
}
.tb-block.done .tb-block-del {
  background: rgba(255, 255, 255, 0.15);
  color: var(--ink-soft);
}

/* ---------- Touch drag (mobile long-press) ----------
   touch-action: none is required (not just preventDefault in JS) for iOS/Android
   to hand the gesture to us instead of starting a native scroll once the finger moves. */
.braindump-item,
.tb-block {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
.tb-block-handle { touch-action: none; }
.timebox-grid.pen-active { touch-action: none; }

.drag-ghost {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  transform: translate(-50%, -125%);
  max-width: 220px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: #171331;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.95;
}

@media (pointer: coarse) {
  .braindump-item .del-btn,
  .braindump-item .sched-btn,
  .braindump-item .recur-btn,
  .priority-recur-btn,
  .tb-block-del,
  .tb-block-done,
  .tb-block-recur {
    opacity: 1;
  }
  .tb-block-handle {
    width: 46px;
    height: 22px;
    font-size: 12px;
    color: rgba(0, 0, 0, 0.4);
    background: rgba(255, 255, 255, 0.4);
  }
  .tb-block-handle-top { top: -13px; }
  .tb-block-handle-bottom { bottom: -13px; }
}

/* ---------- Block color picker & context menu (floating, position:fixed) ---------- */
.tb-color-menu,
.tb-context-menu,
.recur-popover {
  position: fixed;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 8px;
}

.recur-popover {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 220px;
  padding: 12px;
}
.recur-popover h4 { margin: 0; font-size: 13px; color: var(--ink); }
.recur-freq-select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
.recur-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}
.recur-interval-row input[type="number"] {
  width: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
.recur-row input[type="date"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
.recur-weekday-row { flex-wrap: wrap; gap: 4px; }
.recur-wd-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.recur-wd-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #171331;
  font-weight: 700;
}
.recur-actions {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}
.recur-save-btn {
  flex: 1;
  border: none;
  background: var(--accent);
  color: #171331;
  border-radius: 8px;
  padding: 7px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.recur-save-btn:hover { opacity: 0.92; }
.recur-stop-btn {
  border: 1px solid var(--ring);
  background: var(--surface);
  color: #d1445a;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
}
.recur-stop-btn:hover { background: var(--surface-hover); }

.tb-color-menu {
  display: flex;
  gap: 6px;
}
.tb-color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  background: var(--sc, var(--eraser-bg));
  cursor: pointer;
  padding: 0;
}
.tb-color-swatch:hover { transform: scale(1.12); }

.tb-context-menu {
  display: flex;
  flex-direction: column;
  min-width: 120px;
  padding: 4px;
}
.tb-context-item {
  border: none;
  background: transparent;
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}
.tb-context-item:hover { background: var(--surface-hover); }

/* ---------- Detail modal (title big, one-line description) ---------- */
.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.detail-modal.hidden { display: none; }
.detail-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 20, 0.45);
}
.detail-modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px 22px;
}
.detail-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px;
}
.detail-modal-close:hover { color: var(--ink); }
.detail-modal-title {
  margin: 0 0 20px;
  font-size: 34px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--ink);
  word-break: break-word;
  padding-right: 20px;
}
.detail-modal-desc {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink-soft);
  outline: none;
  box-sizing: border-box;
}
.detail-modal-desc::placeholder { color: var(--muted); }
.detail-modal-desc:focus { border-color: var(--accent); }

/* ---------- Auth overlay ---------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 8, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.auth-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}
.auth-sub {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
.auth-card input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
.auth-card input::placeholder { color: var(--muted); }
.auth-card input:focus { border-color: var(--accent); }
.auth-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.auth-btn {
  flex: 1;
  border: 1px solid var(--ring);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.auth-btn:hover { background: var(--surface-hover); }
.auth-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #171331;
}
.auth-btn.primary:hover { opacity: 0.92; }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-error {
  min-height: 16px;
  margin: 0;
  font-size: 12.5px;
  color: #d1445a;
}
.auth-error.is-notice { color: var(--accent); }
.auth-guest-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12.5px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 0;
  text-align: center;
}
.auth-guest-btn:hover { color: var(--accent); }
.auth-notice {
  margin: 4px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}
.auth-privacy-link {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  text-decoration: underline;
}
.auth-privacy-link:hover { color: var(--accent); }

.page-footer {
  text-align: center;
  padding: 18px 0 6px;
}
.page-footer a {
  font-size: 11.5px;
  color: var(--muted);
  text-decoration: underline;
}
.page-footer a:hover { color: var(--accent); }

.user-badge {
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--surface-hover);
  border-radius: 999px;
  padding: 5px 10px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Mobile layout ---------- */
@media (max-width: 760px) {
  body { padding: 0; }

  .notebook {
    max-width: 100%;
    border-radius: 0;
    border-width: 0 0 1px;
    padding: 14px 12px 24px;
  }
  .spiral { display: none; }

  .brand { font-size: 17px; }
  .topbar-right { gap: 8px; }
  .date-nav {
    flex: 1 1 100%;
    order: 5;
    justify-content: center;
    margin-top: 4px;
  }
  .nav-btn { width: 36px; height: 36px; font-size: 18px; }
  .today-btn { padding: 7px 14px; font-size: 13.5px; }
  .date-display { font-size: 16px; padding: 6px 10px; }

  .theme-swatch { width: 28px; height: 28px; }

  .calendar-popover { width: calc(100vw - 32px); max-width: 320px; }

  .board {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .card { padding: 12px 14px; }

  .priority-slot { min-height: 44px; font-size: 15px; }

  .add-item-form input { padding: 10px 12px; font-size: 14.5px; }
  .add-btn { width: 38px; }

  .braindump-item { padding: 9px 6px 9px 4px; }
  .braindump-item .del-btn { font-size: 15px; padding: 4px; }
  .braindump-list { max-height: 300px; }

  .pen-toolbar { gap: 8px; }
  .pen-swatch { width: 28px; height: 28px; }
  .pen-mode-btn { padding: 7px 12px; font-size: 13px; }

  .timebox-scroll { max-height: 62vh; }
  .tb-row { height: 40px; }
  .tb-hour-label { font-size: 11px; }
  .tb-cell { font-size: 13.5px; padding: 6px 8px; }
  .tb-block { font-size: 13.5px; padding: 6px 8px; }
}
