:root {
  color-scheme: light;
  --bg: #f5f0e8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #66717a;
  --line: #d9e0dc;
  --accent: #126c5f;
  --accent-strong: #0e564c;
  --accent-soft: #d7eee8;
  --mine: #126c5f;
  --theirs: #eef3f1;
  --danger: #b42318;
  --shadow: 0 24px 60px rgba(42, 48, 45, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(18, 108, 95, 0.16), transparent 32rem),
    linear-gradient(135deg, #f5f0e8 0%, #edf5f2 52%, #f3f4ee 100%);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel,
.chat-panel {
  width: min(100%, 920px);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  max-width: 420px;
  padding: 36px;
}

.brand-mark {
  width: 58px;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
}

.brand-mark span {
  display: block;
  width: 28px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  transform: rotate(-7deg);
}

.brand-mark span + span {
  width: 22px;
  height: 26px;
  background: #d29f43;
  transform: rotate(8deg);
}

.auth-panel h1,
.chat-header h1 {
  margin: 0;
  letter-spacing: 0;
}

.auth-panel h1 {
  font-size: 32px;
  line-height: 1.15;
}

.muted {
  color: var(--muted);
  margin: 10px 0 24px;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: #334047;
  font-size: 14px;
}

.auth-form .remember-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
}

.auth-form .remember-row input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.auth-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.auth-form input {
  height: 46px;
  padding: 0 14px;
}

.auth-form input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 108, 95, 0.14);
}

.auth-form button,
.send-button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.auth-form button {
  height: 48px;
}

.auth-form button:hover,
.send-button:hover {
  background: var(--accent-strong);
}

.error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.chat-panel {
  height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  overflow: hidden;
}

.chat-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.chat-header h1 {
  font-size: 20px;
  line-height: 1.2;
}

.chat-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.presence {
  min-width: 86px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #2a373d;
  background: #fff;
  font-size: 13px;
  white-space: nowrap;
}

.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2fb170;
  box-shadow: 0 0 0 4px rgba(47, 177, 112, 0.16);
}

.call-button {
  height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: #334047;
  font-weight: 700;
}

.call-button:hover {
  background: #172026;
}

.call-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #e0c77e;
  background: #fff3c6;
}

.call-banner div:first-child {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.call-banner strong,
.call-banner span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-banner-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.call-banner-actions button {
  height: 34px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.call-banner-actions button + button {
  color: #39464c;
  background: #f1e4b8;
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}

.view-tabs button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #334047;
  background: #fff;
  font-weight: 700;
}

.view-tabs button.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.view-panel {
  min-height: 0;
}

.chat-view {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
}

.diary-view {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
    repeating-linear-gradient(135deg, transparent 0 16px, rgba(210, 159, 67, 0.06) 16px 32px);
}

.sesame-view {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.74)),
    repeating-linear-gradient(135deg, transparent 0 16px, rgba(146, 92, 56, 0.055) 16px 32px);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 20px 18px 26px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.62)),
    repeating-linear-gradient(135deg, transparent 0 16px, rgba(18, 108, 95, 0.03) 16px 32px);
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
}

.empty-visual {
  width: 110px;
  height: 68px;
  position: relative;
}

.empty-visual span {
  position: absolute;
  display: block;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid #b8d8d0;
}

.empty-visual span:nth-child(1) {
  width: 76px;
  height: 42px;
  left: 0;
  top: 8px;
}

.empty-visual span:nth-child(2) {
  width: 70px;
  height: 38px;
  right: 0;
  bottom: 0;
  background: #f2dfb7;
  border-color: #e2c784;
}

.empty-visual span:nth-child(3) {
  width: 18px;
  height: 18px;
  left: 68px;
  top: 0;
  border-radius: 50%;
  background: #fffbf3;
}

.message {
  max-width: min(72%, 560px);
  display: grid;
  gap: 5px;
}

.date-separator {
  align-self: center;
  margin: 4px 0;
  border: 1px solid rgba(18, 108, 95, 0.14);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 700;
}

.message.mine {
  align-self: flex-end;
}

.message.theirs {
  align-self: flex-start;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  padding: 0 4px;
}

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

.bubble {
  padding: 11px 13px;
  border-radius: 8px;
  overflow: hidden;
  word-break: break-word;
  line-height: 1.55;
  box-shadow: 0 8px 24px rgba(34, 44, 40, 0.08);
}

.message.mine .bubble {
  background: var(--mine);
  color: #fff;
  border-top-right-radius: 2px;
}

.message.theirs .bubble {
  background: var(--theirs);
  color: var(--ink);
  border-top-left-radius: 2px;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.media {
  margin-top: 8px;
}

.media:first-child {
  margin-top: 0;
}

.media img,
.media video {
  display: block;
  width: 100%;
  max-height: 430px;
  object-fit: contain;
  border-radius: 8px;
  background: #101418;
}

.media-name {
  display: block;
  margin-top: 6px;
  color: inherit;
  opacity: 0.78;
  font-size: 12px;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
}

.preview div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.preview strong,
.preview span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview strong {
  font-size: 14px;
}

.preview span {
  color: var(--muted);
  font-size: 12px;
}

.preview button,
.file-button {
  flex: 0 0 auto;
}

.preview button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: #e9efed;
  color: #334047;
  font-size: 24px;
  line-height: 1;
}

.composer-row {
  display: grid;
  grid-template-columns: 44px 1fr 76px;
  align-items: end;
  gap: 10px;
}

.file-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
}

.file-button input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-button span {
  font-size: 28px;
  line-height: 1;
  transform: translateY(-1px);
}

