:root {
  --desk: #2b2723;
  --paper: #ece7da;
  --paper-2: #e4ddcd;
  --ink: #1d1a16;
  --muted: #7a7263;
  --line: #c9c1ae;
  --accent: #6b4df0;
  --accent-soft: #e6dff8;
  --tape: rgba(196, 178, 140, 0.55);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { overflow-y: scroll; scrollbar-gutter: stable; }

/* тёмный «стол» с зерном под листами бумаги */
body {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23g)' opacity='0.07'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 30%, #35302a 0%, var(--desk) 70%);
  color: var(--ink);
  font-family: 'Courier Prime', 'JetBrains Mono', monospace;
  font-size: 13px;
}

#app { display: flex; flex-direction: column; height: 100vh; }

.hidden { display: none !important; }

/* ---- бумажный лист с рваным краем ---- */
.paper { position: relative; z-index: 0; }
.paper::before {
  content: '';
  position: absolute;
  inset: -7px;
  z-index: -1;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' seed='5'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23p)' opacity='0.05'/%3E%3C/svg%3E"),
    linear-gradient(174deg, var(--paper) 0%, var(--paper-2) 100%);
  filter: url(#torn1);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}
.paper.t2::before { filter: url(#torn2); }

/* скотч */
.paper::after {
  content: '';
  position: absolute;
  top: -12px; left: 50%;
  width: 92px; height: 24px;
  margin-left: -46px;
  background: var(--tape);
  transform: rotate(-2deg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ---- top bar: бумажная лента ---- */
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; flex-shrink: 0;
  margin: 12px 14px 4px;
}
#topbar.paper::after { left: auto; right: 120px; margin: 0; transform: rotate(3deg); top: -10px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 36px; width: auto; }
.wordmark { font-family: 'Special Elite', 'Courier Prime', monospace; font-weight: 400; font-size: 26px; letter-spacing: 1px; }
.tagline { color: var(--muted); font-size: 11px; }
#tabs { display: flex; gap: 4px; margin-left: 20px; }
.tab {
  font-family: 'Special Elite', monospace; font-size: 12px;
  letter-spacing: 1px; background: none; border: none;
  color: var(--muted); padding: 6px 12px; cursor: pointer; position: relative;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); }
.tab.active::after {
  content: ''; position: absolute; left: 8px; right: 8px; bottom: 0; height: 4px;
  background: var(--accent); opacity: 0.85;
  transform: rotate(-1.2deg); border-radius: 2px;
}
.topstats { display: flex; align-items: center; gap: 18px; }
.stat { font-size: 11px; color: var(--muted); }
.stat span { color: var(--ink); font-weight: 700; font-size: 13px; }
.btn-accent {
  font-family: 'Special Elite', monospace; font-size: 13px;
  background: var(--accent); color: #fff; border: none;
  padding: 10px 18px; cursor: pointer; letter-spacing: 1px;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35);
  transform: rotate(-0.5deg);
}
.btn-accent:hover { background: #5a3de0; }
.btn-accent:disabled { background: var(--muted); cursor: default; }
.btn-accent.wide { width: 100%; margin-top: 16px; transform: none; }

/* ---- layout: листы на столе ---- */
#main {
  display: grid; grid-template-columns: 275px 1fr 335px;
  gap: 18px; flex: 1; min-height: 0;
  padding: 14px 14px 18px;
}
.panel {
  padding: 16px; overflow: hidden; display: flex; flex-direction: column; min-height: 0;
}
#leftPanel { transform: rotate(-0.35deg); }
#rightPanel { transform: rotate(0.3deg); }
#rightPanel.paper::after { transform: rotate(2.5deg); left: 24%; }
.panel-title {
  font-family: 'Special Elite', monospace; font-size: 13px;
  letter-spacing: 1.5px; margin-bottom: 12px; flex-shrink: 0;
}
.panel-title.mt { margin-top: 18px; }
.blink { animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; min-height: 0; }
#brainList { max-height: clamp(170px, 28vh, 400px); }
#tweetsFeed { flex: 1; min-height: 110px; padding: 2px 4px 6px 2px; }
#feed { flex: 1; padding: 2px 4px 6px 2px; }
#infGrid { max-height: clamp(200px, 32vh, 420px); }

/* ---- brain composition ---- */
.brain-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 2px;
  border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink);
}
.brain-row:hover { background: rgba(107, 77, 240, 0.07); }
.brain-row:hover .brain-name { color: var(--accent); }
.brain-row img { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--paper); outline: 1px solid var(--line); object-fit: cover; filter: saturate(0.9) contrast(1.02); }
.brain-row img.brand-icon { width: auto; height: 10px; border-radius: 0; border: none; outline: none; object-fit: contain; }
.brand-icon { height: 13px; vertical-align: -2px; }
.brand-icon.xsm { height: 10px; vertical-align: 0; opacity: 0.5; }
.brain-meta { flex: 1; min-width: 0; }
.brain-name { font-weight: 700; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brain-handle { color: var(--muted); font-size: 10.5px; }
.brain-pct { font-weight: 700; font-size: 13px; color: var(--accent); font-family: 'JetBrains Mono', monospace; }
.brain-bar { height: 4px; background: rgba(29, 26, 22, 0.08); margin-top: 4px; border-radius: 2px; }
.brain-bar i { display: block; height: 4px; background: var(--accent); border-radius: 2px; transform: rotate(-0.3deg); }

/* ---- tone mix: звуковая дорожка ---- */
.tone-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 11.5px; }
.tone-row .tone-name { width: 84px; color: var(--muted); }
.tone-row .tone-wave { flex: 1; height: 22px; }
.tone-row .tone-wave rect { transform-origin: center; transform-box: fill-box; animation: pulse 1.6s ease-in-out infinite; }
.tone-row .tone-pct { width: 36px; text-align: right; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
@keyframes pulse { 0%, 100% { transform: scaleY(0.72); } 50% { transform: scaleY(1); } }
.tone-wave rect[fill="var(--line)"] { fill: rgba(29, 26, 22, 0.14); }

/* ---- карта: большой лист ---- */
#mapWrap { position: relative; min-width: 0; min-height: 0; }
#mapWrap.paper::after { width: 120px; left: 12%; transform: rotate(-3deg); }
#map { width: 100%; height: 100%; display: block; }
.bubble { cursor: pointer; }
.bubble circle.ring {
  fill: #f3efe4; stroke: var(--ink); stroke-width: 1.4;
  filter: url(#torn3);
}
.bubble.mine circle.ring { stroke: var(--accent); stroke-width: 3; }
.bubble.empty circle.ring { fill: rgba(243, 239, 228, 0.5); stroke: var(--muted); stroke-dasharray: 5 4; filter: none; }
.bubble.empty:hover circle.ring { stroke: var(--accent); fill: var(--accent-soft); }
.bubble text { font-family: 'Courier Prime', monospace; fill: var(--muted); }
.bubble image { filter: saturate(0.88) contrast(1.03); }
.thread {
  fill: none; stroke: var(--accent); stroke-width: 1.2; opacity: 0.5;
  stroke-dasharray: 5 7; animation: flow 1.4s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -12; } }
#tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: #f3efe4;
  padding: 8px 10px; font-size: 11px; line-height: 1.5; z-index: 5; max-width: 220px;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.3);
}
#tooltip .t-accent { color: #b7a5ff; }

