:root {
  color-scheme: light dark;
  --paper: #eef2ee;
  --panel: #e3e9e1;
  --panel-line: #c7d0c4;
  --ink: #202821;
  --muted: #5c6558;
  --line: #ccd4c8;
  --accent: #b8672a;
  --accent-soft: #f2e0cc;
  --live: #3e8c4e;
  --live-soft: #e2efe2;
  --danger: #ab3d3d;
  --danger-soft: #f4e2e0;
  --card-bg: #f7f9f6;
  --tab-monthly: #5b7596;
  --tab-monthly-soft: #dde6ee;
  --tab-daily: #3f7a75;
  --tab-daily-soft: #dbeae7;
  --tab-weekly: #a3651f;
  --tab-weekly-soft: #f2e0c8;
  --tab-breakdown: #7a6ba8;
  --tab-breakdown-soft: #e6e1f2;
  --tab-history: #62744c;
  --tab-history-soft: #e3e9da;
  --daycycle-night: #d8d8dd;
  --daycycle-morning: #f7ddc0;
  --daycycle-day: #f8f0bf;
  --daycycle-evening: #f3cfcf;
  --daycycle-dusk: #ddccec;
}

:root[data-theme="dark"] {
  --paper: #12160f;
  --panel: #1b2118;
  --panel-line: #303a2c;
  --ink: #e9efe4;
  --muted: #93a08c;
  --line: #2b342a;
  --accent: #e08c46;
  --accent-soft: #3a2a17;
  --live: #57c26a;
  --live-soft: #16281a;
  --danger: #e17b7b;
  --danger-soft: #33201f;
  --card-bg: #171d15;
  --tab-monthly: #8fb0d6;
  --tab-monthly-soft: #223040;
  --tab-daily: #6fbdb2;
  --tab-daily-soft: #163330;
  --tab-weekly: #d9974f;
  --tab-weekly-soft: #3a2c17;
  --tab-breakdown: #b3a2e0;
  --tab-breakdown-soft: #2c2540;
  --tab-history: #a3c07f;
  --tab-history-soft: #262f1c;
  --daycycle-night: #191f1a;
  --daycycle-morning: #3a2c1c;
  --daycycle-day: #38381d;
  --daycycle-evening: #391f1f;
  --daycycle-dusk: #291f39;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12160f;
    --panel: #1b2118;
    --panel-line: #303a2c;
    --ink: #e9efe4;
    --muted: #93a08c;
    --line: #2b342a;
    --accent: #e08c46;
    --accent-soft: #3a2a17;
    --live: #57c26a;
    --live-soft: #16281a;
    --danger: #e17b7b;
    --danger-soft: #33201f;
    --card-bg: #171d15;
    --tab-monthly: #8fb0d6;
    --tab-monthly-soft: #223040;
    --tab-daily: #6fbdb2;
    --tab-daily-soft: #163330;
    --tab-weekly: #d9974f;
    --tab-weekly-soft: #3a2c17;
    --tab-breakdown: #b3a2e0;
    --tab-breakdown-soft: #2c2540;
    --tab-history: #a3c07f;
    --tab-history-soft: #262f1c;
    --daycycle-night: #191f1a;
    --daycycle-morning: #3a2c1c;
    --daycycle-day: #38381d;
    --daycycle-evening: #391f1f;
    --daycycle-dusk: #291f39;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", "Yu Gothic Medium", "Meiryo", "Noto Sans JP", sans-serif;
}

.wrap {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: clamp(6px, 1.4vh, 14px) clamp(10px, 2.5vw, 22px);
  gap: clamp(4px, 1vh, 10px);
}

.app-header[hidden] {
  display: none;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  flex: none;
  padding-bottom: clamp(5px, 1vh, 10px);
  border-bottom: 1px solid var(--line);
}

.header-left {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.6vw, 12px);
  min-width: 0;
  flex-wrap: wrap;
}

