:root {
  color-scheme: light;
  --bg: #f7f3ec;
  --surface: #fffaf1;
  --surface-2: #efe7da;
  --text: #28322f;
  --muted: #6f746e;
  --line: #ded2c1;
  --accent: #b9653a;
  --accent-dark: #884929;
  --ink-red: #9e2f24;
  --paper: #fbf2df;
  --paper-deep: #ead6b8;
  --green: #547166;
  --blue: #607c93;
  --rose: #ad6972;
  --shadow: 0 18px 50px rgba(70, 54, 36, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(142, 96, 55, 0.03) 1px, transparent 1px),
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 30%),
    var(--bg);
  background-size: 100% 26px, auto, auto;
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

body.walking {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 22px 104px;
}

.topbar,
.today-hero,
.section-heading,
.action-row,
.recipient-row,
.tabbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 28px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.eyebrow,
.section-heading p,
.date-line {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 5vw, 52px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.2;
  letter-spacing: 0;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 22px;
  background: var(--bg);
}

.access-gate.hidden {
  display: none;
}

.access-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.94);
  box-shadow: var(--shadow);
  padding: 26px;
}

.access-card h1 {
  margin-bottom: 10px;
  font-size: clamp(30px, 7vw, 44px);
}

.gate-copy {
  margin-bottom: 22px;
  color: var(--muted);
  line-height: 1.8;
}

.access-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
}

.access-card input {
  height: 48px;
  font-size: 18px;
}

.access-card button {
  width: 100%;
  margin-top: 8px;
}

.access-error {
  min-height: 24px;
  margin-bottom: 0;
  color: #a43e33;
  font-size: 14px;
}

.today-hero {
  align-items: stretch;
  margin-bottom: 20px;
}

.quote-strip {
  width: min(360px, 40%);
  min-height: 104px;
  padding: 18px;
  border-left: 3px double var(--ink-red);
  background:
    linear-gradient(90deg, rgba(158, 47, 36, 0.08), transparent 18px),
    rgba(255, 250, 241, 0.72);
  color: var(--muted);
  line-height: 1.7;
}

.record-panel,
.summary-panel,
.entry-detail,
.card-form,
.letter-list,
.metric,
.echo-line {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.82);
  box-shadow: var(--shadow);
}

.record-panel {
  padding: 22px;
}

.recipient-row {
  justify-content: flex-start;
  margin-bottom: 24px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--text);
}

select,
input {
  height: 42px;
  padding: 0 12px;
}

.recipient-row select {
  width: 190px;
}

.record-core {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 16px 0 20px;
}

.walk-button {
  min-height: 40px;
  border: 1px solid rgba(185, 101, 58, 0.28);
  border-radius: 999px;
  background: rgba(185, 101, 58, 0.1);
  color: var(--accent-dark);
  padding: 0 16px;
  font-weight: 700;
}

.record-button {
  width: 160px;
  height: 160px;
  display: grid;
  place-items: center;
  gap: 8px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  box-shadow: 0 18px 42px rgba(185, 101, 58, 0.32);
}

.record-button.recording {
  background: #8c3d2d;
  animation: pulse 1.5s infinite;
}

.record-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: currentColor;
}

.timer {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.hint {
  color: var(--muted);
}

textarea {
  min-height: 180px;
  padding: 14px;
  resize: vertical;
  line-height: 1.75;
}

.primary,
.secondary,
.text-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 18px;
}

.primary {
  background: var(--accent);
  color: white;
}

