:root {
  --bg: #ffffff;
  --bg2: #fafafa;
  --card: #ffffff;
  --text: #121212;
  --muted: #737373;
  --line: #dbdbdb;
  --chip: #efefef;
  --blue: #0095f6;
  --blue-d: #1877f2;
  --red: #ed4956;
  --grad: linear-gradient(45deg, #fcb045 0%, #fd1d1d 50%, #833ab4 100%);
  --tab-h: 54px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #000000;
    --bg2: #0b0b0b;
    --card: #000000;
    --text: #f5f5f5;
    --muted: #a8a8a8;
    --line: #262626;
    --chip: #1c1c1c;
  }
}
:root[data-theme='dark'] {
  --bg: #000000;
  --bg2: #0b0b0b;
  --card: #000000;
  --text: #f5f5f5;
  --muted: #a8a8a8;
  --line: #262626;
  --chip: #1c1c1c;
  color-scheme: dark;
}
:root[data-theme='light'] { color-scheme: light; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.fill { fill: currentColor; }

/* ---------- przyciski / pola ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--blue); color: #fff; border-radius: 8px; padding: 7px 16px; font-weight: 600; min-height: 32px;
}
.btn:active { opacity: .75; }
.btn.block { display: flex; width: 100%; padding: 10px 16px; }
.btn.secondary { background: var(--chip); color: var(--text); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--line); }
.btn.sm { padding: 5px 12px; min-height: 28px; font-size: 13px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.linkbtn { color: var(--blue); font-weight: 600; }
.field { display: block; margin: 0 0 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=search], textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--muted); }
textarea { resize: vertical; min-height: 84px; }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--muted);
  animation: spin .8s linear infinite; margin: 18px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.02em; }
.logo .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; color: #fff; }
.logo .mark svg { width: 18px; height: 18px; stroke-width: 2.6; }
.logo .word { font-size: 22px; font-style: italic; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- logowanie ---------- */
.auth { min-height: 100%; display: grid; grid-template-columns: 1fr; place-items: center; padding: 24px 16px; gap: 20px; }
.auth-hero { max-width: 380px; text-align: center; }
.auth-hero .logo .word { font-size: 40px; }
.auth-hero .logo .mark { width: 52px; height: 52px; border-radius: 15px; }
.auth-hero .logo .mark svg { width: 30px; height: 30px; }
.auth-hero p { color: var(--muted); }
.auth-hero ul { list-style: none; padding: 0; margin: 14px 0 0; text-align: left; display: inline-block; }
.auth-hero li { display: flex; gap: 8px; align-items: center; margin: 7px 0; color: var(--muted); }
.auth-hero li svg { width: 18px; height: 18px; color: #1fa971; }
.auth-card { width: 100%; max-width: 350px; border: 1px solid var(--line); border-radius: 12px; padding: 24px; background: var(--card); }
.auth-card h2 { margin: 0 0 6px; font-size: 20px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }
.steps { padding-left: 18px; color: var(--muted); }
.steps li { margin: 6px 0; }
.code { font-size: 44px; letter-spacing: .25em; font-weight: 800; text-align: center; padding: 10px 0 0 .25em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tabs2 { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs2 button { flex: 1; padding: 7px; border-radius: 8px; background: var(--chip); font-weight: 600; font-size: 13px; }
.tabs2 button.on { background: var(--text); color: var(--bg); }
@media (min-width: 860px) {
  .auth { grid-template-columns: 1fr 1fr; max-width: 920px; margin: 0 auto; }
}
html.embedded .auth { grid-template-columns: 1fr; padding-top: 12px; }
html.embedded .auth-hero ul, html.embedded .auth-hero p { display: none; }

/* ---------- powloka ---------- */
.shell { display: flex; min-height: 100%; }
.side {
  display: none; position: sticky; top: 0; height: 100vh; width: 244px; flex: none;
  border-right: 1px solid var(--line); padding: 18px 12px; flex-direction: column; gap: 4px;
}
.side .logo { padding: 8px 12px 20px; }
.side a, .side button.navitem {
  display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 10px; font-size: 15px; width: 100%; text-align: left; position: relative;
}
.side a:hover, .side button.navitem:hover { background: var(--chip); }
.side a.on { font-weight: 800; }
.side .grow { flex: 1; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
main#view { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding-bottom: calc(var(--tab-h) + 8px + env(safe-area-inset-bottom)); }
main#view.wide { max-width: 940px; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; min-height: 48px;
}
.topbar .icons { display: flex; gap: 14px; align-items: center; }
.topbar h1 { margin: 0; font-size: 16px; font-weight: 700; }
.topbar .back { margin-right: 10px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg); border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: center;
}
.tabbar a { flex: 1; display: grid; place-items: center; height: var(--tab-h); position: relative; }
.tabbar a.on svg { stroke-width: 2.8; }
.badge {
  position: absolute; top: 4px; right: calc(50% - 20px); background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px; display: grid; place-items: center; padding: 0 4px;
}
.side .badge { top: 8px; right: auto; left: 28px; }
@media (min-width: 860px) {
  .side { display: flex; }
  .tabbar, .topbar.mobile-only { display: none; }
  main#view { padding-bottom: 40px; }
}
html.embedded .side { display: none; }
html.embedded .tabbar, html.embedded .topbar.mobile-only { display: flex; }
html.embedded main#view { max-width: none; }

/* ---------- avatar ---------- */
.av { width: 32px; height: 32px; border-radius: 50%; background: var(--chip); object-fit: cover; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; overflow: hidden; font-size: 13px; }
.av.lg { width: 82px; height: 82px; font-size: 30px; }
.av.md { width: 44px; height: 44px; font-size: 17px; }
.av.ring { padding: 2px; background: var(--grad); }
.av img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ---------- tablica ---------- */
.post { border-bottom: 1px solid var(--line); background: var(--card); padding-bottom: 6px; margin-bottom: 4px; }
.post-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.post-head .who { font-weight: 700; }
.post-head .when { color: var(--muted); font-weight: 400; margin-left: 6px; }
.post-head .more { margin-left: auto; color: var(--muted); }
.post-media { position: relative; background: var(--chip); aspect-ratio: 1 / 1; overflow: hidden; display: grid; place-items: center; }
.post-media.reel { aspect-ratio: 4 / 5; }
.post-media img, .post-media video { width: 100%; height: 100%; object-fit: cover; }
.post-media .pop { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; color: #fff; opacity: 0; }
.post-media .pop svg { width: 90px; height: 90px; filter: drop-shadow(0 2px 10px rgba(0,0,0,.4)); }
.post-media .pop.go { animation: pop .8s ease; }
@keyframes pop { 0% { opacity: 0; transform: scale(.4); } 25% { opacity: 1; transform: scale(1.1); } 60% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1); } }
.post-bar { display: flex; gap: 16px; padding: 10px 12px 4px; align-items: center; }
.post-bar button { display: flex; align-items: center; }
.post-bar .liked { color: var(--red); }
.post-bar .liked svg { fill: var(--red); }
.post-body { padding: 0 12px; }
.post-body .likes { font-weight: 700; }
.post-body .cap b { margin-right: 6px; }
.post-body a.tag, .cap a.tag { color: var(--blue-d); }
.post-body .viewc { color: var(--muted); display: block; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 60px 24px; }
.empty .big { width: 64px; height: 64px; margin: 0 auto 14px; border: 2px solid var(--text); border-radius: 50%; display: grid; place-items: center; color: var(--text); }
.empty .big svg { width: 30px; height: 30px; }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 20px; }

.sugg { display: flex; gap: 10px; overflow-x: auto; padding: 10px 12px 14px; }
.sugg .card { flex: none; width: 150px; border: 1px solid var(--line); border-radius: 10px; padding: 14px 10px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.sugg .card .nm { font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- siatka ---------- */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.tile { position: relative; aspect-ratio: 1 / 1; background: var(--chip); overflow: hidden; display: block; width: 100%; }
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; }
.tile .corner { position: absolute; top: 6px; right: 6px; color: #fff; filter: drop-shadow(0 1px 3px rgba(0,0,0,.6)); }
.tile .corner svg { width: 18px; height: 18px; }
.tile .count { position: absolute; left: 6px; bottom: 6px; color: #fff; font-size: 12px; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,.7); display: none; align-items: center; gap: 4px; }
@media (hover: hover) { .tile:hover .count { display: flex; } }
.tile.audio { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 8px; padding: 8px; }

/* ---------- wyszukiwarka ---------- */
.searchbar { position: sticky; top: 0; z-index: 15; background: var(--bg); padding: 10px 12px; }
.searchbar input { border-radius: 10px; background: var(--chip); border: 0; padding: 10px 14px; }
.sec-title { padding: 10px 14px 6px; font-weight: 700; }
.ulist { display: flex; flex-direction: column; }
.urow { display: flex; align-items: center; gap: 12px; padding: 8px 14px; }
.urow .meta { flex: 1; min-width: 0; }
.urow .meta .h { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.urow .meta .n { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- rolki ---------- */
.reels-wrap { position: fixed; inset: 0; z-index: 40; background: #000; }
.reels { height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none; }
.reels::-webkit-scrollbar { display: none; }
.reel { position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; display: grid; place-items: center; background: #000; }
.reel video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.reel .shade { position: absolute; left: 0; right: 0; bottom: 0; height: 40%; background: linear-gradient(transparent, rgba(0,0,0,.65)); pointer-events: none; }
.reel .info { position: absolute; left: 14px; right: 76px; bottom: calc(var(--tab-h) + 14px + env(safe-area-inset-bottom)); color: #fff; }
.reel .info .u { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 8px; }
.reel .info .c { font-size: 13.5px; max-height: 4.2em; overflow: hidden; }
.reel .side-actions { position: absolute; right: 10px; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px; align-items: center; color: #fff; }
.reel .side-actions button { display: flex; flex-direction: column; align-items: center; gap: 2px; color: #fff; font-size: 12px; font-weight: 600; }
.reel .side-actions svg { width: 30px; height: 30px; filter: drop-shadow(0 1px 4px rgba(0,0,0,.6)); }
.reel .side-actions .liked svg { fill: var(--red); stroke: var(--red); }
.reel .playicon { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; pointer-events: none; opacity: 0; transition: opacity .2s; }
.reel .playicon svg { width: 80px; height: 80px; }
.reel.paused .playicon { opacity: .85; }
.reels-top { position: absolute; top: 0; left: 0; right: 0; z-index: 3; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; color: #fff; font-weight: 800; font-size: 20px; pointer-events: none; }
.reels-top button { pointer-events: auto; color: #fff; }
.reels-top svg { filter: drop-shadow(0 1px 4px rgba(0,0,0,.6)); }
@media (min-width: 860px) {
  .reels-wrap { left: 244px; }
  .reel video { max-width: 440px; }
  .reel .info { left: calc(50% - 220px + 14px); right: auto; width: 340px; }
  .reel .side-actions { right: calc(50% - 220px - 60px); }
  .reel .shade { display: none; }
}
html.embedded .reels-wrap { left: 0; }

/* ---------- profil ---------- */
.prof-head { display: flex; gap: 22px; padding: 18px 14px 8px; align-items: center; }
.prof-stats { display: flex; gap: 22px; flex: 1; justify-content: space-around; text-align: center; }
.prof-stats button, .prof-stats div { display: block; }
.prof-stats b { display: block; font-size: 17px; }
.prof-stats span { color: var(--muted); font-size: 13px; }
.prof-bio { padding: 4px 14px 10px; }
.prof-bio .nm { font-weight: 700; }
.prof-bio .bio { white-space: pre-wrap; }
.prof-actions { display: flex; gap: 8px; padding: 0 14px 14px; }
.prof-actions .btn { flex: 1; }
.seg { display: flex; border-top: 1px solid var(--line); }
.seg button { flex: 1; padding: 12px; display: grid; place-items: center; color: var(--muted); border-top: 1px solid transparent; margin-top: -1px; }
.seg button.on { color: var(--text); border-top-color: var(--text); }

/* ---------- aktywnosc / DM ---------- */
.act { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.act .txt { flex: 1; min-width: 0; }
.act .thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; flex: none; background: var(--chip); }
.thread { display: flex; align-items: center; gap: 12px; padding: 10px 14px; width: 100%; text-align: left; }
.thread:active { background: var(--chip); }
.thread .meta { flex: 1; min-width: 0; }
.thread .meta .h { font-weight: 600; }
.thread .meta .l { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread.unread .meta .h, .thread.unread .meta .l { font-weight: 800; color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue); flex: none; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 48px); }
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.bub { max-width: 76%; padding: 8px 12px; border-radius: 18px; background: var(--chip); align-self: flex-start; word-break: break-word; white-space: pre-wrap; }
.bub.me { align-self: flex-end; background: var(--blue); color: #fff; }
.bub.media { padding: 4px; background: transparent; }
.bub.media.me { background: transparent; }
.bub img, .bub video { border-radius: 14px; max-width: 240px; max-height: 300px; }
.bub .t { display: block; font-size: 10.5px; opacity: .65; margin-top: 2px; }
.bub audio { width: 230px; max-width: 100%; height: 38px; }
.composer { display: flex; align-items: center; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.composer input { border-radius: 22px; background: var(--chip); border: 0; padding: 10px 14px; flex: 1; }
.composer button { color: var(--blue); font-weight: 700; display: grid; place-items: center; }
html.embedded .chat { height: calc(100vh - 48px - var(--tab-h)); }
.attach-chip { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--chip); font-size: 13px; }
.attach-chip button { margin-left: auto; color: var(--muted); }

/* ---------- tworzenie / pliki ---------- */
.create { padding: 14px; }
.create .types { display: flex; gap: 8px; margin-bottom: 14px; }
.create .types button { flex: 1; padding: 10px; border-radius: 10px; background: var(--chip); font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.create .types button.on { background: var(--text); color: var(--bg); }
.preview { aspect-ratio: 1 / 1; background: var(--chip); border-radius: 10px; overflow: hidden; display: grid; place-items: center; margin-bottom: 12px; color: var(--muted); text-align: center; padding: 12px; }
.preview.reel { aspect-ratio: 9 / 14; max-height: 60vh; margin-inline: auto; }
.preview img, .preview video { width: 100%; height: 100%; object-fit: cover; }
.row2 { display: flex; gap: 8px; margin-bottom: 12px; }
.row2 .btn { flex: 1; }
.fileitem { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.fileitem .th { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; background: var(--chip); flex: none; display: grid; place-items: center; overflow: hidden; color: var(--muted); }
.fileitem .th img, .fileitem .th video { width: 100%; height: 100%; object-fit: cover; }
.fileitem .meta { flex: 1; min-width: 0; }
.fileitem .meta .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fileitem .acts { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 13px; }
.fileitem audio { width: 100%; height: 34px; margin-top: 4px; }
.quota { height: 6px; border-radius: 3px; background: var(--chip); margin: 4px 14px 10px; overflow: hidden; }
.quota i { display: block; height: 100%; background: var(--grad); }
.rec { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--chip); margin: 0 14px 10px; border-radius: 10px; }
.rec .led { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- modal ---------- */
#modals .overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
#modals .sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; }
#modals .sheet.tall { height: 92vh; }
@media (min-width: 700px) {
  #modals .overlay { align-items: center; }
  #modals .sheet { border-radius: 14px; max-height: 88vh; }
  #modals .sheet.tall { height: auto; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 700; position: sticky; top: 0; background: var(--card); z-index: 2; }
.sheet-body { padding: 0; }
.cmt { display: flex; gap: 10px; padding: 8px 14px; }
.cmt .b { flex: 1; min-width: 0; word-break: break-word; }
.cmt .b b { margin-right: 6px; }
.cmt .x { color: var(--muted); }
.cmt-form { display: flex; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--card); }
.cmt-form input { flex: 1; border-radius: 20px; background: var(--chip); border: 0; }
.menu-list button { display: block; width: 100%; text-align: center; padding: 14px; border-top: 1px solid var(--line); }
.menu-list button.red { color: var(--red); font-weight: 700; }
.picker-grid { padding: 2px; }

/* ---------- toast ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-size: 13.5px; font-weight: 600; max-width: 90%; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: tin .2s ease; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
