:root {
  color-scheme: light dark;
  --background: #fbf8f2;
  --surface: #fffdf9;
  --raised: #f3ece3;
  --text: #2d2825;
  --muted: #6b6058;
  --accent: #b7472f;
  --accent-text: #fff;
  --accent-surface: #f6dccc;
  --border: #ded3c8;
  font:
    16px 'Noto Sans JP',
    system-ui,
    sans-serif;
  color: var(--text);
  background: var(--background);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #17120f;
    --surface: #241b17;
    --raised: #30231d;
    --text: #fff7f0;
    --muted: #d5c0b4;
    --accent: #ff8a70;
    --accent-text: #26120c;
    --accent-surface: #4e3026;
    --border: #5a4439;
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
}
button,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  min-height: 44px;
}
button:disabled {
  cursor: default;
  opacity: 0.55;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
h1,
h2,
p {
  margin: 0;
}
h1 {
  font-size: 2rem;
  font-weight: 900;
}
h2 {
  font-size: 1rem;
}
#session-panel {
  max-width: 420px;
  margin: auto;
  padding: calc(32px + env(safe-area-inset-top)) 16px;
}
#session-form,
#otp-field {
  display: grid;
  gap: 12px;
}
#session-form input,
#session-form button,
#sign-out {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
}
ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
a {
  color: var(--accent);
}

.talk {
  display: grid;
  height: var(--viewport-height, 100dvh);
  max-width: 1280px;
  margin: auto;
  padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
}
.list-pane {
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  overflow: auto;
}
.heading,
.thread-heading,
.composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.heading {
  justify-content: space-between;
}
.heading button,
.composer-row button,
#attachment button {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 0 12px;
  font-weight: 700;
}
.preview {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.75rem;
}
.list-pane section {
  margin-top: 16px;
}
#contacts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}
#contacts button {
  display: grid;
  justify-items: center;
  gap: 4px;
  font-size: 0.75rem;
}
#contacts button,
.conversation,
#back {
  border: 0;
  background: transparent;
}
#contacts button[aria-pressed='true'] {
  background: var(--accent-surface);
  border-radius: 12px;
}
#start-talk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
#start-talk button,
#group-title {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
}
.conversation {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 76px;
  padding: 12px 0;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.conversation[aria-current='true'] {
  background: var(--raised);
}
.conversation-text {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 4px;
}
.conversation-text strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation small,
.message-meta {
  font-size: 0.75rem;
  color: var(--muted);
}
.unread {
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 900;
  padding-inline-end: 8px;
}
.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex: none;
  background: var(--accent-surface);
}
.avatar span,
.avatar.group::before {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid currentColor;
  border-radius: 6px;
  transform: rotate(-7deg);
  background: var(--surface);
  font-size: 0.95rem;
  font-weight: 800;
}
.avatar.group::before {
  content: '';
  position: absolute;
  transform: translateX(3px) rotate(8deg);
}
.thread-pane {
  display: none;
  min-height: 0;
  min-width: 0;
}
.thread-open .list-pane {
  display: none;
}
.thread-open .thread-pane {
  display: block;
}
.thread-open .empty {
  display: none;
}
.empty {
  padding: 24px;
  color: var(--muted);
}
#thread {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.thread-heading {
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--border);
}
#back {
  min-width: 44px;
  font-size: 2rem;
  padding: 0;
}
#messages {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
  padding: 16px;
}
.message {
  display: grid;
  gap: 4px;
  justify-items: start;
}
.message.own {
  justify-items: end;
}
.bubble {
  padding: 10px 14px;
  max-width: min(85%, 38rem);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.own .bubble {
  background: var(--accent-surface);
}
#composer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
#message {
  flex: 1;
  min-width: 0;
  max-height: 7rem;
  resize: none;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
#send {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
#attachment {
  overflow-wrap: anywhere;
  margin-bottom: 8px;
}
#attachment button {
  margin-inline-start: 8px;
}
#status:not(:empty) {
  position: fixed;
  inset: calc(8px + env(safe-area-inset-top)) 16px auto;
  max-width: 420px;
  margin: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  pointer-events: none;
}

@media (min-width: 800px) {
  .talk {
    grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  }
  .talk .list-pane,
  .talk .thread-pane {
    display: block;
  }
  .thread-pane {
    border-inline-start: 1px solid var(--border);
  }
}
