:root {
  --paper: #fffff8;
  --ink: #111;
  --ink-mid: #3f3f3f;
  --ink-light: #5f5f5f;
  --ink-faint: #737373;
  --red: #8b0000;
  --red-light: #a52a2a;
  --rule: #e0dcd6;
  --hover: rgba(0, 0, 0, 0.02);
  --font: "Crimson Pro", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

[hidden] {
  display: none !important;
}

body.no-scroll {
  overflow: hidden;
}

#app {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0) 24px 80px;
}

header {
  padding-top: 48px;
  margin-bottom: 32px;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 10px;
}

header h1 {
  font-family: var(--font);
  font-size: 44px;
  font-style: italic;
  font-weight: 300;
  letter-spacing: 0;
  line-height: 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  padding-top: 7px;
}

.header-user {
  max-width: 180px;
  overflow: hidden;
  border: none;
  background: none;
  color: var(--ink-light);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0;
  text-decoration: underline;
  text-overflow: ellipsis;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.header-user:hover {
  color: var(--ink-mid);
}

.sync-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--red);
}

.sync-dot.synced {
  background: #237a3b;
}

.sync-dot.unsynced {
  background: var(--red);
}

#stats {
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0;
}

.nav-item,
.filter-item,
.add-btn,
.back-btn,
.action-link,
.name-option {
  background: none;
  border: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.nav-row,
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: 8px;
}

.nav-item {
  margin-right: 18px;
  padding: 6px 0;
  color: var(--ink-light);
  font-size: 14px;
  font-weight: 400;
  transition: color 0.15s;
  white-space: nowrap;
}

.nav-item:hover {
  color: var(--ink-mid);
}

.nav-item.active {
  color: var(--ink);
}

.filter-row {
  margin-bottom: 16px;
}

.filter-item {
  margin-right: 14px;
  padding: 4px 0;
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0;
  transition: color 0.15s;
  white-space: nowrap;
}

.filter-item:hover {
  color: var(--ink-mid);
}

.filter-item.active {
  color: var(--ink);
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 24px;
  margin-bottom: 2px;
}

.section-label {
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.add-btn {
  padding: 0;
  color: var(--red);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1;
  transition: color 0.15s;
}

.add-btn:hover {
  color: var(--red-light);
}

.task-item {
  padding: 16px 0;
  border-top: 1px solid var(--rule);
  cursor: pointer;
  transition: opacity 0.2s;
}

.task-item:last-child {
  border-bottom: 1px solid var(--rule);
}

.task-item:active {
  opacity: 0.55;
}

.task-item.completed {
  opacity: 1;
}

.task-item.completed .task-description {
  color: var(--ink-light);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.task-item.completed .task-meta,
.task-item.completed .task-sub {
  color: var(--ink-light);
}

.task-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 3px;
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  gap: 14px;
  letter-spacing: 0;
}

.task-description {
  margin-bottom: 4px;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.3;
}

.task-sub {
  color: var(--ink-mid);
  font-size: 14px;
  line-height: 1.4;
}

.task-due {
  color: var(--red);
}

.task-due.past {
  color: var(--red);
  font-weight: 500;
}

.empty-state {
  padding: 32px 0;
  color: var(--ink-faint);
  font-size: 15px;
  font-style: italic;
  text-align: center;
}

.overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  overflow-y: auto;
  visibility: hidden;
  background: var(--paper);
  overscroll-behavior-y: contain;
  transform: translateX(100%);
  transition: transform 0.35s var(--ease), visibility 0s linear 0.35s;
  -webkit-overflow-scrolling: touch;
}

.overlay.active {
  visibility: visible;
  transform: translateX(0);
  transition: transform 0.35s var(--ease), visibility 0s linear 0s;
}

#create-overlay {
  z-index: 150;
}

#log-overlay {
  z-index: 200;
}

.overlay-content {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top, 0)) 24px calc(60px + env(safe-area-inset-bottom, 0));
}

.back-btn {
  display: inline-block;
  margin-bottom: 20px;
  padding: 12px 16px 12px 0;
  color: var(--ink-light);
  font-family: var(--font);
  font-size: 15px;
  transition: color 0.15s;
}

.back-btn:hover {
  color: var(--ink);
}

.detail-description {
  margin-bottom: 10px;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.25;
}

.detail-meta {
  margin-bottom: 6px;
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0;
}

.detail-rule {
  margin: 24px 0;
  border: none;
  border-top: 1px solid var(--rule);
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.field-input,
.field-textarea,
.field-select {
  width: 100%;
  margin-bottom: 20px;
  padding: 8px 0;
  border: none;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  transition: border-color 0.2s;
}

.field-input:focus,
.field-textarea:focus,
.field-select:focus {
  border-bottom-color: var(--ink);
}

.field-input::placeholder,
.field-textarea::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

.field-textarea {
  min-height: 60px;
  line-height: 1.6;
  resize: none;
}

.details-textarea {
  min-height: 120px;
}

.field-select {
  padding-right: 16px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235f5f5f'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
}

.date-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.date-field .field-input {
  margin-bottom: 0;
}

.date-clear {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-light);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1;
}

.date-clear:hover {
  color: var(--ink);
}

.create-calendar {
  margin: -4px 0 20px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: 18px repeat(7, minmax(0, 1fr)) 18px;
  gap: 4px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--red);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1;
}