.day-picker {
  flex: none;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: clamp(3px, 0.8vh, 6px) clamp(5px, 1.2vw, 8px);
  border-radius: 7px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--ink);
}

.day-picker:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.day-picker.is-draft {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.draft-badge {
  flex: none;
  font-size: clamp(0.6rem, 1.4vw, 0.72rem);
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 999px;
}

.draft-badge[hidden] {
  display: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.total-panel {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.total-panel .caption {
  font-size: 0.63rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}

.total-panel .value {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.9rem, 1.9vw, 1.15rem);
  font-weight: 600;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 7px;
  padding: 6px 12px;
  font-size: clamp(0.68rem, 1.5vw, 0.8rem);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-reset-all {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-sync {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--panel-line);
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-sync[hidden] {
  display: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tabs {
  flex: none;
  display: flex;
  gap: 6px;
}

.settings-btn {
  all: unset;
  flex: 0.5;
  box-sizing: border-box;
  text-align: center;
  padding: clamp(4px, 1vh, 7px) 4px;
  border-radius: 7px;
  font-size: clamp(0.68rem, 1.5vw, 0.8rem);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  background: var(--panel);
  border: 1.5px solid var(--panel-line);
}

.settings-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tab-btn {
  all: unset;
  flex: 1;
  box-sizing: border-box;
  text-align: center;
  padding: clamp(4px, 1vh, 7px) 4px;
  border-radius: 7px;
  font-size: clamp(0.68rem, 1.5vw, 0.8rem);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  background: var(--panel);
  border: 1.5px solid var(--panel-line);
}

.tab-btn.tab-monthly.active {
  background: var(--tab-monthly-soft);
  color: var(--tab-monthly);
  border-color: var(--tab-monthly);
}

.tab-btn.tab-weekly.active {
  background: var(--tab-weekly-soft);
  color: var(--tab-weekly);
  border-color: var(--tab-weekly);
}

.tab-btn.tab-daily.active {
  background: var(--tab-daily-soft);
  color: var(--tab-daily);
  border-color: var(--tab-daily);
}

.tab-btn.tab-task.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- ログページ上部: 内訳 / 履歴 パネルを開く小さな丸ボタン --- */

.task-page-header {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-bottom: clamp(3px, 0.6vh, 5px);
}

.tab-round-btn {
  all: unset;
  box-sizing: border-box;
  flex: none;
  width: clamp(26px, 6vw, 32px);
  height: clamp(26px, 6vw, 32px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid transparent;
}

.tab-round-breakdown {
  background: var(--tab-breakdown-soft);
  color: var(--tab-breakdown);
}

.tab-round-history {
  background: var(--tab-history-soft);
  color: var(--tab-history);
}

.tab-round-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.pages {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.pages-track {
  height: 100%;
  display: flex;
  /* Tab switching is tap-only: this is driven entirely by goToPage() setting
     translateX below, never by native scrolling/swiping. */
  transition: transform 0.25s ease;
}

.page {
  position: relative;
  flex: 0 0 100%;
  min-width: 100%;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --- sidework bar (fixed, top of timer tab) --- */

.sidework-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2vw, 14px);
  padding: clamp(2px, 0.5vh, 4px) 2px clamp(3px, 0.6vh, 5px);
  border-bottom: 1px solid var(--line);
  margin-bottom: clamp(2px, 0.5vh, 4px);
}

.side-btn-stack {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.5vh, 4px);
}

.side-btn {
  all: unset;
  box-sizing: border-box;
  flex: none;
  width: clamp(76px, 20vw, 106px);
  text-align: center;
  line-height: 1.15;
  padding: clamp(3px, 0.6vh, 4px) clamp(4px, 1vw, 8px);
  border-radius: 9px;
  font-weight: 700;
  font-size: clamp(0.58rem, 1.3vw, 0.7rem);
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--panel-line);
  cursor: pointer;
}

.side-btn:active {
  transform: translateY(1px);
}

.side-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.side-btn:disabled,
.sidework-circle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sidework-widget {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(2px, 0.5vh, 4px);
}

.sidework-input {
  width: clamp(70px, 26vw, 104px);
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
}

.sidework-input:focus {
  outline: none;
  color: var(--accent);
}

.sidework-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.sidework-circle {
  all: unset;
  box-sizing: border-box;
  width: clamp(42px, 11vw, 56px);
  height: clamp(42px, 11vw, 56px);
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.sidework-widget.running .sidework-circle {
  border-color: var(--live);
  background: var(--live-soft);
  animation: breathe 2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .sidework-widget.running .sidework-circle { animation: none; }
}

.sidework-time {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.46rem, 1.15vw, 0.6rem);
  font-weight: 700;
}

/* --- timer list --- */

.list-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  transition: background 0.15s ease;
}

.list-wrap.drop-target {
  background: var(--accent-soft);
}

.list {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1vh, 10px);
  padding: 1px 1px 2px;
}

.row {
  position: relative;
  flex: none;
  height: clamp(42px, 7vh, 58px);
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.6vw, 12px);
  padding: 0 clamp(6px, 1.6vw, 12px) 0 clamp(8px, 2vw, 14px);
  background: var(--card-bg);
  border: 1.5px solid var(--line);
  border-radius: clamp(8px, 1.4vh, 14px);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.row.dragging {
  z-index: 30;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.2);
  cursor: grabbing;
}

.row.running {
  border-color: var(--live);
  background: var(--live-soft);
  animation: breathe 2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .row.running { animation: none; }
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(62, 140, 78, 0.25); }
  50% { box-shadow: 0 0 0 4px rgba(62, 140, 78, 0); }
}

