:root {
  --bg: #000;
  --fg: #fff;
  --border: #fff;
  --border-dim: #444;
  --dim: #999;
  --danger: #e06c5c;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Courier New", ui-monospace, SFMono-Regular, monospace;
  font-size: 13px;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.logo { letter-spacing: 2px; font-size: 14px; }
.header-right { display: flex; gap: 10px; align-items: center; }
.icon-btn {
  background: none; border: none; color: var(--fg);
  font-size: 15px; line-height: 1; padding: 2px 3px; cursor: pointer;
}
.icon-btn:hover { opacity: 0.75; }
.icon-btn.muted { opacity: 0.4; }
#who { color: var(--dim); font-size: 11px; }
.badge { color: var(--dim); font-size: 11px; border: 1px solid var(--border-dim); padding: 2px 6px; }

/* --- tabs --- */
#tabs { display: flex; gap: 14px; }
#tabs a { text-decoration: none; color: var(--dim); font-size: 12px; padding-bottom: 2px; }
#tabs a.active { color: var(--fg); border-bottom: 1px solid var(--fg); }

.tab-panel { flex: 1; display: flex; min-height: 0; }
.tab-panel[hidden] { display: none; }

/* --- login --- */
.login-inner {
  padding: 40px 20px 32px; width: 100%; max-width: 520px; margin: 0 auto;
}
.login-mark {
  font-size: 20px; letter-spacing: 5px; margin-bottom: 18px;
  border-bottom: 1px solid var(--border); padding-bottom: 14px;
}
.login-tagline { line-height: 1.9; margin: 0 0 22px; }

.login-points { list-style: none; margin: 0 0 26px; padding: 0; }
.login-points li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid #1c1c1c;
  color: var(--dim); line-height: 1.7; font-size: 12px;
}
.login-points .n { color: var(--fg); flex-shrink: 0; }

.login-label {
  display: block; font-size: 10px; letter-spacing: 2px;
  color: var(--dim); margin-bottom: 6px; text-transform: uppercase;
}
#login-form { display: block; margin-top: 0; }
.login-row { display: flex; gap: 8px; flex-wrap: wrap; }
#login-form input {
  flex: 1; min-width: 200px; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 9px 10px; font-family: inherit; font-size: 13px;
}
#login-form input:focus { outline: none; box-shadow: inset 0 0 0 1px var(--fg); }
#login-form button { padding: 9px 16px; }
.login-hint { margin: 8px 0 0; font-size: 11px; color: var(--dim); line-height: 1.7; }

.login-signup {
  margin-top: 20px; padding: 10px 12px;
  border: 1px solid var(--border-dim); font-size: 12px; color: var(--dim);
}
.login-signup a { color: var(--fg); }

.login-foot {
  margin-top: 26px; padding-top: 14px; border-top: 1px solid #1c1c1c;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 10px; color: #666; line-height: 1.7;
}

/* --- shared buttons --- */
button {
  background: var(--fg); color: var(--bg); border: none;
  padding: 6px 14px; font-family: inherit; font-size: 12px; cursor: pointer;
}
button:disabled { background: #444; color: #888; cursor: not-allowed; }
button.ghost { background: var(--bg); color: var(--fg); border: 1px solid var(--border); }

.panel-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-head button { padding: 4px 10px; font-size: 11px; }

/* --- chat --- */
.rooms-panel {
  flex: 0 0 220px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#room-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#room-list li {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-dim);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#room-list li:hover { background: #111; }
#room-list li.active { background: #1a1a1a; }
#room-list .online { color: var(--dim); font-size: 11px; }
#room-list .online .dot { color: #6ab04c; }

#messages {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 240px;
}
#messages .msg { line-height: 1.5; }
#messages .msg .nick { font-weight: 700; margin-right: 6px; }
#messages .msg.me .nick { text-decoration: underline; }
#messages .system { color: var(--dim); font-style: italic; font-size: 12px; }
#messages img.chat-image {
  max-width: 200px; max-height: 200px; border: 1px solid var(--border);
  display: block; margin-top: 4px; cursor: pointer;
}

