:root {
  --bg-deep: #11151a;
  --bg-panel: #161b22;
  --bg-raised: #1d2329;
  --bg-hover: #232a32;
  --line: #2a3138;
  --line-soft: #20262d;
  --text: #e6e9ec;
  --text-muted: #8b95a1;
  --text-faint: #5a6470;
  --accent: #ffb020;
  --accent-dim: #8a611c;
  --signal: #3ddc97;
  --danger: #ff6b6b;
  --radius: 5px;
  --mono: 'JetBrains Mono', 'SF Mono', Consolas, 'Courier New', monospace;
  --sans: -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--sans);
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
.hidden { display: none !important; }

/* ===================== 認証画面 ===================== */

.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,176,32,0.06), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(61,220,151,0.05), transparent 40%),
    var(--bg-deep);
}

.auth-card {
  width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
}

.brand-mark {
  display: inline-block;
  color: var(--accent);
  font-size: 22px;
  filter: drop-shadow(0 0 6px rgba(255,176,32,0.5));
}
.brand-mark.small { font-size: 16px; }

.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin: 8px 0 4px;
}
.brand-accent { color: var(--accent); }
.brand-sub {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-faint);
  margin: 0;
}

.auth-tabs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  background: var(--bg-raised);
  color: var(--text-muted);
  border: none;
  padding: 9px 0;
  font-size: 13px;
  border-right: 1px solid var(--line);
}
.auth-tab:last-child { border-right: none; }
.auth-tab.active { background: var(--accent); color: #1a1306; font-weight: 600; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.auth-form .hint { color: var(--text-faint); font-size: 11px; }

.auth-form input {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255,176,32,0.3);
}

.auth-error {
  color: var(--danger);
  font-size: 12px;
  margin: -4px 0 0;
  min-height: 14px;
}

.btn-primary {
  background: var(--accent);
  color: #1a1306;
  border: none;
  border-radius: var(--radius);
  padding: 10px 0;
  font-weight: 600;
  font-size: 14px;
  margin-top: 4px;
  transition: filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
}

/* ===================== チャット画面 ===================== */

.chat-screen {
  height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr 180px;
}

/* --- サイドバー --- */
.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.sidebar-title { font-family: var(--mono); font-weight: 600; font-size: 14px; }

.channel-list-wrap { flex: 1; overflow-y: auto; padding: 12px 0; }

.channel-list-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-faint);
  padding: 0 16px 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 14px;
  padding: 0 4px;
  border-radius: 3px;
}
.icon-btn:hover { color: var(--accent); background: var(--bg-hover); }

.channel-list { list-style: none; margin: 0; padding: 0; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  color: var(--text-muted);
  font-size: 13.5px;
  cursor: pointer;
  border-left: 2px solid transparent;
  position: relative;
}
.channel-item::before {
  content: '';
  width: 6px;
  height: 1px;
  background: var(--line);
}
.channel-item:hover { background: var(--bg-hover); color: var(--text); }
.channel-item.active {
  background: var(--bg-raised);
  color: var(--accent);
  border-left-color: var(--accent);
}
.channel-item.active::before { background: var(--accent); }

.channel-item .del-channel {
  margin-left: auto;
  opacity: 0;
  font-size: 11px;
  color: var(--text-faint);
}
.channel-item:hover .del-channel { opacity: 1; }
.channel-item .del-channel:hover { color: var(--danger); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.self-color-dot {
  width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 5px currentColor;
}
.self-username {
  font-family: var(--mono);
  font-size: 12.5px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- メインパネル --- */
.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.channel-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, var(--bg-panel), var(--bg-deep) 130%);
  position: relative;
}
.channel-header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 20px; right: 20px;
  height: 1px;
  background: linear-gradient(to right, var(--accent), transparent 60%);
  opacity: 0.5;
}
.channel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.hash { color: var(--text-faint); margin-right: 2px; }
.channel-topic {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-faint);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-row {
  display: flex;
  gap: 12px;
  padding: 6px 8px;
  border-radius: var(--radius);
}
.message-row:hover { background: var(--bg-panel); }

.message-avatar {
  width: 34px; height: 34px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: #11151a;
  margin-top: 2px;
}

.message-body { min-width: 0; flex: 1; }
.message-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.message-username { font-weight: 600; font-size: 13.5px; }
.message-time {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
}
.message-content {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-row.grouped { padding-top: 0; }
.message-row.grouped .message-avatar { visibility: hidden; height: 4px; }
.message-row.grouped .message-meta { display: none; }

.divider-day {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 8px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
}
.divider-day::before, .divider-day::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}

.typing-indicator {
  height: 18px;
  padding: 0 20px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--mono);
}

.message-form {
  display: flex;
  gap: 10px;
  padding: 14px 20px 18px;
}
.message-form input {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.message-form input:focus { border-color: var(--accent-dim); }

.btn-send {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 0 18px;
  font-size: 13px;
  font-weight: 600;
}
.btn-send:hover { background: var(--accent); color: #1a1306; }

/* --- 在籍パネル --- */
.presence-panel {
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
  padding: 16px 12px;
}
.presence-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-faint);
  margin-bottom: 10px;
}
#online-count { color: var(--signal); }
.presence-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.presence-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-muted); }
.presence-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 5px var(--signal);
  flex-shrink: 0;
}

/* ===================== モーダル ===================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-card {
  width: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.modal-card h3 { margin: 0 0 16px; font-size: 15px; }
#channel-form { display: flex; flex-direction: column; gap: 12px; }
#channel-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--text-muted);
}
#channel-form input {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--text);
  font-size: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ===================== スクロールバー ===================== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ===================== レスポンシブ ===================== */
@media (max-width: 800px) {
  .chat-screen { grid-template-columns: 76px 1fr; }
  .presence-panel { display: none; }
  .sidebar-title, .self-username, .channel-list-label span:first-child { display: none; }
  .channel-item { justify-content: center; padding: 10px 6px; }
  .channel-item::before { display: none; }
}

/* キーボードフォーカスの可視化 */
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
