:root {
  --bg: #0a0a0a;
  --panel: #111111;
  --surface: #131313;
  --surface-2: #1a1a1a;
  --line: #222222;
  --line-2: #333333;
  --text: #f2ede4;
  --muted: #a39e96;
  --dim: #5e5a55;
  --red: #c21f1a;
  --red-hi: #d9261f;
  --red-text: #e5392f;
  --red-deep: #2a0d0b;
  --red-line: #5c1814;
  --serif: 'EB Garamond', Garamond, 'Times New Roman', serif;
  --display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
input, textarea { font: inherit; color: inherit; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--red-text); outline-offset: 2px; }

/* ---------- type ---------- */

.logo { font-family: var(--display); font-weight: 700; font-size: 26px; letter-spacing: -0.01em; line-height: 1; color: var(--text); }
.logo .x { color: var(--red-text); }

.eyebrow {
  font-size: 13px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--red-text); margin: 0 0 6px;
}
.display {
  font-family: var(--display); font-weight: 500; font-size: 36px; line-height: 1.1; margin: 0; letter-spacing: -0.005em;
  overflow-wrap: anywhere;
}
.label {
  display: block; font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px;
}
.muted { color: var(--muted); }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 48px; padding: 0 22px; border-radius: 6px; font-size: 18px; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn-red { background: var(--red); color: #fff; font-weight: 700; }
.btn-red:hover { background: var(--red-hi); }
.btn-red:disabled { opacity: .6; }
.btn-outline { border: 1px solid var(--line-2); color: var(--text); font-weight: 500; }
.btn-outline:hover { border-color: #555; }
.btn-danger { border: 1px solid var(--red-line); color: var(--red-text); font-weight: 500; }
.btn-danger:hover { border-color: var(--red); }
.btn-block { width: 100%; }

.input {
  display: block; width: 100%; height: 48px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 6px;
  font-size: 18px; outline: none; transition: border-color .15s;
}
textarea.input { height: 94px; padding: 12px 14px; resize: vertical; line-height: 1.35; }
.input::placeholder { color: #6f6a64; }
.input:focus { border-color: #6a6560; }
.input[type="date"]::-webkit-calendar-picker-indicator { opacity: .9; cursor: pointer; }

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

.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  height: calc(56px + var(--safe-top)); padding: var(--safe-top) 18px 0;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.fab {
  width: 41px; height: 41px; border-radius: 50%; background: var(--red); color: #fff;
  display: grid; place-items: center; box-shadow: 0 2px 10px rgba(194, 31, 26, .25);
}
.fab svg { width: 18px; height: 18px; }

.main { padding: 30px 18px calc(110px + var(--safe-bottom)); }
.content { max-width: 815px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 10px 0 calc(10px + var(--safe-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; letter-spacing: .16em; text-transform: uppercase; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--red-text); }

.avatar {
  flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--red); color: #fff; font-family: var(--display); font-weight: 400;
  width: 40px; height: 40px; font-size: 15px;
}

/* ---------- today ---------- */

.today-title { font-size: 40px; }
.progress { display: flex; align-items: center; gap: 14px; margin: 16px 0 6px; }
.progress .bar { flex: 1; height: 3px; background: #262626; border-radius: 2px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; background: var(--red-text); transition: width .3s ease; }
.progress-label { font-size: 14px; color: var(--muted); white-space: nowrap; }

.section { margin-top: 36px; }
.section-label {
  font-size: 13px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
  padding-bottom: 10px; border-bottom: 1px solid var(--line);
}

.trow { display: flex; align-items: center; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.trow-main { flex: 1; min-width: 0; text-align: left; }
.trow-title { font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.trow-title.done { text-decoration: line-through; color: var(--muted); text-decoration-color: var(--muted); }
.trow-sub { font-size: 14px; color: var(--muted); margin-top: 3px; }
.trow-count { text-align: right; flex: none; }
.trow-count .n { font-size: 28px; line-height: 1; color: var(--red-text); font-weight: 500; }
.trow-count .cap { font-size: 12px; letter-spacing: .14em; color: var(--muted); text-transform: uppercase; margin-top: 2px; }

.check {
  flex: none; width: 30px; height: 30px; border-radius: 4px; border: 1.5px solid #4a4a4a;
  display: grid; place-items: center; color: var(--red-text); transition: border-color .15s, transform .1s;
}
.check:active { transform: scale(.92); }
.check.on { border-color: var(--red-text); }
.check svg { width: 20px; height: 20px; }

.mini { display: flex; gap: 6px; margin: 6px 0 2px; }
.mini i {
  width: 14px; height: 14px; border-radius: 2px; border: 1px solid #555; display: grid; place-items: center;
}
.mini i.on { background: var(--red-deep); border-color: var(--red-line); }
.mini i svg { width: 10px; height: 10px; color: var(--red-text); }

.date-badge {
  flex: none; width: 35px; height: 35px; border-radius: 50%; border: 1px solid var(--line-2);
  display: grid; place-items: center; font-size: 16px; color: var(--text);
}

.empty { text-align: center; padding: 56px 0 24px; }
.empty .strip { justify-content: center; margin-bottom: 22px; }
.empty h2 { font-family: var(--display); font-weight: 500; font-size: 26px; margin: 0 0 6px; }
.empty p { color: var(--muted); margin: 0 0 24px; font-style: italic; }

/* ---------- task list ---------- */

.pills { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 22px; }
.pill {
  height: 37px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-2);
  display: inline-flex; align-items: center; gap: 8px; font-size: 17px;
}
.pill small { font-size: 14px; color: var(--muted); }
.pill.active { background: var(--text); color: #111; border-color: var(--text); }
.pill.active small { color: #555; }

.list { border-top: 1px solid var(--line); }
.lrow { display: flex; align-items: center; gap: 14px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.lrow-main { flex: 1; min-width: 0; }
.lrow-title { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.lrow-sub { font-size: 15px; color: var(--muted); margin-top: 2px; }
.ticon {
  flex: none; width: 35px; height: 35px; border-radius: 50%; border: 1px solid var(--line-2);
  display: grid; place-items: center; font-size: 15px;
}
.ticon.daily { border-color: var(--red-line); color: var(--red-text); font-size: 16px; }
.icon-btn { flex: none; width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.danger { color: var(--red-text); }

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

.back { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 18px; margin-bottom: 26px; }
.back svg { width: 16px; height: 16px; }
.note { font-style: italic; color: var(--muted); margin: 8px 0 0; font-size: 17px; overflow-wrap: anywhere; }

.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 26px 0 26px; }
.stats3 > div { border-top: 1px solid var(--line-2); padding-top: 14px; }
.stats3 .n { font-size: 40px; line-height: 1; font-weight: 500; }
.stats3 .n.red { color: var(--red-text); }
.stats3 .cap { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }

.cal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px 12px 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 10px; margin-bottom: 14px; }
.cal-title { font-family: var(--display); font-size: 26px; color: var(--red-text); font-weight: 500; }
.cal-title span { font-family: var(--serif); color: var(--muted); font-size: 22px; }
.cal-nav { display: flex; gap: 8px; }
.round-btn {
  width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line-2);
  display: grid; place-items: center; color: var(--text);
}
.round-btn svg { width: 14px; height: 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 6px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 600; letter-spacing: .1em; color: var(--muted); padding-bottom: 8px; }
.day {
  position: relative; height: 42px; display: grid; place-items: center;
  font-size: 16px; font-weight: 600; color: var(--text);
}
.day .n { position: relative; z-index: 1; }
.day.pre { color: var(--dim); font-weight: 500; }
.day.future { color: var(--dim); font-weight: 500; }
.day.marked .n { color: #6b6661; font-weight: 500; }
.day .xm { position: absolute; z-index: 2; width: 32px; height: 32px; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--red-text); pointer-events: none; }
.day.today::before {
  content: ''; position: absolute; width: 36px; height: 36px; left: 50%; top: 50%; transform: translate(-50%, -50%);
  border: 1.5px solid var(--red-text); border-radius: 50%;
}
.day.today .n { color: var(--red-text); }
button.day:not(:disabled):hover .n { text-decoration: underline; text-underline-offset: 3px; }
.cal-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; border-top: 1px solid var(--line);
  margin-top: 10px; padding: 14px 12px 2px; color: var(--muted); font-size: 16px;
}
.cal-legend .k { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.cal-legend svg { width: 16px; height: 16px; color: var(--red-text); }
.cal-legend .ring { width: 16px; height: 16px; border: 1.5px solid var(--red-text); border-radius: 50%; }
.cal-legend em { flex-basis: 100%; }

.actions { display: flex; gap: 12px; margin-top: 22px; }
.actions .btn { flex: 1 1 auto; min-width: 0; padding: 0 16px; }
.actions .btn:first-child { flex-grow: 3; }

/* ---------- form ---------- */

.form { margin-top: 20px; }
.field { margin-bottom: 22px; }
.seg3 { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg3 button { padding: 14px 6px; background: var(--surface); text-align: center; border-left: 1px solid var(--line-2); }
.seg3 button:first-child { border-left: 0; }
.seg3 .t { display: block; font-size: 18px; }
.seg3 .s { display: block; font-size: 14px; color: var(--muted); margin-top: 1px; }
.seg3 button.active { background: var(--red); }
.seg3 button.active .s { color: #f3cfcc; }
.hint { font-style: italic; color: var(--muted); font-size: 16px; margin: -10px 0 22px; }
.form-actions { display: flex; gap: 22px; }
.form-actions .btn-red { flex: 1; }
.danger-zone { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 18px; }
.link-danger { display: inline-flex; align-items: center; gap: 10px; color: var(--red-text); font-size: 18px; }
.link-danger svg { width: 17px; height: 17px; }

/* ---------- profile ---------- */

.phead { display: flex; align-items: center; gap: 18px; }
.phead .avatar { width: 70px; height: 70px; font-size: 26px; }
.phead h1 { font-family: var(--display); font-weight: 500; font-size: 28px; margin: 0; line-height: 1.1; overflow-wrap: anywhere; }
.phead .email { color: var(--muted); font-size: 16px; overflow-wrap: anywhere; }
.phead .since { color: var(--muted); font-size: 15px; font-style: italic; }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; margin: 32px 0 36px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 22px 16px 16px; }
.card .n { font-size: 36px; line-height: 1; font-weight: 500; }
.card .n.red { color: var(--red-text); }
.card .cap { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-top: 8px; }

.settings .section-label { padding-bottom: 12px; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; min-height: 70px; border-bottom: 1px solid var(--line); }
.srow .t { font-size: 18px; }
.srow .s { font-size: 15px; color: var(--muted); }
.seg2 { display: flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; flex: none; }
.seg2 button { padding: 8px 13px; font-size: 16px; }
.seg2 button + button { border-left: 1px solid var(--line-2); }
.seg2 button.active { background: var(--text); color: #111; }
.switch { flex: none; position: relative; width: 52px; height: 30px; border-radius: 999px; background: #333; transition: background .2s; }
.switch::after {
  content: ''; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--text); transition: transform .2s;
}
.switch.on { background: var(--red); }
.switch.on::after { transform: translateX(22px); }
.signout { margin-top: 30px; }

/* ---------- auth ---------- */

.auth { min-height: 100vh; min-height: 100dvh; display: flex; }
.auth-art { display: none; }
.auth-side { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: calc(40px + var(--safe-top)) 26px calc(40px + var(--safe-bottom)); }
.auth-brand { text-align: center; margin-bottom: 44px; }
.auth-brand .logo { font-size: 46px; }
.tagline { font-style: italic; color: var(--muted); font-size: 18px; margin: 8px 0 22px; }
.strip { display: flex; justify-content: center; gap: 6px; }
.strip i {
  width: 31px; height: 31px; border-radius: 3px; border: 1px solid var(--red-line); background: var(--red-deep);
  display: grid; place-items: center; color: var(--red-text);
}
.strip i svg { width: 20px; height: 20px; }
.strip i.open { background: none; border-color: var(--red-text); }
.auth-form { width: 100%; max-width: 408px; margin: 0 auto; }
.auth-form h1 { font-family: var(--display); font-weight: 500; font-size: 31px; margin: 0; line-height: 1.15; }
.auth-form .sub { color: var(--muted); font-size: 17px; margin: 2px 0 24px; }
.auth-form .field { margin-bottom: 20px; }
.form-error { color: var(--red-text); font-style: italic; font-size: 16px; margin: -6px 0 14px; min-height: 0; }
.form-error:empty { display: none; }
.switch-line { text-align: center; color: var(--muted); margin-top: 26px; font-size: 17px; }
.switch-line a { color: var(--red-text); text-decoration: underline; text-underline-offset: 3px; margin-left: 6px; }

.splash { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.splash .logo { font-size: 44px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translate(-50%, 20px);
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text);
  padding: 10px 18px; border-radius: 8px; font-size: 16px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- desktop ---------- */

@media (min-width: 900px) {
  body { font-size: 16px; }
  .topbar, .tabbar { display: none; }

  .shell { display: grid; grid-template-columns: 265px 1fr; }
  .sidebar {
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
    background: var(--panel); border-right: 1px solid var(--line); padding: 38px 21px 0;
  }
  .sidebar .logo { font-size: 32px; padding-left: 13px; }
  .new-btn { margin: 32px 0 30px; font-size: 17px; }
  .side-nav { display: flex; flex-direction: column; gap: 4px; }
  .side-nav a { display: flex; align-items: center; gap: 16px; height: 49px; padding: 0 13px; border-radius: 6px; color: var(--muted); font-size: 18px; }
  .side-nav a svg { width: 19px; height: 19px; }
  .side-nav a:hover { color: var(--text); }
  .side-nav a.active { background: var(--surface-2); color: var(--red-text); }
  .side-user { margin-top: auto; display: flex; align-items: center; gap: 13px; padding: 16px 13px 36px; border-top: 1px solid var(--line); }
  .side-user .name { font-size: 16px; line-height: 1.2; }
  .side-user .sub { font-size: 14px; color: var(--muted); }

  .main { padding: 50px 40px 60px; }

  .display { font-size: 52px; }
  .today-title { font-size: 54px; }
  .back { font-size: 17px; margin-bottom: 30px; }
  .note { font-size: 17px; }

  .trow-title { font-size: 18px; }
  .lrow { padding: 12px 0; }
  .lrow-title { font-size: 19px; }
  .lrow-sub { font-size: 14px; }
  .pills { gap: 9px; margin: 18px 0 22px; }
  .pill { height: 42px; }

  .stats3 { gap: 28px; }
  .stats3 .n { font-size: 38px; }

  .cal { padding: 18px 14px 14px; }
  .cal-title { font-size: 26px; }
  .day { height: 56px; font-size: 17px; }
  .day .xm { width: 36px; height: 36px; }
  .day.today::before { width: 44px; height: 44px; }
  .cal-legend em { flex-basis: auto; }

  .seg3 button { padding: 12px 6px; }

  .phead .avatar { width: 80px; height: 80px; font-size: 30px; }
  .phead h1 { font-size: 34px; }
  .cards { grid-template-columns: repeat(4, 1fr); gap: 13px; margin: 36px 0 40px; }
  .card { padding: 22px 18px 16px; }

  .auth-art {
    display: flex; flex-direction: column; flex: 1; background: var(--panel); border-right: 1px solid var(--line);
    padding: 68px 68px 68px;
  }
  .auth-art .logo { font-size: 32px; }
  .art-grid { display: grid; grid-template-columns: repeat(7, 52px); gap: 14px; margin: auto 0 34px; }
  .art-grid i {
    width: 52px; height: 52px; border: 1px solid var(--line); border-radius: 3px;
    display: grid; place-items: center; color: var(--red-text);
  }
  .art-grid i svg { width: 30px; height: 30px; }
  .art-grid i .ring { width: 32px; height: 32px; border: 1.5px solid var(--red-text); border-radius: 50%; }
  .art-title { font-family: var(--display); font-weight: 500; font-size: 62px; line-height: 1.02; margin: 0 0 30px; }
  .art-copy { color: var(--muted); font-size: 21px; max-width: 460px; margin: 0; line-height: 1.45; }
  .art-foot { margin-top: auto; font-style: italic; color: var(--dim); font-size: 16px; }
  .auth-side { padding: 40px; }
  .auth-brand { display: none; }
  .auth-form h1 { font-size: 34px; }
  .auth-form .sub { font-size: 17px; margin-bottom: 24px; }
  .auth-form .input { height: 53px; font-size: 18px; }
  .auth-form .btn { height: 55px; }

  #toast { bottom: 32px; }
}

@media (min-width: 900px) and (max-height: 760px) {
  .art-grid { grid-template-columns: repeat(7, 40px); gap: 10px; }
  .art-grid i { width: 40px; height: 40px; }
  .art-title { font-size: 48px; }
}

@media (max-width: 360px) {
  .display { font-size: 31px; }
  .seg3 .t { font-size: 16px; }
  .seg3 .s { font-size: 12px; }
  .srow { flex-wrap: wrap; }
}