#message-form {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--border); align-items: center;
}
#message-input {
  flex: 1; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 7px 8px; font-family: inherit; font-size: 13px;
}

.image-preview { padding: 8px 12px; }
.image-preview img { max-width: 90px; max-height: 90px; border: 1px solid var(--border); display: block; }
.image-preview button {
  margin-top: 4px; background: transparent; color: var(--fg);
  border: 1px solid var(--border-dim); font-size: 11px; padding: 2px 6px;
}

/* --- board --- */
.board-inner { width: 100%; padding: 0 0 20px; }
#new-post-form {
  padding: 12px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
#new-post-form input, #new-post-form textarea {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 7px 8px; font-family: inherit; font-size: 13px; width: 100%; resize: vertical;
}
.row { display: flex; gap: 8px; align-items: center; }

#post-list { width: 100%; border-collapse: collapse; }
#post-list td { padding: 10px 12px; border-bottom: 1px solid var(--border-dim); cursor: pointer; }
#post-list tr:hover td { background: #111; }
#post-list td.meta { text-align: right; color: var(--dim); white-space: nowrap; font-size: 11px; }
#post-list img.thumb {
  width: 28px; height: 28px; object-fit: cover;
  border: 1px solid var(--border); margin-right: 6px; vertical-align: middle;
}

#post-detail { padding: 12px; border-top: 1px solid var(--border); }
#post-detail .post-image { max-width: 100%; max-height: 400px; border: 1px solid var(--border); margin: 8px 0; }
#post-detail .comment { border-top: 1px solid #333; padding: 6px 0; }
#post-detail #comment-form { display: flex; gap: 8px; margin-top: 10px; }
#post-detail #comment-input {
  flex: 1; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 6px 8px; font-family: inherit;
}

/* --- mastodon --- */
#mastodon-view { flex-direction: column; }
#toot-composer {
  border-bottom: 1px solid var(--border);
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
#toot-composer input, #toot-composer textarea {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 8px; font-family: inherit; font-size: 13px;
}
#toot-composer textarea { resize: vertical; min-height: 60px; }
#toot-composer .toot-row { display: flex; justify-content: space-between; align-items: center; }
#toot-composer .count { color: var(--dim); font-size: 11px; }
#toot-composer .count.over { color: var(--danger); }

