/* EARTH public channels. Tokens are shared with the messenger (tokens.css);
   this file is the layout a channel reader needs on top of them. The look is
   deliberately that of an ordinary consumer app: distribution and signatures
   are properties of the architecture, not something to draw on the screen. */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Manrope", ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -.005em;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
[hidden] { display: none !important; }
.icon { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 11px; }
.error { color: var(--danger); font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; line-height: 1.5; }
h1 { font-size: 22px; margin: 0 0 8px; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 12px; margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
a { color: var(--accent); }
label { display: block; margin-top: 14px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  font: max(16px, 1em) inherit;
  width: 100%;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: var(--r-s);
  padding: 10px 12px;
  margin-top: 6px;
  min-height: 42px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 96px; }

/* --- buttons ---------------------------------------------------------- */

button { font: inherit; cursor: pointer; color: inherit; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 15px;
  border-radius: var(--r-m);
  font-weight: 700;
  border: none;
  background: var(--panel-2);
  color: var(--text);
  min-height: var(--tap);
  text-decoration: none;
}
.btn:hover { background: var(--panel-3); }
.btn.primary { background: linear-gradient(140deg, var(--accent), var(--teal)); color: #fff; box-shadow: var(--shadow); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.btn.danger { color: var(--danger); background: var(--panel-2); }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 999px; }
.btn.subscribed { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.iconbtn {
  width: 36px; height: 36px; min-width: 36px; min-height: 36px;
  padding: 0; display: grid; place-items: center;
  border-radius: 12px; border: none; background: transparent; color: var(--muted);
}
.iconbtn:hover { background: var(--panel-2); color: var(--text); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btnrow > * { flex: 1; min-width: 120px; }

/* --- screens (welcome) ------------------------------------------------ */

.screen { height: 100%; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.card { width: 100%; max-width: 440px; background: var(--panel); border-radius: var(--r-xl); padding: 24px; box-shadow: var(--shadow); }

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

#app { display: grid; height: 100%; grid-template-columns: 64px 340px 1fr; grid-template-rows: 1fr; }
@media (min-width: 720px) and (max-width: 1023px) { #app { grid-template-columns: 64px minmax(250px, 290px) 1fr; } }
@media (max-width: 719px) { #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; } }

.rail {
  grid-row: 1; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: calc(12px + var(--safe-top)) 0 12px;
}
.rail-logo { color: var(--accent); margin-bottom: 6px; display: grid; }
.rail-grow { flex: 1; }
.railbtn {
  width: 44px; height: 44px; min-height: 44px; display: grid; place-items: center;
  border-radius: var(--r-m); border: none; background: transparent; color: var(--muted); position: relative; padding: 0;
  text-decoration: none;
}
.railbtn:hover { background: var(--panel-2); color: var(--text); }
.railbtn[aria-selected='true'] { color: var(--accent); background: var(--accent-soft); }
.railbtn[aria-selected='true']::before {
  content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.rail-badge { position: absolute; top: 3px; right: 3px; }
.badge { font-size: 11px; background: var(--teal); color: #04201d; border-radius: 999px; padding: 1px 7px; font-weight: 800; }
.badge.quiet { background: var(--panel-3); color: var(--muted); }
@media (max-width: 719px) { .rail { display: none; } }

.tabbar { display: none; }
@media (max-width: 719px) {
  .tabbar { grid-row: 2; display: flex; background: var(--panel); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + var(--safe-bottom)); }
  #app.detail-open .tabbar { display: none; }
  .tabbar button, .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0;
    border: none; border-radius: 12px; background: transparent; color: var(--faint);
    font-size: 10.5px; font-weight: 700; min-height: 0; text-decoration: none;
  }
  .tabbar [aria-selected='true'] { color: var(--accent); }
}

/* --- sidebar: subscriptions ------------------------------------------- */

#sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { padding: calc(10px + var(--safe-top)) 12px 8px; display: flex; flex-direction: column; align-items: stretch; gap: 8px; border-bottom: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; padding: 4px 4px 0; }
.me-text { min-width: 0; flex: 1; }
.me-name { font-weight: 700; }
.addr { color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 12px; padding: 8px 10px; color: var(--muted); }
.search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; font-size: 13.5px; margin: 0; padding: 0; min-height: 0; color: inherit; }
.peers { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; margin: 0; list-style: none; -webkit-overflow-scrolling: touch; }
.peers li {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: 'avatar name meta' 'avatar sub meta';
  column-gap: 11px; align-items: center; padding: 9px 10px; border-radius: var(--r-m); cursor: pointer; min-height: var(--tap);
}
.peers li:hover { background: var(--panel-2); }
.peers li.active { background: var(--accent-soft); }
.peers li > .av { grid-area: avatar; }
.peers .peer-name { grid-area: name; font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.peers .peer-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peers .peer-sub { grid-area: sub; color: var(--muted); font-size: 12.8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peers .peer-meta { grid-area: meta; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 11px; color: var(--faint); }
.peers li.empty { display: block; color: var(--muted); font-size: 13px; padding: 16px 12px; cursor: default; line-height: 1.5; }
.peers li.empty:hover { background: transparent; }
.sidebar-foot { padding: 8px; border-top: 1px solid var(--line); display: flex; gap: 6px; }
.sidebar-foot .btn { flex: 1; min-width: 0; }

/* --- avatars ---------------------------------------------------------- */

.av, .avatar {
  --avatar-size: 44px; width: var(--avatar-size); height: var(--avatar-size);
  border-radius: calc(var(--avatar-size) / 2.9); flex: none; display: grid; place-items: center;
  font-weight: 800; color: #fff; overflow: hidden; position: relative;
  background: linear-gradient(140deg, var(--accent), var(--teal));
}
.av-sm { --avatar-size: 32px; }
.avatar.big { --avatar-size: 112px; margin: 0 auto 12px; }
.av img, .avatar img { width: 100%; height: 100%; object-fit: cover; }
.av::after, .avatar::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); }

/* --- main pane -------------------------------------------------------- */

#main { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
@media (max-width: 719px) {
  #app:not(.detail-open) #main { display: none; }
  #app.detail-open #sidebar { display: none; }
}
.pane-head {
  min-height: 60px; padding: calc(9px + var(--safe-top)) 12px 9px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; min-width: 0;
}
.pane-head .who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: none; padding: 0; text-align: left; color: inherit; }
.pane-head .who-text { min-width: 0; display: flex; flex-direction: column; }
.pane-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-actions { display: flex; gap: 2px; align-items: center; flex: none; }
.pane-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 18px calc(20px + var(--safe-bottom)); }
.pane-body.narrow { max-width: 640px; width: 100%; margin: 0 auto; }
.pane-body.ground { background: var(--ground), var(--bg); padding: 16px 12px 8px; }
.pane-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 32px; }
.pane-empty .icon { color: var(--faint); margin-bottom: 8px; }
.pane-empty p { max-width: 320px; line-height: 1.5; margin: 0; }
.pane-empty .btn { margin-top: 14px; }
.mobile-only { display: none; }
@media (max-width: 719px) { .mobile-only { display: grid; } }

/* --- grouped lists (the phone-settings shape) ------------------------- */

.tg-hero { text-align: center; padding: 8px 12px 20px; }
.tg-hero-name { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.tg-hero-sub { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.tg-hero-sub:empty { display: none; }
.tg-hero .btn { margin-top: 14px; }
.tg-group { background: var(--panel); border-radius: var(--r-l); overflow: hidden; margin-top: 14px; }
.tg-group.fields { padding: 6px 16px; }
.tg-row {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 10px 16px;
  background: transparent; border: none; border-radius: 0; text-align: left; color: inherit; font: inherit; text-decoration: none;
}
.tg-row + .tg-row { box-shadow: inset 0 1px 0 var(--line); }
button.tg-row:hover, label.tg-row:hover, a.tg-row:hover { background: var(--panel-2); }
.tg-row.static { cursor: default; }
.tg-row.action.accent { color: var(--accent); font-weight: 600; }
.tg-row.danger { color: var(--danger); }
.tg-ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none; color: #fff; }
.tg-ic .icon { width: 18px; height: 18px; }
.tg-ic.blue { background: #3e88f7; }
.tg-ic.green { background: #4cae4f; }
.tg-ic.red { background: #e0564f; }
.tg-ic.violet { background: #7e6ce0; }
.tg-ic.orange { background: #dd9b3c; }
.tg-ic.grey { background: #7c8f9f; }
.tg-ic.teal { background: var(--teal); color: #04201d; }
.tg-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.tg-text b { font-weight: 500; overflow-wrap: anywhere; }
.tg-text i { font-style: normal; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.tg-text i:empty { display: none; }
.tg-text code { font-family: var(--mono); font-size: 12px; }
.tg-row.switch { justify-content: space-between; cursor: pointer; }
.tg-row.switch input { margin: 0; flex: none; width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.tg-chev { color: var(--faint); flex: none; display: grid; }
.tg-field { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; }
.tg-field + .tg-field { box-shadow: inset 0 1px 0 var(--line); }
.tg-field span { font-size: 12px; color: var(--accent); }
.tg-field input, .tg-field textarea, .tg-field select { margin: 0; border: none; background: transparent; padding: 2px 0; min-height: 32px; border-radius: 0; }
.tg-field input:focus, .tg-field textarea:focus { outline: none; }
.tg-field textarea { min-height: 64px; }
.tg-note { color: var(--muted); font-size: 12.5px; margin: 8px 4px 0; line-height: 1.5; }
.tg-value { color: var(--muted); font-size: 13px; flex: none; }
.avatar-edit { background: transparent; border: none; padding: 0; display: grid; gap: 4px; justify-items: center; min-height: 0; margin-inline: auto; }
.avatar-edit-hint { font-size: 11px; color: var(--muted); }

/* --- channel: posts ---------------------------------------------------- */

.posts { list-style: none; margin: 0 auto; padding: 0; display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.post {
  background: var(--bubble-in); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden;
  font-size: 14.2px; line-height: 1.42;
}
.post-media { display: grid; gap: 2px; background: var(--bg); }
.post-media[data-count='2'], .post-media[data-count='3'], .post-media[data-count='4'] { grid-template-columns: 1fr 1fr; }
.post-media[data-count='3'] .post-cell:first-child { grid-column: span 2; }
.post-cell { padding: 0; border: none; background: var(--panel-2); display: grid; place-items: center; min-height: 0; overflow: hidden; cursor: zoom-in; aspect-ratio: 4 / 3; color: var(--muted); }
.post-media[data-count='1'] .post-cell { aspect-ratio: auto; max-height: 70vh; }
.post-cell img, .post-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-media[data-count='1'] .post-cell img, .post-media[data-count='1'] .post-cell video { height: auto; max-height: 70vh; object-fit: contain; background: #000; }
.post-cell.waiting { cursor: default; }
.post-cell video { cursor: default; }
.post-file { display: flex; align-items: center; gap: 12px; padding: 10px 14px 0; color: inherit; text-decoration: none; }
.post-file .tg-ic { border-radius: 10px; }
.post-file b { display: block; font-weight: 600; overflow-wrap: anywhere; }
.post-file i { font-style: normal; font-size: 12px; color: var(--muted); }
.post-text { padding: 10px 14px 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.post-text:empty { display: none; }
.post-text a { color: var(--accent); text-decoration: none; }
.post-text a:hover { text-decoration: underline; }
.post-links { padding: 4px 14px 0; display: flex; flex-direction: column; gap: 6px; }
.post-link { display: block; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 6px; font-size: 13px; text-decoration: none; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-foot { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; color: var(--faint); font-size: 11.5px; }
.post-foot .grow { flex: 1; }
.post-foot .stat { display: inline-flex; align-items: center; gap: 4px; }
.post-foot .iconbtn { width: 32px; height: 32px; min-width: 32px; min-height: 32px; border-radius: 10px; }
.post-edited { font-style: italic; }
.day { text-align: center; margin: 6px 0 2px; }
.day span { display: inline-block; background: var(--panel); color: var(--muted); border-radius: 999px; padding: 3px 10px; font-size: 11.5px; box-shadow: var(--shadow); }
.newpost-bar { padding: 8px 12px calc(8px + var(--safe-bottom)); background: var(--panel); border-top: 1px solid var(--line); display: flex; gap: 8px; }
.newpost-bar .btn { flex: 1; }

/* --- composer ---------------------------------------------------------- */

.composer-card { background: var(--panel); border-radius: var(--r-l); padding: 14px 16px; }
.composer-card textarea { background: transparent; border: none; padding: 4px 0; min-height: 120px; font-size: 15px; margin: 0; }
.composer-card textarea:focus { outline: none; }
.staged { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.staged-item { position: relative; width: 88px; height: 88px; border-radius: 12px; overflow: hidden; background: var(--panel-2); display: grid; place-items: center; color: var(--muted); font-size: 11px; text-align: center; padding: 4px; }
.staged-item img, .staged-item video { width: 100%; height: 100%; object-fit: cover; }
.staged-item .remove { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; min-width: 0; min-height: 0; border-radius: 999px; background: rgba(0, 0, 0, .55); color: #fff; }
.composer-tools { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.composer-tools .grow { flex: 1; }
.progress { height: 4px; border-radius: 4px; background: var(--panel-3); overflow: hidden; margin-top: 10px; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--teal)); transition: width .2s; }

/* --- search / results -------------------------------------------------- */

.result { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-m); cursor: pointer; }
.result:hover { background: var(--panel-2); }
.result .tg-text b { font-weight: 700; }
.results { list-style: none; margin: 0; padding: 0; background: var(--panel); border-radius: var(--r-l); overflow: hidden; margin-top: 14px; }
.results li + li { box-shadow: inset 0 1px 0 var(--line); }

/* --- misc -------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; top: calc(74px + var(--safe-top)); transform: translateX(-50%);
  border-radius: 999px; background: var(--text); color: var(--bg); border: none; font-weight: 700;
  padding: 10px 16px; z-index: 80; max-width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg);
}
.toast.bad { background: var(--danger); color: #fff; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 60; display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.lightbox-close { position: absolute; top: calc(12px + var(--safe-top)); right: 12px; color: #fff; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; vertical-align: 1px; }
.brand-mark { display: block; border-radius: 50%; }
h1 .brand-mark { display: inline-block; }
.rail-logo { display: grid; }
.meter { height: 8px; border-radius: 8px; background: var(--panel-3); overflow: hidden; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--teal)); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
