:root {
  --blue: #0B3D91;
  --blue-deep: #072A66;
  --blue-darker: #051d47;
  --blue-2: #1450B8;
  --blue-line: rgba(255, 255, 255, .12);
  --orange: #FF7A1A;
  --orange-2: #FF9A4D;
  --text: #ffffff;
  --muted: #A9BDE6;
  --danger: #ff6b6b;
  --ok: #7CE3A1;
  --radius: 14px;
  --tabbar-h: 62px;
  --topbar-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--blue-darker); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4; overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .55; cursor: default; }
img, video { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
[hidden] { display: none !important; }

#app {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
  background: linear-gradient(180deg, var(--blue) 0%, var(--blue-deep) 100%);
  position: relative; overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  flex: 0 0 auto; height: calc(var(--topbar-h) + var(--safe-t)); padding: var(--safe-t) 8px 0;
  display: flex; align-items: center; gap: 6px;
  background: var(--blue); border-bottom: 1px solid var(--blue-line);
}
#title { font-size: 19px; font-weight: 800; padding-left: 6px; flex: 1; text-align: center; }
.topbar-spacer { width: 40px; }
#backBtn { font-size: 34px; line-height: 1; width: 40px; }
body.feed-mode #topbar, body.auth-mode #topbar { display: none; }

/* ---------- main view ---------- */
#view { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }

/* ---------- tab bar ---------- */
#tabbar {
  flex: 0 0 auto; height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; align-items: stretch; justify-content: space-around;
  background: var(--blue-darker); border-top: 1px solid var(--blue-line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted); position: relative; }
.tab .ico svg { width: 24px; height: 24px; fill: currentColor; }
.tab.active { color: var(--orange); }
.tab-plus .plus-box { width: 50px; height: 34px; border-radius: 11px; background: var(--orange); color: #fff;
  font-size: 28px; font-weight: 700; line-height: 34px; text-align: center; box-shadow: 0 0 0 3px rgba(255, 122, 26, .25); }
.badge { position: absolute; top: 6px; right: 22%; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--orange); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }

/* ---------- generic ---------- */
.pad { padding: 14px; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > .input { flex: 1; min-width: 0; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }
.section-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px; }
.section-h h3 { font-size: 16px; }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; background: rgba(255, 122, 26, .16); color: var(--orange-2); font-size: 13px; font-weight: 600; }

.ico { display: inline-flex; }
.ico svg { width: 22px; height: 22px; fill: currentColor; }

