:root {
  --bg: #ffffff;
  --line: #ededed;
  --text: #1a1a1a;
  --muted: #9a9a9a;
  --faint: #bdbdbd;
  --brand: #06c755;
  --bubble-in: #f2f2f2;
  --app-height: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", "Meiryo", "Noto Sans JP", sans-serif;
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  background: var(--bg);
}

@media (min-width: 620px) {
  .app {
    max-width: 460px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 14px;
  border-bottom: 0.5px solid var(--line);
  background: #fff;
}

.peer { display: flex; align-items: center; gap: 10px; min-width: 0; }

.peer-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: #e8eef7;
}

.peer-avatar img { width: 100%; height: 100%; display: block; }

.peer-meta { min-width: 0; }

.peer-name {
  font-size: 15px;
  font-weight: 500;
  color: #1a1a1a;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.peer-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1;
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
  display: inline-block;
}

.close-btn {
  background: none;
  border: none;
  padding: 6px;
  margin-right: -6px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.day-divider { text-align: center; margin: 4px 0 14px; }

.day-divider span {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  background: #f5f5f5;
  padding: 3px 10px;
  border-radius: 10px;
}

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

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

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

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

.bubble-wrap { max-width: 76%; display: flex; flex-direction: column; }
.row.out .bubble-wrap { align-items: flex-end; }
.row.in .bubble-wrap { align-items: flex-start; }

.bubble {
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.row.in .bubble {
  background: var(--bubble-in);
  color: var(--text);
  border-bottom-left-radius: 5px;
}

.meta {
  font-size: 10.5px;
  color: #b0b0b0;
  margin-top: 4px;
  padding: 0 3px;
  line-height: 1;
}

.typing {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  padding: 12px 14px;
  background: var(--bubble-in);
  border-radius: 18px;
  border-bottom-left-radius: 5px;
}

.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #b4b4b4;
  animation: bounce 1.1s infinite ease-in-out;
}

.typing i:nth-child(2) { animation-delay: 0.14s; }
.typing i:nth-child(3) { animation-delay: 0.28s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.composer {
  flex: 0 0 auto;
  border-top: 0.5px solid var(--line);
  background: #fff;
  padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
}

.composer-field { padding: 6px 2px 6px; }

#input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  max-height: 116px;
  overflow-y: auto;
  padding: 0;
  display: block;
}

#input::placeholder { color: #b3b3b3; }

.composer-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 2px;
}

.tools-left { display: flex; align-items: center; gap: 16px; }

.tool {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 4px 0;
  font-family: inherit;
  font-size: 12.5px;
  color: #8a8a8a;
  cursor: pointer;
}

.tool svg { width: 15px; height: 15px; color: #8a8a8a; flex: 0 0 auto; }

.send-btn {
  border: none;
  border-radius: 7px;
  padding: 7px 20px;
  font-family: inherit;
  font-size: 13.5px;
  background: #f2f2f2;
  color: var(--faint);
  cursor: default;
  transition: background 0.15s, color 0.15s;
}

.send-btn.active {
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}

.name-gate {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.name-gate-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.name-gate-card h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 8px;
  color: #16233a;
}

.name-gate-card p {
  font-size: 13px;
  color: #7b8ba3;
  margin: 0 0 20px;
  line-height: 1.6;
}

.name-gate-card input {
  width: 100%;
  height: 46px;
  border: 1px solid #dfe6ef;
  border-radius: 10px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 16px;
  outline: none;
  text-align: center;
  box-sizing: border-box;
}

.name-gate-card input:focus { border-color: #0d3b75; }

.name-gate-card button {
  width: 100%;
  height: 46px;
  margin-top: 12px;
  border: none;
  border-radius: 10px;
  background: #0d3b75;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.name-gate-card button:active { transform: translateY(1px); }

.name-gate-err {
  color: #d33;
  font-size: 12.5px;
  margin: 10px 0 0;
  min-height: 16px;
}

.blocked-screen {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.blocked-screen p {
  font-size: 14px;
  color: #6b7b91;
  text-align: center;
  line-height: 1.8;
  margin: 0;
}

.bubble.bubble-media {
  background: transparent !important;
  padding: 0 !important;
  box-shadow: none;
}

.att-img {
  display: block;
  max-width: 212px;
  max-height: 280px;
  border-radius: 12px;
  cursor: zoom-in;
}

.att-video {
  display: block;
  max-width: 238px;
  border-radius: 12px;
  background: #000;
}

.att-file {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  background: #f2f2f2;
  border-radius: 10px;
  color: #1a1a1a;
  text-decoration: none;
  font-size: 13px;
  max-width: 220px;
}

.att-file-ic { font-size: 15px; line-height: 1; }

.att-file-nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bubble-text { margin-top: 5px; word-break: break-word; }
.bubble-media .bubble-text { margin-top: 6px; }

.upload-tip {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 13.5px;
  z-index: 300;
}
