:root,
html[data-skin="western"],
html.skin-western {
  /* Western / iMessage–WhatsApp-ish (default EN) */
  --bg: #0b1220;
  --bg-elev: #121a2b;
  --bg-bubble: #1a2438;
  --bg-bubble-self: #0a84ff;
  --bg-quote: #0f172a;
  --border: #243049;
  --text: #e8eefc;
  --muted: #8b9bb8;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.18);
  --danger: #ff6b7a;
  --radius: 18px;
  --bubble-tail: 4px 18px 18px 18px;
  --font: "Segoe UI", system-ui, -apple-system, "Noto Sans SC", "Noto Sans JP", sans-serif;
  --scrollbar-size: 8px;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(139, 155, 184, 0.35);
  --scrollbar-thumb-hover: rgba(139, 155, 184, 0.55);
  --scrollbar-chat-thumb: rgba(91, 140, 255, 0.4);
  --scrollbar-chat-thumb-hover: rgba(91, 140, 255, 0.65);
  --media-max-height: min(70vh, 520px);
  --media-fit: contain;
  --chat-pad: 16px 14px 24px;
  --topbar-accent: #0a84ff;
  --topbar-bg: linear-gradient(180deg, #1a2744 0%, #121a2b 100%);
  --chat-wallpaper:
    radial-gradient(ellipse 800px 400px at 20% 0%, rgba(10, 132, 255, 0.12), transparent 60%),
    radial-gradient(ellipse 600px 500px at 90% 80%, rgba(91, 140, 255, 0.08), transparent 55%),
    #0b1220;
  --sidebar-bg: rgba(18, 26, 43, 0.75);
  --app-bg: rgba(11, 18, 32, 0.92);
  --skin-chip-bg: rgba(10, 132, 255, 0.2);
  --skin-chip-fg: #9ec5ff;
  --bubble-border: 1px solid var(--border);
  --accent-pill: #0a84ff;
}

html[data-skin="wechat"],
html.skin-wechat {
  /* WeChat-like (ZH) — green chrome, tighter radius, distinct wallpaper */
  --bg: #0e1a14;
  --bg-elev: #1a2e24;
  --bg-bubble: #23352c;
  --bg-bubble-self: #07c160;
  --bg-quote: #16241c;
  --border: #2d4638;
  --text: #e9edef;
  --muted: #8aa396;
  --accent: #07c160;
  --accent-soft: rgba(7, 193, 96, 0.22);
  --danger: #fa5151;
  --radius: 6px;
  --bubble-tail: 2px 8px 8px 8px;
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --scrollbar-size: 7px;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(7, 193, 96, 0.35);
  --scrollbar-thumb-hover: rgba(7, 193, 96, 0.55);
  --scrollbar-chat-thumb: rgba(7, 193, 96, 0.45);
  --scrollbar-chat-thumb-hover: rgba(7, 193, 96, 0.7);
  --media-max-height: min(70vh, 520px);
  --media-fit: contain;
  --topbar-accent: #07c160;
  --topbar-bg: linear-gradient(180deg, #1f3d2e 0%, #1a2e24 100%);
  --chat-wallpaper:
    repeating-linear-gradient(
      -12deg,
      transparent,
      transparent 11px,
      rgba(7, 193, 96, 0.035) 11px,
      rgba(7, 193, 96, 0.035) 12px
    ),
    radial-gradient(ellipse 700px 360px at 10% 0%, rgba(7, 193, 96, 0.14), transparent 55%),
    #111b16;
  --sidebar-bg: rgba(26, 46, 36, 0.85);
  --app-bg: rgba(14, 26, 20, 0.94);
  --skin-chip-bg: rgba(7, 193, 96, 0.25);
  --skin-chip-fg: #6dffb0;
  --bubble-border: 1px solid rgba(7, 193, 96, 0.18);
  --accent-pill: #07c160;
}

html[data-skin="line"],
html.skin-line {
  /* LINE-like (JA) — brighter green, rounder bubbles, soft wallpaper */
  --bg: #101418;
  --bg-elev: #1c2620;
  --bg-bubble: #2a3830;
  --bg-bubble-self: #06c755;
  --bg-quote: #151e1a;
  --border: #334038;
  --text: #f5f7f8;
  --muted: #8b9aa3;
  --accent: #06c755;
  --accent-soft: rgba(6, 199, 85, 0.22);
  --danger: #ff5a5a;
  --radius: 18px;
  --bubble-tail: 18px 18px 4px 18px;
  --font: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  --scrollbar-size: 8px;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(6, 199, 85, 0.35);
  --scrollbar-thumb-hover: rgba(6, 199, 85, 0.55);
  --scrollbar-chat-thumb: rgba(6, 199, 85, 0.45);
  --scrollbar-chat-thumb-hover: rgba(6, 199, 85, 0.7);
  --media-max-height: min(70vh, 520px);
  --media-fit: contain;
  --topbar-accent: #06c755;
  --topbar-bg: linear-gradient(180deg, #1e3328 0%, #1c2620 100%);
  --chat-wallpaper:
    radial-gradient(circle at 15% 20%, rgba(6, 199, 85, 0.1) 0 2px, transparent 3px),
    radial-gradient(circle at 75% 60%, rgba(6, 199, 85, 0.08) 0 1.5px, transparent 2.5px),
    radial-gradient(ellipse 600px 400px at 85% 10%, rgba(6, 199, 85, 0.12), transparent 50%),
    #121816;
  --sidebar-bg: rgba(28, 38, 32, 0.88);
  --app-bg: rgba(16, 20, 24, 0.94);
  --skin-chip-bg: rgba(6, 199, 85, 0.25);
  --skin-chip-fg: #7dffb0;
  --bubble-border: 1px solid rgba(6, 199, 85, 0.2);
  --accent-pill: #06c755;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--chat-wallpaper);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.2s ease;
}

/* Refined thin scrollbars — skins override via --scrollbar-* vars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
*::-webkit-scrollbar {
  width: var(--scrollbar-size, 8px);
  height: var(--scrollbar-size, 8px);
}
*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}
.chat {
  scrollbar-color: var(--scrollbar-chat-thumb) var(--scrollbar-track);
}
.chat::-webkit-scrollbar-thumb {
  background: var(--scrollbar-chat-thumb);
  background-clip: padding-box;
}
.chat::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-chat-thumb-hover);
  background-clip: padding-box;
}

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top top"
    "side chat"
    "status status";
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--app-bg);
  backdrop-filter: blur(8px);
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  min-height: 44px;
  border-bottom: 2px solid var(--topbar-accent);
  background: var(--topbar-bg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.brand { display: flex; gap: 8px; align-items: center; min-width: 0; flex: 1; }
.logo { font-size: 1.25rem; line-height: 1; }
.topbar h1 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Keep subtitle in DOM for i18n but never show — one-line header */
.subtitle { display: none !important; }

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Visible locale skin chip — updates with language */
.skin-chip {
  display: none !important; /* removed from UI */
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--skin-chip-bg);
  color: var(--skin-chip-fg);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  white-space: nowrap;
  user-select: none;
}
.skin-chip::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-pill);
  box-shadow: 0 0 6px var(--accent-pill);
}

