/* ============================================================
   信笺 · 样式
   ============================================================ */

:root {
  --paper:      #fbf6ec;
  --paper-2:    #f5eddd;
  --desk:       #e6dccb;
  --ink:        #33302a;
  --ink-soft:   #6d6558;
  --ink-faint:  #9a8f7d;
  --rule:       #d8ccb4;
  --rule-soft:  rgba(150, 130, 100, .28);
  --seal:       #b03a2e;
  --seal-dark:  #8f2d24;
  --line:       34px;

  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", SimSun, Georgia, serif;
  --kai:   "Kaiti SC", "STKaiti", KaiTi, "Noto Serif SC", "Songti SC", serif;
  --sans:  -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--desk);
  background-image:
    radial-gradient(120% 80% at 50% -10%, #f3ecdd 0%, #e6dccb 45%, #ddd0bb 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.045'/%3E%3C/svg%3E");
}

.app {
  position: relative;
  z-index: 1;
  max-width: 700px;
  margin: 0 auto;
  padding: 46px 22px 96px;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ----------------------------------------------------- 页头 */

.masthead {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  margin-bottom: 34px;
}

/* ----------------------------------------------------- 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 17px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--seal);
  color: #fff6ef;
  font-size: 13.5px;
  letter-spacing: .06em;
  white-space: nowrap;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
  box-shadow: 0 4px 12px -6px rgba(140, 45, 35, .8);
}
.btn:hover { background: var(--seal-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--rule);
  box-shadow: none;
}
.btn.ghost:hover { background: rgba(255,255,255,.5); color: var(--ink); }

.btn.small { padding: 6px 13px; font-size: 12.5px; }

/* ----------------------------------------------------- 首页列表 */

.ledger-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.ledger { list-style: none; margin: 0; padding: 0; }

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

.entry a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 10px 15px 4px;
  transition: background .15s ease, padding-left .18s ease;
}
.entry a:hover { background: rgba(255, 255, 255, .55); padding-left: 10px; }
.entry a:hover .entry-title { color: var(--seal); }

.entry-no {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  flex: 0 0 22px;
  padding-top: 3px;
}

.entry-title {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--serif);
  font-size: 18.5px;
  line-height: 1.4;
  letter-spacing: .03em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color .15s ease;
}

.entry-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.tag {
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 2px 6px;
  letter-spacing: .06em;
  color: var(--ink-soft);
  background: rgba(255,255,255,.4);
}
.tag.fire { color: var(--seal); border-color: rgba(176, 58, 46, .45); background: rgba(176, 58, 46, .07); }
.tag.lock { color: #7a5c2e; border-color: rgba(122, 92, 46, .35); background: rgba(160, 130, 70, .1); }

.entry-date { font-family: var(--mono); font-size: 11.5px; }

.row-tool {
  flex: 0 0 auto;
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  transition: opacity .15s ease, color .15s ease;
}
.entry a:hover ~ .row-tool, .row-tool:hover, .row-tool:focus-visible { opacity: 1; }
.row-tool:hover { color: var(--seal); }

.entry-row { display: flex; align-items: center; }
.entry-row a { flex: 1 1 auto; min-width: 0; }

.empty {
  padding: 54px 10px;
  text-align: center;
  color: var(--ink-faint);
  font-family: var(--kai);
  font-size: 17px;
  line-height: 2;
}

/* ----------------------------------------------------- 信纸 */

.sheet {
  position: relative;
  background: var(--paper);
  background-image: linear-gradient(180deg, #fffdf8 0%, #faf4e8 100%);
  border-radius: 4px;
  padding: 34px 30px 30px 74px;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.6),
    0 1px 2px rgba(90, 70, 45, .12),
    0 14px 34px -14px rgba(80, 60, 35, .5);
}

.sheet::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 58px;
  width: 1px;
  background: rgba(176, 58, 46, .32);
}

.sheet.compact { padding: 34px 30px 32px; }
.sheet.compact::before { display: none; }

/* 信纸上的横格：与 34px 行高严格对齐 */
.ruled {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line) - 1px),
    var(--rule-soft) calc(var(--line) - 1px),
    var(--rule-soft) var(--line)
  );
  background-attachment: local;
}

.letter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.letter-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .05em;
  line-height: 1.5;
  word-break: break-word;
}

.letter-date {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  padding-top: 4px;
}

.letter-body {
  font-family: var(--kai);
  font-size: 18px;
  color: #2c2822;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.letter-body .ln {
  margin: 0;
  min-height: var(--line);
  line-height: var(--line);
  white-space: pre-wrap;
}

.letter-sign {
  margin-top: 20px;
  text-align: right;
  font-family: var(--kai);
  font-size: 17px;
  color: var(--ink-soft);
}

/* ----------------------------------------------------- 写信 */

.field { margin-bottom: 22px; }

.field-label {
  display: block;
  font-size: 11.5px;
  letter-spacing: .18em;
  color: var(--ink-faint);
  margin-bottom: 9px;
}

