:root {
  color-scheme: light;
  --paper: #f3f0e8;
  --paper-deep: #e7e1d5;
  --ink: #20231f;
  --muted: #6f756c;
  --line: #cbc6ba;
  --green: #285e4e;
  --green-soft: #dce8df;
  --coral: #d9684f;
  --coral-dark: #ad4333;
  --white: #fffdf8;
  --shadow: 0 18px 48px rgba(32, 35, 31, 0.12);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

button,
textarea,
input {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: 100%;
  min-height: 100dvh;
}

.lock-view {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 100dvh;
  padding:
    calc(42px + env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    calc(22px + env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
  overflow: hidden;
}

.lock-view::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(32, 35, 31, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 35, 31, 0.035) 1px, transparent 1px);
  background-size: 26px 26px;
  content: "";
  pointer-events: none;
}

.lock-view > * {
  position: relative;
  z-index: 1;
}

.brand-mark,
.peer-mark {
  position: relative;
  width: 46px;
  height: 46px;
}

.brand-mark span,
.peer-mark span {
  position: absolute;
  display: block;
  width: 30px;
  height: 30px;
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.brand-mark span:first-child,
.peer-mark span:first-child {
  top: 0;
  left: 0;
}

.brand-mark span:last-child,
.peer-mark span:last-child {
  right: 0;
  bottom: 0;
  border-color: var(--coral);
}

.brand-mark span:last-child::after,
.peer-mark span:last-child::after {
  position: absolute;
  top: 9px;
  left: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--coral);
  content: "";
}

.lock-copy {
  margin-top: clamp(44px, 10vh, 84px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}

.lock-copy h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", serif;
  font-size: clamp(56px, 18vw, 78px);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: 0;
}

.lock-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-family: "Songti SC", "STSong", serif;
  font-size: 18px;
}

.unlock-form {
  align-self: end;
  margin-top: 42px;
}

.unlock-form label {
  display: block;
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.unlock-form input {
  width: 100%;
  height: 52px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  transition: border-color 160ms ease;
}

.unlock-form input:focus {
  border-color: var(--green);
}

.unlock-form input::placeholder,
.composer textarea::placeholder {
  color: #989b94;
}

.secret-field {
  position: relative;
}

.secret-field input {
  padding-right: 48px;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  place-items: center;
  background: transparent;
  cursor: pointer;
}

.icon-button:active {
  background: rgba(32, 35, 31, 0.08);
}

.secret-field .icon-button {
  position: absolute;
  right: -8px;
  bottom: 5px;
  color: var(--muted);
  font-size: 18px;
}

.form-error {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--coral-dark);
  font-size: 12px;
}

.primary-button {
  display: flex;
  width: 100%;
  height: 54px;
  margin-top: 14px;
  padding: 0 18px 0 20px;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: var(--white);
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.primary-button span:last-child {
  color: var(--coral);
  font-size: 22px;
}

.privacy-line {
  display: flex;
  margin: 24px 0 0;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.privacy-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.chat-view {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--paper);
  overflow: hidden;
}

.chat-header {
  display: flex;
  min-height: 78px;
  padding:
    calc(12px + env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    10px
    max(18px, env(safe-area-inset-left));
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.peer,
.header-actions {
  display: flex;
  align-items: center;
}

.peer {
  gap: 10px;
}

.peer-mark {
  width: 34px;
  height: 34px;
}

.peer-mark span {
  width: 22px;
  height: 22px;
  border-width: 1.5px;
}

.peer-mark span:last-child::after {
  top: 6px;
  left: 6px;
  width: 7px;
  height: 7px;
}

.peer h2 {
  margin: 0;
  font-family: "Songti SC", "STSong", serif;
  font-size: 20px;
  line-height: 1.1;
}

#presence {
  display: flex;
  margin: 4px 0 0;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
}

#presence span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a5a79f;
}

#presence.online span {
  background: var(--green);
}

.header-actions {
  gap: 2px;
}

.header-actions .icon-button {
  font-size: 18px;
}

.notification-glyph {
  position: relative;
  display: block;
  width: 15px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-radius: 8px 8px 3px 3px;
}

