:root {
  --desk: #b7a48a;
  --desk-shadow: #8e7a62;
  --paper: #f3ead6;
  --paper-edge: #e2d4b8;
  --page: #fbf7ec;
  --page-rule: rgba(176, 150, 110, 0.28);
  --ink: #1c1610;
  --ink-soft: #5a5046;
  --ink-faint: #8a7e70;
  --seal: #b32622;
  --seal-deep: #8e1c1a;
  --seal-wash: rgba(179, 38, 34, 0.1);
  --pine: #2c4a3e;
  --pine-wash: rgba(44, 74, 62, 0.1);
  --gold: #b0894f;
  --line: #e6d9c3;
  --binding: #6b2b28;
  --shadow: 0 18px 50px rgba(48, 28, 10, 0.22), 0 2px 6px rgba(48, 28, 10, 0.12);
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", "Times New Roman", serif;
  --sans: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --index-w: 21.5rem;
  --radius: 2px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255, 244, 220, 0.35), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(80, 50, 20, 0.12), transparent 50%),
    repeating-linear-gradient(135deg, rgba(70, 50, 30, 0.03) 0 2px, transparent 2px 7px),
    var(--desk);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.desk {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
  min-height: 100vh;
  min-height: 100dvh;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.25rem 0.4rem 0.95rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.seal {
  width: 3rem;
  height: 3rem;
  border: 2px solid var(--seal);
  color: var(--seal);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.45rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-9deg);
  box-shadow: 0 0 0 3px rgba(179, 38, 34, 0.06);
  background: rgba(251, 247, 236, 0.7);
  user-select: none;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.85rem;
  letter-spacing: 0.18em;
  line-height: 1.2;
}

.owner {
  margin: 0.1rem 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  letter-spacing: 0.22em;
}

.btn-ink {
  appearance: none;
  border: 1px solid var(--seal);
  background: var(--seal);
  color: #fbf7ec;
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  padding: 0.4rem 0.95rem 0.42rem;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(80, 16, 12, 0.18);
}

.btn-ink:hover { background: var(--seal-deep); border-color: var(--seal-deep); }
.btn-ink:focus-visible { outline: 2px solid var(--seal); outline-offset: 3px; }

.notebook {
  display: grid;
  grid-template-columns: var(--index-w) 1fr;
  min-height: calc(100dvh - 7.2rem);
  background: var(--paper);
  box-shadow: var(--shadow);
  border: 1px solid rgba(90, 60, 30, 0.18);
  position: relative;
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 18%),
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(90, 60, 30, 0.02) 3px, rgba(90, 60, 30, 0.02) 4px);
}

.index-pane {
  border-right: 1px solid var(--paper-edge);
  padding: 1rem 0.9rem 1.25rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: linear-gradient(90deg, rgba(210, 190, 155, 0.18), transparent 40%);
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.4rem 1.6rem 0.45rem 0;
  border-radius: 0;
}

.search-wrap input:focus {
  outline: none;
  border-bottom-color: var(--seal);
}

.search-wrap input::placeholder { color: var(--ink-faint); }

.key-hint {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--ink-faint);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  padding: 0 0.28rem;
  border-radius: 3px;
  background: var(--page);
}

.type-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.9rem 0 0.55rem;
}

.chip {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  padding: 0.18rem 0.55rem;
  cursor: pointer;
  border-radius: 999px;
}

.chip:hover { color: var(--ink); background: rgba(255, 255, 255, 0.35); }

.chip.is-on {
  border-color: var(--seal);
  color: var(--seal);
  background: var(--seal-wash);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.45rem;
}

.tag-chip {
  appearance: none;
  border: 1px dashed var(--gold);
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.75rem;
  padding: 0.08rem 0.45rem;
  cursor: pointer;
  border-radius: 999px;
}

.tag-chip.is-on {
  border-style: solid;
  border-color: var(--pine);
  color: var(--pine);
  background: var(--pine-wash);
}

.archive-toggle { margin: 0.15rem 0 0.5rem; }

.text-btn {
  appearance: none;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  padding: 0.15rem 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line);
}

.text-btn:hover { color: var(--ink); text-decoration-color: var(--ink); }
.text-btn.danger { color: var(--seal); text-decoration-color: rgba(179, 38, 34, 0.35); }
.text-btn.danger:hover { text-decoration-color: var(--seal); }
.text-btn[aria-pressed="true"] { color: var(--seal); text-decoration-color: var(--seal); }

.memo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
}

.memo-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.35rem 0.5rem;
  align-items: start;
  padding: 0.62rem 0.35rem 0.68rem;
  border-bottom: 1px solid rgba(180, 155, 120, 0.28);
  cursor: pointer;
  position: relative;
}

.memo-item:hover { background: rgba(255, 255, 255, 0.28); }

.memo-item.is-selected {
  background: var(--page);
  box-shadow: inset 3px 0 0 var(--seal);
}

.memo-item.is-done .item-title {
  color: var(--ink-faint);
  text-decoration: line-through;
  text-decoration-color: rgba(90, 80, 70, 0.45);
}

.item-mark {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  font-size: 0.78rem;
}