.secondary {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.text-button {
  background: transparent;
  color: var(--accent-dark);
}

.summary-panel {
  display: none;
  margin-top: 20px;
  padding: 20px;
}

.summary-panel.visible {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.summary-grid div,
.future-note {
  padding: 16px;
  border-radius: 8px;
  background: #fffdf8;
}

.summary-grid span {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

.summary-grid p,
.future-note {
  margin-bottom: 0;
  line-height: 1.75;
}

.page-heading {
  margin-bottom: 18px;
}

.calendar-controls {
  display: grid;
  grid-template-columns: 42px minmax(92px, 1fr) minmax(82px, 1fr) 42px;
  gap: 8px;
  align-items: center;
}

.calendar-controls select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 0 10px;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.weekday-cell {
  padding: 0 8px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.day-cell {
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.72);
  padding: 10px;
  text-align: left;
}

.day-cell.empty {
  border-color: transparent;
  background: transparent;
  pointer-events: none;
}

.day-cell.has-entry {
  border-color: rgba(185, 101, 58, 0.58);
  background: #fffdf8;
}

.day-cell.is-today {
  box-shadow: inset 0 0 0 2px rgba(84, 113, 102, 0.32);
}

.day-cell strong {
  display: block;
  font-size: 18px;
}

.day-cell span {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.day-cell em {
  display: inline-flex;
  margin-top: 8px;
  border-radius: 999px;
  background: rgba(84, 113, 102, 0.12);
  padding: 3px 8px;
  color: var(--green);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.entry-detail {
  margin-top: 16px;
  padding: 18px;
  line-height: 1.75;
}

.entry-audio {
  display: block;
  width: 100%;
  margin: 14px 0;
}

.entry-segment {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.62);
  padding: 14px;
}

.entry-segment p {
  margin: 8px 0 0;
}

.card-workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
  align-items: stretch;
}

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

.card-form label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.mail-button {
  min-height: 42px;
  border: 1px solid rgba(84, 113, 102, 0.45);
  border-radius: 8px;
  background: rgba(84, 113, 102, 0.1);
  color: var(--green);
  font-weight: 800;
}

.letter-actions {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 18px;
}

.letter-actions .mail-button {
  grid-column: 1 / -1;
}

.letter-actions button {
  width: 100%;
}

.swatches {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 2px solid transparent;
  border-radius: 50%;
}

.swatch.active {
  border-color: var(--text);
}

.swatch[data-tone="warm"] {
  background: #d9a16f;
}

.swatch[data-tone="green"] {
  background: #6f8a76;
}

.swatch[data-tone="blue"] {
  background: #7a98ad;
}

.swatch[data-tone="rose"] {
  background: #c7838b;
}

.postcard {
  --letter-font-size: 28px;
  --letter-ink: #352b22;
  min-height: 780px;
  display: block;
  overflow: visible;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background:
    linear-gradient(135deg, rgba(190, 112, 61, 0.18), transparent 32%),
    #ead0b3;
  padding: 26px;
}

.postcard.green {
  background-color: #eef3df;
}

.postcard.blue {
  background-color: #e8f0f4;
}

.postcard.rose {
  background-color: #f7e8e6;
}

.stamp {
  width: fit-content;
  border: 2px solid var(--ink-red);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--ink-red);
  letter-spacing: 0;
  transform: rotate(-2deg);
}

.post-date {
  position: absolute;
  left: 24px;
  top: 24px;
  color: #6e5a48;
  font-size: 13px;
}

.qiaopi-mark {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.qiaopi-fold {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 48%, rgba(120, 74, 35, 0.14) 49%, transparent 50%),
    linear-gradient(45deg, transparent 48%, rgba(255, 255, 255, 0.32) 49%, transparent 50%);
  opacity: 0.55;
}

.qiaopi-note {
  width: fit-content;
  max-width: 86%;
  margin: 22px 0 0;
  border-top: 1px solid rgba(158, 47, 36, 0.34);
  padding-top: 10px;
  color: #7c6754;
  font-size: 13px;
  line-height: 1.7;
}

.qiaopi-seal {
  position: absolute;
  left: 22px;
  bottom: 22px;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink-red);
  color: var(--ink-red);
  font-weight: 800;
  font-size: 14px;
  transform: rotate(5deg);
}

.letter-paper {
  position: relative;
  width: min(100%, 680px);
  aspect-ratio: 210 / 297;
  margin: 0 auto;
  border: 2px solid var(--ink-red);
  border-radius: 4px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.36), rgba(255, 255, 255, 0.18)),
    var(--paper);
  padding: 44px 56px;
}

.letter-grid {
  height: 100%;
  display: grid;
  grid-template-columns: 62px repeat(8, 56px) 62px;
  grid-auto-flow: column;
  direction: rtl;
  justify-content: center;
  margin: 0 auto;
  border-top: 1px solid rgba(158, 47, 36, 0.5);
  border-bottom: 1px solid rgba(158, 47, 36, 0.5);
}

.letter-column {
  direction: ltr;
  min-height: 100%;
  border-left: 1px solid rgba(158, 47, 36, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 18px 8px;
  color: #352b22;
  color: var(--letter-ink);
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: "KaiTi", "STKaiti", "SimSun", serif;
  font-size: var(--letter-font-size);
  line-height: 1.6;
}

.recipient-column {
  font-weight: 700;
}

.message-column {
  display: contents;
}

.message-column span {
  direction: ltr;
  min-height: 100%;
  border-left: 1px solid rgba(158, 47, 36, 0.55);
  display: block;
  padding: 18px 8px;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: "KaiTi", "STKaiti", "SimSun", serif;
  font-size: var(--letter-font-size);
  color: var(--letter-ink);
  line-height: 1.6;
}

.signature-column {
  align-self: end;
  min-height: 200px;
  margin-top: auto;
  border: 1px solid rgba(158, 47, 36, 0.55);
  font-size: calc(var(--letter-font-size) - 3px);
  font-weight: 700;
}

.postcard[data-font="song"] .letter-column,
.postcard[data-font="song"] .message-column span {
  font-family: "SimSun", "Songti SC", serif;
}

.postcard[data-font="hei"] .letter-column,
.postcard[data-font="hei"] .message-column span {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
}

.letter-list {
  margin-top: 18px;
  padding: 14px;
}

.letter-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

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

.letter-item p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.letter-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.text-button.danger {
  color: #a43e33;
}

.echo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  padding: 20px;
}

