* { box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  --bg: #0e0e10;
  --bg-alt: #18181b;
  --text: #efeff1;
  --muted: #848494;
  --border: #2a2a2e;
  --accent: #9147ff;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  flex: none;
}

header #title {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

#chanmenu {
  position: fixed;
  top: calc(40px + env(safe-area-inset-top));
  left: 8px;
  z-index: 30;
  min-width: 230px;
  max-width: 85vw;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}

.chanrow { display: flex; align-items: center; }
.chanrow .chango {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.chanrow .chango:hover { background: var(--bg); }
.chanrow.current .chango { color: var(--accent); font-weight: 700; }
.chanx {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  padding: 8px;
  cursor: pointer;
}
.chanx:hover { color: var(--text); }

.chanadd {
  display: flex;
  gap: 6px;
  padding: 6px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.chanadd input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
}
.chanadd input:focus { outline: none; border-color: var(--accent); }
.chanadd button {
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
  cursor: pointer;
}

.channote {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.landing {
  color: var(--muted);
  text-align: center;
  padding: 40vh 24px 0;
}

header #acctbtn {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
  max-width: 40vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
header #acctbtn:hover { color: var(--text); }

#acctmenu {
  position: fixed;
  top: calc(40px + env(safe-area-inset-top));
  right: 8px;
  z-index: 30;
  min-width: 180px;
  max-width: 85vw;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
.acctrow { display: flex; align-items: center; }
.acctrow .acctgo {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.acctrow .acctgo:hover { background: var(--bg); }
.acctrow.current .acctgo { color: var(--accent); font-weight: 700; cursor: default; }
.acctrow.current .acctgo:hover { background: none; }
.acctx {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  padding: 8px;
  cursor: pointer;
}
.acctx:hover { color: var(--text); }
#acctmenu .acctlink {
  display: block;
  width: 100%;
  padding: 8px 10px;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  text-align: left;
  text-decoration: none;
  background: none;
  border: none;
  border-radius: 0;
  cursor: pointer;
}
#acctmenu .acctlink.sep { border-top: 1px solid var(--border); margin-top: 4px; }
#acctmenu .acctlink:hover { color: var(--text); }

/* blocked users panel, opened from the account menu */
#blockmenu {
  position: fixed;
  top: calc(40px + env(safe-area-inset-top));
  right: 8px;
  z-index: 30;
  min-width: 220px;
  max-width: 85vw;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
.blockhead {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 8px 10px 4px;
}
.blockrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 10px;
}
.blockrow .bname {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.blockrow button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.blockrow button:hover { color: var(--text); border-color: var(--accent); }
.blocknote {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 10px;
}

/* user card: actions for the name you clicked */
#usercard {
  position: fixed;
  z-index: 35;
  min-width: 170px;
  max-width: 70vw;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
#usercard .uc-name {
  font-weight: 700;
  padding: 8px 10px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#usercard button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
#usercard button:hover { background: var(--bg); }

/* pinned strip while viewing a single user's messages */
#filterbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
#filterbar #filterinfo {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#filterbar button {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 2px 6px;
}
#filterbar button:hover { color: var(--text); }

#dropzone {
  position: fixed;
  inset: 12px;
  z-index: 40;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: rgba(14, 14, 16, 0.75);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.dot.online { background: #00e676; }
.dot.connecting { background: #ffb300; }
.dot.offline { background: #f44336; }

#chat {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 6px 0;
  -webkit-overflow-scrolling: touch;
}

.msg {
  padding: 3px 12px;
  overflow-wrap: anywhere;
  /* skip layout/paint for offscreen rows (and pause their animated emotes) —
     scrolling a chat full of gifs was chugging without this */
  content-visibility: auto;
  contain-intrinsic-size: auto 26px;
}
.msg:hover { background: var(--bg-alt); }

/* deleted while on screen: struck through but readable until reload (chatterino-style) */
.msg.deleted .text,
.msg.deleted .emote {
  opacity: 0.4;
  text-decoration: line-through;
}

/* deleted before this page load: placeholder only */
.deleted-note {
  color: var(--muted);
}

.msg.system .time { margin-right: 6px; }
.msg.system .text { color: var(--muted); }

.reply {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 1px;
}

.time {
  color: var(--muted);
  font-size: 11px;
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
}

.name { font-weight: 700; cursor: pointer; }

.emote {
  height: 1.75em;
  vertical-align: middle;
  margin: -0.4em 1px;
}

.msg a { color: var(--accent); }

.day-sep {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  padding: 8px 0 2px;
}

#jump {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(64px + env(safe-area-inset-bottom));
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

#composer {
  flex: none;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--bg-alt);
  border-top: 1px solid var(--border);
}

#inputrow {
  display: flex;
  gap: 8px;
  align-items: center;
}

#emotebtn,
#attachbtn {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
#emotebtn.active { border-color: var(--accent); color: var(--accent); }
#attachbtn { font-size: 16px; }

#uploadbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px 6px;
  font-size: 12px;
  color: var(--muted);
}
#uploadname {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#uploadbar select,
#uploadbar button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
  cursor: pointer;
}
#uploadbar #uploadgo { border-color: var(--accent); color: var(--accent); font-weight: 600; }
#uploadbar #uploadcancel { border: none; color: var(--muted); }

a.imglink { word-break: break-all; }

#imgpreview {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
#imgpreview img {
  display: block;
  max-width: 320px;
  max-height: 320px;
  border-radius: 6px;
}

/* messages from users this viewer has blocked */
.msg.blocked { display: none; }

#suggestions {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 0 2px 6px;
  scrollbar-width: none;
}
#suggestions::-webkit-scrollbar { display: none; }

#suggestions button {
  flex: none;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
#suggestions button.selected { border-color: var(--accent); }
#suggestions img { height: 24px; }

#picker {
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  padding: 6px;
}

.picker-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 8px 4px 4px;
}

.picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.picker-grid button {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: none;
  cursor: pointer;
}
.picker-grid button:hover { background: var(--bg-alt); }
.picker-grid img { max-width: 32px; max-height: 32px; }

#input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#input:disabled { opacity: 0.5; }
#input:focus { outline: none; border-color: var(--accent); }

#signin {
  display: block;
  text-align: center;
  padding: 9px 12px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

#replybar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px 6px;
  color: var(--muted);
  font-size: 12px;
}
#replybar #replyinfo {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#replybar button {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 2px 6px;
}

.msg.reply-target { background: rgba(145, 71, 255, 0.15); }

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(110px + env(safe-area-inset-bottom));
  background: #3a1d1d;
  border: 1px solid #f44336;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 14px;
  max-width: 90vw;
  z-index: 10;
}