.row-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(1rem, 1.9vw, 1.05rem);
}

.row-input::placeholder {
  color: var(--muted);
  font-weight: 500;
}

.row-input:focus {
  outline: none;
}

.row-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.row-time {
  all: unset;
  box-sizing: border-box;
  flex: none;
  min-width: clamp(58px, 11vw, 88px);
  text-align: right;
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.7rem, 1.8vw, 0.95rem);
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 6px;
}

.row-time:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.row-time:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.row-time:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: transparent;
  color: var(--ink);
}

.row-toggle {
  all: unset;
  box-sizing: border-box;
  flex: none;
  cursor: pointer;
  text-align: center;
  padding: clamp(4px, 1vh, 8px) clamp(9px, 2.2vw, 15px);
  border-radius: 999px;
  font-weight: 700;
  font-size: clamp(0.62rem, 1.5vw, 0.78rem);
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.row.running .row-toggle {
  background: var(--live);
  color: #fff;
}

.row-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.row-toggle:disabled,
.row-reset:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.row-reset {
  all: unset;
  box-sizing: border-box;
  flex: none;
  width: clamp(20px, 3vw, 28px);
  height: clamp(20px, 3vw, 28px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: clamp(0.62rem, 1.4vw, 0.78rem);
  cursor: pointer;
}

.row-reset:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.row-reset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.row-handle {
  all: unset;
  box-sizing: border-box;
  flex: none;
  width: clamp(22px, 3.4vw, 30px);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}

.row-handle:active {
  cursor: grabbing;
}

.row-handle .bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.row-handle .bars span {
  display: block;
  width: clamp(14px, 2.6vw, 18px);
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}

.row-handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.add-row {
  all: unset;
  box-sizing: border-box;
  flex: none;
  height: clamp(38px, 6vh, 50px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px dashed var(--line);
  border-radius: clamp(8px, 1.4vh, 14px);
  color: var(--muted);
  font-weight: 700;
  font-size: clamp(0.7rem, 1.6vw, 0.85rem);
  cursor: pointer;
}

.add-row:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.add-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- breakdown page --- */

.breakdown {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(3px, 1.1vh, 10px);
  padding: 2px 2px 4px;
  overflow: hidden;
}

.breakdown-empty,
.history-empty {
  margin: auto;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.breakdown-row {
  flex: 0 0 auto;
  height: clamp(22px, 5.2vh, 42px);
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.6vw, 12px);
}

.breakdown-row .b-label {
  width: 26%;
  flex: none;
  font-weight: 700;
  font-size: clamp(0.68rem, 1.5vw, 0.85rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breakdown-row .bar-track {
  flex: 1;
  height: clamp(10px, 2.6vh, 20px);
  background: var(--panel);
  border-radius: 999px;
  overflow: hidden;
}

.breakdown-row .bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.breakdown-row.running .bar-fill {
  background: var(--live);
}

.breakdown-row .b-time {
  flex: none;
  width: clamp(52px, 9vw, 78px);
  text-align: right;
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.6rem, 1.4vw, 0.76rem);
  color: var(--muted);
}

.breakdown-row .b-pct {
  flex: none;
  width: clamp(30px, 5vw, 42px);
  text-align: right;
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.6rem, 1.4vw, 0.76rem);
  font-weight: 600;
  color: var(--accent);
}

.breakdown-row.running .b-pct {
  color: var(--live);
}

/* --- history page --- */

.history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 2px 12px;
}

.history-row {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 9px 11px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.history-row .h-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.history-row .h-date {
  font-weight: 700;
  font-size: 0.85rem;
}

.history-row .h-total {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--muted);
}

.history-stack {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--panel);
  gap: 1px;
}

.history-stack span {
  height: 100%;
  background: var(--accent);
}

.history-legend {
  font-size: 0.72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- monthly calendar page (Monday-start, exactly the weeks the current
   month needs, all fitting on one screen with no scrolling — only a
   horizontal swipe or the prev/next buttons change month; tap a day to
   jump the daily view to it) --- */

.monthly-calendar {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.8vh, 6px);
  padding: 2px 2px 4px;
  overflow: hidden;
}

.monthly-weekday-row {
  flex: none;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.monthly-weekday-row span {
  text-align: center;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
  padding: 2px 0;
}

.monthly-weekday-row span.saturday {
  color: var(--tab-monthly);
}

.monthly-weekday-row span.sunday {
  color: var(--danger);
}

/* No scrolling — the grid always shows exactly this month's weeks (4-6
   rows), so this box just claims whatever vertical space is left. */
.monthly-weeks-scroll {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.monthly-weeks {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* flex:1 (not a fixed height) so 4, 5, or 6 week rows always split the
   available height evenly and the whole month fits on one screen. */
.monthly-week-row {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.monthly-cell {
  all: unset;
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding: 4px 2px;
  cursor: pointer;
  color: var(--ink);
  overflow: hidden;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  /* nothing here scrolls (the grid never scrolls), so claim the whole
     gesture — this keeps the browser from intercepting it as a native pan,
     giving the horizontal swipe-navigation gesture (which changes month) a
     clean, uncontested pointer stream */
  touch-action: none;
}

.monthly-cell:hover {
  background: var(--panel);
}

.monthly-cell.drop-target {
  background: var(--accent-soft);
}

/* a lead/trail day from the adjacent month, shown only to complete a
   Monday-start week row — dimmed so the current month's own days read as
   the primary content */
.monthly-cell.other-month {
  opacity: 0.45;
}

.mc-month-tag {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 0.52rem;
  font-weight: 700;
  color: var(--tab-monthly);
}

.monthly-cell .mc-date {
  font-size: clamp(0.68rem, 1.6vw, 0.85rem);
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.monthly-cell.saturday:not(.today) .mc-date {
  color: var(--tab-monthly);
}

.monthly-cell.sunday:not(.today) .mc-date {
  color: var(--danger);
}

.monthly-cell.today .mc-date {
  background: var(--tab-monthly);
  color: #fff;
}

/* body column: day title (if any) stacked above the task labels */
.mc-body {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* day title: a label on the date itself (e.g. "旅行"), separate from any
   plan or task on it — shown filled-in so it reads as a title. Horizontal,
   as small as stays legible, and allowed to wrap onto 2 lines (the cell has
   height to spare) instead of truncating a single line too eagerly. */
.mc-day-title {
  flex: none;
  align-self: stretch;
  width: 100%;
  box-sizing: border-box;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.42rem;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: var(--accent);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  cursor: pointer;
}

.mc-day-title.empty {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  -webkit-line-clamp: 1;
}

.mc-events {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.mc-event {
  flex: none;
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mc-event-more {
  color: var(--muted);
  font-weight: 600;
}

.monthly-cell:focus-visible {
  outline: 2px solid var(--tab-monthly);
  outline-offset: 1px;
}

/* --- calendar page (weekly, vertical) --- */

.calendar {
  --cal-gutter: 30px;
  --hour-h: 40px;
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.8vh, 6px);
  padding: 2px 2px 4px;
  overflow: hidden;
}

.calendar-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.calendar-month-label {
  font-weight: 700;
  font-size: clamp(0.78rem, 1.7vw, 0.92rem);
}

.calendar-nav-btn {
  all: unset;
  box-sizing: border-box;
  width: clamp(24px, 4vw, 30px);
  height: clamp(24px, 4vw, 30px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.calendar-nav-btn:hover {
  color: var(--accent);
}

.calendar-nav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- デイリーページ専用: 「土/日付/タイトル」表示(#calendarWeekHeader、
   ウィークリーの1日ぶんと同じ .calendar-day-header を使い回す)を左寄せの
   自然幅にし、空いた右側をブリーフィングメモ欄にする。ID指定なので
   ウィークリー側(#weeklyWeekHeader、7日分を均等幅で並べる)には影響しない。 */
.daily-header-row {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: 8px;
}

#calendarWeekHeader {
  flex: none;
}

#calendarWeekHeader .calendar-day-header {
  flex: none;
  min-width: 64px;
  padding-left: 8px;
  padding-right: 8px;
}

.briefing-memo-input {
  flex: 1;
  min-width: 0;
  height: 96px;
  resize: none;
  text-align: left;
  font-family: inherit;
  /* iOS Safari auto-zooms on focus for any text input under 16px, so this
     stays at 16px rather than matching the app's usual small UI text. */
  font-size: 16px;
  line-height: 1.3;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  padding: 5px 10px;
}

.briefing-memo-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.calendar-week-header {
  flex: none;
  display: flex;
}

.cal-gutter-spacer {
  flex: none;
  width: var(--cal-gutter);
}

.calendar-day-header {
  all: unset;
  box-sizing: border-box;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px 0 4px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
}

.calendar-day-header:hover {
  background: var(--panel);
}

.calendar-day-header:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.calendar-day-header.selected {
  background: var(--accent-soft);
}

.calendar-day-header .cdh-weekday {
  font-size: clamp(0.55rem, 1.2vw, 0.65rem);
  color: var(--muted);
  font-weight: 600;
}

.calendar-day-header.saturday .cdh-weekday {
  color: var(--tab-monthly);
}

.calendar-day-header.sunday .cdh-weekday {
  color: var(--danger);
}

.calendar-day-header .cdh-date {
  font-size: clamp(0.68rem, 1.5vw, 0.82rem);
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-day-header.saturday:not(.today) .cdh-date {
  color: var(--tab-monthly);
}

.calendar-day-header.sunday:not(.today) .cdh-date {
  color: var(--danger);
}

.calendar-day-header.today .cdh-date {
  color: #fff;
  background: var(--accent);
}

/* day title: separate from any plan/task on the date, so it's shown filled
   solid to read as a title, sitting right under the date and above the
   scrollable hour grid below it */
.calendar-day-header .cdh-title {
  max-width: 100%;
  box-sizing: border-box;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.58rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-day-header .cdh-title.empty {
  background: transparent;
  border: 1.5px dashed var(--line);
  color: var(--muted);
  padding: 1px 6px;
}

.calendar-day-header .cdh-dot {
  position: absolute;
  top: 1px;
  right: 22%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.calendar-week-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.calendar-hours {
  flex: none;
  width: var(--cal-gutter);
  height: calc(var(--hour-h) * 24);
  position: relative;
}

.cal-hour-label {
  position: absolute;
  left: 0;
  right: 4px;
  text-align: right;
  font-size: 0.55rem;
  color: var(--muted);
  transform: translateY(-50%);
  white-space: nowrap;
}

/* 時限マーク: 8-9時を0限として9-13時に1-4限、14-20時に5-10限を振る
   (13-14時の昼休みは番号なし)。丸囲み文字だと小さくなりすぎるので、
   はっきり見える色つきの四角バッジにしている。 */
.cal-period-label {
  position: absolute;
  right: 1px;
  min-width: 20px;
  height: 20px;
  padding: 0 2px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: var(--tab-daily);
  font-size: 0.76rem;
  font-weight: 700;
  color: #fff;
  transform: translateY(-50%);
  white-space: nowrap;
}

.calendar-week-grid {
  flex: 1;
  min-width: 0;
  display: flex;
  height: calc(var(--hour-h) * 24);
  position: relative;
  /* Two layers: the hour gridlines on top, and a 0:00-24:00 time-of-day
     tint underneath (night -> morning -> daytime -> evening -> dusk ->
     night again) so the grid gives an at-a-glance sense of what part of
     the day a slot falls in. The tint layer is pinned to exactly 24 hours
     via background-size, independent of the grid's actual height (which
     grows to fit the "time undetermined" zone below the 24:00 line). */
  background-image:
    repeating-linear-gradient(
      to bottom,
      var(--line) 0,
      var(--line) 1px,
      transparent 1px,
      transparent var(--hour-h)
    ),
    linear-gradient(
      to bottom,
      var(--daycycle-night) 0%,
      var(--daycycle-night) 18.75%,
      var(--daycycle-morning) 29.17%,
      var(--daycycle-day) 39.58%,
      var(--daycycle-day) 58.33%,
      var(--daycycle-evening) 68.75%,
      var(--daycycle-dusk) 75%,
      var(--daycycle-night) 81.25%,
      var(--daycycle-night) 100%
    );
  background-size: 100% 100%, 100% calc(var(--hour-h) * 24);
  background-repeat: repeat, no-repeat;
  background-position: top, top;
}

/* デイリーの時間軸グリッド(#calendarWeekBody、スクロールする)と、その
   右のメモ欄をこの行で横に並べる。メモ欄はこの行の外にある
   calendar-week-body の内部スクロールに巻き込まれず、画面に見えている
   範囲の高さで固定される。 */
.calendar-schedule-row {
  flex: 1;
  min-height: 0;
  display: flex;
}

.daily-notes-input {
  flex: 1;
  min-width: 0;
  resize: none;
  box-sizing: border-box;
  border: none;
  border-left: 1px solid var(--line);
  background: var(--card-bg);
  color: var(--ink);
  font-family: inherit;
  /* iOS Safari auto-zooms on focus for any text input under 16px */
  font-size: 16px;
  line-height: 1.05;
  padding: 8px 10px;
}

.daily-notes-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.calendar-day-col {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  border-left: 1px solid var(--line);
  /* JS owns this gesture (long-press to create vs. drag to scroll) so native
     touch panning is off here; script.js scrolls calendarWeekBody itself. */
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.15s ease;
}

.calendar-day-col.drop-target {
  background: var(--accent-soft);
}

.cal-block {
  position: absolute;
  z-index: 3;
  border-radius: 4px;
  padding: 1px 3px;
  font-size: 0.55rem;
  font-weight: 600;
  line-height: 1.3;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.cal-plan-block {
  position: absolute;
  z-index: 2;
  box-sizing: border-box;
  border: 2px dashed var(--muted);
  border-radius: 4px;
  padding: 1px 3px;
  font-size: 0.55rem;
  font-weight: 600;
  line-height: 1.3;
  background: var(--card-bg);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.cal-plan-block.dragging {
  z-index: 20;
  opacity: 0.85;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  cursor: grabbing;
}

/* shown once the long-press to arm a move has fired, before any actual
   drag movement — the same "ready to grab" cue used on いつか chips */
.cal-plan-block.armed {
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.cal-plan-block.selected {
  z-index: 10;
  border-style: solid;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.cal-plan-resize-handle {
  position: absolute;
  z-index: 12;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 14px;
  border-radius: 7px;
  border: 2px solid var(--card-bg);
  cursor: ns-resize;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.cal-now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px solid var(--danger);
  z-index: 5;
  pointer-events: none;
}

.cal-now-line::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

.calendar-unplanned {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  /* extra top padding gives the child-count badge (which pokes up past its
     own chip's corner) guaranteed clearance from this row's own top edge */
  padding: 10px 2px 6px;
  border-top: 1px solid var(--line);
  transition: background 0.15s ease;
  /* Chips already block iOS's text-selection callout, but the title label
     and the gaps around chips didn't — a press-and-drag starting there
     could trigger native text selection instead of the tray's own drag
     gestures. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.calendar-unplanned.drop-target {
  background: var(--accent-soft);
}

.calendar-unplanned[hidden] {
  display: none;
}

.calendar-unplanned-title {
  flex: none;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.calendar-unplanned-list {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0;
  /* Without this, scrolling past either edge of the いつか tray chains into
     whatever scrollable ancestor sits behind it, so a swipe meant to browse
     チップs could scroll something else instead. */
  overscroll-behavior-x: contain;
}

.calendar-unplanned-empty {
  flex: none;
  font-size: 0.65rem;
  color: var(--muted);
}

/* a small org-chart from the currently active parent chip down to its own
   children just below — a stem, a horizontal spine, and one drop per child
   — so the family relationship reads as an actual branching tree instead
   of only being inferable from the active-parent ring. Just a positioning
   root; the visible lines are .someday-branch-line children generated in
   JS, since their count depends on how many children there are. Position
   is computed from the real on-screen positions of the parent chip and
   every child chip, since any of them can sit anywhere along their own
   horizontally-scrolling tray. */
.someday-branch[hidden] {
  display: none;
}

.someday-branch-line {
  position: absolute;
  background: var(--accent);
  pointer-events: none;
  z-index: 1;
}

.cal-unplanned-chip {
  all: unset;
  position: relative;
  box-sizing: border-box;
  display: inline-block;
  flex: none;
  max-width: 120px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: grab;
  /* touch-action: pan-x (native horizontal panning) was tried here, but the
     browser can claim a touch as a pan too eagerly — before our own JS ever
     sees enough movement to tell a scroll swipe apart from a vertical
     schedule-drag or a long-press reorder — which made both unreliable.
     JS now owns the whole gesture (see onSomedayChipDragMove) and scrolls
     the tray itself, so no native panning here at all. */
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  border: 1.5px solid var(--line);
  background: var(--card-bg);
  color: var(--ink);
}

.cal-unplanned-chip.dragging {
  opacity: 0.5;
}

/* a いつか task with subtasks of its own — filled solid so it visibly reads
   as a "parent," distinct from a plain leaf task's outlined chip */
/* a parent (has children) reads as a container at a glance, distinct from
   a leaf's pill shape — square-ish corners instead of fully round */
.cal-unplanned-chip.parent {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
}

.cal-unplanned-chip.parent.active-parent {
  box-shadow: 0 0 0 2px var(--ink) inset;
}

.cal-unplanned-chip.armed {
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.cal-unplanned-chip.reordering {
  z-index: 5;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22);
  cursor: grabbing;
}

/* the chip itself no longer clips its own overflow (the child-count badge
   below needs to spill past its corner), so truncation for a long label
   lives here instead */
.cal-unplanned-chip-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* small corner badge on every いつか/子/孫 task (not ひ孫, always a leaf)
   showing how many of the next tier hang off it — shown even at 0, so a
   glance says whether there's more to drill into without tapping in */
.cal-child-count-badge {
  position: absolute;
  top: -3px;
  right: -6px;
  min-width: 15px;
  height: 15px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--ink);
  pointer-events: none;
}

/* the digit is CSS-generated content, not a text node, so it never shows up
   in chip.textContent (which the rest of the someday code, and its tests,
   read as the task's plain label) */
.cal-child-count-badge::before {
  content: attr(data-count);
  display: block;
  padding: 0 3px;
  color: var(--paper);
  font-size: 0.55rem;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  white-space: nowrap;
}

.cal-plan-preview {
  opacity: 0.7;
  z-index: 15;
}

/* a small chip that tracks the pointer 1:1 for the whole drag, positioned
   just above the finger/cursor so it stays visible instead of being hidden
   underneath it */
.drag-ghost {
  position: fixed;
  z-index: 100;
  transform: translate(-50%, -135%);
  max-width: 160px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.calendar-someday-add {
  all: unset;
  box-sizing: border-box;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
}

.calendar-someday-add:hover {
  background: var(--accent);
  color: #fff;
}

.calendar-someday-add:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* 「時間未定」タスクの常時表示行: 時間軸グリッドとは別の、スクロールし
   ない領域に置く(存在する数だけ常に見えることで、放置するほど画面を
   占領して「早く時間帯を決めよう」という圧になる、という狙い)。
   gutter+day-col と同じ横幅構成を再利用して、上の日付列と揃える。 */
.unscheduled-week-row {
  flex: none;
  display: flex;
  border-top: 1px solid var(--line);
  padding: 4px 0;
}

.cal-unscheduled-day {
  box-sizing: border-box;
  flex: 1 1 0;
  min-width: 0;
  padding: 0 3px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cal-unscheduled-day.drop-target {
  background: var(--accent-soft);
}

.cal-unscheduled-row {
  box-sizing: border-box;
  height: 30px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px dashed var(--line);
  background: var(--card-bg);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.cal-unscheduled-row.dragging {
  opacity: 0.5;
}

.cal-unscheduled-row.armed {
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.cal-unscheduled-empty {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  color: var(--muted);
}

.calendar-detail {
  flex: none;
  max-height: 28%;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding-top: 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calendar-detail[hidden] {
  display: none;
}

.cal-block-detail {
  font-size: 0.75rem;
  font-weight: 600;
}

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

.cal-plan-edit,
.cal-plan-delete {
  padding: 5px 12px;
  font-size: 0.68rem;
}

.calendar-legend {
  white-space: normal;
}

/* --- name modal --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 10, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-box {
  width: min(90vw, 320px);
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.modal-box h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.modal-box input {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.modal-box input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.modal-duration {
  display: flex;
  gap: 10px;
}

.modal-duration[hidden] {
  display: none;
}

.duration-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.duration-field input {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.duration-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-actions .btn {
  padding: 8px 16px;
}

.modal-actions-stack {
  flex-direction: column;
}

.modal-actions-stack .btn {
  width: 100%;
}

.btn-modal-cancel {
  background: var(--panel);
  color: var(--muted);
}

.btn-modal-ok {
  background: var(--accent);
  color: #fff;
}

.btn-modal-delete {
  background: var(--danger-soft);
  color: var(--danger);
}

/* --- 内訳 / 履歴 panels: opened as modals from the round buttons on the
   タスク tab, since they're no longer top-level swipeable pages --- */

.modal-box-wide {
  width: min(92vw, 420px);
  max-height: 80vh;
}

.modal-panel-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-panel-header h2 {
  margin: 0;
}

.modal-close-btn {
  all: unset;
  box-sizing: border-box;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
  background: var(--panel);
  cursor: pointer;
}

.modal-close-btn:hover {
  color: var(--danger);
}

.modal-close-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#breakdownModal .breakdown,
#historyModal .history {
  min-height: 200px;
  max-height: 60vh;
}
