:root {
  color-scheme: light;
  --paper: #f4efe6;
  --paper-deep: #ebe3d4;
  --card: #fffdf8;
  --ink: #1c1917;
  --muted: #6f675e;
  --line: #ddd4c4;
  --rule: #c44732;
  --rule-soft: rgba(196, 71, 50, 0.38);
  --rule-line: rgba(196, 71, 50, 0.08);
  --shadow: 0 10px 30px rgba(48, 32, 16, 0.08);
  --glow: #fffaf1;
  --field: #ffffff;
  --empty: rgba(255, 253, 248, 0.55);
  --meta-line: #efe8db;
  --link: #1d4ed8;
  --ok: #3f6f4a;
  --btn-shadow: 0 8px 18px rgba(28, 25, 23, 0.16);
  --sheet-shadow: 0 24px 80px rgba(28, 25, 23, 0.22);
  --backdrop: rgba(44, 32, 20, 0.38);
  --radius: 18px;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "Times New Roman", serif;
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, var(--glow) 0%, transparent 55%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button,
input,
textarea {
  touch-action: manipulation;
}

.page {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 calc(48px + env(safe-area-inset-bottom));
  overflow: visible;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
  overflow: visible;
}

.seal {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 13px;
  letter-spacing: 0.42em;
  color: var(--rule);
}

.identity {
  position: relative;
  flex: 0 0 auto;
  overflow: visible;
}

.brand-wrap {
  position: relative;
  display: inline-block;
  overflow: visible;
  line-height: 1.25;
}

.brand {
  appearance: none;
  -webkit-appearance: none;
  display: inline-block;
  margin: 0;
  padding: 0.12em 0.2em 0.18em 0;
  border: 0;
  background: transparent;
  font-family: var(--font-serif);
  font-size: 42px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.25;
  height: auto;
  min-height: 1.5em;
  max-height: none;
  overflow: visible;
  color: var(--ink);
  cursor: pointer;
}

.brand.has-hidden::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--rule);
  vertical-align: 0.15em;
}