.metric span {
  display: block;
  margin-bottom: 8px;
  font-size: 32px;
  font-weight: 800;
}

.metric p {
  margin-bottom: 0;
  color: var(--muted);
}

.echo-line {
  margin-top: 14px;
  padding: 18px;
  line-height: 1.8;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 28px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.tab {
  flex: 1;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--text);
  color: white;
}

.walk-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  min-height: 100dvh;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background:
    repeating-linear-gradient(0deg, transparent, transparent 34px, rgba(120, 74, 35, 0.09) 35px),
    linear-gradient(180deg, rgba(255, 250, 241, 0.97), rgba(247, 243, 236, 0.98));
  color: var(--text);
}

.walk-overlay.visible {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.walk-top,
.walk-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.walk-top p {
  margin: 0;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 800;
}

.walk-body {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 22px;
  text-align: center;
}

.walk-body h2 {
  max-width: 520px;
  font-size: clamp(28px, 9vw, 54px);
}

.walk-date {
  margin: 0;
  color: var(--muted);
}

.walk-timer {
  margin: 0;
  font-size: clamp(54px, 18vw, 96px);
  font-weight: 900;
  line-height: 1;
}

.walk-record {
  width: min(54vw, 220px);
  height: min(54vw, 220px);
}

.walk-actions button {
  flex: 1;
}

.dark {
  color-scheme: dark;
  --bg: #1f211e;
  --surface: #2c2b26;
  --surface-2: #38352e;
  --text: #f6efe4;
  --muted: #c3b9aa;
  --line: #514b41;
  --accent: #d08a5f;
  --accent-dark: #f1b486;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.dark select,
.dark input,
.dark textarea,
.dark .summary-grid div,
.dark .future-note,
.dark .postcard-back,
.dark .walk-overlay,
.dark .access-card {
  background: #252620;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
  }
}

@media (max-width: 760px) {
  .app-shell {
    min-height: 100dvh;
    padding: 18px 14px 104px;
  }

  .topbar {
    margin-bottom: 18px;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 28px;
  }

  .topbar,
  .today-hero,
  .section-heading {
    align-items: flex-start;
  }

  .today-hero,
  .card-workspace,
  .postcard,
  .summary-grid,
  .echo-grid {
    grid-template-columns: 1fr;
  }

  .today-hero {
    display: grid;
  }

  .quote-strip {
    width: 100%;
    min-height: 74px;
  }

  .record-panel {
    padding: 18px;
  }

  .recipient-row {
    display: grid;
    grid-template-columns: auto 1fr;
    margin-bottom: 14px;
  }

  .recipient-row select {
    width: 100%;
  }

  .record-core {
    min-height: calc(100dvh - 440px);
    padding: 8px 0 18px;
  }

  .record-button {
    width: min(54vw, 190px);
    height: min(54vw, 190px);
  }

  .postcard {
    min-height: 650px;
    padding: 14px;
    overflow-x: auto;
  }

  .letter-paper {
    width: 620px;
    padding: 28px 40px;
  }

  .letter-grid {
    grid-template-columns: 52px repeat(8, 44px) 52px;
  }

  .letter-column,
  .message-column span {
    font-size: 23px;
    padding: 14px 6px;
  }

  .signature-column {
    min-height: 150px;
    font-size: 21px;
  }

  textarea {
    min-height: 132px;
  }

  .calendar-controls {
    width: 100%;
    grid-template-columns: 40px minmax(84px, 1fr) minmax(74px, 1fr) 40px;
  }

  .calendar-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
  }

  .weekday-cell {
    padding-inline: 0;
  }

  .day-cell {
    min-height: 62px;
    padding: 7px 4px;
  }

  .day-cell strong {
    font-size: 15px;
  }

  .day-cell span {
    margin-top: 5px;
    font-size: 10px;
  }

  .action-row {
    flex-direction: column-reverse;
  }

  .letter-actions {
    grid-template-columns: 1fr;
  }

  .action-row button {
    width: 100%;
  }

  .tabbar {
    bottom: max(10px, env(safe-area-inset-bottom));
    width: calc(100% - 20px);
  }

  .tab {
    min-height: 48px;
  }
}

@media (max-width: 420px) {
  .calendar-grid {
    grid-template-columns: 1fr;
  }

  .postcard {
    min-height: 540px;
  }
}