/* ---- influencers table ---- */
#infView {
  position: absolute; inset: 0; overflow-y: auto; scrollbar-width: thin;
  padding: 4px 22px 22px;
}
#infView table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#infView th {
  position: sticky; top: 0; background: var(--paper); text-align: left;
  font-family: 'Special Elite', monospace; font-size: 11px;
  letter-spacing: 1px; color: var(--muted); padding: 14px 10px 10px;
  border-bottom: 2px solid var(--ink); z-index: 2;
}
#infView td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; }
#infView tr:hover td { background: rgba(107, 77, 240, 0.06); }
.inf-cell { display: flex; align-items: center; gap: 10px; }
.inf-cell img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 2px solid var(--paper); outline: 1px solid var(--line); filter: saturate(0.9); }
.inf-cell a { color: var(--ink); text-decoration: none; font-weight: 700; font-family: 'Courier Prime', monospace; font-size: 12.5px; }
.inf-cell a:hover { color: var(--accent); }
.inf-cell .ih { color: var(--muted); font-size: 10px; font-weight: 400; }
.cat-chip {
  font-size: 9px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  border: 1px solid var(--muted); padding: 2px 6px; color: var(--muted);
}
.score-val { font-weight: 700; color: var(--accent); }
.brain-val { font-weight: 700; }