.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--blue-line);
  background: rgba(5, 29, 71, .55); color: var(--text); outline: none; font-size: 16px;
}
.input::placeholder { color: #7f96c6; }
.input:focus { border-color: var(--orange); }
select.input { appearance: none; -webkit-appearance: none; }
select.input option { background: var(--blue-deep); }
textarea.input { resize: vertical; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 16px;
  border-radius: 12px; font-weight: 700; white-space: nowrap; }
.btn.block { width: 100%; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-orange:active { background: #e86a0f; }
.btn-blue { background: var(--blue-2); color: #fff; }
.btn-ghost { background: rgba(255, 255, 255, .08); color: #fff; border: 1px solid var(--blue-line); }
.btn-link { color: var(--orange-2); font-weight: 600; padding: 8px; }
.btn-link .ico svg { width: 16px; height: 16px; }
.btn-small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 20px; color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn.small { width: 28px; height: 28px; font-size: 14px; }

.avatar { border-radius: 50%; object-fit: cover; background: var(--blue-2); }
.avatar-fallback { display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--orange), var(--blue-2)); }

.progress { display: flex; flex-direction: column; gap: 6px; }
.progress-track { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.progress-track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--orange), var(--orange-2)); transition: width .2s; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px);
  max-width: min(92vw, 520px); padding: 11px 16px; border-radius: 12px; background: #fff; color: var(--blue-deep);
  font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- overlay / sheets ---------- */
#overlay { position: fixed; inset: 0; z-index: 50; }
#overlay .backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
#overlay .sheet {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 560px; max-height: 82vh;
  display: flex; flex-direction: column; background: var(--blue-deep); border-radius: 20px 20px 0 0;
  border-top: 3px solid var(--orange); padding-bottom: var(--safe-b); animation: up .2s ease-out;
}
@keyframes up { from { transform: translate(-50%, 40px); opacity: .4; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 6px 16px; }
.sheet-body { padding: 6px 16px 16px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; min-height: 0; }
.sheet-list { max-height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.composer-row { position: sticky; bottom: 0; }
.comment { display: flex; gap: 10px; align-items: flex-start; }
.comment p { word-break: break-word; }
#overlay.full-mode { background: #000; }

/* ---------- auth ---------- */
.auth { padding: calc(40px + var(--safe-t)) 22px 24px; display: flex; flex-direction: column; gap: 10px; }
.auth-logo { width: 92px; height: 92px; margin: 0 auto 4px; border-radius: 22px; box-shadow: 0 10px 30px rgba(255, 122, 26, .3); }
.auth h2 { font-size: 32px; font-weight: 900; color: var(--orange); }
.auth .stack { margin-top: 18px; }

/* ---------- feed ---------- */
#view.feed { padding: 0; scroll-snap-type: y mandatory; background: #000; scrollbar-width: none; }
#view.feed::-webkit-scrollbar { display: none; }
.feed-logo { position: absolute; top: calc(10px + var(--safe-t)); left: 0; right: 0; text-align: center; z-index: 5;
  font-weight: 900; font-size: 20px; color: var(--orange); text-shadow: 0 1px 6px rgba(0, 0, 0, .6); pointer-events: none; }
.feed-card { position: relative; height: 100%; width: 100%; scroll-snap-align: start; scroll-snap-stop: always; background: #000; overflow: hidden; }
.feed-video { width: 100%; height: 100%; object-fit: cover; }
.play-ind { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 64px; color: rgba(255, 255, 255, .8); pointer-events: none; }
.feed-meta { position: absolute; left: 0; right: 74px; bottom: 0; padding: 40px 14px 16px;
  background: linear-gradient(transparent, rgba(5, 29, 71, .85)); pointer-events: none; }
.feed-user { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.feed-caption { font-size: 15px; word-break: break-word; max-height: 6.5em; overflow: hidden; }
.rail { position: absolute; right: 8px; bottom: 18px; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.rail-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; color: #fff; font-size: 12px; font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
.rail-btn .ico { width: 46px; height: 46px; border-radius: 50%; background: rgba(11, 61, 145, .7); align-items: center; justify-content: center; }
.rail-btn .ico svg { width: 26px; height: 26px; }
.rail-btn.like.on .ico { background: var(--orange); }
.feed-sentinel { height: 1px; }
.feed-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center;
  background: linear-gradient(180deg, var(--blue), var(--blue-deep)); scroll-snap-align: start; }

/* ---------- upload ---------- */
.upload-preview { width: 100%; max-height: 50vh; border-radius: var(--radius); background: #000; }

/* ---------- stories ---------- */
.stories-row { display: flex; gap: 14px; overflow-x: auto; padding: 4px 14px 8px; scrollbar-width: none; }
.stories-row::-webkit-scrollbar { display: none; }
.story-bubble { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 70px; flex: 0 0 auto; }
.story-ring { position: relative; padding: 3px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .2); }
.story-ring.has { border-color: var(--orange); }
.story-plus { position: absolute; right: -2px; bottom: -2px; width: 24px; height: 24px; border-radius: 50%; background: var(--orange);
  color: #fff; font-weight: 800; line-height: 22px; text-align: center; border: 2px solid var(--blue); }
.story-name { font-size: 12px; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-viewer { position: absolute; inset: 0; max-width: 560px; margin: 0 auto; background: #000; }
.story-media { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.story-media img, .story-media video { width: 100%; height: 100%; object-fit: contain; }
.story-tap { position: absolute; top: 70px; bottom: 80px; width: 40%; z-index: 2; }
.story-tap.left { left: 0; } .story-tap.right { right: 0; width: 60%; }
.story-bars { position: absolute; top: calc(8px + var(--safe-t)); left: 8px; right: 8px; display: flex; gap: 4px; z-index: 3; }
.story-bars .bar { flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .3); overflow: hidden; }
.story-bars .bar i { display: block; height: 100%; background: #fff; }
.story-head { position: absolute; top: calc(20px + var(--safe-t)); left: 12px; right: 56px; display: flex; align-items: center; gap: 8px; z-index: 3;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
.story-close { position: absolute; top: calc(14px + var(--safe-t)); right: 8px; z-index: 4; }
.story-foot { position: absolute; bottom: calc(16px + var(--safe-b)); left: 12px; right: 12px; display: flex; gap: 8px; justify-content: flex-end; z-index: 4; }

/* ---------- conversations / dm ---------- */
.convo-list { display: flex; flex-direction: column; }
.convo { display: flex; gap: 12px; align-items: center; padding: 10px 14px; text-align: left; width: 100%; border-bottom: 1px solid var(--blue-line); }
.convo:active { background: rgba(255, 255, 255, .05); }
.convo-text { min-width: 0; flex: 1; }
#view.dm { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.msg-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 16px; word-break: break-word; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; background: var(--orange); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--blue-2); border-bottom-left-radius: 4px; }
.msg-time { font-size: 10px; opacity: .75; margin-top: 2px; text-align: right; }
.msg-listing { font-size: 12px; font-weight: 700; text-decoration: underline; padding: 0 0 4px; }
.composer { padding: 8px 10px calc(8px + var(--safe-b)); border-top: 1px solid var(--blue-line); background: var(--blue-deep); display: flex; flex-direction: column; gap: 6px; }
.msg-input { max-height: 120px; resize: none; }
.listing-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 10px;
  background: rgba(255, 122, 26, .16); color: var(--orange-2); font-size: 13px; font-weight: 600; }

/* ---------- marketplace ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 0 14px 14px; }
.card { text-align: left; background: rgba(5, 29, 71, .6); border: 1px solid var(--blue-line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card-img { position: relative; aspect-ratio: 1 / 1; background: var(--blue-darker); }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.card-title { font-size: 14px; }
.price { color: var(--orange); font-weight: 800; }
.price.big { font-size: 28px; }
.noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 40px; }
.noimg.big { font-size: 80px; }
.sold-badge { position: absolute; top: 8px; left: 8px; padding: 3px 8px; border-radius: 6px; background: var(--danger); color: #fff; font-size: 12px; font-weight: 800; }
.sold-badge.big { font-size: 16px; top: 12px; left: 12px; }
.carousel-wrap { position: relative; }
.carousel { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; aspect-ratio: 1 / 1; background: #000; scrollbar-width: none; }
.carousel::-webkit-scrollbar { display: none; }
.carousel > * { flex: 0 0 100%; width: 100%; height: 100%; object-fit: contain; scroll-snap-align: start; }
.carousel-count { position: absolute; bottom: 10px; right: 10px; padding: 3px 9px; border-radius: 999px; background: rgba(0, 0, 0, .55); font-size: 12px; }
.item-title { font-size: 22px; word-break: break-word; }
.item-desc { white-space: pre-wrap; word-break: break-word; color: #dfe8fb; }
.seller { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: var(--radius); background: rgba(5, 29, 71, .5); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.thumb { position: relative; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0, 0, 0, .65); color: #fff; font-size: 12px; }

/* ---------- profile ---------- */
.profile-top { display: flex; gap: 16px; align-items: center; }
.profile-top .stack { gap: 4px; align-items: flex-start; min-width: 0; }
.profile-avatar .avatar { border: 3px solid var(--orange); }
.big-name { font-size: 20px; word-break: break-all; }
.vid-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; padding: 0 14px; }
.vid-tile { aspect-ratio: 9 / 16; background: #000; border-radius: 6px; overflow: hidden; }
.vid-tile video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.player { position: absolute; inset: 0; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; background: #000; }
.player video { flex: 1; width: 100%; min-height: 0; object-fit: contain; }
.player-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px calc(10px + var(--safe-b)); background: var(--blue-deep); }

@media (min-width: 561px) {
  #app { box-shadow: 0 0 40px rgba(0, 0, 0, .5); }
}

/* File picker buttons: invisible input layered over the button */
.file-btn { position: relative; overflow: hidden; cursor: pointer; }
.file-btn .file-overlay { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 100px; z-index: 2; }
.file-btn.is-disabled { opacity: .55; pointer-events: none; }

/* Delete button on profile video tiles */
.vid-tile { position: relative; cursor: pointer; }
.tile-del { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 16px; display: flex; align-items: center; justify-content: center; z-index: 2; }
.tile-del:active { background: var(--orange); }

/* In-app confirm dialog */
.confirm-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 24px; }
.confirm-box { background: var(--blue-2, #0B3D91); color: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 340px; }
.confirm-msg { margin: 0 0 16px; font-size: 16px; line-height: 1.4; }