.notification-glyph::before {
  position: absolute;
  top: -4px;
  left: 5px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.notification-glyph::after {
  position: absolute;
  right: 4px;
  bottom: -5px;
  width: 5px;
  height: 2px;
  border-radius: 0 0 4px 4px;
  background: currentColor;
  content: "";
}

#notification-button.enabled {
  background: var(--green-soft);
  color: var(--green);
}

.connection-banner {
  padding: 6px 16px;
  background: var(--paper-deep);
  color: var(--muted);
  text-align: center;
  font-size: 10px;
}

.messages {
  display: flex;
  min-height: 0;
  padding: 22px max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
  flex-direction: column;
  gap: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.empty-state {
  display: grid;
  min-height: 100%;
  padding: 32px;
  place-content: center;
  text-align: center;
}

.empty-signal {
  position: relative;
  width: 62px;
  height: 44px;
  margin: 0 auto 22px;
}

.empty-signal::before,
.empty-signal::after,
.empty-signal span {
  position: absolute;
  height: 1px;
  background: var(--line);
  content: "";
}

.empty-signal::before {
  top: 8px;
  left: 8px;
  width: 46px;
}

.empty-signal::after {
  right: 0;
  bottom: 8px;
  width: 46px;
}

.empty-signal span {
  top: 21px;
  left: 0;
  width: 62px;
  background: var(--coral);
}

.empty-state p {
  margin: 0;
  font-family: "Songti SC", "STSong", serif;
  font-size: 18px;
}

.empty-state small {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.message-row {
  display: flex;
  width: 100%;
  animation: message-in 220ms ease-out both;
}

.message-row.no-animation {
  animation: none;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(78%, 520px);
}

.sender-name {
  margin: 0 0 4px 4px;
  color: var(--muted);
  font-size: 10px;
}

.message-body {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 3px 8px 8px;
  background: var(--white);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.mine .message-body {
  border-color: var(--green);
  border-radius: 8px 3px 8px 8px;
  background: var(--green);
  color: var(--white);
}

.message-meta {
  margin: 4px 4px 0;
  color: var(--muted);
  font-size: 9px;
  text-align: left;
}

.mine .message-meta {
  text-align: right;
}

.message-row.pending .message-meta::after {
  content: " · 发送中";
}

.message-row.failed .message-meta {
  color: var(--coral-dark);
}

.message-row.failed .message-meta::after {
  content: " · 发送失败";
}

.composer {
  display: grid;
  padding:
    10px
    max(12px, env(safe-area-inset-right))
    calc(10px + env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: end;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 124px;
  padding: 11px 12px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: var(--white);
  color: var(--ink);
  font-size: 16px;
  line-height: 20px;
}

.composer textarea:focus {
  border-color: var(--green);
}

.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  place-items: center;
  background: var(--coral);
  color: var(--white);
  font-size: 22px;
  cursor: pointer;
}

.send-button:disabled {
  background: var(--paper-deep);
  color: #a4a39d;
  cursor: default;
}

dialog {
  width: calc(100% - 40px);
  max-width: 360px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: var(--white);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(32, 35, 31, 0.5);
}

.dialog-mark {
  color: var(--coral);
  font-size: 28px;
}

dialog h3 {
  margin: 14px 0 8px;
  font-family: "Songti SC", "STSong", serif;
  font-size: 21px;
}

dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.dialog-actions {
  display: grid;
  margin-top: 24px;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.secondary-button,
.danger-button {
  height: 42px;
  border-radius: 5px;
  font-weight: 600;
}

.secondary-button {
  border: 1px solid var(--line);
  background: transparent;
}

.danger-button {
  border: 1px solid var(--coral);
  background: var(--coral);
  color: var(--white);
}

.toast {
  position: fixed;
  z-index: 10;
  right: 18px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 18px;
  max-width: 380px;
  margin: auto;
  padding: 10px 14px;
  border-radius: 5px;
  background: var(--ink);
  color: var(--white);
  font-size: 12px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 720px) {
  body {
    display: grid;
    padding: 28px;
    place-items: center;
    background: #d8d4ca;
  }

  .app-shell {
    width: min(100%, 460px);
    min-height: min(860px, calc(100dvh - 56px));
    border: 1px solid #bdb8ac;
    box-shadow: var(--shadow);
  }

  .lock-view,
  .chat-view {
    min-height: min(860px, calc(100dvh - 56px));
    height: min(860px, calc(100dvh - 56px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
