:root {
  --bg: #f9fafb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.4 "Arial", sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app { padding: 12px; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.settings-anchor {
  position: relative;
  flex: 0 0 auto;
}

.brand { min-width: 0; }
.brand-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.title { font-weight: 700; font-size: 16px; }
.subtitle { color: var(--muted); font-size: 12px; }
.ver {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.section { margin-bottom: 12px; }
.scope-box {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.scope-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
  background: #fff;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.scope-chip.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #fff;
}
.scope-country {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  height: 28px;
  background: #fff;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
}

.mode-switch {
  display: flex;
  gap: 6px;
}
.mode-chip {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  background: #fff;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.mode-chip.active {
  background: #111827;
  border-color: #111827;
  color: #fff;
}

.chat-top {
  display: flex;
  gap: 6px;
  align-items: center;
}
.chat-select {
  margin-bottom: 0;
  height: 34px;
}
.chat-create {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.chat-create-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 4px;
}
.chat-messages {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  height: 320px;
  overflow: auto;
  padding: 8px;
}
.chat-msg {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
  position: relative;
}
.chat-msg:last-child { border-bottom: 0; }
.chat-msg-main { min-width: 0; flex: 1; }
.chat-msg-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: baseline;
  flex-wrap: wrap;
}
.chat-msg-name {
  font-weight: 800;
  color: #111827;
}
.chat-msg-text {
  margin-top: 2px;
  font-size: 13px;
  color: #0f172a;
  word-break: break-word;
}
.chat-reply-btn {
  position: absolute;
  right: 6px;
  top: 8px;
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--border);
  background: #fff;
  color: #111827;
  border-radius: 10px;
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.chat-msg:hover .chat-reply-btn,
.chat-msg.is-active .chat-reply-btn {
  opacity: 1;
  pointer-events: auto;
}
.chat-reply-preview {
  margin-top: 4px;
  padding: 6px 8px;
  border-left: 3px solid #c7d2fe;
  background: #eef2ff;
  border-radius: 8px;
  color: #1f2937;
  font-size: 12px;
  cursor: pointer;
}
.chat-reply-preview .who {
  font-weight: 800;
}
.chat-reply-bar {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-reply-bar .txt {
  font-size: 12px;
  color: #374151;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-reply-bar .x {
  border: 1px solid var(--border);
  background: #fff;
  width: 28px;
  height: 28px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 900;
  line-height: 1;
}
.chat-compose {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font: 14px/1.3 "Arial", sans-serif;
  resize: none;
  max-height: 120px;
}
.chat-status {
  margin-top: 6px;
  font-size: 12px;
  min-height: 16px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}
.version-notice {
  margin-bottom: 10px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #fde68a;
  background: #fffbeb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.version-notice.is-hard {
  border-color: #fecaca;
  background: #fef2f2;
}
.version-notice-text {
  font-size: 12px;
  color: #7c2d12;
}
.version-notice.is-hard .version-notice-text {
  color: #991b1b;
}

.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 6px;
}
.editor-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  margin-bottom: 6px;
}
.editor-box.editor-host-tiny {
  border: 0;
  background: transparent;
}
.editor-box.editor-host-tiny .tox-tinymce {
  border: 1px solid var(--border);
  border-radius: 8px;
}
.editor-box.editor-host-tiny .tox .tox-toolbar__primary {
  border-bottom: 1px solid var(--border);
}
.editor-box.editor-host-tiny .tox .tox-toolbar__primary,
.editor-box.editor-host-tiny .tox .tox-toolbar__overflow {
  scrollbar-width: thin;
  scrollbar-color: #9ca3af transparent;
}
.editor-box.editor-host-tiny .tox .tox-toolbar__primary::-webkit-scrollbar,
.editor-box.editor-host-tiny .tox .tox-toolbar__overflow::-webkit-scrollbar {
  height: 3px;
}
.editor-box.editor-host-tiny .tox .tox-toolbar__primary::-webkit-scrollbar-track,
.editor-box.editor-host-tiny .tox .tox-toolbar__overflow::-webkit-scrollbar-track {
  background: transparent;
}
.editor-box.editor-host-tiny .tox .tox-toolbar__primary::-webkit-scrollbar-thumb,
.editor-box.editor-host-tiny .tox .tox-toolbar__overflow::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 999px;
}
.editor-box-inline.editor-host-tiny .tox .tox-edit-area__iframe {
  min-height: 96px;
}
.editor-box .sf-editor-toolbar {
  border-bottom: 1px solid var(--border);
  padding: 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}
.editor-box .sf-editor-btn {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #444;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
.editor-box .sf-editor-btn:nth-child(4),
.editor-box .sf-editor-btn:nth-child(5) {
  font-size: 13px;
  font-weight: 600;
}
.editor-box .sf-editor-btn:nth-child(8) {
  font-size: 12px;
  font-weight: 700;
}
.editor-box .sf-editor-btn:nth-child(9) {
  width: 24px;
  font-size: 14px;
}
.editor-box .sf-editor-btn:hover,
.editor-box .sf-editor-btn:focus-visible {
  background: #eef2ff;
}
.editor-box .sf-editor-btn.is-active {
  color: #2563eb;
  background: #dbeafe;
}
.editor-box .sf-editor-content {
  min-height: 110px;
  font-size: 14px;
}
.editor-box-inline .sf-editor-content {
  min-height: 82px;
}
.editor-box .sf-editor-area {
  min-height: 96px;
  padding: 10px 12px;
  outline: none;
}
.editor-box-inline .sf-editor-area {
  min-height: 72px;
}
.editor-box .sf-editor-area p {
  margin: 0;
}
.editor-box .sf-editor-area p + p {
  margin-top: 6px;
}
.editor-box .sf-editor-area p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  color: #6b7280;
  pointer-events: none;
  float: left;
  height: 0;
}