.calendar-day {
  display: flex;
  min-width: 0;
  aspect-ratio: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3px 2px;
  border: 1px solid var(--rule);
  background: rgba(0, 0, 0, 0.015);
  color: var(--ink-mid);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.1;
}

.calendar-day.load-1 {
  background: rgba(139, 0, 0, 0.05);
}

.calendar-day.load-2 {
  background: rgba(139, 0, 0, 0.08);
}

.calendar-day.load-3 {
  background: rgba(139, 0, 0, 0.12);
}

.calendar-day.load-4 {
  background: rgba(139, 0, 0, 0.16);
}

.calendar-day.today {
  border-color: var(--ink-light);
}

.calendar-day.selected {
  border-color: var(--red);
  color: var(--ink);
  font-weight: 600;
}

.calendar-dow,
.calendar-count {
  color: var(--ink-light);
  font-size: 9px;
}

.calendar-date {
  font-size: 15px;
}

.calendar-count {
  min-height: 10px;
}

.calendar-task-list {
  margin-top: 8px;
}

.calendar-empty,
.calendar-task-line {
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.4;
}

.calendar-task-line {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 4px 0;
  border-top: 1px solid var(--rule);
  white-space: nowrap;
}

.calendar-task-line:last-child {
  border-bottom: 1px solid var(--rule);
}

.calendar-task-line span:first-child {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-mid);
  text-overflow: ellipsis;
}

.calendar-task-line span:last-child {
  flex: 0 0 auto;
  color: var(--red);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 20px;
}

.action-link {
  display: inline-block;
  padding: 10px 0;
  color: var(--red);
  font-family: var(--font);
  font-size: 15px;
  text-decoration: none;
  transition: color 0.15s, opacity 0.15s;
}

.action-link:hover {
  color: var(--red-light);
}

.action-link.muted {
  color: var(--ink-light);
}

.action-link.muted:hover {
  color: var(--ink-mid);
}

.log-entry {
  padding: 10px 0;
  border-top: 1px solid var(--rule);
}

.log-entry:last-child {
  border-bottom: 1px solid var(--rule);
}

.log-date {
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0;
}

.log-duration {
  font-size: 16px;
  font-weight: 500;
}

.log-notes {
  color: var(--ink-mid);
  font-size: 14px;
  font-style: italic;
}

.report-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.report-bar-label {
  flex-shrink: 0;
  min-width: 80px;
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0;
  text-align: right;
}

.report-bar-track {
  position: relative;
  flex: 1;
  height: 12px;
  overflow: hidden;
  background: var(--rule);
}

.report-bar-fill {
  height: 100%;
  background: var(--ink);
  transition: width 0.5s var(--ease);
}

.report-bar-value {
  flex-shrink: 0;
  min-width: 40px;
  color: var(--ink-mid);
  font-family: var(--mono);
  font-size: 10.5px;
}

.report-total {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0;
}

.report-filter-group {
  margin-bottom: 14px;
}

.report-filter-group .filter-row {
  margin-bottom: 0;
}

.report-week-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-top: 1px solid var(--rule);
}

.report-week-row:last-of-type {
  border-bottom: 1px solid var(--rule);
}

.report-week-row span:first-child {
  color: var(--ink-light);
  font-family: var(--mono);
  font-size: 10.5px;
}

.report-week-row span:last-child {
  font-size: 16px;
  font-weight: 500;
}

.setup-overlay {
  z-index: 250;
}

.setup-content {
  position: relative;
}

.setup-back {
  display: inline-block;
  margin-bottom: 20px;
  padding: 12px 16px 12px 0;
  border: none;
  background: none;
  color: var(--ink-light);
  cursor: pointer;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1;
}

.setup-back:hover {
  color: var(--ink);
}

.setup-content h1 {
  margin-bottom: 24px;
  font-size: 44px;
  font-style: italic;
  font-weight: 300;
  letter-spacing: 0;
  line-height: 1;
}

.setup-content p {
  margin-bottom: 22px;
  color: var(--ink-mid);
  font-size: 15px;
  font-style: italic;
}

.name-options {
  display: grid;
  gap: 8px;
}

.name-option {
  width: 100%;
  padding: 10px 0;
  border-top: 1px solid var(--rule);
  color: var(--ink);
  font-size: 20px;
}

.name-option:last-child {
  border-bottom: 1px solid var(--rule);
}

.name-option:active {
  opacity: 0.55;
}

.name-option-muted {
  color: var(--ink-light);
}

.name-option-input-row {
  cursor: default;
}

.name-option-input-row:active {
  opacity: 1;
}

.name-option-input {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.6;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}

.setup-input {
  text-align: left;
}

.setup-actions {
  justify-content: flex-start;
}

.name-options + .setup-actions {
  margin-top: 18px;
}

.warning-text {
  margin-top: 14px;
  color: var(--red);
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.4;
}

.detail-copy {
  margin-top: 8px;
  color: var(--ink-mid);
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  z-index: 9999;
  bottom: calc(28px + env(safe-area-inset-bottom, 0));
  left: 50%;
  padding: 8px 20px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px);
  transition: opacity 0.3s, transform 0.3s var(--ease);
  white-space: nowrap;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 700px) {
  #app,
  .overlay-content {
    padding-right: 40px;
    padding-left: 40px;
  }
}

@media (max-width: 380px) {
  header h1 {
    font-size: 36px;
  }

  .detail-description {
    font-size: 24px;
  }

  .nav-item {
    margin-right: 12px;
    font-size: 13px;
  }

  .header-user {
    max-width: 118px;
  }
}
