:root {
  --bg: #0c0a17;
  --bg2: #131029;
  --panel: #191634;
  --panel2: #221d45;
  --line: #3d3670;
  --line2: #59509b;
  --ink: #ece9ff;
  --dim: #9d95cf;
  --accent: #ffd23f;
  --accent2: #5ef0a8;
  --danger: #ff6f91;
  --shadow: #06040d;
  --font-pixel: "Pixelify Sans", "Handjet", "Trebuchet MS", system-ui, sans-serif;
  --font-read: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

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

html, body { margin: 0; padding: 0; }

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px);
  background-size: 8px 8px;
  color: var(--ink);
  font-family: var(--font-read);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

.scanlines {
  position: fixed; inset: 0; z-index: 90; pointer-events: none; opacity: .35;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, .22) 0 2px, transparent 2px 4px);
}

.hidden { display: none !important; }

.ico { display: inline-block; vertical-align: -2px; flex: none; }

/* --- шапка --- */

.top {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px;
  background: var(--bg2);
  border-bottom: 2px solid var(--line);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .45);
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-pixel); font-weight: 700; font-size: 17px;
  letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
}
.brand .ico { color: var(--accent2); }

.topmeta {
  font-family: var(--font-pixel); font-size: 12px; letter-spacing: .04em;
  color: var(--dim); text-align: right;
}

main { padding: 12px; }

.panel { display: none; }
.panel.on { display: block; }

/* --- фильтры --- */

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-family: var(--font-pixel); font-size: 13px; letter-spacing: .04em;
  color: var(--dim); background: var(--panel);
  border: 2px solid var(--line); padding: 6px 10px;
  box-shadow: 3px 3px 0 var(--shadow);
}
.chip.on { color: #17121f; background: var(--accent); border-color: var(--accent); }
.chip:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }

/* --- карточки --- */

.card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--line); box-shadow: 4px 4px 0 var(--shadow);
  padding: 10px 12px; margin-bottom: 10px;
}
.card:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--shadow); }
.card.block { cursor: default; }
.card.block:active { transform: none; box-shadow: 4px 4px 0 var(--shadow); }

.chat { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; flex: none; color: var(--accent2);
  display: flex; align-items: center; justify-content: center;
  background: var(--panel2); border: 2px solid var(--line);
}
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ctitle {
  font-family: var(--font-pixel); font-weight: 600; font-size: 15px; letter-spacing: .03em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmeta { font-size: 12px; color: var(--dim); }
.cright { display: flex; align-items: center; gap: 6px; color: var(--line2); }

.badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-family: var(--font-pixel); font-size: 11px;
  padding: 2px 5px; border: 1px solid var(--danger);
  color: var(--danger); background: rgba(255, 111, 145, .1);
}

/* --- сообщения --- */

.msg {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--line); border-left: 4px solid var(--line2);
  padding: 8px 10px; margin-bottom: 8px;
  box-shadow: 3px 3px 0 var(--shadow);
}
.msg.out { border-left-color: var(--accent); background: #1b1839; }
.msg:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }

.mhead { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.mwho {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-pixel); font-weight: 600; font-size: 13px; color: var(--accent2);
  max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mtime { font-size: 11px; color: var(--dim); margin-left: auto; }

.mark {
  display: inline-flex; align-items: center; gap: 2px;
  font-family: var(--font-pixel); font-size: 10px; letter-spacing: .04em;
  padding: 1px 4px; border: 1px solid currentColor;
}
.mark.del { color: var(--danger); }
.mark.ed { color: var(--accent); }

.mtext { display: block; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.mtext mark { background: var(--accent); color: #17121f; }
.msub { display: block; margin-top: 5px; font-size: 11px; color: var(--dim); }

.media {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 6px;
  font-family: var(--font-pixel); font-size: 12px; color: var(--dim);
  border: 1px dashed var(--line2); padding: 2px 6px;
}

/* --- поиск --- */

.searchbar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  background: var(--panel); border: 2px solid var(--line);
  box-shadow: 3px 3px 0 var(--shadow); padding: 8px 10px; color: var(--accent2);
}
.searchbar input {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: none;
  color: var(--ink); font-family: var(--font-pixel); font-size: 15px; letter-spacing: .03em;
}
.searchbar input::placeholder { color: var(--line2); }
.icon-btn { background: transparent; border: 0; color: var(--dim); padding: 2px; cursor: pointer; }

/* --- низ --- */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; background: var(--bg2); border-top: 2px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 0 rgba(0, 0, 0, .4);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: transparent; border: 0; cursor: pointer; padding: 6px 2px; color: var(--dim);
  font-family: var(--font-pixel); font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
}
.tab.on { color: var(--accent); background: rgba(255, 210, 63, .08); }
.tab:active { transform: translateY(1px); }

.fab {
  position: fixed; right: 12px; z-index: 46; cursor: pointer;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #17121f; border: 2px solid #b98f14;
  box-shadow: 4px 4px 0 var(--shadow); padding: 8px 12px;
  font-family: var(--font-pixel); font-weight: 700; font-size: 13px;
  letter-spacing: .05em; text-transform: uppercase;
}
.fab:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--shadow); }