.label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  display: block;
}

.settings {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  position: relative;
  z-index: 3;
  pointer-events: auto;
}

.position-menu {
  position: absolute;
  top: 44px;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 4;
}

#app.mode-chat {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#app.mode-chat { padding: 12px 12px 0 12px; }
.mode-chat .section {
  flex: 0 0 auto;
}
.mode-chat .chat {
  flex: 1 1 auto;
  display: flex !important;
  flex-direction: column;
  min-height: 0;
}
.mode-chat .chat-messages {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}
.mode-chat .chat-compose {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  background: var(--bg);
  margin: 0 -12px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  z-index: 2;
}
.mode-chat .chat-status {
  order: 2;
  margin-top: 8px;
  margin-bottom: 6px;
  min-height: 0;
}
.mode-chat .chat-reply-bar { order: 3; }
.mode-chat .chat-compose { order: 4; }
.mode-chat .chat-messages { order: 1; }

.pos-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 6px;
  font-size: 12px;
  cursor: pointer;
}

.pos-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}
.btn-ghost {
  background: #fff;
  color: #111827;
  border: 1px solid var(--border);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}

.topic-card { cursor: pointer; }

.collapsible-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}

.collapsible-title { font-weight: 700; }

.collapsible-body.hidden { display: none; }
.auth-notice {
  border: 1px dashed var(--border);
  background: #f8fafc;
  color: var(--muted);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  margin-bottom: 6px;
}
.auth-notice.compact {
  margin-top: 6px;
  margin-bottom: 0;
  padding: 8px 10px;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.topic-main {
  min-width: 0;
  flex: 1 1 auto;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-box.auth {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 4px 6px;
}

.user-name {
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
}
.rep-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  height: 18px;
  line-height: 18px;
  border-radius: 999px;
  border: 1px solid #86efac;
  background: #f0fdf4;
  color: #166534;
  font-size: 10px;
  font-weight: 600;
  vertical-align: baseline;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e5e7eb;
  flex: 0 0 28px;
  object-fit: cover;
}

.avatar-fallback {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #dbeafe;
  color: #1e3a8a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex: 0 0 28px;
}

.topic-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.topic-meta {
  color: var(--muted);
  font-size: 12px;
}
.topic-count {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #4b5563;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  margin-top: 2px;
  margin-left: auto;
  flex: 0 0 auto;
}
.topic-lead-label {
  margin-top: 8px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}
.topic-comment {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  padding: 8px;
  font-size: 14px;
}

.tags { margin-top: 6px; }
.tag {
  display: inline-block;
  padding: 2px 6px;
  margin-right: 4px;
  border-radius: 6px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 11px;
}

.comment {
  border-left: 2px solid #d1d5db;
  padding-left: 8px;
  margin-top: 8px;
}

.comment-text { white-space: normal; }

:root {
  --mf-media-max: 640px;
}

.mf-img {
  width: min(100%, var(--mf-media-max));
  aspect-ratio: 16 / 9;
  object-fit: contain;
  display: block;
  margin: 6px auto 0;
  border-radius: 8px;
  background: #0b1220;
  border: 1px solid #e5e7eb;
}

.mf-embed {
  position: relative;
  width: min(100%, var(--mf-media-max));
  aspect-ratio: 16 / 9;
  padding-top: 0;
  margin: 6px auto 0;
  border-radius: 8px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid #e5e7eb;
}

.mf-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

@supports not (aspect-ratio: 16 / 9) {
  .mf-embed {
    aspect-ratio: auto;
    padding-top: 56.25%;
  }
}

.mf-broken {
  width: min(100%, var(--mf-media-max));
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 6px auto 0;
  border-radius: 8px;
  background: #0b1220;
  border: 1px solid #e5e7eb;
  color: #e5e7eb;
  text-align: center;
  padding: 12px;
}
.mf-broken-title {
  font-weight: 800;
  font-size: 13px;
}
.mf-broken-link {
  display: inline-flex;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid rgba(229,231,235,0.25);
  background: rgba(255,255,255,0.06);
  color: #e5e7eb;
  text-decoration: none;
  font-size: 12px;
}
.mf-broken-link:hover { text-decoration: underline; }

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

.link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font-size: 12px;
}

.reply-box { margin-top: 6px; }

.hidden { display: none; }

.hide-when-topic { display: block; }
.topic-open .hide-when-topic { display: none; }

.toast {
  position: sticky;
  top: 0;
  background: #111827;
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  margin-bottom: 8px;
}

.toast.success { background: #047857; }
.toast.error { background: #b91c1c; }

.load-more {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