/* ---- feed: твит-виджеты — бумажные обрывки ---- */
#thinking {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  font-size: 11.5px; color: var(--muted); padding: 8px 10px; margin-top: 12px;
  border: 1px dashed var(--muted); background: rgba(29, 26, 22, 0.03);
}
#thinking .th-dot { width: 7px; height: 7px; background: var(--accent); border-radius: 50%; animation: pulse 1.2s ease-in-out infinite; flex-shrink: 0; }
#thinking .th-dots::after { content: ''; animation: dots 1.6s steps(4) infinite; }
#thinking.fresh { border-color: var(--accent); color: var(--accent); }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* X-виджет: фото-обрывок бумаги */
.tweet-card {
  display: block; position: relative; z-index: 0;
  padding: 15px 19px; margin: 2px 6px 18px; text-decoration: none; color: var(--ink);
}
.tweet-card::before {
  content: ''; position: absolute; inset: -9px -12px; z-index: -1;
  /* 9-slice: рваные кромки не растягиваются с высотой карточки */
  border: 30px solid transparent;
  border-image: url('paper-scrap.png') 110 fill stretch;
}
.tweet-card:nth-child(even) { transform: rotate(0.5deg); }
.tweet-card:nth-child(odd) { transform: rotate(-0.45deg); }
.tweet-card:nth-child(even)::before { transform: scaleX(-1); }
.tweet-card.live:hover { filter: brightness(1.04); }

