:root {
  --bg: #0b1020;
  --panel: #141a2e;
  --panel-2: #1c2440;
  --line: #2a3354;
  --text: #e8ecf6;
  --muted: #8a93b2;
  --accent: #5b8cff;
  --accent-2: #3a6bff;
  --mine: #2f6bff;
  --bubble: #222b48;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { cursor: pointer; font: inherit; }

/* --- 認証 --- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { margin: 0; text-align: center; font-size: 34px; letter-spacing: 2px; font-weight: 700; }
.tagline { margin: -8px 0 6px; text-align: center; color: var(--muted); font-size: 13px; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.card input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 15px; outline: none;
}
.card input:focus { border-color: var(--accent); }
#signupFields { display: flex; flex-direction: column; gap: 14px; }
.primary {
  background: var(--accent-2); color: #fff; border: 0; border-radius: 10px;
  padding: 12px; font-size: 15px; font-weight: 600;
}
.primary:hover { background: var(--accent); }
.link { background: none; border: 0; color: var(--accent); font-size: 13px; padding: 4px; }
.error { background: #3a1722; border: 1px solid #6b2435; color: #ffb3c0;
  border-radius: 10px; padding: 9px 12px; font-size: 13px; }

/* --- アプリ --- */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; width: 34px; height: 34px; font-size: 16px; flex: 0 0 auto; }
.icon-btn:hover { border-color: var(--accent); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; color: var(--muted); padding: 12px 0;
  font-size: 14px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.group-btn { margin: 10px 14px 0; background: var(--panel-2); border: 1px dashed var(--line);
  color: var(--accent); border-radius: 8px; padding: 9px; font-size: 13px; }
.group-btn:hover { border-color: var(--accent); }
.group-form { margin: 10px 14px; padding: 12px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; gap: 10px; }
.group-form input { background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 10px; outline: none; }
.group-hint { font-size: 12px; color: var(--muted); }
.group-members { display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow-y: auto; }
.group-members label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.group-actions { display: flex; justify-content: flex-end; gap: 10px; align-items: center; }
.friend { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); }
.friend-info { display: flex; flex-direction: column; min-width: 0; }
.friend-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-handle { color: var(--muted); font-size: 12px; }
.friend-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.mini-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 5px 10px; font-size: 12px; }
.mini-btn:hover { border-color: var(--accent); }
.mini-btn.danger:hover { border-color: #6b2435; color: #ffb3c0; }
.new-chat { display: flex; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.new-chat input { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 9px 10px; outline: none; }
.new-chat input:focus { border-color: var(--accent); }
.conv-list { flex: 1; overflow-y: auto; }
.conv {
  display: flex; flex-direction: column; gap: 3px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--panel-2); border-left: 3px solid var(--accent); }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: 11px; flex: 0 0 auto; }
.conv-preview { color: var(--muted); font-size: 13px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent-2); color: #fff; border-radius: 999px; font-size: 11px;
  padding: 1px 7px; align-self: flex-start; }
.empty { color: var(--muted); text-align: center; padding: 30px 16px; font-size: 13px; }

.chat { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg-row { display: flex; align-items: center; gap: 6px; max-width: 100%; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }
.msg-tools { display: flex; gap: 2px; opacity: .45; transition: opacity .15s; flex: 0 0 auto; }
.msg-row:hover .msg-tools { opacity: 1; }
.tool { background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; width: 28px; height: 28px; font-size: 13px; line-height: 1; }
.tool:hover { border-color: var(--accent); }
.msg { position: relative; max-width: 72%; padding: 9px 13px; border-radius: 14px; font-size: 14px;
  line-height: 1.45; word-wrap: break-word; white-space: pre-wrap; }
.reaction-badge { position: absolute; bottom: -11px; right: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 11px; padding: 0 5px; font-size: 12px; }
.reaction-palette { position: fixed; z-index: 50; display: flex; gap: 4px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px; box-shadow: 0 6px 20px rgba(0,0,0,.45); }
.reaction-palette button { background: none; border: 0; font-size: 20px; line-height: 1; cursor: pointer; }
.reaction-palette button:hover { transform: scale(1.25); }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 10px;
  border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 8px; }
.reply-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.reply-to { font-size: 11px; color: var(--accent); }
.reply-text { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg .quote { border-left: 2px solid var(--accent); padding-left: 8px; margin-bottom: 5px;
  color: var(--muted); font-size: 12px; }
.msg.theirs { background: var(--bubble); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.mine { background: var(--mine); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .time { font-size: 10px; opacity: .7; margin-top: 4px; text-align: right; }
.composer { display: flex; flex-direction: column; padding: 14px; border-top: 1px solid var(--line); }
.composer-row { display: flex; gap: 10px; }
.composer input { flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 15px; outline: none; }
.composer input:focus { border-color: var(--accent); }

/* モバイル */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app.show-chat .sidebar { display: none; }
  .app:not(.show-chat) .chat { display: none; }
}