.lang-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}
.lang-toggle button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.lang-toggle button.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}

.sidebar {
  grid-area: side;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  background: var(--sidebar-bg);
}
.account-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.8rem;
}
.account-chip:hover { background: var(--accent-soft); color: var(--text); }
.account-chip .person-avatar {
  width: 30px; height: 30px;
}
.account-chip .person-avatar .person-initials { font-size: 0.55rem; }
.account-chip .faction-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.88rem;
  line-height: 1;
  background: #0a0f14;
  border: 2.5px solid #f5f7fa;
  box-shadow:
    0 0 0 1.5px rgba(0, 0, 0, 0.55),
    0 2px 8px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  z-index: 3;
}
.account-chip .meta { min-width: 0; }
.account-chip .name { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-chip .handle { opacity: 0.8; font-size: 0.7rem; }

.chat {
  grid-area: chat;
  background: transparent;
  overflow-y: auto;
  padding: var(--chat-pad, 16px 14px 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: transparent;
}

.loading, .empty {
  color: var(--muted);
  text-align: center;
  margin: 40px auto;
  font-size: 0.95rem;
}

.msg {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  max-width: 720px;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Dual identity: person photo/initials + LARGE faction flag corner badge */
.person-avatar {
  position: relative;
  width: 44px; height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg-bubble);
  border: 2px solid var(--border);
  overflow: visible;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.person-avatar .person-img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  background: var(--bg-elev);
}
.person-avatar .person-initials {
  width: 100%; height: 100%;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 25%, #243049), var(--bg-elev));
}
.person-avatar.fallback .person-initials { display: grid; }
.faction-badge {
  position: absolute;
  bottom: -4px; right: -4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.85rem;
  line-height: 1;
  background: #0a0f14;
  border: 2px solid #f0f4f8;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.45),
    0 2px 6px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 2;
}
/* legacy alias kept for any leftover markup */
.flag-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg-bubble);
  border: 1px solid var(--border);
  font-size: 1.25rem;
  flex-shrink: 0;
}

.bubble {
  background: var(--bg-bubble);
  border: var(--bubble-border, 1px solid var(--border));
  border-radius: var(--bubble-tail, var(--radius));
  padding: 10px 12px 12px;
  min-width: 0;
}
.bubble-head {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  align-items: baseline; margin-bottom: 6px;
}
.bubble-head .label { font-weight: 700; font-size: 0.9rem; }
.bubble-head .handle { color: var(--muted); font-size: 0.78rem; }
.bubble-head .time { color: var(--muted); font-size: 0.72rem; margin-left: auto; }
.bubble-head .demo-tag {
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: #ffd166; border: 1px solid rgba(255,209,102,0.35);
  padding: 1px 6px; border-radius: 999px;
}