/* размышление: без X, лёгкий CSS-обрывок */
.thought-card {
  position: relative; z-index: 0;
  padding: 12px 15px; margin: 0 4px 15px; color: var(--ink);
}
.thought-card::before {
  content: ''; position: absolute; inset: -6px; z-index: -1;
  background: linear-gradient(178deg, #f1ecdf, #e9e2d1);
  filter: url(#torn2);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
}
.thought-card:nth-child(even) { transform: rotate(0.4deg); }
.thought-card:nth-child(odd) { transform: rotate(-0.35deg); }
.thought-card:nth-child(even)::before { filter: url(#torn1); }
.thought-card .post-content { font-style: italic; }
.thought-card.newest .post-content::after { content: '▌'; color: var(--accent); animation: blink 1s steps(1) infinite; }
.tw-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tw-avatar { width: 28px; height: 26px; object-fit: contain; }
.tw-names { display: flex; flex-direction: column; line-height: 1.2; }
.tw-name { font-weight: 700; font-size: 11.5px; font-family: 'Special Elite', monospace; }
.tw-handle { color: var(--muted); font-size: 10px; }
.tw-x { margin-left: auto; height: 12px; opacity: 0.5; }
.tw-replyto { font-size: 10px; color: var(--muted); margin-bottom: 5px; }
.tw-replyto .pm-link { color: var(--accent); cursor: pointer; }
.tw-replyto .pm-link:hover { text-decoration: underline; }
.post-content { font-size: 12.5px; line-height: 1.5; }
.post-meta { margin-top: 8px; font-size: 10px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.post-meta .pm-tone { color: var(--accent); font-weight: 700; }
.post-meta .pm-inf { color: var(--muted); text-decoration: none; border-bottom: 1px dotted var(--muted); }
.post-meta .pm-inf:hover { color: var(--accent); border-color: var(--accent); }
.tweet-card.newest .post-content::after { content: '▌'; color: var(--accent); animation: blink 1s steps(1) infinite; }

/* ---- модалки: большой рваный лист со скотчем ---- */
#modal, #holderModal {
  position: fixed; inset: 0; background: rgba(20, 17, 13, 0.62);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
#modalCard, #holderCard {
  position: relative; z-index: 0;
  width: 580px; max-width: 92vw; max-height: 88vh;
  padding: 26px; overflow-y: auto; scrollbar-width: thin;
  transform: rotate(-0.4deg);
}
#holderCard { width: 390px; transform: rotate(0.5deg); }
/* стейк-модалка: настоящий фото-лист (GPT Image 2, фон выбит в прозрачность) */
#modalCard { padding: 44px 52px 40px; }
#modalCard::before {
  content: ''; position: absolute; inset: -26px -30px; z-index: -1;
  background: url('paper-stake.png') center / 100% 100% no-repeat;
  /* без drop-shadow: Chrome тенит bounding box, а не альфу картинки */
}
#holderCard { padding: 40px 42px 36px; }
#holderCard::before {
  content: ''; position: absolute; inset: -20px -24px; z-index: -1;
  background: url('paper-note.png') center / 100% 100% no-repeat;
}

/* окно текущего голоса */
#voiceModal {
  position: fixed; inset: 0; background: rgba(20, 17, 13, 0.62);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
#voiceCard {
  position: relative; z-index: 0;
  width: 430px; max-width: 92vw; max-height: 86vh;
  padding: 42px 44px 38px; overflow-y: auto; scrollbar-width: thin;
  transform: rotate(-0.5deg);
}
#voiceCard::before {
  content: ''; position: absolute; inset: -20px -24px; z-index: -1;
  background: url('paper-note.png') center / 100% 100% no-repeat;
  transform: scaleX(-1);
}
#voiceDominant { margin: 14px 0 10px; }
#voiceSummary { font-size: 13px; line-height: 1.6; margin: 6px 0 4px; }

/* чернильный штамп */
.stamp {
  display: inline-block; font-family: 'Special Elite', monospace;
  font-size: 13px; letter-spacing: 2px; text-transform: uppercase;
  color: #a13328; border: 2.5px solid #a13328; padding: 4px 10px;
  transform: rotate(-2deg); opacity: 0.85; border-radius: 3px;
  margin-right: 8px;
}
#modalMsg .stamp { font-size: 11px; padding: 3px 8px; }