.item-check {
  appearance: none;
  width: 0.95rem;
  height: 0.95rem;
  margin: 0;
  border: 1px solid var(--ink);
  background: var(--page);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.item-check:checked {
  background: var(--pine);
  border-color: var(--pine);
}

.item-check:checked::after {
  content: "";
  width: 0.28rem;
  height: 0.5rem;
  border: solid #fbf7ec;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(40deg) translate(-0.5px, -0.5px);
}

.item-body { min-width: 0; }

.item-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.98rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  margin-top: 0.12rem;
  color: var(--ink-faint);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta .overdue { color: var(--seal); }

.item-pins {
  color: var(--seal);
  font-size: 0.78rem;
  margin-top: 0.18rem;
}

.list-empty {
  margin: 1.4rem 0.4rem;
  color: var(--ink-soft);
  font-family: var(--serif);
  text-align: center;
  line-height: 1.8;
}

.page-pane {
  position: relative;
  min-width: 0;
  background: var(--page);
  display: flex;
  flex-direction: column;
}

.binding {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 14px;
  background:
    repeating-linear-gradient(
      180deg,
      #7a322e 0 10px,
      #5c221f 10px 12px,
      #8a3c36 12px 22px,
      #5c221f 22px 24px
    );
  box-shadow: 3px 0 8px rgba(40, 10, 8, 0.18);
  z-index: 2;
}

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.1rem 1.4rem 1rem 2rem;
}

.page.is-hidden { display: none; }

.empty-invite {
  margin: auto;
  text-align: center;
  max-width: 16rem;
  color: var(--ink-soft);
}

.empty-mark {
  display: inline-flex;
  width: 3.4rem;
  height: 3.4rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--seal);
  color: var(--seal);
  font-family: var(--serif);
  font-size: 1.6rem;
  transform: rotate(-8deg);
  margin-bottom: 0.9rem;
  opacity: 0.85;
}

.empty-invite p {
  font-family: var(--serif);
  margin: 0 0 1.1rem;
}

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 1.4rem;
  margin-bottom: 0.2rem;
}

.back-btn { display: none; }

.save-state {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
}

.save-state.is-saving { color: var(--gold); }
.save-state.is-error { color: var(--seal); }

.title-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.7rem;
  letter-spacing: 0.06em;
  padding: 0.15rem 0 0.35rem;
  border-radius: 0;
}

.title-input:focus {
  outline: none;
  border-bottom-color: var(--seal);
}

.title-input::placeholder { color: #c9bfab; font-weight: 500; }

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem 1rem;
  padding: 0.65rem 0 0.55rem;
  border-bottom: 1px solid var(--line);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 7.5rem;
}

.field-grow { flex: 1; min-width: 10rem; }

.field span {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}

.field input,
.field select {
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.15rem 0 0.2rem;
  border-radius: 0;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-bottom-color: var(--seal);
}

.body-input {
  flex: 1;
  width: 100%;
  margin-top: 0.7rem;
  border: none;
  resize: none;
  background:
    repeating-linear-gradient(
      transparent 0,
      transparent 27px,
      var(--page-rule) 28px
    );
  background-attachment: local;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 28px;
  padding: 0 0 1rem;
  min-height: 12rem;
  border-radius: 0;
}

.body-input:focus { outline: none; }
.body-input::placeholder { color: #c9bfab; }

.page-foot {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}

.check-label input { accent-color: var(--seal); }

.stamps {
  font-size: 0.75rem;
  color: var(--ink-faint);
}

.foot-spacer { flex: 1; }

.confirm-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding: 0.45rem 0 0;
  color: var(--seal);
  font-size: 0.85rem;
}

.confirm-bar.is-hidden { display: none; }


.countdown-rail {
  margin: 0 0 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.countdown-rail[hidden] { display: none; }

.countdown-card {
  background: var(--page);
  border: 1px solid rgba(90, 60, 30, 0.18);
  box-shadow: 0 8px 24px rgba(48, 28, 10, 0.12);
  padding: 0.75rem 1rem 0.8rem;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 0.9rem;
  row-gap: 0.15rem;
  align-items: center;
  position: relative;
}

.countdown-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--seal);
}

.countdown-kicker {
  grid-column: 2;
  margin: 0;
  color: var(--seal);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
}

.countdown-card h2 {
  grid-column: 2;
  margin: 0;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.countdown-clock {
  grid-row: 1 / span 3;
  grid-column: 1;
  margin: 0;
  font-family: var(--serif);
  color: var(--seal);
  display: flex;
  align-items: baseline;
  gap: 0.15rem 0.28rem;
  min-width: 9.5rem;
}

.countdown-clock .n {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.countdown-clock .u {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.countdown-meta {
  grid-column: 2;
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.countdown-meta a {
  color: var(--pine);
  text-decoration: none;
  border-bottom: 1px solid rgba(44, 74, 62, 0.35);
}

.countdown-meta a:hover { border-bottom-color: var(--pine); }

.countdown-clock.is-over .n,
.countdown-clock.is-over { color: var(--ink-soft); }

@media (max-width: 800px) {
  .desk { padding: 0.6rem 0.55rem 1.2rem; }

  .brand-text h1 { font-size: 1.45rem; letter-spacing: 0.14em; }
  .seal { width: 2.5rem; height: 2.5rem; font-size: 1.2rem; }

  .notebook {
    display: block;
    min-height: calc(100dvh - 5.6rem);
  }

  .index-pane { border-right: none; padding-bottom: 2rem; }

  .page-pane { min-height: calc(100dvh - 5.6rem); }

  body.is-editing .index-pane { display: none; }
  body:not(.is-editing) .page-pane { display: none; }

  .binding { display: none; }
  .page { padding: 0.8rem 0.95rem 1rem; }
  .back-btn { display: inline; }
  .title-input { font-size: 1.4rem; }

  .countdown-card {
    grid-template-columns: 1fr;
    padding: 0.7rem 0.85rem 0.8rem 1rem;
  }
  .countdown-clock {
    grid-row: auto;
    grid-column: 1;
    min-width: 0;
    margin-bottom: 0.25rem;
  }
  .countdown-kicker,
  .countdown-card h2,
  .countdown-meta { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
