:root {
  --paper: #f4efe5;
  --paper-soft: #fbf8f1;
  --card: #fffdf8;
  --ink: #211e19;
  --ink-soft: #4d473e;
  --muted: #7c7468;
  --line: #e5ddcf;
  --accent: #b8432c;
  --accent-strong: #9d3522;
  --accent-soft: #f4ddd4;
  --accent-ink: #8f2f1d;
  --done: #65765c;
  --danger: #b42318;
  --danger-soft: #fde8e4;
  --nav-bg: rgba(255, 253, 248, 0.94);
  --overlay: rgba(24, 19, 13, 0.46);
  --shadow: 0 18px 48px rgba(62, 49, 33, 0.09);
  --shadow-soft: 0 8px 24px rgba(62, 49, 33, 0.06);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151412;
    --paper-soft: #1b1a17;
    --card: #211f1b;
    --ink: #f3eee4;
    --ink-soft: #d8d0c2;
    --muted: #a1988a;
    --line: #37322a;
    --accent: #e07355;
    --accent-strong: #ee8a6e;
    --accent-soft: #3a241e;
    --accent-ink: #f0a48f;
    --done: #9bb08e;
    --danger: #ff8b7d;
    --danger-soft: #3b211f;
    --nav-bg: rgba(27, 26, 23, 0.94);
    --overlay: rgba(0, 0, 0, 0.62);
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
    --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.2);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.sheet-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--accent);
  text-transform: uppercase;
}

/* ---------- login ---------- */

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(circle at 15% 0%, rgba(184, 67, 44, 0.1), transparent 42%),
    radial-gradient(circle at 90% 100%, rgba(101, 118, 92, 0.1), transparent 40%),
    var(--paper);
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 38px 28px 26px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 17px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fffaf2;
  margin-bottom: 22px;
  box-shadow: 0 8px 20px rgba(184, 67, 44, 0.28);
}

.brand-mark svg {
  width: 32px;
  height: 32px;
}

.login-card h1 {
  margin-top: 6px;
  font-size: 34px;
  letter-spacing: -0.04em;
  line-height: 1.2;
}

.login-intro {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.login-card .stack {
  margin-top: 28px;
}

.login-note {
  margin-top: 22px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- app shell ---------- */

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(26px + var(--safe-top)) 16px calc(132px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}

.topbar h1 {
  margin-top: 2px;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: -0.045em;
}

.count-pill {
  min-width: 46px;
  height: 46px;
  padding: 0 12px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fffaf2;
  font-size: 18px;
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(184, 67, 44, 0.22);
}

.main {
  min-height: 40vh;
}

.view {
  animation: view-in 0.22s ease;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 0 12px;
}

.section-head:first-child {
  margin-top: 0;
}

.section-head h2 {
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

.section-hint {
  font-size: 11px;
  color: var(--muted);
}

.task-section {
  margin-bottom: 28px;
}

.task-section:last-child {
  margin-bottom: 0;
}

.task-list {
  display: grid;
  gap: 10px;
}

.task-card {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding: 15px 15px 15px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.task-card:active {
  transform: scale(0.994);
}

.task-card.is-overdue {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
}

.task-card.is-overdue .task-title {
  color: var(--accent-ink);
}

.task-open {
  flex: 1;
  min-width: 0;
  padding: 0;
  text-align: left;
  display: block;
}

.task-title {
  display: block;
  font-size: 16.5px;
  font-weight: 680;
  line-height: 1.45;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.task-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--paper-soft);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: transparent;
}

.badge-done {
  background: transparent;
  color: var(--done);
  border-color: color-mix(in srgb, var(--done) 35%, var(--line));
}

.task-meta {
  margin-top: 7px;
  font-size: 12px;
  line-height: 1.65;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 2px 6px;
}

.task-meta span + span::before {
  content: "·";
  margin-right: 6px;
  color: var(--line);
}

.task-note {
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.complete-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  margin-top: 0;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: transparent;
  background: transparent;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.complete-btn svg {
  width: 16px;
  height: 16px;
}

.complete-btn:hover,
.complete-btn:focus-visible {
  border-color: var(--done);
  color: var(--done);
}

.complete-btn:active {
  background: var(--done);
  border-color: var(--done);
  color: var(--card);
}

.complete-btn.is-done {
  border-color: var(--done);
  color: var(--done);
}

.done-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  text-align: left;
  width: 100%;
  box-shadow: var(--shadow-soft);
}

.done-check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  color: var(--done);
}

.done-check svg {
  width: 24px;
  height: 24px;
}

.done-copy {
  min-width: 0;
  flex: 1;
}

.done-title {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink-soft);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--muted) 55%, transparent);
  word-break: break-word;
}

.done-meta {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
}

.empty {
  padding: 30px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  background: color-mix(in srgb, var(--card) 55%, transparent);
}

