/* User app (Telegram Mini App). Mobile-first. */
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
main { max-width: 560px; margin: 0 auto; padding: 4px 16px 24px; }
.tab > h2 { margin: 8px 0 12px; }
.tab > .lead { margin: -4px 0 16px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; max-width: 560px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; letter-spacing: -.02em; font-weight: 800; }
.brand .mark { width: 28px; height: 28px; border-radius: 9px; }
.brand .brand-logo { width: 28px; height: 28px; border-radius: 8px; object-fit: contain; }
.brand .mark::before { filter: blur(3px); }
#langChip { padding: 6px 12px; font-size: 13px; }

/* ---- Studio viewfinder: the one showpiece ---- */
.stage { display: grid; place-items: center; height: 352px; margin: 4px 0 6px; }
.frame { position: relative; border-radius: 20px; box-shadow: var(--shadow); color: #fff;
  transition: width .55s var(--ease), height .55s var(--ease); display: grid; place-items: center; padding: 22px 18px; }
.frame.p { width: 198px; height: 352px; }
.frame.l { width: min(340px, calc(100vw - 32px)); height: 191px; }
.frame .m { position: absolute; width: 16px; height: 16px; border: 0 solid rgba(255, 255, 255, .9); pointer-events: none; }
.frame .m.tl { left: 10px; top: 10px; border-left-width: 2px; border-top-width: 2px; border-top-left-radius: 5px; }
.frame .m.tr { right: 10px; top: 10px; border-right-width: 2px; border-top-width: 2px; border-top-right-radius: 5px; }
.frame .m.bl { left: 10px; bottom: 10px; border-left-width: 2px; border-bottom-width: 2px; border-bottom-left-radius: 5px; }
.frame .m.br { right: 10px; bottom: 10px; border-right-width: 2px; border-bottom-width: 2px; border-bottom-right-radius: 5px; }
.fmt-tag { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); font-size: 11px; font-weight: 600; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 99px; background: rgba(0, 0, 0, .35); backdrop-filter: blur(4px); }
.cap { margin: 0; text-align: center; font-weight: 800; font-size: 21px; line-height: 1.2; letter-spacing: -.01em; text-wrap: balance;
  text-shadow: 0 2px 14px rgba(0, 0, 0, .55); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.frame.l .cap { font-size: 18px; -webkit-line-clamp: 4; }
.cap.empty { font-weight: 600; font-size: 15px; opacity: .8; }
.sub { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: 82%; padding: 3px 10px; border-radius: 6px;
  background: rgba(0, 0, 0, .62); font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.fmts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 18px; }
.fmtbtn { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px; border-radius: var(--r-field);
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 500; font-size: 14px; transition: all .15s; }
.fmtbtn[aria-checked="true"] { border-color: var(--accent); background: var(--accent-wash); color: var(--accent); }
.fmtbtn .g { display: block; border: 2px solid currentColor; border-radius: 3px; }
.fmtbtn .g.p { width: 11px; height: 19px; } .fmtbtn .g.l { width: 19px; height: 11px; }

.counter { text-align: end; margin: 4px 2px 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 2px 16px 6px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chips .chip { scroll-snap-align: start; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; margin-bottom: 8px; cursor: pointer; font-weight: 500; }
#generate { margin-top: 6px; }

/* ---- Videos ---- */
.vgrid { display: grid; grid-auto-flow: dense; grid-template-columns: repeat(2, 1fr); gap: 14px 12px; align-items: start; }
.vcard { all: unset; display: block; cursor: pointer; border-radius: 14px; }
.vcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.vcard .meta { display: flex; align-items: center; justify-content: space-between; padding: 7px 3px 0; font-size: 12px; color: var(--muted); }
.vcard .thumb { transition: transform .18s var(--ease); }
.vcard:active .thumb { transform: scale(.98); }
.thumb.a169 { grid-column: auto; }
.vcard.wide { grid-column: 1 / -1; }
.empty { text-align: center; padding: 28px 12px 12px; }
.empty .ikat { width: 120px; height: 120px; border-radius: 28px; margin: 0 auto 18px; }
.empty h3 { margin-bottom: 6px; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.strip { display: flex; gap: 4px; justify-content: center; margin: 10px 0 0; }
.strip i { width: 14px; height: 20px; border-radius: 3px; background: rgba(255, 255, 255, .25); animation: tick 1.4s steps(1) infinite; }
.strip i:nth-child(2) { animation-delay: .23s; } .strip i:nth-child(3) { animation-delay: .46s; }
.strip i:nth-child(4) { animation-delay: .69s; } .strip i:nth-child(5) { animation-delay: .92s; } .strip i:nth-child(6) { animation-delay: 1.15s; }
@keyframes tick { 0% { background: rgba(255, 255, 255, .9); } 17% { background: rgba(255, 255, 255, .25); } }

.player { width: 100%; border-radius: 16px; overflow: hidden; background: #000; display: grid; place-items: center; }
.player.p { aspect-ratio: 9 / 16; max-height: 62vh; width: auto; margin: 0 auto; }
.player.l { aspect-ratio: 16 / 9; }
.player video { width: 100%; height: 100%; display: block; background: #000; }
.player.pending { color: #fff; text-align: center; padding: 20px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.sheet-actions .btn.danger { grid-column: 1 / -1; }
.sheet .prompt-text { margin: 14px 0 4px; font-weight: 500; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }

/* ---- Keys ---- */
.slot { margin-bottom: 14px; }
.slot .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.slot .head .ico { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-wash); color: var(--accent); flex: none; }
.slot .head h3 { flex: 1; }
.slot .provs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.slot .keyrow { display: flex; gap: 8px; }
.slot .saved { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--wash); }
.slot .saved .mono { letter-spacing: .08em; }
.note { display: flex; gap: 10px; align-items: flex-start; margin: 8px 2px 0; }
.note svg { margin-top: 2px; color: var(--muted); }

/* ---- Settings ---- */
.langgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 0 0 20px; }
.langgrid .chip { justify-content: space-between; padding: 13px 14px; border-radius: 14px; font-size: 15px; }
#adminBox, #deleteBtn { margin-top: 12px; }

/* ---- Tab bar ---- */
.tabbar { position: fixed; inset: auto 0 0 0; display: flex; justify-content: center; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabbar button { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 4px 10px;
  border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 500; cursor: pointer; position: relative; }
.tabbar button[aria-selected="true"] { color: var(--accent); }
.tabbar button[aria-selected="true"]::before { content: ""; position: absolute; top: -1px; width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }

/* ---- gates ---- */
.gate { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: grid; place-items: center; padding: 20px; overflow: auto; }
.gate-card { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; }
.gate-band { height: 120px; border-radius: 20px; margin-bottom: 6px; }
.gate-card p { line-height: 1.55; }

/* ---- watch page ---- */
#watch { margin: 0 -16px; }
.watch-stage { padding: 20px 16px; display: grid; place-items: center; min-height: 52vh; }
.watch-stage .player { box-shadow: 0 20px 50px -20px rgba(0, 0, 0, .7); }
.watch-body { padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.watch-body .btn { align-self: stretch; }

/* thumbs: poster fills the box; watch mode hides the app chrome */
.thumb > .ikat { position: absolute; inset: 0; }
body.watching .tabbar, body.watching .tab, body.watching .top { display: none; }
body.watching { padding-bottom: 0; }

/* ---- Close: red ✕ top-right of every screen + red Close button at the bottom centre ---- */
.top { padding-right: 62px; }
.xclose { position: fixed; top: calc(env(safe-area-inset-top) + 10px); right: 12px; z-index: 90; width: 38px; height: 38px; border-radius: 50%;
  border: 0; cursor: pointer; display: grid; place-items: center; background: var(--crit); color: #fff;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--crit) 45%, transparent); transition: transform .12s var(--ease), filter .12s; }
.xclose:hover { filter: brightness(1.08); } .xclose:active { transform: scale(.92); }
.xclose:focus-visible { outline: 3px solid color-mix(in srgb, var(--crit) 40%, transparent); outline-offset: 2px; }
.xclose:disabled, .js-close:disabled { opacity: .55; cursor: progress; }
.xclose .ic svg { width: 20px; height: 20px; stroke-width: 2.6; }
.closebar { display: flex; justify-content: center; margin: 30px 0 6px; }
.closebar .btn { min-width: 190px; padding: 12px 26px; }
.watch-body .closebar, .gate-card .closebar { margin-top: 10px; }

/* ---- Free mode: upload your own audio + thumbnail ---- */
.modeseg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: var(--r-field); background: var(--accent-wash); margin: 0 0 14px; }
.modeseg[hidden] { display: none; }
.modeseg button { border: 0; background: none; padding: 10px 8px; border-radius: calc(var(--r-field) - 3px); font: inherit; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.modeseg button[aria-checked="true"] { background: var(--card, #fff); color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.ai-only[hidden], #uploadBox[hidden] { display: none; }
.pickrow { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 12px 0; }
.pickrow .pick { cursor: pointer; flex: 0 0 auto; }
.pickname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frame.has-thumb { background-size: cover !important; background-position: center !important; }
.player.audio-player { position: relative; }
.player.audio-player img.cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.player.audio-player audio { position: absolute; left: 8px; right: 8px; bottom: 8px; width: calc(100% - 16px); }

.vitem.wide { grid-column: 1 / -1; }
.vshare { margin-top: 8px; }

.imgstrip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0; }
.imgstrip:empty { display: none; }
.imgchip { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: 0 0 auto; width: 64px; }
.imgchip-pic { width: 64px; height: 64px; border-radius: 10px; overflow: hidden; }
.imgchip-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.imgchip.saving .imgchip-pic { opacity: .45; }
.imgchip-del { width: 100%; height: 22px; padding: 0; border: 0; border-radius: 8px; background: color-mix(in srgb, var(--crit, #d03b3b) 14%, transparent); color: var(--crit, #d03b3b); display: grid; place-items: center; cursor: pointer; }
.imgchip-del:active { background: color-mix(in srgb, var(--crit, #d03b3b) 24%, transparent); }
.req { color: #d64545; margin: -4px 0 8px; }
.req[hidden] { display: none; }

.cambox { position: fixed; inset: 0; z-index: 1000; background: #000; display: flex; flex-direction: column; }
.cambox[hidden] { display: none; }
.camoverlay { position:absolute; inset:0; display:flex; padding:16px; pointer-events:none; } .camoverlay img { width:var(--cam-cover,35%); max-width:100%; max-height:80%; object-fit:contain; }
.camoverlay[data-pos="left-top"]{justify-content:flex-start;align-items:flex-start}.camoverlay[data-pos="center-top"]{justify-content:center;align-items:flex-start}.camoverlay[data-pos="right-top"]{justify-content:flex-end;align-items:flex-start}.camoverlay[data-pos="left-center"]{justify-content:flex-start;align-items:center}.camoverlay[data-pos="center"]{justify-content:center;align-items:center}.camoverlay[data-pos="right-center"]{justify-content:flex-end;align-items:center}.camoverlay[data-pos="left-bottom"]{justify-content:flex-start;align-items:flex-end}.camoverlay[data-pos="center-bottom"]{justify-content:center;align-items:flex-end}.camoverlay[data-pos="right-bottom"]{justify-content:flex-end;align-items:flex-end}
.cambox video { flex: 1 1 auto; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.camctl { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px)); background: #000; }
.camctl .btn { min-width: 84px; color: #fff; }
.shutter { width: 68px; height: 68px; border-radius: 50%; border: 4px solid #fff; background: rgba(255,255,255,.25); cursor: pointer; padding: 0; }
.shutter:active { background: #fff; }
.camcount { position: absolute; inset: 0 0 120px 0; display: flex; align-items: center; justify-content: center; font-size: 110px; font-weight: 800; color: #fff; text-shadow: 0 2px 16px rgba(0,0,0,.6); pointer-events: none; }

/* A tab that is switched off for users but still shown to admins */
.modeseg button[hidden] { display: none; }
.modeseg button.admin-only { opacity: .75; }
.modeseg button.admin-only::after { content: ' · admin'; font-size: 10px; font-weight: 500; opacity: .8; }

/* Admin-only details (Comment, URL, Category) above the pickers, in both Studio tabs */
.adminx { border: 1px dashed var(--line); border-radius: 16px; padding: 12px 12px 2px; margin: 0 0 14px; background: var(--wash); }
.adminx[hidden], #xCatWrap[hidden], #xSubWrap[hidden] { display: none; }
.adminx-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.adminx .field { margin-bottom: 10px; }
.adminx textarea.field { min-height: 56px; }
#watchSendFile[hidden] { display: none; }

/* Web Studio (normal web browser): no tabs, no Close buttons; step 1 = pictures only, step 2 = title, audio, make the video */
body.web-studio .tabbar, body.web-studio #langChip, body.web-studio .xclose, body.web-studio .closebar, body.web-studio #modeSeg { display: none !important; }
body.web-studio main { padding-bottom: 40px; }
body.web-studio.ws-step1 #promptLbl, body.web-studio.ws-step1 #prompt, body.web-studio.ws-step1 .counter, body.web-studio.ws-step1 #uploadBox, body.web-studio.ws-step1 #adminExtra { display: none !important; }
body.web-studio #webAddAudio { margin-top: 12px; }
.webbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.webbtns .btn { width: 100%; }
#webShare .watch-stage { margin-bottom: 14px; }