.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-size: 0.92rem;
}

.quote {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: var(--bg-quote);
  border-radius: 0 10px 10px 0;
  font-size: 0.85rem;
  color: #c5d0e6;
}
.quote .q-head { color: var(--muted); font-size: 0.75rem; margin-bottom: 4px; }
.quote a { color: var(--accent); text-decoration: none; }

.gallery {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.gallery img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: var(--media-max-height);
  object-fit: var(--media-fit, contain);
  object-position: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: #0a0f18;
}
.gallery.gallery-multi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
}
.gallery.gallery-multi img {
  width: 100%;
  height: auto;
  max-height: min(240px, var(--media-max-height));
  object-fit: var(--media-fit, contain);
}
.video-card {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px;
  padding: 8px;
  border-radius: 10px;
  background: var(--bg-quote);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}
.video-card img {
  width: 96px; height: 64px; object-fit: cover; border-radius: 8px;
}
.video-card .v-meta { font-size: 0.8rem; color: var(--muted); }
.video-card strong { display: block; color: var(--accent); margin-bottom: 2px; }

.bubble-foot {
  margin-top: 8px;
  display: flex; gap: 10px; align-items: center;
}
.bubble-foot a {
  color: var(--muted);
  font-size: 0.72rem;
  text-decoration: none;
}
.bubble-foot a:hover { color: var(--accent); }

.statusbar {
  grid-area: status;
  display: flex; justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.72rem;
}

.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.88);
  display: grid; place-items: center;
  padding: 20px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: min(96vw, 1000px);
  max-height: 90vh;
  border-radius: 8px;
  object-fit: contain;
}
.lightbox-close {
  position: absolute; top: 12px; right: 16px;
  background: transparent; border: 0; color: #fff;
  font-size: 2rem; cursor: pointer;
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "chat"
      "status";
  }
  .sidebar {
    display: none;
  }
  .topbar { padding: 10px 12px; }
  .chat { padding: 12px 10px 20px; }
  .msg { grid-template-columns: 40px 1fr; }
  .person-avatar { width: 36px; height: 36px; }
  .faction-badge { width: 20px; height: 20px; font-size: 0.78rem; }
  .flag-avatar { width: 36px; height: 36px; font-size: 1.1rem; }
  .skin-chip { font-size: 0.62rem; padding: 3px 8px; }
}

/* Relation: supplement / retraction quotes */
.quote-supplement {
  border-left-color: #7aa2ff;
}

/* News-agency source chip — tiny, non-intrusive */
.source-chip {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--muted);
  opacity: 0.7;
  text-decoration: none;
  border: 1px solid transparent;
  padding: 1px 6px;
  border-radius: 999px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.source-chip:hover {
  opacity: 1;
  color: var(--accent);
  border-color: var(--border);
}

/* Locale skin chrome tweaks — make switch OBVIOUS */
html[data-skin="western"] .lang-toggle button.active,
html.skin-western .lang-toggle button.active {
  background: var(--accent-soft);
  color: var(--text);
}
html[data-skin="wechat"] .bubble,
html.skin-wechat .bubble {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 2px 4px rgba(0, 0, 0, 0.25);
}
html[data-skin="wechat"] .quote,
html.skin-wechat .quote {
  border-left-color: var(--accent);
  border-radius: 0 4px 4px 0;
}
html[data-skin="wechat"] .lang-toggle,
html.skin-wechat .lang-toggle {
  border-radius: 4px;
}
html[data-skin="wechat"] .lang-toggle button,
html.skin-wechat .lang-toggle button {
  border-radius: 3px;
}
html[data-skin="line"] .bubble,
html.skin-line .bubble {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
html[data-skin="line"] .lang-toggle,
html.skin-line .lang-toggle {
  border-radius: 12px;
}
html[data-skin="western"] .bubble,
html.skin-western .bubble {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}


/* --- compact header + foot time (2026-09-21) --- */
.skin-chip { display: none !important; }
.bubble-head {
  flex-wrap: nowrap;
}
.bubble-head .handle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.bubble-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: nowrap;
}
.bubble-foot .time {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.68rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.bubble-head .time { display: none; }
@media (max-width: 760px) {
  .topbar { padding: 6px 10px; gap: 6px; }
  .topbar h1 { font-size: 0.88rem; }
  .logo { font-size: 1.1rem; }
  .lang-toggle button { padding: 4px 8px; font-size: 0.72rem; }
}

/* one-line topbar forced */
.topbar { flex-wrap: nowrap !important; align-items: center !important; padding: 6px 12px !important; min-height: 40px !important; }
.brand > div { display: flex; align-items: center; min-width: 0; }
.subtitle, .skin-chip { display: none !important; height: 0 !important; overflow: hidden !important; }
.topbar h1 { line-height: 1.2; }
.controls { flex-shrink: 0; }