.empty strong {
  display: block;
  color: var(--ink-soft);
  font-size: 14.5px;
  font-weight: 650;
}

.empty p {
  margin-top: 5px;
  font-size: 12.5px;
  line-height: 1.6;
}

/* ---------- bottom nav & fab ---------- */

.bottom-nav {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(720px, 100%);
  display: flex;
  gap: 4px;
  padding: 7px 12px calc(7px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.nav-btn {
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: 13px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

.nav-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.fab {
  position: fixed;
  z-index: 45;
  right: max(18px, calc((100vw - 720px) / 2 + 18px));
  bottom: calc(84px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fffaf2;
  box-shadow: 0 12px 28px rgba(184, 67, 44, 0.32);
  transition: transform 0.15s ease, background 0.15s ease;
}

.fab svg {
  width: 26px;
  height: 26px;
}

.fab:active {
  transform: scale(0.94);
  background: var(--accent-strong);
}

/* ---------- forms ---------- */

.stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--muted);
}

.field em {
  font-style: normal;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
  font-weight: 400;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea {
  resize: vertical;
  min-height: 86px;
  line-height: 1.6;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.field input::placeholder,
.field textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fffaf2;
  box-shadow: 0 6px 16px rgba(184, 67, 44, 0.18);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-secondary {
  background: var(--paper-soft);
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-block {
  width: 100%;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 3px;
}

.form-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.55;
}

.hint {
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--muted);
}

.inline-link {
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
}

/* ---------- cards & settings ---------- */

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-soft);
  margin-bottom: 14px;
}

.card h3 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.status-text {
  margin-top: 8px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
  white-space: pre-line;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-soft);
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 28px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.switch-track {
  display: block;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.18s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16);
  transition: transform 0.18s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.version-label {
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  padding: 6px 0 10px;
}

/* ---------- sheets ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--overlay);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.sheet-backdrop.is-open {
  opacity: 1;
}

.sheet {
  position: fixed;
  z-index: 61;
  left: 50%;
  bottom: 0;
  width: min(720px, 100%);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 20px calc(24px + var(--safe-bottom));
  border-radius: 24px 24px 0 0;
  background: var(--paper-soft);
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, 104%);
  transition: transform 0.24s cubic-bezier(0.22, 0.8, 0.28, 1);
}

.sheet.is-open {
  transform: translate(-50%, 0);
}

.sheet-grabber {
  width: 42px;
  height: 4px;
  margin: 2px auto 12px;
  border-radius: 999px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.sheet-head h2 {
  font-size: 21px;
  letter-spacing: -0.03em;
  line-height: 1.3;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
}

.icon-btn:active {
  background: var(--line);
}

/* ---------- detail ---------- */

.detail-title {
  font-size: 23px;
  font-weight: 720;
  line-height: 1.4;
  letter-spacing: -0.025em;
  word-break: break-word;
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.detail-grid {
  display: grid;
  gap: 0;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 14px;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}

.detail-row:last-child {
  border-bottom: 0;
}

.detail-row dt {
  color: var(--muted);
  flex: 0 0 auto;
}

.detail-row dd {
  margin: 0;
  text-align: right;
  color: var(--ink-soft);
  word-break: break-word;
}

.detail-note {
  margin-top: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-history {
  margin-top: 20px;
}

.detail-history h3 {
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.completion-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.completion-item:last-child {
  border-bottom: 0;
}

.completion-item strong {
  color: var(--ink-soft);
  font-weight: 600;
}

.detail-actions {
  display: grid;
  gap: 9px;
  margin-top: 20px;
}

.detail-actions .btn {
  width: 100%;
}

/* ---------- confirm & toast ---------- */

.confirm {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 22px;
  background: var(--overlay);
}

.confirm-card {
  width: 100%;
  max-width: 360px;
  padding: 22px;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.confirm-card p {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--ink-soft);
  white-space: pre-wrap;
}

.confirm-card .form-actions {
  margin-top: 20px;
}

.toast {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 36px);
  padding: 11px 17px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  animation: toast-in 0.18s ease;
}

.toast.is-error {
  background: var(--danger);
  color: #fff;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- responsive ---------- */

@media (max-width: 380px) {
  .app {
    padding-left: 13px;
    padding-right: 13px;
  }

  .topbar h1 {
    font-size: 30px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .sheet {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (min-width: 721px) {
  .app {
    padding-top: 46px;
  }

  .topbar h1 {
    font-size: 38px;
  }

  .sheet {
    bottom: 24px;
    border-radius: 24px;
    max-height: min(86vh, 820px);
    transform: translate(-50%, calc(100% + 40px));
  }

  .sheet.is-open {
    transform: translate(-50%, 0);
  }

  .fab {
    bottom: 94px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
