:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #e9ece8;
  color: #202522;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: #e9ece8;
}

button, textarea { font: inherit; }

.app-shell {
  width: min(100%, 860px);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  background: #f7f8f5;
  border-inline: 1px solid #d5dad5;
}

.view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid #dce1dc;
  background: #fbfcfa;
}

.view-tab {
  min-height: 42px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #66716b;
  cursor: pointer;
}

.view-tab.is-active { border-bottom-color: #315c50; color: #26483f; font-weight: 700; }

.archive-browser { padding: 18px; border-bottom: 1px solid #dce1dc; background: #f3f5f2; }
.archive-browser h2 { margin: 0 0 12px; font-size: 15px; }
.archive-dates { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.archive-date {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid #cbd2cc;
  border-radius: 6px;
  background: #fff;
  color: #34413b;
  cursor: pointer;
}
.archive-date.is-active { border-color: #315c50; background: #e3ece7; }

.topbar {
  min-height: 76px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #dce1dc;
  background: #fbfcfa;
}

.brand-block { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #26483f;
  color: #fff;
  font-family: Georgia, serif;
  font-size: 22px;
}

h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: 21px; font-weight: 600; }
.brand-block p { margin: 3px 0 0; color: #66716b; font-size: 12px; }

.icon-button, .send-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: transparent;
  color: #4d5752;
  font-size: 24px;
}

.conversation {
  min-height: 0;
  padding: 26px 18px 120px;
  overflow-y: auto;
}

.day-divider { display: flex; align-items: center; gap: 12px; color: #7b837f; font-size: 12px; }
.day-divider::before, .day-divider::after { content: ""; height: 1px; flex: 1; background: #dce1dc; }

.message-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 28px;
}

.haru-row .message { width: min(calc(100% - 62px), 560px); }
.user-row { justify-content: flex-end; }
.user-row .user-message { margin-left: 0; }
.message-row .message { margin-top: 0; }

.haru-avatar-button {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: zoom-in;
}

.haru-avatar {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid #cbd5cf;
  border-radius: 50%;
  background: #e3ece7;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(40, 72, 62, 0.14);
}

.haru-avatar-button:focus-visible {
  outline: 3px solid #699789;
  outline-offset: 3px;
}

.avatar-preview {
  width: min(86vw, 540px);
  padding: 42px 18px 18px;
  border: 1px solid #b8c9c0;
  border-radius: 8px;
  background: #fbfcfa;
  color: #315c50;
  box-shadow: 0 18px 60px rgba(24, 47, 40, 0.3);
}

.avatar-preview::backdrop { background: rgba(20, 31, 27, 0.72); }
.avatar-preview img {
  display: block;
  width: min(100%, 480px);
  height: auto;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 8px;
  object-fit: cover;
}
.avatar-preview p { margin: 12px 0 0; text-align: center; font-weight: 700; }
.avatar-preview-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e3ece7;
  color: #26483f;
  font-size: 24px;
  line-height: 1;
}

.message {
  width: min(78%, 560px);
  margin-top: 28px;
  padding: 14px 16px;
  border-radius: 8px;
}

.haru-message { background: #e3ece7; border-left: 3px solid #437565; }
.user-message { margin-left: auto; background: #f0ebe1; border-right: 3px solid #9a7a4d; }
.user-message .speaker { color: #745b39; }
.error-message { background: #f4e4e1; border-left-color: #a75c52; }
.speaker { margin-bottom: 6px; color: #315c50; font-size: 12px; font-weight: 700; }
.message p { margin: 0; line-height: 1.75; white-space: pre-wrap; }
.message-speech + .message-action,
.message-action + .message-speech { margin-top: 8px; }
.message-action {
  color: #60756d;
  font-size: 0.9em;
  font-style: italic;
  line-height: 1.6;
}
.message-action + .message-action { margin-top: 3px; }

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 10px;
  padding: 14px 18px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid #dce1dc;
  background: rgba(251, 252, 250, 0.96);
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 132px;
  resize: none;
  border: 1px solid #cbd2cc;
  border-radius: 8px;
  padding: 11px 13px;
  background: #fff;
  color: #202522;
  line-height: 1.45;
}

textarea:focus { outline: 2px solid #699789; outline-offset: 1px; }

.send-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #26483f;
  color: #fff;
  font-size: 23px;
}

button:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.5; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 640px) {
  .app-shell { border: 0; }
  .message { width: 90%; }
  .haru-row .message { width: calc(100% - 58px); }
  .message-row { gap: 8px; }
  .haru-avatar-button { flex-basis: 50px; width: 50px; height: 50px; }
  .avatar-preview { width: 92vw; }
}