.composer textarea {
  min-height: 44px;
  max-height: 126px;
  resize: none;
  padding: 10px 12px;
  line-height: 1.45;
}

.send-button {
  height: 44px;
  padding: 0 14px;
}

.diary-form {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.diary-form input,
.diary-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.diary-form input {
  height: 42px;
  padding: 0 12px;
}

.diary-form textarea {
  min-height: 108px;
  max-height: 180px;
  resize: none;
  padding: 10px 12px;
  line-height: 1.55;
}

.diary-form input:focus,
.diary-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 108, 95, 0.14);
}

.diary-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.diary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.diary-file-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--accent);
  background: #fff;
  font-weight: 700;
}

.diary-file-button input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.diary-preview {
  display: grid;
  gap: 6px;
}

.diary-preview-item {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  background: #f7faf8;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diary-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.diary-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.diary-entry {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 26px rgba(34, 44, 40, 0.08);
}

.diary-entry-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: start;
}

.diary-entry h2 {
  grid-column: 1;
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.3;
  word-break: break-word;
}

.diary-entry time {
  grid-column: 1;
  color: var(--muted);
  font-size: 12px;
}

.entry-action,
.ghost-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--accent);
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}

.entry-action {
  align-self: center;
}

.entry-actions {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.entry-actions .entry-action {
  grid-column: auto;
  grid-row: auto;
}

.secondary-action {
  color: #6c5540;
}

.entry-action:hover,
.ghost-button:hover {
  border-color: var(--accent);
  background: #eef8f4;
}

.goals-view {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 0;
}

.goal-form {
  display: grid;
  grid-template-columns: 118px 1fr 82px;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.goal-form input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.goal-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 108, 95, 0.14);
}

.goal-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.goal-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 26px rgba(34, 44, 40, 0.08);
}

.goal-item .entry-action {
  grid-column: auto;
  grid-row: auto;
}

.goal-item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.goal-content {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.goal-content strong {
  color: var(--ink);
  line-height: 1.35;
  word-break: break-word;
}

.goal-content span {
  color: var(--muted);
  font-size: 12px;
}

.diary-entry-text {
  margin: 0;
  color: #26343a;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.diary-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.diary-media-grid .media {
  margin-top: 0;
}

.diary-media-grid .media img,
.diary-media-grid .media video {
  max-height: 280px;
}

.call-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(13, 18, 22, 0.82);
}

.call-stage {
  position: relative;
  width: min(100%, 960px);
  height: min(720px, calc(100vh - 48px));
  overflow: hidden;
  border-radius: 8px;
  background: #06090c;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.36);
}

#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #11181d;
}

#localVideo {
  position: absolute;
  right: 16px;
  bottom: 86px;
  width: min(28%, 220px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: #1f2a30;
}

.call-status {
  position: absolute;
  left: 16px;
  top: 16px;
  max-width: calc(100% - 32px);
  padding: 8px 10px;
  border-radius: 8px;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  font-size: 14px;
}

.call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.68));
}

.call-controls button {
  height: 42px;
  min-width: 82px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 700;
}

.call-controls .hangup-button {
  background: #c0362c;
}

@media (max-width: 640px) {
  .shell {
    min-height: 100svh;
    padding: 0;
  }

  .auth-panel {
    width: calc(100% - 28px);
    padding: 28px 22px;
  }

  .chat-panel {
    width: 100%;
    height: 100svh;
    border: 0;
    border-radius: 0;
  }

  .chat-header {
    padding: 14px;
  }

  .header-actions {
    gap: 8px;
  }

  .call-button {
    width: 42px;
    padding: 0;
    font-size: 12px;
  }

  .presence {
    min-width: 74px;
    padding: 0 10px;
  }

  .messages {
    padding: 16px 12px 22px;
  }

  .view-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .view-tabs button {
    height: 36px;
    padding: 0 4px;
    font-size: 13px;
  }

  .diary-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .diary-toolbar .send-button,
  .diary-file-button,
  .diary-actions,
  .ghost-button {
    width: 100%;
  }

  .diary-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .diary-list {
    gap: 12px;
    padding: 10px;
  }

  .diary-entry {
    gap: 8px;
    padding: 12px;
  }

  .diary-entry-header {
    grid-template-columns: 1fr;
  }

  .diary-entry h2 {
    font-size: 16px;
  }

  .diary-entry time {
    font-size: 12px;
  }

  .entry-actions {
    grid-column: 1;
    grid-row: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .entry-actions .entry-action,
  .diary-entry-header > .entry-action {
    width: 100%;
  }

  .diary-entry-text {
    font-size: 14px;
    line-height: 1.7;
  }

  .diary-media-grid {
    grid-template-columns: 1fr;
  }

  .goal-form {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .goal-list {
    padding: 12px;
  }

  .goal-item {
    grid-template-columns: 28px 1fr;
  }

  .goal-item .entry-action {
    grid-column: 1 / -1;
    width: 100%;
  }

  .message {
    max-width: 86%;
  }

  .composer-row {
    grid-template-columns: 42px 1fr 64px;
    gap: 8px;
  }

  .file-button,
  .send-button {
    height: 42px;
  }

  .file-button {
    width: 42px;
  }

  .call-modal {
    padding: 0;
  }

  .call-stage {
    width: 100%;
    height: 100svh;
    border-radius: 0;
  }

  #localVideo {
    right: 12px;
    bottom: 84px;
    width: 34%;
  }

  .call-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .call-banner-actions {
    justify-content: flex-end;
  }
}
