:root {
  --line-green: #797979;
  --bg: #ebebeb;
  --text: #111;
  --muted: #7f7f7f;
  --me-bg: #e3e3e3;
  --me-text: #0b2b00;
  --bubble: #fff;
  --border: #e0e0e0;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Zen Kaku Gothic New", system-ui, -apple-system, Segoe UI,
    Roboto, Helvetica, Arial, "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--line-green);
  color: #fff;
}

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

.back-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
}

.room-title {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-select {
  appearance: none;
  border: none;
  border-radius: 16px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.9);
  color: #0f172a;
  font-weight: 500;
}

.chat {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.group.me {
  align-items: flex-end;
}

.avatar {
  grid-row: 1 / span 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #dbdbdb;
  color: #0f172a;
  display: grid;
  place-items: center;
  font-weight: 700;
  user-select: none;
}

.group.me .avatar {
  grid-column: 2;
}

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

.bubble {
  position: relative;
  display: inline-block;          /* shrink to fit content */
  width: fit-content;             /* modern browsers: tight width */
  max-width: min(76%, 620px);     /* but never exceed container */
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--bubble);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.group.me .bubble {
  margin-left: auto;
  background: var(--me-bg);
  color: var(--me-text);
}

/* マスク済みメッセージを黒背景・白文字に統一 */
.bubble.masked,
.group .bubble.masked,
.group.me .bubble.masked {
  background: #111111;
  color: #ffffff;
}

/* Ensure bubbles don't stretch to full column width */
.group .bubble { align-self: flex-start; }
.group.me .bubble { align-self: flex-end; }

.timestamp {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--border);
}

.composer-input {
  width: 100%;
  min-height: 40px;
  max-height: 38vh;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}

.send-btn {
  padding: 0 16px;
  border: none;
  border-radius: 12px;
  background: #5b5b5b; /* green when enabled */
  color: #ffffff;
  font-weight: 700;
}

.send-btn:disabled,
.send-btn.disabled {
  background: #b1b1b1; /* gray */
  color: #fff;
  cursor: not-allowed;
}

.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 (min-width: 640px) {
  .app {
    max-width: 900px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    background: var(--bg);
  }
}