#timeline { overflow-y: auto; flex: 1; }
.toot { border-bottom: 1px solid var(--border-dim); padding: 12px; display: flex; gap: 10px; }
.toot .avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  border: 1px solid var(--border);
  object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  filter: grayscale(100%);
}
.toot .toot-body { flex: 1; min-width: 0; }
.toot .toot-head { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.toot .display-name { font-weight: 700; }
.toot .handle { color: var(--dim); font-size: 11px; }
.toot .time { color: var(--dim); font-size: 11px; margin-left: auto; }
.toot .content { margin-top: 4px; line-height: 1.6; word-wrap: break-word; }
.toot .content a { color: var(--fg); text-decoration: underline; }
.toot .content a:hover { background: var(--fg); color: var(--bg); text-decoration: none; }
.toot .boosted-label { color: var(--dim); font-size: 11px; margin-bottom: 4px; }
.toot .spoiler {
  border: 1px solid var(--border-dim); padding: 6px 8px; margin-top: 4px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.toot .spoiler button { padding: 2px 8px; font-size: 11px; }
.toot .media { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.toot .media img {
  max-width: 160px; max-height: 160px; border: 1px solid var(--border);
  cursor: pointer; filter: grayscale(100%);
}
.toot .media img:hover { filter: none; }
.toot .actions { display: flex; gap: 18px; margin-top: 8px; }
.toot .actions button {
  background: none; border: none; color: var(--dim); font-family: inherit;
  font-size: 11px; cursor: pointer; padding: 0; display: flex; gap: 4px; align-items: center;
}
.toot .actions button:hover { color: var(--fg); }
.toot .actions button.active { color: var(--fg); font-weight: 700; }

.empty, .error {
  padding: 20px 16px; color: var(--dim); text-align: center; line-height: 1.6;
}
.error { color: var(--danger); }

::placeholder { color: #666; }
a { color: var(--fg); }

@media (max-width: 640px) {
  #chat-view { flex-direction: column; }
  .rooms-panel { flex: none; border-right: none; border-bottom: 1px solid var(--border); max-height: 180px; }
}

/* ===================================================================
   이번 패치에서 추가된 UI
   (DM, 알림, 스레드, 모달, 신고·차단 도구, 토스트)
   =================================================================== */

/* --- 탭 뱃지 --- */
.tab-badge {
  display: inline-block;
  margin-left: 4px;
  min-width: 15px;
  padding: 0 3px;
  background: var(--fg);
  color: var(--bg);
  font-size: 10px;
  line-height: 14px;
  text-align: center;
}

.head-tools { display: flex; gap: 8px; align-items: center; }
button.tiny { padding: 2px 8px; font-size: 11px; }

/* 메시지/글에 붙는 작은 텍스트 버튼 (report, del, block ...) */
.link-btn {
  background: none;
  border: none;
  color: #666;
  font-family: inherit;
  font-size: 10px;
  padding: 0 4px;
  cursor: pointer;
}
.link-btn:hover { color: var(--fg); text-decoration: underline; background: none; }
.msg-tools {
  margin-left: 8px;
  opacity: 0;
  transition: opacity .12s;
  white-space: nowrap;
}
.msg:hover .msg-tools,
.comment:hover .msg-tools,
.post-head:hover .msg-tools,
.list-row .msg-tools { opacity: 1; }
#messages .msg .deleted { color: var(--dim); font-style: italic; }

.empty-li { padding: 16px 12px; color: var(--dim); font-size: 12px; line-height: 1.6; }

/* --- DM --- */
#dm-view { display: flex; }
#dm-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#dm-list li {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-dim);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
#dm-list li:hover { background: #111; }
#dm-list li.active { background: #1a1a1a; }
.dm-item { min-width: 0; }
.dm-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-preview {
  color: var(--dim); font-size: 11px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;
}
.dm-meta { color: var(--dim); font-size: 10px; text-align: right; white-space: nowrap; }
.dm-meta .unread {
  display: block; margin-top: 4px;
  background: var(--fg); color: var(--bg); padding: 0 4px; font-size: 10px;
}
#dm-messages {
  flex: 1; padding: 12px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px; min-height: 240px;
}
#dm-messages .msg { line-height: 1.5; }
#dm-messages .msg .nick { font-weight: 700; margin-right: 6px; }
#dm-messages .msg.me .nick { text-decoration: underline; }
#dm-messages img.chat-image {
  max-width: 200px; max-height: 200px; border: 1px solid var(--border);
  display: block; margin-top: 4px; cursor: pointer;
}
#dm-form {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--border); align-items: center;
}
#dm-input {
  flex: 1; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 7px 8px; font-family: inherit; font-size: 13px;
}
#dm-input:disabled { border-color: var(--border-dim); color: #666; }