.hidden-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  min-width: 220px;
  max-width: min(360px, 80vw);
  max-height: 280px;
  overflow: auto;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.hidden-item {
  display: block;
  width: 100%;
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden-item:hover {
  background: var(--paper);
}

.hidden-empty {
  margin: 0;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

.date-range {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.date-sep {
  color: var(--muted);
  font-size: 12px;
  flex: 0 0 auto;
}

.date-field {
  appearance: none;
  box-sizing: border-box;
  width: 7.4rem;
  max-width: 7.4rem;
  flex: 0 0 7.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 6px;
  font: inherit;
  font-size: 13px;
  background: var(--card);
  color: var(--ink);
}

.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.gate[hidden] {
  display: none !important;
}

.gate-card {
  width: min(320px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}

.gate-card h1 {
  margin: 0 0 4px;
  padding: 0.12em 0;
  font-family: var(--font-serif);
  font-size: 42px;
  font-weight: 600;
  line-height: 1.25;
  overflow: visible;
  text-align: center;
}

.pin-field {
  text-align: center;
  letter-spacing: 0.4em;
  font-size: 22px;
}

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 11px 20px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

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

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: var(--ink);
  color: var(--card);
  box-shadow: var(--btn-shadow);
}

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

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

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 1;
  min-width: 0;
}

.btn.secondary {
  background: var(--card);
  color: var(--ink);
  box-shadow: none;
  border: 1px solid var(--line);
}

.status {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.status.ok {
  color: var(--ok);
}

.status.err {
  color: var(--rule);
}

.lead {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.65;
}

.field {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  background: var(--field);
  color: var(--ink);
}

.field:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.title-field {
  margin-bottom: 10px;
  font-family: var(--font-serif);
  font-size: 18px;
}

.view-title {
  margin: 0 0 10px;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.view-body {
  margin: 0;
  min-height: 120px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
  font-size: 16px;
}

.sheet.viewing .title-field,
.sheet.viewing .format-bar,
.sheet.viewing .rich-editor,
.sheet.viewing textarea,
.sheet.viewing .photo-tools,
.sheet.viewing .sheet-foot {
  display: none;
}

.sheet.viewing .photo-bar {
  margin-top: 16px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

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

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--empty);
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
}

.empty strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-weight: 600;
}

.memo {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 20px 14px 48px;
  overflow: hidden;
}

.memo.selected {
  border-color: var(--ink);
}

.memo-check {
  position: absolute;
  left: 22px;
  top: 22px;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.memo::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  background: var(--rule-soft);
  border-radius: 2px;
}

.memo-title {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.memo-title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.memo-body {
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  max-height: calc(1.65em * 3);
  font-size: 15px;
  color: var(--muted);
}

.memo.compact .memo-title {
  margin-bottom: 0;
}

.memo-link {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.memo-photos,
.photo-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.memo-photo,
.photo-item {
  position: relative;
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.memo-photo img,
.photo-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(28, 25, 23, 0.72);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.photo-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.photo-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.memo-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--meta-line);
}

.time {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.linkish {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.linkish:hover {
  background: var(--paper);
}

.linkish.delete {
  color: var(--rule);
}

.sheet {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 0;
  background: var(--card);
  box-shadow: var(--sheet-shadow);
}

.sheet::backdrop {
  background: var(--backdrop);
}

.sheet form {
  display: flex;
  flex-direction: column;
  padding: 18px 18px 16px;
}

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

.sheet h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.format-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.fmt-btn {
  appearance: none;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.fmt-btn:hover,
.fmt-swatch:hover,
.fmt-sizes:hover {
  border-color: var(--ink);
}

.fmt-swatches {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fmt-swatch {
  appearance: none;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.fmt-sizes {
  display: inline-flex;
  align-items: stretch;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.fmt-size {
  appearance: none;
  min-width: 2.4em;
  height: 36px;
  padding: 0 9px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.fmt-size:last-child {
  border-right: 0;
}

.fmt-size.is-active {
  background: var(--ink);
  color: var(--card);
}

.rich-editor {
  width: 100%;
  min-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  font: inherit;
  font-size: 16px;
  line-height: 1.7;
  background:
    repeating-linear-gradient(
      transparent,
      transparent 26px,
      var(--rule-line) 27px
    ),
    var(--field);
  background-origin: content-box;
  color: var(--ink);
  outline: none;
}

.rich-editor:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.rich-editor.is-empty:before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.rich-editor a,
.view-body a,
.memo-body a {
  color: var(--link);
}

.view-body strong,
.memo-body strong,
.rich-editor strong,
.view-body b,
.memo-body b,
.rich-editor b {
  font-weight: 700;
}

.view-body u,
.memo-body u,
.rich-editor u {
  text-decoration: underline;
}

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

.counter {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.counter.warn {
  color: var(--rule);
}

.mini {
  width: min(380px, calc(100% - 24px));
}

.mini p {
  margin: 8px 0 0;
  color: var(--muted);
}

.confirm-form {
  padding: 22px 20px 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--card);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

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

@media (max-width: 520px) {
  .page {
    width: calc(100% - 20px);
    padding-top: 16px;
  }

  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .brand {
    font-size: 32px;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: flex-start;
    width: 100%;
  }

  .date-range {
    width: auto;
  }

  .date-field {
    width: 6.8rem;
    max-width: 6.8rem;
    flex: 0 0 6.8rem;
    font-size: 13px;
  }

  .btn {
    padding: 10px 14px;
    min-height: 44px;
  }

  .memo {
    padding: 18px 16px 12px 44px;
  }

  .memo-check {
    width: 18px;
    height: 18px;
    left: 18px;
    top: 20px;
  }

  .memo-title {
    font-size: 18px;
  }

  .rich-editor {
    min-height: 180px;
  }

  .sheet {
    width: calc(100% - 16px);
    border-radius: 18px;
  }

  .hidden-menu {
    min-width: 160px;
  }
}

@media (max-width: 380px) {
  .page {
    width: calc(100% - 16px);
  }

  .brand {
    font-size: 28px;
  }

  .date-field {
    width: 6.4rem;
    max-width: 6.4rem;
    flex: 0 0 6.4rem;
  }
}

@media (min-width: 700px) and (max-height: 740px) {
  .page {
    width: min(980px, calc(100% - 28px));
    padding-top: 16px;
    padding-bottom: 28px;
  }

  .top {
    margin-bottom: 16px;
    align-items: center;
  }

  .board {
    grid-template-columns: 1fr 1fr;
  }

  .empty {
    grid-column: 1 / -1;
    padding: 36px 20px;
  }

  .rich-editor {
    min-height: 140px;
  }

  .gate-card h1,
  .brand {
    font-size: 36px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #1a1612;
    --paper-deep: #120f0c;
    --card: #241f1a;
    --ink: #f4efe6;
    --muted: #b6aea3;
    --line: #3d362e;
    --rule: #e06a54;
    --rule-soft: rgba(224, 106, 84, 0.5);
    --rule-line: rgba(224, 106, 84, 0.2);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
    --glow: #2c2418;
    --field: #1c1814;
    --empty: rgba(36, 31, 26, 0.7);
    --meta-line: #3a332c;
    --link: #8ab4ff;
    --ok: #7dba88;
    --btn-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
    --sheet-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
    --backdrop: rgba(8, 6, 4, 0.62);
  }

  .date-field::-webkit-calendar-picker-indicator {
    filter: invert(1);
  }
}
