:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #12151b;
  --line: #22262f;
  --bubble-me: #1f6feb;
  --bubble-peer: #262b35;
  --text: #e6e8ec;
  --muted: #8b93a1;
  --danger: #e5484d;
  --ok: #2ea043;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

body,
input,
textarea,
button,
select {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------------ auth */

#auth {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow-y: auto;
}

#auth .box {
  margin: auto;
  width: min(92vw, 400px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 0;
}

#auth h1 {
  font-size: 1.3rem;
  margin: 0;
  text-align: center;
}

#auth p.sub {
  margin: 0 0 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.78rem;
  color: var(--muted);
}

input,
select {
  background: var(--panel);
  border: 1px solid #2b303b;
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--bubble-me);
}

button {
  background: var(--bubble-me);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
}

button.ghost {
  background: transparent;
  border: 1px solid #2b303b;
  color: var(--text);
  font-weight: 500;
}

button.link {
  background: transparent;
  border: none;
  color: var(--bubble-me);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px;
}

.switch {
  text-align: center;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.1em;
  text-align: center;
}

.muted {
  color: var(--muted);
  font-size: 0.78rem;
}

/* ----------------------------------------------------------------- shell */

#shell {
  display: none;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-top);
}

#shell.active {
  display: flex;
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}

header .grow {
  flex: 1;
  min-width: 0;
}

header .title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header .sub {
  font-size: 0.72rem;
  color: var(--muted);
}

header .sub.online {
  color: var(--ok);
}

header .sub.secure {
  color: var(--bubble-me);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 8px;
  border-radius: 8px;
  font-weight: 500;
  white-space: nowrap;
}

#main {
  flex: 1;
  min-height: 0;
  display: flex;
}

/* -------------------------------------------------------------- list view */

#list-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.tabs button {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--muted);
  padding: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border-bottom: 2px solid transparent;
}

.tabs button.active {
  color: var(--text);
  border-bottom-color: var(--bubble-me);
}

.tabpane {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  gap: 10px;
}

.tabpane.active {
  display: flex;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: none;
}

.panel h3 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.row {
  display: flex;
  gap: 8px;
}

.row > * {
  flex: 1;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.item .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bubble-peer);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex: none;
}

.item .info {
  flex: 1;
  min-width: 0;
}

.item .name {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item .tag {
  font-size: 0.7rem;
  color: var(--muted);
}

.item .tag.online {
  color: var(--ok);
}

.item button {
  padding: 8px 12px;
  font-size: 0.8rem;
  flex: none;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 18px 8px;
}

/* -------------------------------------------------------------- chat view */

#chat-view {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

#chat-view.active {
  display: flex;
}

#main.chat-open #list-view {
  display: none;
}

#main.chat-open #chat-view {
  display: flex;
}

@media (min-width: 820px) {
  #list-view {
    max-width: 380px;
    border-right: 1px solid var(--line);
  }
  #main.chat-open #list-view {
    display: flex;
  }
  #chat-view {
    display: flex;
  }
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  line-height: 1.42;
  word-break: break-word;
  position: relative;
  overflow: hidden;
  font-size: 0.95rem;
}

.msg.me {
  align-self: flex-end;
  background: var(--bubble-me);
  border-bottom-right-radius: 4px;
}

.msg.peer {
  align-self: flex-start;
  background: var(--bubble-peer);
  border-bottom-left-radius: 4px;
}

.msg .sender {
  font-size: 0.68rem;
  color: #ffd479;
  margin-bottom: 3px;
}

.msg .meta {
  font-size: 0.62rem;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

.msg .burn-count {
  font-variant-numeric: tabular-nums;
}

.msg .watermark {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.09;
  font-size: 0.6rem;
  color: #fff;
  line-height: 1.6;
  white-space: pre;
  overflow: hidden;
  transform: rotate(-18deg) scale(1.6);
  transform-origin: center;
}

.sys {
  align-self: center;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  max-width: 90%;
  padding: 2px 8px;
}

#composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: none;
}

#composer input {
  flex: 1;
  border-radius: 20px;
}

#composer button {
  border-radius: 20px;
  padding: 0 18px;
}

.burn-config {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: var(--muted);
}

.burn-config select {
  width: auto;
  padding: 4px;
  font-size: 0.7rem;
}

/* --------------------------------------------------------------- overlay */

#shield {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 9, 12, 0.98);
  color: var(--muted);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  padding: 24px;
}

body.is-hidden #shield {
  display: flex;
}

body.is-hidden #shell,
body.is-hidden #auth {
  filter: blur(14px);
  pointer-events: none;
}

#screen-watermark {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0.05;
  display: none;
  overflow: hidden;
}

body.chat-on #screen-watermark {
  display: block;
}

#screen-watermark span {
  position: absolute;
  font-size: 0.72rem;
  white-space: nowrap;
  color: #fff;
  transform: rotate(-24deg);
}

#info-panel {
  display: none;
  padding: 12px;
  background: var(--panel2);
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--muted);
  flex: none;
}

#info-panel.open {
  display: block;
}

#info-panel .num {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  margin: 6px 0;
  letter-spacing: 1px;
  word-break: break-all;
}

#info-panel .code {
  color: #ffd479;
  font-size: 0.85rem;
  word-break: break-all;
  margin: 6px 0;
}

.allow-copy {
  -webkit-user-select: text;
  user-select: text;
}