/* --- 타임라인 전환 바 --- */
.timeline-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
}
.tl-switch { display: flex; gap: 12px; }
.tl-switch a { color: var(--dim); font-size: 11px; text-decoration: none; padding-bottom: 2px; }
.tl-switch a.active { color: var(--fg); border-bottom: 1px solid var(--fg); }
.live { font-size: 10px; color: #555; }
.live.on { color: #6ab04c; }

.new-toot-bar {
  padding: 7px 12px; text-align: center; font-size: 11px;
  border-bottom: 1px solid var(--border-dim); cursor: pointer; background: #111;
}
.new-toot-bar:hover { background: #1a1a1a; }
.more-btn { display: block; margin: 12px auto; }

#toot-composer select, #report-modal select {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border-dim);
  font-family: inherit; font-size: 11px; padding: 4px 6px;
}
.reply-context {
  display: flex; justify-content: space-between; align-items: center;
  border: 1px solid var(--border-dim); padding: 4px 8px; font-size: 11px; color: var(--dim);
}
.toot .time.clickable { cursor: pointer; }
.toot .time.clickable:hover { color: var(--fg); text-decoration: underline; }
.toot.focus { background: #0d0d0d; border-left: 2px solid var(--fg); }
.thread-label {
  padding: 8px 12px; color: var(--dim); font-size: 11px;
  border-bottom: 1px solid var(--border-dim);
}
#thread-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#thread-body { overflow-y: auto; }

/* --- 알림 --- */
.notification { padding: 10px 12px; border-bottom: 1px solid var(--border-dim); }
.notification-head {
  display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; font-size: 12px;
}
.notification-head .kind {
  border: 1px solid var(--border-dim); padding: 1px 5px; font-size: 10px; color: var(--dim);
}
.notification-head .display-name { font-weight: 700; }
.notification-head .handle { color: var(--dim); font-size: 11px; }
.notification-head .time { color: var(--dim); font-size: 11px; margin-left: auto; }
.notification-body {
  margin-top: 6px; color: var(--dim); line-height: 1.6; cursor: pointer;
  font-size: 12px; max-height: 5.5em; overflow: hidden;
}
.notification-body:hover { color: var(--fg); }
.notification-body a { color: inherit; }

/* --- 설정 / 관리 --- */
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 12px; border-bottom: 1px solid var(--border-dim); font-size: 12px;
}
.list-row .dim { color: var(--dim); font-size: 11px; margin-top: 2px; }
.list-row .note {
  margin-top: 4px; color: var(--dim); font-size: 11px;
  border-left: 2px solid var(--border-dim); padding-left: 6px; white-space: pre-wrap;
}
.report-row { align-items: flex-start; }
.about-box { padding: 12px; color: var(--dim); font-size: 11px; line-height: 1.8; }

/* --- 모달 --- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .75);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal[hidden] { display: none; }
.modal-inner {
  background: var(--bg); border: 1px solid var(--border);
  width: 100%; max-width: 420px; max-height: 80vh; overflow-y: auto;
  display: flex; flex-direction: column;
}
.modal-inner input, .modal-inner textarea, .modal-inner select {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border-dim);
  font-family: inherit; font-size: 13px; padding: 7px 8px; margin: 10px 12px 0;
}
.modal-inner .row { padding: 12px; justify-content: flex-end; }
.modal-desc { padding: 10px 12px 0; margin: 0; color: var(--dim); font-size: 11px; }
#user-results { list-style: none; margin: 10px 0 0; padding: 0; }
#user-results li {
  padding: 8px 12px; border-top: 1px solid var(--border-dim); cursor: pointer;
}
#user-results li:hover { background: #111; }

/* --- 토스트 --- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 8px 14px;
  font-size: 12px; z-index: 100; max-width: 90vw; text-align: center;
}
.toast.error { background: var(--danger); color: #fff; }
.toast[hidden] { display: none; }

@media (max-width: 640px) {
  #dm-view { flex-direction: column; }
  #dm-view .rooms-panel { flex: none; border-right: none; border-bottom: 1px solid var(--border); max-height: 180px; }
  #tabs { gap: 10px; font-size: 11px; }
  .msg-tools { opacity: 1; }
}

/* --- 연결 상태 배너 --- */
.conn-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 7px 12px; font-size: 11px; line-height: 1.5;
  border-bottom: 1px solid var(--border);
}
.conn-banner.warn  { background: #2a1d0e; color: #e0a45c; }
.conn-banner.fatal { background: #2a0e0e; color: #ff9a8a; }
.conn-banner.ok    { background: #0e2a12; color: #8ad38f; }
.conn-actions { display: flex; gap: 6px; flex-shrink: 0; }
.conn-banner button { background: transparent; color: inherit; border: 1px solid currentColor; }
.conn-banner button:hover { background: currentColor; }

.conn-detail {
  margin: 0; padding: 10px 12px; font-family: inherit; font-size: 10px;
  line-height: 1.6; color: var(--dim); background: #0a0a0a;
  border-bottom: 1px solid var(--border-dim);
  white-space: pre-wrap; word-break: break-all; max-height: 40vh; overflow-y: auto;
}

/* hidden 속성이 항상 이기도록 못 박습니다.
   위에서 .more-btn{display:block}, .tab-badge{display:inline-block} 처럼
   display를 직접 지정한 요소들은 이 규칙이 없으면 hidden이 걸려도 보입니다. */
[hidden] { display: none !important; }
