.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* ---------- header ---------- */

.hdr {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  flex: none;
  background: var(--accent);
  letter-spacing: 0.5px;
}

.who {
  min-width: 0;
  flex: 1;
}

.who .name {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.who .sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

/* ---------- messages ---------- */

.msgs {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.7;
  padding: 0 30px;
  max-width: 320px;
}

.day {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
  margin: 16px 0 10px;
  letter-spacing: 0.3px;
}

.day:first-child {
  margin-top: 2px;
}

.row {
  display: flex;
  margin-bottom: 3px;
  animation: pop 0.16s ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .row {
    animation: none;
  }
}

.row.out {
  justify-content: flex-end;
}

.bubble {
  max-width: 79%;
  padding: 8px 13px 9px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.row.in .bubble {
  background: var(--in-bubble);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.row.out .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: 5px;
}

.meta {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 3px;
  font-size: 10.5px;
  line-height: 1;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
}

.row.in .meta {
  justify-content: flex-start;
}

.tick {
  font-size: 11px;
  letter-spacing: -1px;
}

/* ---------- save hint ---------- */

.hint {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px 8px;
  padding: 9px 11px 9px 13px;
  background: var(--accent-soft);
  border-radius: 12px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.4;
}

.hint p {
  margin: 0;
  flex: 1;
}

.hint button.ghost {
  background: none;
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.hint button.x {
  background: none;
  border: 0;
  color: var(--text-3);
  font-size: 15px;
  padding: 2px 4px;
  line-height: 1;
}

/* ---------- composer ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 20px;
  padding: 10px 15px;
  font-size: 15px;
  line-height: 1.4;
  max-height: 132px;
  outline: none;
  transition: border-color 0.15s;
}

.composer textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.composer textarea::placeholder {
  color: var(--text-3);
}

.send {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 17px;
  display: grid;
  place-items: center;
  transition: opacity 0.15s, transform 0.12s;
}

.send:disabled {
  opacity: 0.32;
  cursor: default;
}

.send:not(:disabled):active {
  transform: scale(0.93);
}

/* ---------- full screen states ---------- */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  text-align: center;
  padding: 0 32px;
  gap: 10px;
}

.state h1 {
  font-size: 17px;
  font-weight: 500;
  margin: 0;
}

.state p {
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.65;
  margin: 0;
  max-width: 320px;
}

.state .pill {
  margin-top: 10px;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  text-decoration: none;
  display: inline-block;
}

.skeleton {
  animation: pulse 1.4s ease-in-out infinite;
  color: var(--text-3);
  font-size: 13px;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

.state .pill {
  border: 0;
  cursor: pointer;
}

.state .sub-link {
  background: none;
  border: 0;
  color: var(--text-3);
  font-size: 12.5px;
  padding: 6px;
  margin-top: 2px;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

/* ---------- 媒體 ---------- */

.send.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 20px;
  font-weight: 300;
  line-height: 1;
}

.send.rec {
  background: #dc2626;
}

.bubble.media {
  padding: 4px;
  overflow: hidden;
}

.bubble.media .meta {
  padding: 0 6px 2px;
}

.media-img {
  display: block;
  line-height: 0;
}

.media-img img {
  display: block;
  width: 250px;
  max-width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 14px;
}

.media-audio audio {
  width: 232px;
  max-width: 100%;
  height: 36px;
  display: block;
}

.media-file {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 4px;
  text-decoration: none;
  color: inherit;
  max-width: 230px;
}

.file-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex: none;
}

.file-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.file-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  font-size: 10.5px;
  opacity: 0.6;
  margin-top: 1px;
}

.row.out .media-file .file-icon {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.caption {
  padding: 5px 8px 0;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 錄音 ---------- */

.recbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, #dc2626 10%, transparent);
  font-size: 13px;
}

.recbar[hidden] {
  display: none;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #dc2626;
  animation: pulse 1.1s ease-in-out infinite;
  flex: none;
}

.rec-time {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.rec-hint {
  flex: 1;
  color: var(--text-3);
  font-size: 11.5px;
}

.rec-cancel {
  background: none;
  border: 0;
  color: var(--text-2);
  font-size: 12px;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  padding: 0;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(86px + env(safe-area-inset-bottom));
  background: rgba(18, 20, 24, 0.94);
  color: #fff;
  font-size: 12.5px;
  padding: 9px 14px;
  border-radius: 10px;
  z-index: 60;
  max-width: 82vw;
  text-align: center;
}

.toast[hidden] {
  display: none;
}

/* 原生 audio 控制項放在深色氣泡上很醜，語音一律用淺色底 */
.row.out .bubble.media.is-audio {
  background: var(--in-bubble);
  border: 1px solid var(--line);
  color: var(--text);
}

.row.out .bubble.media.is-audio .meta {
  color: var(--text-3);
  opacity: 1;
}