/* граф связей */
#graphView { position: absolute; inset: 0; width: 100%; height: 100%; }
.g-thread {
  fill: none; stroke: var(--accent); opacity: 0.45;
  stroke-dasharray: 6 7; animation: flow 1.6s linear infinite;
}
.g-ring { fill: #f3efe4; stroke: var(--ink); stroke-width: 1.4; filter: url(#torn3); }
.g-center { fill: #f3efe4; stroke: var(--accent); stroke-width: 2.5; filter: url(#torn3); }
#graphView text { font-family: 'Courier Prime', monospace; }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  font-family: 'Special Elite', monospace; font-size: 19px; letter-spacing: 1px;
}
.modal-head > span { position: relative; }
.modal-head > span::after {
  content: ''; position: absolute; left: 0; bottom: -4px; width: 60%; height: 5px;
  background: var(--accent); opacity: 0.8; transform: rotate(-1deg); border-radius: 3px;
}
#modalClose, #hmClose { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--ink); font-family: 'Courier Prime', monospace; }
.modal-sub { color: var(--muted); font-size: 11.5px; margin: 14px 0 16px; }
.modal-sub span { color: var(--ink); font-weight: 700; }
.modal-label { font-size: 12.5px; font-weight: 700; letter-spacing: 0.5px; margin: 14px 0 8px; font-family: 'Courier Prime', monospace; }
#infSearch {
  width: 100%; font-family: 'Courier Prime', monospace; font-size: 12.5px;
  padding: 9px 10px; border: 1px solid var(--ink); background: rgba(255, 255, 255, 0.4);
  color: var(--ink); margin-bottom: 8px; outline: none;
}
#infSearch:focus { border-color: var(--accent); box-shadow: 1px 2px 0 var(--accent); }
#infGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.inf-card {
  position: relative; z-index: 0;
  display: flex; align-items: center; gap: 8px; padding: 8px;
  cursor: pointer;
}
.inf-card::before {
  content: ''; position: absolute; inset: -2px; z-index: -1;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--line);
  filter: url(#torn3);
}
.inf-card:hover::before { border-color: var(--accent); }
.inf-card.sel::before { border: 2px solid var(--accent); background: var(--accent-soft); }
.inf-card img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; filter: saturate(0.9); }
.inf-card .ic-name { font-size: 11.5px; font-weight: 700; line-height: 1.2; }
.inf-card .ic-handle { font-size: 9px; color: var(--muted); }
.inf-card .ic-x { margin-left: auto; opacity: 0.4; flex-shrink: 0; }
.inf-card .ic-x:hover { opacity: 1; }
.inf-card .ic-x img { width: 11px; height: 11px; border-radius: 0; }
#toneGrid { display: flex; gap: 9px; }
.tone-card {
  flex: 1; text-align: center; padding: 10px 4px;
  cursor: pointer; font-size: 12px; font-weight: 700;
  position: relative; z-index: 0; font-family: 'Courier Prime', monospace;
}
.tone-card::before {
  content: ''; position: absolute; inset: -2px; z-index: -1;
  background: rgba(255, 255, 255, 0.45); border: 1px solid var(--line);
  filter: url(#torn3);
}
.tone-card:hover::before { border-color: var(--accent); }
.tone-card.sel { color: var(--accent); }
.tone-card.sel::after {
  content: ''; position: absolute; left: 14%; right: 14%; bottom: 4px; height: 4px;
  background: var(--accent); opacity: 0.8; transform: rotate(-1.2deg); border-radius: 2px;
}
#stakeBtn {
  background: var(--ink); color: #f3efe4;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.4);
  position: relative;
}
#stakeBtn:hover:not(:disabled) { background: #000; }
#stakeBtn::after {
  content: ''; position: absolute; left: 34%; right: 34%; bottom: 6px; height: 3px;
  background: var(--accent); border-radius: 2px; transform: rotate(-0.8deg);
}
#modalMsg { margin-top: 10px; font-size: 11.5px; color: var(--accent); min-height: 16px; }
#modalMsg.err { color: #b03a2e; }

/* ---- окно холдера ---- */
.hm-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.hm-row:last-child { border-bottom: none; }
.hm-avatar-row { padding-top: 16px; }
.hm-avatar-row img#hmAvatar { width: 54px; height: 54px; border-radius: 50%; border: 2px solid var(--accent); object-fit: cover; filter: saturate(0.9); }
.hm-label { color: var(--muted); font-size: 10px; width: 86px; flex-shrink: 0; letter-spacing: 0.5px; }
.hm-big { font-weight: 700; font-size: 15px; font-family: 'JetBrains Mono', monospace; }
.hm-token { color: var(--muted); font-size: 10px; }
.hm-tone { color: var(--accent); font-weight: 700; }
.hm-wallet { color: var(--ink); text-decoration: none; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; overflow-wrap: anywhere; font-family: 'JetBrains Mono', monospace; font-size: 11px; }
.hm-wallet:hover { color: var(--accent); }
#hmInfLink { color: var(--muted); text-decoration: none; font-size: 11px; display: inline-flex; align-items: center; gap: 5px; }
#hmInfLink:hover { color: var(--accent); }
#hmInfLink .brand-icon { height: 11px; }
.hm-foll { color: var(--muted); font-size: 10px; margin-top: 2px; }
.badge {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent); padding: 3px 7px;
}

@media (max-width: 980px) {
  #main { grid-template-columns: 1fr; grid-template-rows: auto 440px auto; overflow-y: auto; }
  #app { height: auto; }
  #leftPanel, #rightPanel { transform: none; }
}