.input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  padding: 9px 2px;
  font-family: var(--serif);
  font-size: 19px;
  color: var(--ink);
  outline: 0;
  transition: border-color .18s ease;
}
.input:focus { border-bottom-color: var(--seal); }
.input::placeholder { color: #bdb2a0; }
.input.small { font-size: 15px; font-family: var(--sans); padding: 7px 2px; }

/* 写信时间：原生日期/时刻控件收窄一点，图标压得不那么刺眼 */
.datetime {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.datetime .input { width: auto; flex: 0 0 auto; }
.input[type="date"], .input[type="time"] {
  color-scheme: light;
  font-variant-numeric: tabular-nums;
}
.input[type="date"] { max-width: 230px; }
.input[type="time"] { max-width: 150px; }
.input[type="date"]::-webkit-calendar-picker-indicator,
.input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: .38;
  cursor: pointer;
  transition: opacity .18s ease;
}
.input[type="date"]::-webkit-calendar-picker-indicator:hover,
.input[type="time"]::-webkit-calendar-picker-indicator:hover { opacity: .8; }

textarea.editor {
  display: block;
  width: 100%;
  min-height: calc(var(--line) * 11);
  border: 0;
  outline: 0;
  padding: 0;
  margin: 0;
  resize: none;
  overflow: hidden;
  background-color: transparent;
  color: #2c2822;
  font-family: var(--kai);
  font-size: 18px;
  line-height: var(--line);
  letter-spacing: .02em;
  caret-color: var(--seal);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line) - 1px),
    var(--rule-soft) calc(var(--line) - 1px),
    var(--rule-soft) var(--line)
  );
  background-attachment: local;
}
textarea.editor::placeholder { color: #c3b8a6; }

/* ----------------------------------------------------- 选项 */

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 26px;
  align-items: flex-start;
  margin: 30px 0 26px;
}

.opt-group { flex: 1 1 240px; min-width: 200px; }

.opt-desc { margin: 9px 2px 0; font-size: 12px; color: var(--ink-faint); line-height: 1.65; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }

.switch .track {
  width: 44px; height: 24px;
  border-radius: 999px;
  background: #cfc3ad;
  position: relative;
  transition: background .2s ease;
  flex: 0 0 44px;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fffdf8;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s cubic-bezier(.4,1.4,.6,1);
}
.switch input:checked + .track { background: var(--seal); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(176,58,46,.25); }
.switch .txt { font-size: 13.5px; color: var(--ink); letter-spacing: .04em; }

.seg {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 3px;
  background: rgba(255,255,255,.45);
}
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  padding: 5px 15px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ink-soft);
  transition: background .18s ease, color .18s ease;
}
.seg input:checked + span { background: var(--seal); color: #fff6ef; }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px rgba(176,58,46,.22); }

.pw-wrap { margin-top: 12px; display: none; }
.pw-wrap.on { display: block; }

/* ----------------------------------------------------- 门禁 */

.gate { text-align: center; padding: 44px 30px 38px; }
.gate::before { display: none; }

.gate-icon {
  width: 46px; height: 46px;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--rule);
  color: var(--seal);
  background: rgba(255,255,255,.55);
}

.gate h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 20px;
  letter-spacing: .05em;
  word-break: break-word;
}
.gate p { margin: 0 0 24px; font-size: 12.5px; color: var(--ink-faint); letter-spacing: .04em; }

.gate-form {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  max-width: 380px;
  margin: 0 auto;
}
.gate-form .input {
  width: auto;
  flex: 1 1 120px;
  min-width: 0;
  font-family: var(--sans);
  font-size: 15px;
  text-align: center;
  letter-spacing: .2em;
}
.gate-form .btn { flex: 0 0 auto; }

.msg { min-height: 19px; margin-top: 13px; font-size: 12.5px; color: var(--seal); }

/* ----------------------------------------------------- 提示条 */

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 15px;
  border-radius: 4px;
  font-size: 12.5px;
  letter-spacing: .04em;
  margin-bottom: 20px;
  background: rgba(176, 58, 46, .09);
  border: 1px solid rgba(176, 58, 46, .3);
  color: var(--seal-dark);
}
.notice.plain { background: rgba(255,255,255,.5); border-color: var(--rule); color: var(--ink-soft); }

/* ----------------------------------------------------- 完成页 */

.done { text-align: center; }
.done .stamp {
  width: 74px; height: 74px;
  margin: 6px auto 20px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--seal);
  color: #fff6ef;
  font-family: var(--kai);
  font-size: 34px;
  box-shadow: inset 0 0 0 2.5px rgba(255,246,239,.5), 0 6px 18px -8px rgba(140,45,35,.9);
  transform: rotate(-4deg);
}
.done h2 { margin: 0 0 8px; font-family: var(--serif); font-size: 21px; letter-spacing: .06em; }
.done p { margin: 0 0 24px; font-size: 13px; color: var(--ink-faint); line-height: 1.8; }

.linkset {
  display: flex;
  gap: 8px;
  align-items: stretch;
  max-width: 100%;
  margin: 0 auto;
}
.linkset .input {
  font-family: var(--mono);
  font-size: 12px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 10px 12px;
  background: rgba(255,255,255,.6);
  text-overflow: ellipsis;
}
.linkset .btn { flex: 0 0 auto; border-radius: 4px; }

.actions { display: flex; gap: 10px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }

/* ----------------------------------------------------- 其他 */

.foot {
  margin-top: 40px;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: .1em;
  font-family: var(--serif);
}

.back { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-faint); margin-bottom: 20px; }
.back:hover { color: var(--seal); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translate(-50%, 16px);
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(45, 40, 33, .93);
  color: #f6efe3;
  font-size: 12.5px;
  letter-spacing: .06em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.fade { animation: fade .42s cubic-bezier(.2,.7,.3,1) both; }
@keyframes fade {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: none; }
}

@media (max-width: 560px) {
  .app { padding: 30px 15px 80px; }
  .masthead { margin-bottom: 26px; }
  .sheet { padding: 26px 18px 24px 54px; }
  .sheet::before { left: 42px; }
  .letter-body, textarea.editor { font-size: 16.5px; }
  .entry-no { display: none; }
  .entry-title { font-size: 17px; }
  .entry-meta .entry-date { display: none; }
  .row-tool { opacity: 1; }
}