.more {
  display: block; width: 100%; cursor: pointer; margin-top: 4px;
  background: var(--panel2); color: var(--ink); border: 2px solid var(--line2);
  box-shadow: 3px 3px 0 var(--shadow); padding: 10px;
  font-family: var(--font-pixel); font-weight: 600; font-size: 13px;
  letter-spacing: .05em; text-transform: uppercase;
}
.more:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }

.viewhead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.viewtitle {
  flex: 1; min-width: 0; font-family: var(--font-pixel); font-weight: 700;
  font-size: 16px; letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ghost {
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  background: var(--panel); color: var(--ink); border: 2px solid var(--line);
  box-shadow: 3px 3px 0 var(--shadow); padding: 6px 8px;
}
.ghost:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.histinfo {
  font-family: var(--font-pixel); font-size: 12px; letter-spacing: .04em;
  color: var(--dim); margin-bottom: 10px;
}

/* --- сводка --- */

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.stat {
  background: var(--panel); border: 2px solid var(--line);
  box-shadow: 4px 4px 0 var(--shadow); padding: 10px;
}
.stat .num {
  font-family: var(--font-pixel); font-weight: 700; font-size: 26px;
  color: var(--accent); line-height: 1;
}
.stat .lbl {
  display: flex; align-items: center; gap: 5px; margin-top: 6px;
  font-family: var(--font-pixel); font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--dim);
}
.block h3 {
  display: flex; align-items: center; gap: 6px; margin: 0 0 10px;
  font-family: var(--font-pixel); font-size: 13px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent);
}
.note {
  font-family: var(--font-pixel); font-size: 12px; letter-spacing: .03em;
  color: var(--dim); margin-bottom: 10px;
}
.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; }
.bar {
  flex: 1; height: 100%; display: flex; flex-direction: column;
  justify-content: flex-end; align-items: center; gap: 4px;
}
.bar i {
  display: block; width: 100%; min-height: 2px;
  background: var(--accent2); border: 1px solid #2f9c6b;
}
.bar span { font-family: var(--font-pixel); font-size: 9px; color: var(--dim); }
.top-list { display: grid; gap: 6px; }
.top-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.top-row .rank { width: 18px; font-family: var(--font-pixel); color: var(--accent); }
.top-row .tname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-row .tcount { font-family: var(--font-pixel); font-size: 12px; color: var(--dim); }

/* --- пусто и уведомления --- */

.empty {
  text-align: center; padding: 30px 16px; color: var(--dim);
  font-family: var(--font-pixel); font-size: 14px; letter-spacing: .04em;
  border: 2px dashed var(--line);
}
.empty .ico { display: block; margin: 0 auto 8px; color: var(--line2); }
.empty b { display: block; margin-bottom: 6px; font-size: 16px; color: var(--ink); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 95;
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  max-width: 90vw; padding: 8px 14px; text-align: center;
  background: var(--accent); color: #17121f; border: 2px solid #b98f14;
  box-shadow: 3px 3px 0 var(--shadow);
  font-family: var(--font-pixel); font-weight: 600; font-size: 13px;
}
.toast.err { background: var(--danger); border-color: #b23a58; color: #2a0710; }

/* --- карточка сообщения --- */

.sheet {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: flex-end; background: rgba(6, 4, 13, .72);
}
.sheet-card {
  width: 100%; max-height: 82vh; overflow-y: auto;
  background: var(--panel); border-top: 3px solid var(--accent);
  box-shadow: 0 -6px 0 rgba(0, 0, 0, .5);
  padding: 12px 12px calc(16px + env(safe-area-inset-bottom, 0px));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-title {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-pixel); font-size: 15px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--accent);
}
.sheet-text {
  margin-bottom: 10px; padding: 8px 10px; max-height: 40vh; overflow-y: auto;
  font-size: 15px; white-space: pre-wrap; word-break: break-word;
  background: var(--bg2); border-left: 3px solid var(--line2);
}
.sheet-text.dim { color: var(--dim); font-style: italic; }
.sheet-meta { display: grid; gap: 4px; margin-bottom: 12px; }
.srow {
  display: flex; justify-content: space-between; gap: 12px; font-size: 12px;
  border-bottom: 1px dashed var(--line); padding-bottom: 4px;
}
.srow span { font-family: var(--font-pixel); letter-spacing: .04em; color: var(--dim); }
.srow b { font-weight: 600; text-align: right; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--accent2); color: #08231a; border: 2px solid #2f9c6b;
  box-shadow: 3px 3px 0 var(--shadow); padding: 8px 12px;
  font-family: var(--font-pixel); font-weight: 600; font-size: 13px;
  letter-spacing: .04em; text-transform: uppercase;
}
.btn.ghost { background: var(--panel2); color: var(--ink); border-color: var(--line2); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
